Use Corrade's String(View) types where possible.

Utility::Directory, efsw, cpr, and json.hpp are the only obstacles to a
complete removal of std::string usages.
This commit is contained in:
Guillaume Jacquemin 2022-03-04 21:18:55 +01:00
parent 2648e1103e
commit 8791eb32ac
104 changed files with 1631 additions and 1290 deletions

View File

@ -18,53 +18,57 @@
#include <map> #include <map>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h> #include <Magnum/Types.h>
using namespace Corrade;
using namespace Containers::Literals;
using namespace Magnum; using namespace Magnum;
static const std::map<Int, const char*> accessories { static const std::map<Int, Containers::StringView> accessories {
// Primitives // Primitives
{1, "Cube (S)"}, {1, "Cube (S)"_s},
{2, "Pentagon (S)"}, {2, "Pentagon (S)"_s},
{3, "Hexagon (S)"}, {3, "Hexagon (S)"_s},
{4, "Cylinder (S)"}, {4, "Cylinder (S)"_s},
{5, "Sphere (S)"}, {5, "Sphere (S)"_s},
{6, "TriPyramid (S)"}, {6, "TriPyramid (S)"_s},
{7, "SquPyramid (S)"}, {7, "SquPyramid (S)"_s},
{8, "PenPyramid (S)"}, {8, "PenPyramid (S)"_s},
{9, "HexPyramid (S)"}, {9, "HexPyramid (S)"_s},
{10, "Cone (S)"}, {10, "Cone (S)"_s},
{11, "SquStick (S)"}, {11, "SquStick (S)"_s},
{12, "PenStick (S)"}, {12, "PenStick (S)"_s},
{13, "HexStick (S)"}, {13, "HexStick (S)"_s},
{14, "CycStick (S)"}, {14, "CycStick (S)"_s},
{15, "Capsule (S)"}, {15, "Capsule (S)"_s},
{16, "Decal Pad 01 (S)"}, {16, "Decal Pad 01 (S)"_s},
{17, "Decal Pad 02 (S)"}, {17, "Decal Pad 02 (S)"_s},
{18, "Decal Pad 03 (S)"}, {18, "Decal Pad 03 (S)"_s},
{19, "Decal Pad 04 (S)"}, {19, "Decal Pad 04 (S)"_s},
{20, "Decal Pad 05 (S)"}, {20, "Decal Pad 05 (S)"_s},
{51, "SquBevel (S)"}, {51, "SquBevel (S)"_s},
{52, "TriBevel (S)"}, {52, "TriBevel (S)"_s},
{53, "PenBevel (S)"}, {53, "PenBevel (S)"_s},
{54, "HexBevel (S)"}, {54, "HexBevel (S)"_s},
{55, "CycBevel (S)"}, {55, "CycBevel (S)"_s},
{56, "RecBevel (S)"}, {56, "RecBevel (S)"_s},
{57, "DaiBevel (S)"}, {57, "DaiBevel (S)"_s},
{58, "MonBevel (S)"}, {58, "MonBevel (S)"_s},
{59, "CofBevel (S)"}, {59, "CofBevel (S)"_s},
{60, "JevBevel (S)"}, {60, "JevBevel (S)"_s},
{61, "SquEmboss (S)"}, {61, "SquEmboss (S)"_s},
{62, "TriEmboss (S)"}, {62, "TriEmboss (S)"_s},
{63, "PenEmboss (S)"}, {63, "PenEmboss (S)"_s},
{64, "HexEmboss (S)"}, {64, "HexEmboss (S)"_s},
{65, "CycEmboss (S)"}, {65, "CycEmboss (S)"_s},
{66, "RecEmboss (S)"}, {66, "RecEmboss (S)"_s},
{67, "DaiEmboss (S)"}, {67, "DaiEmboss (S)"_s},
{68, "MonEmboss (S)"}, {68, "MonEmboss (S)"_s},
{69, "CofEmboss (S)"}, {69, "CofEmboss (S)"_s},
{70, "JevEmboss (S)"}, {70, "JevEmboss (S)"_s},
// Armours // Armours

View File

@ -18,34 +18,38 @@
#include <map> #include <map>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h> #include <Magnum/Types.h>
using namespace Corrade;
using namespace Containers::Literals;
using namespace Magnum; using namespace Magnum;
struct ArmourSet { struct ArmourSet {
const char* name; Containers::StringView name;
bool neck_compatible; bool neck_compatible;
}; };
static const std::map<Int, ArmourSet> armour_sets { static const std::map<Int, ArmourSet> armour_sets {
{-1, {"<unequipped>", true}}, {-1, {"<unequipped>"_s, true}},
{0, {"Vanguard", true}}, {0, {"Vanguard"_s, true}},
{1, {"Assault Mk.I", true}}, {1, {"Assault Mk.I"_s, true}},
{2, {"Assault Mk.II", false}}, {2, {"Assault Mk.II"_s, false}},
{3, {"Assault Mk.III", false}}, {3, {"Assault Mk.III"_s, false}},
{7, {"Titan 001", true}}, {7, {"Titan 001"_s, true}},
{8, {"Titan 002", false}}, {8, {"Titan 002"_s, false}},
{9, {"Titan 003", false}}, {9, {"Titan 003"_s, false}},
{13, {"Blitz X", true}}, {13, {"Blitz X"_s, true}},
{14, {"Blitz EX", false}}, {14, {"Blitz EX"_s, false}},
{15, {"Blitz EXS", false}}, {15, {"Blitz EXS"_s, false}},
{16, {"Kaiser S-R0", true}}, {16, {"Kaiser S-R0"_s, true}},
{17, {"Kaiser S-R1", false}}, {17, {"Kaiser S-R1"_s, false}},
{18, {"Kaiser S-R2", false}}, {18, {"Kaiser S-R2"_s, false}},
{19, {"Hammerfall MG-A", true}}, {19, {"Hammerfall MG-A"_s, true}},
{20, {"Hammerfall MG-S", false}}, {20, {"Hammerfall MG-S"_s, false}},
{21, {"Hammerfall MG-X", false}}, {21, {"Hammerfall MG-X"_s, false}},
{22, {"Panzer S-UC", true}}, {22, {"Panzer S-UC"_s, true}},
{23, {"Panzer L-UC", false}}, {23, {"Panzer L-UC"_s, false}},
{24, {"Panzer H-UC", false}}, {24, {"Panzer H-UC"_s, false}},
}; };

View File

@ -15,42 +15,42 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifdef c #ifdef c
c(Face, "enuArmorSlots::NewEnumerator0", "Face") c(Face, "enuArmorSlots::NewEnumerator0"_s, "Face"_s)
c(UpperHead, "enuArmorSlots::NewEnumerator1", "Upper head") c(UpperHead, "enuArmorSlots::NewEnumerator1"_s, "Upper head"_s)
c(LowerHead, "enuArmorSlots::NewEnumerator2", "Lower head") c(LowerHead, "enuArmorSlots::NewEnumerator2"_s, "Lower head"_s)
c(Neck, "enuArmorSlots::NewEnumerator3", "Neck") c(Neck, "enuArmorSlots::NewEnumerator3"_s, "Neck"_s)
c(UpperBody, "enuArmorSlots::NewEnumerator4", "Upper body") c(UpperBody, "enuArmorSlots::NewEnumerator4"_s, "Upper body"_s)
c(MiddleBody, "enuArmorSlots::NewEnumerator5", "Middle body") c(MiddleBody, "enuArmorSlots::NewEnumerator5"_s, "Middle body"_s)
c(LowerBody, "enuArmorSlots::NewEnumerator6", "Lower body") c(LowerBody, "enuArmorSlots::NewEnumerator6"_s, "Lower body"_s)
c(FrontWaist, "enuArmorSlots::NewEnumerator7", "Front waist") c(FrontWaist, "enuArmorSlots::NewEnumerator7"_s, "Front waist"_s)
c(LeftFrontSkirt, "enuArmorSlots::NewEnumerator8", "Left front skirt") c(LeftFrontSkirt, "enuArmorSlots::NewEnumerator8"_s, "Left front skirt"_s)
c(RightFrontSkirt, "enuArmorSlots::NewEnumerator9", "Right front skirt") c(RightFrontSkirt, "enuArmorSlots::NewEnumerator9"_s, "Right front skirt"_s)
c(LeftSideSkirt, "enuArmorSlots::NewEnumerator10", "Left side skirt") c(LeftSideSkirt, "enuArmorSlots::NewEnumerator10"_s, "Left side skirt"_s)
c(RightSideSkirt, "enuArmorSlots::NewEnumerator11", "Right side skirt") c(RightSideSkirt, "enuArmorSlots::NewEnumerator11"_s, "Right side skirt"_s)
c(LeftBackSkirt, "enuArmorSlots::NewEnumerator12", "Left back skirt") c(LeftBackSkirt, "enuArmorSlots::NewEnumerator12"_s, "Left back skirt"_s)
c(RightBackSkirt, "enuArmorSlots::NewEnumerator13", "Right back skirt") c(RightBackSkirt, "enuArmorSlots::NewEnumerator13"_s, "Right back skirt"_s)
c(BackWaist, "enuArmorSlots::NewEnumerator14", "Back waist") c(BackWaist, "enuArmorSlots::NewEnumerator14"_s, "Back waist"_s)
c(LeftShoulder, "enuArmorSlots::NewEnumerator15", "Left shoulder") c(LeftShoulder, "enuArmorSlots::NewEnumerator15"_s, "Left shoulder"_s)
c(RightShoulder, "enuArmorSlots::NewEnumerator16", "Right shoulder") c(RightShoulder, "enuArmorSlots::NewEnumerator16"_s, "Right shoulder"_s)
c(LeftUpperArm, "enuArmorSlots::NewEnumerator17", "Left upper arm") c(LeftUpperArm, "enuArmorSlots::NewEnumerator17"_s, "Left upper arm"_s)
c(RightUpperArm, "enuArmorSlots::NewEnumerator18", "Right upper arm") c(RightUpperArm, "enuArmorSlots::NewEnumerator18"_s, "Right upper arm"_s)
c(LeftElbow, "enuArmorSlots::NewEnumerator19", "Left elbow") c(LeftElbow, "enuArmorSlots::NewEnumerator19"_s, "Left elbow"_s)
c(RightElbow, "enuArmorSlots::NewEnumerator20", "Right elbow") c(RightElbow, "enuArmorSlots::NewEnumerator20"_s, "Right elbow"_s)
c(LeftLowerArm, "enuArmorSlots::NewEnumerator21", "Left lower arm") c(LeftLowerArm, "enuArmorSlots::NewEnumerator21"_s, "Left lower arm"_s)
c(RightLowerArm, "enuArmorSlots::NewEnumerator22", "Right lower arm") c(RightLowerArm, "enuArmorSlots::NewEnumerator22"_s, "Right lower arm"_s)
c(Backpack, "enuArmorSlots::NewEnumerator23", "Backpack") c(Backpack, "enuArmorSlots::NewEnumerator23"_s, "Backpack"_s)
c(LeftHand, "enuArmorSlots::NewEnumerator24", "Left hand") c(LeftHand, "enuArmorSlots::NewEnumerator24"_s, "Left hand"_s)
c(RightHand, "enuArmorSlots::NewEnumerator25", "Right hand") c(RightHand, "enuArmorSlots::NewEnumerator25"_s, "Right hand"_s)
c(LeftUpperLeg, "enuArmorSlots::NewEnumerator26", "Left upper leg") c(LeftUpperLeg, "enuArmorSlots::NewEnumerator26"_s, "Left upper leg"_s)
c(RightUpperLeg, "enuArmorSlots::NewEnumerator27", "Right upper leg") c(RightUpperLeg, "enuArmorSlots::NewEnumerator27"_s, "Right upper leg"_s)
c(LeftKnee, "enuArmorSlots::NewEnumerator28", "Left knee") c(LeftKnee, "enuArmorSlots::NewEnumerator28"_s, "Left knee"_s)
c(RightKnee, "enuArmorSlots::NewEnumerator29", "Right knee") c(RightKnee, "enuArmorSlots::NewEnumerator29"_s, "Right knee"_s)
c(LeftLowerLeg, "enuArmorSlots::NewEnumerator30", "Left lower leg") c(LeftLowerLeg, "enuArmorSlots::NewEnumerator30"_s, "Left lower leg"_s)
c(RightLowerLeg, "enuArmorSlots::NewEnumerator31", "Right lower leg") c(RightLowerLeg, "enuArmorSlots::NewEnumerator31"_s, "Right lower leg"_s)
c(LeftAnkle, "enuArmorSlots::NewEnumerator32", "Left ankle") c(LeftAnkle, "enuArmorSlots::NewEnumerator32"_s, "Left ankle"_s)
c(RightAnkle, "enuArmorSlots::NewEnumerator33", "Right ankle") c(RightAnkle, "enuArmorSlots::NewEnumerator33"_s, "Right ankle"_s)
c(LeftHeel, "enuArmorSlots::NewEnumerator34", "Left heel") c(LeftHeel, "enuArmorSlots::NewEnumerator34"_s, "Left heel"_s)
c(RightHeel, "enuArmorSlots::NewEnumerator35", "Right heel") c(RightHeel, "enuArmorSlots::NewEnumerator35"_s, "Right heel"_s)
c(LeftFoot, "enuArmorSlots::NewEnumerator36", "Left foot") c(LeftFoot, "enuArmorSlots::NewEnumerator36"_s, "Left foot"_s)
c(RightFoot, "enuArmorSlots::NewEnumerator37", "Right foot") c(RightFoot, "enuArmorSlots::NewEnumerator37"_s, "Right foot"_s)
#endif #endif

View File

@ -15,10 +15,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifdef c #ifdef c
c(Physical, "enuDamageProperty::NewEnumerator0") c(Physical, "enuDamageProperty::NewEnumerator0"_s)
c(Piercing, "enuDamageProperty::NewEnumerator1") c(Piercing, "enuDamageProperty::NewEnumerator1"_s)
c(Heat, "enuDamageProperty::NewEnumerator2") c(Heat, "enuDamageProperty::NewEnumerator2"_s)
c(Freeze, "enuDamageProperty::NewEnumerator3") c(Freeze, "enuDamageProperty::NewEnumerator3"_s)
c(Shock, "enuDamageProperty::NewEnumerator4") c(Shock, "enuDamageProperty::NewEnumerator4"_s)
c(Plasma, "enuDamageProperty::NewEnumerator5") c(Plasma, "enuDamageProperty::NewEnumerator5"_s)
#endif #endif

View File

@ -15,6 +15,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifdef c #ifdef c
c(Default, "enuWeaponEffectColorMode::NewEnumerator0") c(Default, "enuWeaponEffectColorMode::NewEnumerator0"_s)
c(Custom, "enuWeaponEffectColorMode::NewEnumerator1") c(Custom, "enuWeaponEffectColorMode::NewEnumerator1"_s)
#endif #endif

View File

@ -18,31 +18,39 @@
#include <map> #include <map>
static const std::map<Int, const char*> mission_id_map {{ #include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h>
using namespace Corrade;
using namespace Containers::Literals;
using namespace Magnum;
static const std::map<Int, Containers::StringView> mission_id_map {{
// Story missions // Story missions
{0x0064, "Mission 1 - Training"}, {0x0064, "Mission 1 - Training"_s},
{0x0065, "Mission 2 - Patrol Operation"}, {0x0065, "Mission 2 - Patrol Operation"_s},
{0x0066, "Mission 3 - Fusion Cells in the Snow"}, {0x0066, "Mission 3 - Fusion Cells in the Snow"_s},
{0x0067, "Mission 4 - Earning Changes"}, {0x0067, "Mission 4 - Earning Changes"_s},
{0x0068, "Mission 5 - Unexpected Coordination"}, {0x0068, "Mission 5 - Unexpected Coordination"_s},
{0x0069, "Mission 6 - Empowering Void"}, {0x0069, "Mission 6 - Empowering Void"_s},
{0x006A, "Mission 7 - Logisitics Obstacles"}, {0x006A, "Mission 7 - Logisitics Obstacles"_s},
{0x006B, "Mission 8 - Wrath of the Wastelands"}, {0x006B, "Mission 8 - Wrath of the Wastelands"_s},
{0x006C, "Mission 9 - Suspicious Originator"}, {0x006C, "Mission 9 - Suspicious Originator"_s},
{0x006D, "Mission 10 - Researchers Data Recovery"}, {0x006D, "Mission 10 - Researchers Data Recovery"_s},
{0x006E, "Mission 11 - Tempestuous Sector"}, {0x006E, "Mission 11 - Tempestuous Sector"_s},
{0x006F, "Mission 12 - Clashes of Metal"}, {0x006F, "Mission 12 - Clashes of Metal"_s},
{0x0070, "Mission 13 - The Sandstorm Glutton"}, {0x0070, "Mission 13 - The Sandstorm Glutton"_s},
{0x0071, "Mission 14 - An Icy Investigation"}, {0x0071, "Mission 14 - An Icy Investigation"_s},
// Hunting grounds // Hunting grounds
{0x00C8, "Hunt 1 - Desert Pathway Safety"}, {0x00C8, "Hunt 1 - Desert Pathway Safety"_s},
{0x00C9, "Hunt 2 - Snowfield Custodian"}, {0x00C9, "Hunt 2 - Snowfield Custodian"_s},
{0x00CA, "Hunt 3 - Abandoned Valley Raid"}, {0x00CA, "Hunt 3 - Abandoned Valley Raid"_s},
{0x00CB, "Hunt 4 - Depths of the Machineries"}, {0x00CB, "Hunt 4 - Depths of the Machineries"_s},
// Challenges // Challenges
{0x012C, "Challenge 1 - Redline Battlefront"}, {0x012C, "Challenge 1 - Redline Battlefront"_s},
{0x0140, "Challenge 2 - Void Convergence"}, {0x0140, "Challenge 2 - Void Convergence"_s},
{0x0190, "Challenge 3 - Gates of Ascension"} {0x0190, "Challenge 3 - Gates of Ascension"_s}
}}; }};

View File

@ -17,78 +17,85 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h>
using namespace Corrade;
using namespace Containers::Literals;
using namespace Magnum;
struct StoryProgressPoint { struct StoryProgressPoint {
Int id; Int id;
const char* chapter; Containers::StringView chapter;
const char* point; Containers::StringView point;
const char* after = nullptr; Containers::StringView after = nullptr;
}; };
static const Corrade::Containers::Array<StoryProgressPoint> story_progress static const Corrade::Containers::Array<StoryProgressPoint> story_progress
{ {
InPlaceInit, InPlaceInit,
{ {
{0x0000, "Chapter 1", "Chapter start (company isn't named yet)"}, {0x0000, "Chapter 1"_s, "Chapter start (company isn't named yet)"_s},
{0x0064, "Chapter 1", "First time in the hangar"}, {0x0064, "Chapter 1"_s, "First time in the hangar"_s},
{0x0065, "Chapter 1", "After 1st meeting with Quin in mission section"}, {0x0065, "Chapter 1"_s, "After 1st meeting with Quin in mission section"_s},
{0x0066, "Chapter 1", "Talking with Reina and Quin in hangar", "After training"}, {0x0066, "Chapter 1"_s, "Talking with Reina and Quin in hangar"_s, "After training"_s},
{0x0067, "Chapter 1", "Returned to hangar", "After training"}, {0x0067, "Chapter 1"_s, "Returned to hangar"_s, "After training"_s},
{0x0068, "Chapter 1", "Talked with Quin in development section", "After training"}, {0x0068, "Chapter 1"_s, "Talked with Quin in development section"_s, "After training"_s},
{0x0069, "Chapter 1", "Talked with Waltz in armour section", "After training"}, {0x0069, "Chapter 1"_s, "Talked with Waltz in armour section"_s, "After training"_s},
{0x00C8, "Chapter 1", "Talked with Kael in tuning section", "After training"}, {0x00C8, "Chapter 1"_s, "Talked with Kael in tuning section"_s, "After training"_s},
{0x00C9, "Chapter 1", "Got mission 2 briefing", "After training"}, {0x00C9, "Chapter 1"_s, "Got mission 2 briefing"_s, "After training"_s},
{0x012C, "Chapter 1", "Talking with Reina", "After mission 2"}, {0x012C, "Chapter 1"_s, "Talking with Reina"_s, "After mission 2"_s},
{0x012D, "Chapter 1", "Returned to hangar", "After mission 2"}, {0x012D, "Chapter 1"_s, "Returned to hangar"_s, "After mission 2"_s},
{0x012E, "Chapter 1", "Talked with Kael in tuning section", "After mission 2"}, {0x012E, "Chapter 1"_s, "Talked with Kael in tuning section"_s, "After mission 2"_s},
{0x012F, "Chapter 1", "Talked with Reina in hangar", "After mission 2"}, {0x012F, "Chapter 1"_s, "Talked with Reina in hangar"_s, "After mission 2"_s},
{0x0130, "Chapter 1", "Got mission 3 briefing", "After mission 2"}, {0x0130, "Chapter 1"_s, "Got mission 3 briefing"_s, "After mission 2"_s},
{0x0190, "Chapter 1", "Talking with Reina", "After mission 3"}, {0x0190, "Chapter 1"_s, "Talking with Reina"_s, "After mission 3"_s},
{0x0191, "Chapter 1", "Returned to hangar", "After mission 3"}, {0x0191, "Chapter 1"_s, "Returned to hangar"_s, "After mission 3"_s},
{0x0192, "Chapter 1", "Talked with Waltz in armour section", "After mission 3"}, {0x0192, "Chapter 1"_s, "Talked with Waltz in armour section"_s, "After mission 3"_s},
{0x0193, "Chapter 1", "Got mission 4 briefing", "After mission 3"}, {0x0193, "Chapter 1"_s, "Got mission 4 briefing"_s, "After mission 3"_s},
{0x01F4, "Chapter 1", "Talking with Reina", "After mission 4"}, {0x01F4, "Chapter 1"_s, "Talking with Reina"_s, "After mission 4"_s},
{0x01F5, "Chapter 1", "Returned to hangar", "After mission 4"}, {0x01F5, "Chapter 1"_s, "Returned to hangar"_s, "After mission 4"_s},
{0x01F6, "Chapter 1", "Talked with Waltz in armour section", "After mission 4"}, {0x01F6, "Chapter 1"_s, "Talked with Waltz in armour section"_s, "After mission 4"_s},
{0x01F7, "Chapter 1", "Talked with Reina in hangar", "After mission 4"}, {0x01F7, "Chapter 1"_s, "Talked with Reina in hangar"_s, "After mission 4"_s},
{0x01F8, "Chapter 1", "Got mission 5 and hunt 1 briefing", "After mission 4"}, {0x01F8, "Chapter 1"_s, "Got mission 5 and hunt 1 briefing"_s, "After mission 4"_s},
{0x0258, "Chapter 1", "Meeting Neon and Aine", "After mission 5"}, {0x0258, "Chapter 1"_s, "Meeting Neon and Aine"_s, "After mission 5"_s},
{0x0259, "Chapter 1", "Returned to hangar", "After mission 5"}, {0x0259, "Chapter 1"_s, "Returned to hangar"_s, "After mission 5"_s},
{0x025A, "Chapter 1", "Got mission 6 briefing", "After mission 5"}, {0x025A, "Chapter 1"_s, "Got mission 6 briefing"_s, "After mission 5"_s},
{0x02BC, "Chapter 1", "Talking with Reina", "After mission 6"}, {0x02BC, "Chapter 1"_s, "Talking with Reina"_s, "After mission 6"_s},
{0x02BD, "Chapter 1", "Returned to hangar", "After mission 6"}, {0x02BD, "Chapter 1"_s, "Returned to hangar"_s, "After mission 6"_s},
{0x02BE, "Chapter 1", "Got hunt 2 briefing", "After mission 6"}, {0x02BE, "Chapter 1"_s, "Got hunt 2 briefing"_s, "After mission 6"_s},
{0x02BF, "Chapter 1", "Met Ellenier", "After mission 6"}, {0x02BF, "Chapter 1"_s, "Met Ellenier"_s, "After mission 6"_s},
{0x02C0, "Chapter 1", "Got mission 7 briefing", "After mission 6"}, {0x02C0, "Chapter 1"_s, "Got mission 7 briefing"_s, "After mission 6"_s},
{0x0320, "Chapter 1", "Talking with Nier", "After mission 7"}, {0x0320, "Chapter 1"_s, "Talking with Nier"_s, "After mission 7"_s},
{0x0321, "Chapter 1", "Returned to hangar", "After mission 7"}, {0x0321, "Chapter 1"_s, "Returned to hangar"_s, "After mission 7"_s},
{0x0322, "Chapter 1", "Talked with Quin, Reina, and Nier in development section", "After mission 7"}, {0x0322, "Chapter 1"_s, "Talked with Quin, Reina, and Nier in development section"_s, "After mission 7"_s},
{0x0323, "Chapter 1", "Got mission 8 briefing", "After mission 7"}, {0x0323, "Chapter 1"_s, "Got mission 8 briefing"_s, "After mission 7"_s},
{0x0384, "Chapter 1", "Talking with crew in hangar", "After mission 8"}, {0x0384, "Chapter 1"_s, "Talking with crew in hangar"_s, "After mission 8"_s},
{0x0385, "Chapter 1", "Returned to hangar", "After mission 8"}, {0x0385, "Chapter 1"_s, "Returned to hangar"_s, "After mission 8"_s},
{0x0386, "Chapter 1", "Got hunt 3 briefing", "After mission 8"}, {0x0386, "Chapter 1"_s, "Got hunt 3 briefing"_s, "After mission 8"_s},
{0x0387, "Chapter 1", "Talked with Reina, Nier, and Quin in development section", "After mission 8"}, {0x0387, "Chapter 1"_s, "Talked with Reina, Nier, and Quin in development section"_s, "After mission 8"_s},
{0x0388, "Chapter 2", "Chapter start"}, {0x0388, "Chapter 2"_s, "Chapter start"_s},
{0x0389, "Chapter 2", "Got mission 9 briefing"}, {0x0389, "Chapter 2"_s, "Got mission 9 briefing"_s},
{0x03E8, "Chapter 2", "Talking with Reina in hangar", "After mission 9"}, {0x03E8, "Chapter 2"_s, "Talking with Reina in hangar"_s, "After mission 9"_s},
{0x03E9, "Chapter 2", "Returned to hangar", "After mission 9"}, {0x03E9, "Chapter 2"_s, "Returned to hangar"_s, "After mission 9"_s},
{0x03EA, "Chapter 2", "Talked with crew in armour section", "After mission 9"}, {0x03EA, "Chapter 2"_s, "Talked with crew in armour section"_s, "After mission 9"_s},
{0x03EB, "Chapter 2", "Got mission 10 briefing", "After mission 9"}, {0x03EB, "Chapter 2"_s, "Got mission 10 briefing"_s, "After mission 9"_s},
{0x044C, "Chapter 2", "Talking with Reina in hangar", "After mission 10"}, {0x044C, "Chapter 2"_s, "Talking with Reina in hangar"_s, "After mission 10"_s},
{0x044D, "Chapter 2", "Returned to hangar", "After mission 10"}, {0x044D, "Chapter 2"_s, "Returned to hangar"_s, "After mission 10"_s},
{0x044E, "Chapter 2", "Got mission 11 briefing", "After mission 10"}, {0x044E, "Chapter 2"_s, "Got mission 11 briefing"_s, "After mission 10"_s},
{0x04B0, "Chapter 2", "Talking with Reina and Nier in hangar", "After mission 11"}, {0x04B0, "Chapter 2"_s, "Talking with Reina and Nier in hangar"_s, "After mission 11"_s},
{0x04B1, "Chapter 2", "Returned to hangar", "After mission 11"}, {0x04B1, "Chapter 2"_s, "Returned to hangar"_s, "After mission 11"_s},
{0x04B2, "Chapter 2", "Got mission 12 briefing", "After mission 11"}, {0x04B2, "Chapter 2"_s, "Got mission 12 briefing"_s, "After mission 11"_s},
{0x0514, "Chapter 2", "Talking with Reina and Waltz in hangar", "After mission 12"}, {0x0514, "Chapter 2"_s, "Talking with Reina and Waltz in hangar"_s, "After mission 12"_s},
{0x0515, "Chapter 2", "Returned to hangar", "After mission 12"}, {0x0515, "Chapter 2"_s, "Returned to hangar"_s, "After mission 12"_s},
{0x0516, "Chapter 2", "Got hunt 4 and mission 13 briefing", "After mission 12"}, {0x0516, "Chapter 2"_s, "Got hunt 4 and mission 13 briefing"_s, "After mission 12"_s},
{0x0578, "Chapter 2", "Talking with Reina in hangar", "After mission 13"}, {0x0578, "Chapter 2"_s, "Talking with Reina in hangar"_s, "After mission 13"_s},
{0x0579, "Chapter 2", "Returned to hangar", "After mission 13"}, {0x0579, "Chapter 2"_s, "Returned to hangar"_s, "After mission 13"_s},
{0x057A, "Chapter 2", "Talked with Reina in development section", "After mission 13"}, {0x057A, "Chapter 2"_s, "Talked with Reina in development section"_s, "After mission 13"_s},
{0x057B, "Chapter 2", "Got briefing for challenges 1, 2, and 3", "After mission 13"}, {0x057B, "Chapter 2"_s, "Got briefing for challenges 1, 2, and 3"_s, "After mission 13"_s},
{0x057C, "Chapter 2", "Talked with Reina about device", "After mission 13"}, {0x057C, "Chapter 2"_s, "Talked with Reina about device"_s, "After mission 13"_s},
{0x057D, "Chapter 2", "Got mission 14 briefing", "After mission 13"}, {0x057D, "Chapter 2"_s, "Got mission 14 briefing"_s, "After mission 13"_s},
} }
}; };

View File

@ -18,175 +18,179 @@
#include <map> #include <map>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Magnum.h> #include <Magnum/Magnum.h>
using namespace Corrade;
using namespace Containers::Literals;
using namespace Magnum; using namespace Magnum;
extern const std::map<Int, const char*> style_names extern const std::map<Int, Containers::StringView> style_names
#ifdef STYLENAMES_DEFINITION #ifdef STYLENAMES_DEFINITION
{ {
{0, "Custom Style 1"}, {0, "Custom Style 1"_s},
{1, "Custom Style 2"}, {1, "Custom Style 2"_s},
{2, "Custom Style 3"}, {2, "Custom Style 3"_s},
{3, "Custom Style 4"}, {3, "Custom Style 4"_s},
{4, "Custom Style 5"}, {4, "Custom Style 5"_s},
{5, "Custom Style 6"}, {5, "Custom Style 6"_s},
{6, "Custom Style 7"}, {6, "Custom Style 7"_s},
{7, "Custom Style 8"}, {7, "Custom Style 8"_s},
{8, "Custom Style 9"}, {8, "Custom Style 9"_s},
{9, "Custom Style 10"}, {9, "Custom Style 10"_s},
{10, "Custom Style 11"}, {10, "Custom Style 11"_s},
{11, "Custom Style 12"}, {11, "Custom Style 12"_s},
{12, "Custom Style 13"}, {12, "Custom Style 13"_s},
{13, "Custom Style 14"}, {13, "Custom Style 14"_s},
{14, "Custom Style 15"}, {14, "Custom Style 15"_s},
{15, "Custom Style 16"}, {15, "Custom Style 16"_s},
{50, "Global Style 1"}, {50, "Global Style 1"_s},
{51, "Global Style 2"}, {51, "Global Style 2"_s},
{52, "Global Style 3"}, {52, "Global Style 3"_s},
{53, "Global Style 4"}, {53, "Global Style 4"_s},
{54, "Global Style 5"}, {54, "Global Style 5"_s},
{55, "Global Style 6"}, {55, "Global Style 6"_s},
{56, "Global Style 7"}, {56, "Global Style 7"_s},
{57, "Global Style 8"}, {57, "Global Style 8"_s},
{58, "Global Style 9"}, {58, "Global Style 9"_s},
{59, "Global Style 10"}, {59, "Global Style 10"_s},
{60, "Global Style 11"}, {60, "Global Style 11"_s},
{61, "Global Style 12"}, {61, "Global Style 12"_s},
{62, "Global Style 13"}, {62, "Global Style 13"_s},
{63, "Global Style 14"}, {63, "Global Style 14"_s},
{64, "Global Style 15"}, {64, "Global Style 15"_s},
{65, "Global Style 16"}, {65, "Global Style 16"_s},
{100, "Iron"}, {100, "Iron"_s},
{101, "Silver"}, {101, "Silver"_s},
{102, "Gold"}, {102, "Gold"_s},
{103, "Bronze"}, {103, "Bronze"_s},
{104, "Copper"}, {104, "Copper"_s},
{105, "Nickel"}, {105, "Nickel"_s},
{106, "Cobalt"}, {106, "Cobalt"_s},
{107, "Aluminium"}, {107, "Aluminium"_s},
{108, "Titanium"}, {108, "Titanium"_s},
{109, "Platinum"}, {109, "Platinum"_s},
{110, "Gun Metal"}, {110, "Gun Metal"_s},
{111, "White"}, {111, "White"_s},
{112, "White Metal"}, {112, "White Metal"_s},
{113, "White Gloss"}, {113, "White Gloss"_s},
{114, "Grey"}, {114, "Grey"_s},
{115, "Grey Metal"}, {115, "Grey Metal"_s},
{116, "Grey Gloss"}, {116, "Grey Gloss"_s},
{117, "Dark Grey"}, {117, "Dark Grey"_s},
{118, "Dark Grey Metal"}, {118, "Dark Grey Metal"_s},
{119, "Dark Grey Gloss"}, {119, "Dark Grey Gloss"_s},
{120, "Black"}, {120, "Black"_s},
{121, "Black Metal"}, {121, "Black Metal"_s},
{122, "Black Gloss"}, {122, "Black Gloss"_s},
{123, "Red"}, {123, "Red"_s},
{124, "Red Metal"}, {124, "Red Metal"_s},
{125, "Red Gloss"}, {125, "Red Gloss"_s},
{126, "Dark Red"}, {126, "Dark Red"_s},
{127, "Dark Red Metal"}, {127, "Dark Red Metal"_s},
{128, "Dark Red Gloss"}, {128, "Dark Red Gloss"_s},
{129, "Orange"}, {129, "Orange"_s},
{130, "Orange Metal"}, {130, "Orange Metal"_s},
{131, "Orange Gloss"}, {131, "Orange Gloss"_s},
{132, "Dark Orange"}, {132, "Dark Orange"_s},
{133, "Dark Orange Metal"}, {133, "Dark Orange Metal"_s},
{134, "Dark Orange Gloss"}, {134, "Dark Orange Gloss"_s},
{135, "Yellow"}, {135, "Yellow"_s},
{136, "Yellow Metal"}, {136, "Yellow Metal"_s},
{137, "Yellow Gloss"}, {137, "Yellow Gloss"_s},
{138, "Brown"}, {138, "Brown"_s},
{139, "Brown Metal"}, {139, "Brown Metal"_s},
{140, "Brown Gloss"}, {140, "Brown Gloss"_s},
{141, "Dark Brown"}, {141, "Dark Brown"_s},
{142, "Dark Brown Metal"}, {142, "Dark Brown Metal"_s},
{143, "Dark Brown Gloss"}, {143, "Dark Brown Gloss"_s},
{144, "Leafgreen"}, {144, "Leafgreen"_s},
{145, "Leafgreen Metal"}, {145, "Leafgreen Metal"_s},
{146, "Leafgreen Gloss"}, {146, "Leafgreen Gloss"_s},
{147, "Military Green"}, {147, "Military Green"_s},
{148, "Military Green Metal"}, {148, "Military Green Metal"_s},
{149, "Military Green Gloss"}, {149, "Military Green Gloss"_s},
{150, "Green"}, {150, "Green"_s},
{151, "Green Metal"}, {151, "Green Metal"_s},
{152, "Green Gloss"}, {152, "Green Gloss"_s},
{153, "Dark Green"}, {153, "Dark Green"_s},
{154, "Dark Green Metal"}, {154, "Dark Green Metal"_s},
{155, "Dark Green Gloss"}, {155, "Dark Green Gloss"_s},
{156, "Teal"}, {156, "Teal"_s},
{157, "Teal Metal"}, {157, "Teal Metal"_s},
{158, "Teal Gloss"}, {158, "Teal Gloss"_s},
{159, "Cyan"}, {159, "Cyan"_s},
{160, "Cyan Metal"}, {160, "Cyan Metal"_s},
{161, "Cyan Gloss"}, {161, "Cyan Gloss"_s},
{162, "Blue"}, {162, "Blue"_s},
{163, "Blue Metal"}, {163, "Blue Metal"_s},
{164, "Blue Gloss"}, {164, "Blue Gloss"_s},
{165, "Blue Sky"}, {165, "Blue Sky"_s},
{166, "Blue Sky Metal"}, {166, "Blue Sky Metal"_s},
{167, "Blue Sky Gloss"}, {167, "Blue Sky Gloss"_s},
{168, "Dark Blue"}, {168, "Dark Blue"_s},
{169, "Dark Blue Metal"}, {169, "Dark Blue Metal"_s},
{170, "Dark Blue Gloss"}, {170, "Dark Blue Gloss"_s},
{171, "Purple"}, {171, "Purple"_s},
{172, "Purple Metal"}, {172, "Purple Metal"_s},
{173, "Purple Gloss"}, {173, "Purple Gloss"_s},
{174, "Dark Purple"}, {174, "Dark Purple"_s},
{175, "Dark Purple Metal"}, {175, "Dark Purple Metal"_s},
{176, "Dark Purple Gloss"}, {176, "Dark Purple Gloss"_s},
{177, "Pink"}, {177, "Pink"_s},
{178, "Pink Metal"}, {178, "Pink Metal"_s},
{179, "Pink Gloss"}, {179, "Pink Gloss"_s},
{180, "Rosy Brown"}, {180, "Rosy Brown"_s},
{181, "Rosy Brown Metal"}, {181, "Rosy Brown Metal"_s},
{182, "Rosy Brown Gloss"}, {182, "Rosy Brown Gloss"_s},
{183, "Ivory"}, {183, "Ivory"_s},
{184, "Ivory Metal"}, {184, "Ivory Metal"_s},
{185, "Ivory Gloss"}, {185, "Ivory Gloss"_s},
{186, "Slate Brown"}, {186, "Slate Brown"_s},
{187, "Slate Brown Metal"}, {187, "Slate Brown Metal"_s},
{188, "Slate Brown Gloss"}, {188, "Slate Brown Gloss"_s},
{189, "Slate Green"}, {189, "Slate Green"_s},
{190, "Slate Green Metal"}, {190, "Slate Green Metal"_s},
{191, "Slate Green Gloss"}, {191, "Slate Green Gloss"_s},
{192, "Slate Blue"}, {192, "Slate Blue"_s},
{193, "Slate Blue Metal"}, {193, "Slate Blue Metal"_s},
{194, "Slate Blue Gloss"}, {194, "Slate Blue Gloss"_s},
{195, "Slate Purple"}, {195, "Slate Purple"_s},
{196, "Slate Purple Metal"}, {196, "Slate Purple Metal"_s},
{197, "Slate Purple Gloss"}, {197, "Slate Purple Gloss"_s},
{198, "White Glow"}, {198, "White Glow"_s},
{199, "White Radiance"}, {199, "White Radiance"_s},
{200, "Red Glow"}, {200, "Red Glow"_s},
{201, "Red Radiance"}, {201, "Red Radiance"_s},
{202, "Orange Glow"}, {202, "Orange Glow"_s},
{203, "Orange Radiance"}, {203, "Orange Radiance"_s},
{204, "Yellow Glow"}, {204, "Yellow Glow"_s},
{205, "Yellow Radiance"}, {205, "Yellow Radiance"_s},
{206, "Leafgreen Glow"}, {206, "Leafgreen Glow"_s},
{207, "Leafgreen Radiance"}, {207, "Leafgreen Radiance"_s},
{208, "Green Glow"}, {208, "Green Glow"_s},
{209, "Green Radiance"}, {209, "Green Radiance"_s},
{210, "Teal Glow"}, {210, "Teal Glow"_s},
{211, "Teal Radiance"}, {211, "Teal Radiance"_s},
{212, "Cyan Glow"}, {212, "Cyan Glow"_s},
{213, "Cyan Radiance"}, {213, "Cyan Radiance"_s},
{214, "Blue Glow"}, {214, "Blue Glow"_s},
{215, "Blue Radiance"}, {215, "Blue Radiance"_s},
{216, "Purple Glow"}, {216, "Purple Glow"_s},
{217, "Purple Radiance"}, {217, "Purple Radiance"_s},
{218, "Pink Glow"}, {218, "Pink Glow"_s},
{219, "Pink Radiance"}, {219, "Pink Radiance"_s},
{220, "Grey Camo"}, {220, "Grey Camo"_s},
{221, "Dark Grey Camo"}, {221, "Dark Grey Camo"_s},
{222, "Green Camo"}, {222, "Green Camo"_s},
{223, "Dark Green Camo"}, {223, "Dark Green Camo"_s},
{224, "Brown Camo"}, {224, "Brown Camo"_s},
{225, "Dark Brown Camo"}, {225, "Dark Brown Camo"_s},
{226, "Blue Camo"}, {226, "Blue Camo"_s},
{227, "Dark Blue Camo"}, {227, "Dark Blue Camo"_s},
} }
#endif #endif
; ;

View File

@ -15,10 +15,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifdef c #ifdef c
c(Melee, "enuWeaponTypes::NewEnumerator0", "Melee weapon") c(Melee, "enuWeaponTypes::NewEnumerator0"_s, "Melee weapon"_s)
c(BulletShooter, "enuWeaponTypes::NewEnumerator1", "Bullet shooter") c(BulletShooter, "enuWeaponTypes::NewEnumerator1"_s, "Bullet shooter"_s)
c(EnergyShooter, "enuWeaponTypes::NewEnumerator2", "Energy shooter") c(EnergyShooter, "enuWeaponTypes::NewEnumerator2"_s, "Energy shooter"_s)
c(BulletLauncher, "enuWeaponTypes::NewEnumerator3", "Bullet launcher") c(BulletLauncher, "enuWeaponTypes::NewEnumerator3"_s, "Bullet launcher"_s)
c(EnergyLauncher, "enuWeaponTypes::NewEnumerator4", "Energy launcher") c(EnergyLauncher, "enuWeaponTypes::NewEnumerator4"_s, "Energy launcher"_s)
c(Shield, "enuWeaponTypes::NewEnumerator5", "Shield") c(Shield, "enuWeaponTypes::NewEnumerator5"_s, "Shield"_s)
#endif #endif

View File

@ -16,8 +16,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>

View File

@ -16,16 +16,17 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string> #include <Corrade/Containers/String.h>
#include <Magnum/Magnum.h> #include <Magnum/Magnum.h>
#include <Magnum/Math/Color.h> #include <Magnum/Math/Color.h>
#include <Magnum/Math/Vector2.h> #include <Magnum/Math/Vector2.h>
using namespace Corrade;
using namespace Magnum; using namespace Magnum;
struct CustomStyle { struct CustomStyle {
std::string name; Containers::String name;
Color4 colour{0.0f}; Color4 colour{0.0f};
Float metallic = 0.5f; Float metallic = 0.5f;
Float gloss = 0.5f; Float gloss = 0.5f;

View File

@ -16,8 +16,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <Magnum/Magnum.h> #include <Magnum/Magnum.h>
#include <Magnum/Math/Color.h> #include <Magnum/Math/Color.h>
#include <Magnum/Math/Vector2.h> #include <Magnum/Math/Vector2.h>

File diff suppressed because it is too large Load Diff

View File

@ -16,11 +16,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <Corrade/Containers/Optional.h> #include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Magnum.h> #include <Magnum/Magnum.h>
#include <Magnum/Math/Color.h> #include <Magnum/Math/Color.h>
@ -56,16 +56,16 @@ class Mass {
Mass(Mass&&) = default; Mass(Mass&&) = default;
Mass& operator=(Mass&&) = default; Mass& operator=(Mass&&) = default;
auto lastError() -> std::string const&; auto lastError() -> Containers::StringView;
static auto getNameFromFile(const std::string& path) -> Containers::Optional<std::string>; static auto getNameFromFile(Containers::StringView path) -> Containers::Optional<Containers::String>;
void refreshValues(); void refreshValues();
auto filename() -> std::string const&; auto filename() -> Containers::StringView;
auto name() -> Containers::Optional<std::string> const&; auto name() -> Containers::StringView;
auto setName(std::string new_name) -> bool; auto setName(Containers::StringView new_name) -> bool;
auto state() -> State; auto state() -> State;
@ -135,8 +135,8 @@ class Mass {
auto architecture() -> Int&; auto architecture() -> Int&;
auto techs() -> Containers::ArrayView<Int>; auto techs() -> Containers::ArrayView<Int>;
auto account() -> std::string const&; auto account() -> Containers::StringView;
auto updateAccount(const std::string& new_account) -> bool; auto updateAccount(Containers::StringView new_account) -> bool;
private: private:
void getCustomStyles(Containers::ArrayView<CustomStyle> styles, ArrayProperty* style_array); void getCustomStyles(Containers::ArrayView<CustomStyle> styles, ArrayProperty* style_array);
@ -148,37 +148,33 @@ class Mass {
void getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array); void getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array);
void writeAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accs_array); void writeAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accs_array);
void getWeaponType(const char* prop_name, Containers::ArrayView<Weapon> weapon_array); void getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array);
auto writeWeaponType(const char* prop_name, Containers::ArrayView<Weapon> weapon_array) -> bool; auto writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) -> bool;
void getTuningCategory(const char* big_node_prop_name, Int& big_node_id, void getTuningCategory(Containers::StringView big_node_prop_name, Int& big_node_id,
const char* small_nodes_prop_name, Containers::ArrayView<Int> small_nodes_ids); Containers::StringView small_nodes_prop_name, Containers::ArrayView<Int> small_nodes_ids);
Containers::Optional<UESaveFile> _mass; Containers::Optional<UESaveFile> _mass;
std::string _lastError; Containers::String _lastError;
std::string _folder; Containers::String _folder;
std::string _filename; Containers::String _filename;
State _state = State::Empty; State _state = State::Empty;
bool _dirty = false; bool _dirty = false;
Containers::Optional<std::string> _name = Containers::NullOpt; Containers::Optional<Containers::String> _name = Containers::NullOpt;
struct { struct {
Joints joints{}; Joints joints{};
Containers::StaticArray<4, Int> styles{ValueInit}; Containers::StaticArray<4, Int> styles{ValueInit};
Color4 eyeFlare{0.0f}; Color4 eyeFlare{0.0f};
Containers::StaticArray<16, CustomStyle> customStyles; Containers::StaticArray<16, CustomStyle> customStyles;
} _frame; } _frame;
struct { struct {
Containers::StaticArray<38, ArmourPart> parts; Containers::StaticArray<38, ArmourPart> parts;
Containers::StaticArray<16, CustomStyle> customStyles; Containers::StaticArray<16, CustomStyle> customStyles;
} _armour; } _armour;
@ -204,5 +200,5 @@ class Mass {
Containers::StaticArray<7, Int> techIds; Containers::StaticArray<7, Int> techIds;
} _tuning; } _tuning;
std::string _account; Containers::String _account;
}; };

View File

@ -16,10 +16,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/String.h>
#include <Magnum/Magnum.h> #include <Magnum/Magnum.h>
#include <Magnum/Math/Color.h> #include <Magnum/Math/Color.h>
@ -62,7 +61,7 @@ struct Weapon {
Weapon(Weapon&& other) = default; Weapon(Weapon&& other) = default;
Weapon& operator=(Weapon&& other) = default; Weapon& operator=(Weapon&& other) = default;
std::string name; Containers::String name;
WeaponType type = WeaponType::Melee; WeaponType type = WeaponType::Melee;
Containers::Array<WeaponPart> parts; Containers::Array<WeaponPart> parts;
Containers::StaticArray<16, CustomStyle> customStyles{ValueInit}; Containers::StaticArray<16, CustomStyle> customStyles{ValueInit};

View File

@ -19,22 +19,23 @@
#include <Corrade/Utility/Directory.h> #include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
#include <Corrade/Containers/StringStl.h>
#include "MassManager.h" #include "MassManager.h"
static const std::string empty_string = ""; using namespace Containers::Literals;
MassManager::MassManager(const std::string& save_path, const std::string& steam_id, bool demo, const std::string& staging_dir): MassManager::MassManager(Containers::StringView save_path, Containers::StringView account, bool demo, Containers::StringView staging_dir):
_saveDirectory{save_path}, _saveDirectory{save_path},
_steamId{steam_id}, _account{account},
_demo{demo}, _demo{demo},
_stagingAreaDirectory{staging_dir} _stagingAreaDirectory{staging_dir}
{ {
Containers::arrayReserve(_hangars, 32); Containers::arrayReserve(_hangars, 32);
std::string mass_filename = ""; Containers::String mass_filename = "";
for(int i = 0; i < 32; i++) { for(int i = 0; i < 32; i++) {
mass_filename = Utility::Directory::join(_saveDirectory, Utility::formatString("{}Unit{:.2d}{}.sav", demo ? "Demo" : "", i, _steamId)); mass_filename = Utility::Directory::join(_saveDirectory, Utility::formatString("{}Unit{:.2d}{}.sav", demo ? "Demo"_s : ""_s, i, _account));
Containers::arrayAppend(_hangars, Mass{mass_filename}); Containers::arrayAppend(_hangars, Mass{mass_filename});
} }
@ -45,7 +46,7 @@ MassManager::MassManager(const std::string& save_path, const std::string& steam_
refreshStagedMasses(); refreshStagedMasses();
} }
auto MassManager::lastError() -> std::string const& { auto MassManager::lastError() -> Containers::StringView {
return _lastError; return _lastError;
} }
@ -58,43 +59,43 @@ void MassManager::refreshHangar(Int hangar) {
return; return;
} }
std::string mass_filename = Containers::String mass_filename =
Utility::Directory::join(_saveDirectory, Utility::formatString("{}Unit{:.2d}{}.sav", _demo ? "Demo" : "", hangar, _steamId)); Utility::Directory::join(_saveDirectory, Utility::formatString("{}Unit{:.2d}{}.sav", _demo ? "Demo" : "", hangar, _account));
_hangars[hangar] = Mass{mass_filename}; _hangars[hangar] = Mass{mass_filename};
} }
auto MassManager::importMass(const std::string& staged_fn, Int hangar) -> bool { auto MassManager::importMass(Containers::StringView staged_fn, Int hangar) -> bool {
if(hangar < 0 || hangar >= 32) { if(hangar < 0 || hangar >= 32) {
_lastError = "Hangar out of range in MassManager::importMass()"; _lastError = "Hangar out of range in MassManager::importMass()"_s;
return false; return false;
} }
auto it = _stagedMasses.find(staged_fn); auto it = _stagedMasses.find(staged_fn);
if(it == _stagedMasses.end()) { if(it == _stagedMasses.end()) {
_lastError = "Couldn't find " + staged_fn + " in the staged M.A.S.S.es."; _lastError = "Couldn't find "_s + staged_fn + " in the staged M.A.S.S.es."_s;
return false; return false;
} }
std::string source = Utility::Directory::join(_stagingAreaDirectory, staged_fn); Containers::String source = Utility::Directory::join(_stagingAreaDirectory, staged_fn);
Utility::Directory::copy(source, source + ".tmp"); Utility::Directory::copy(source, source + ".tmp"_s);
{ {
Mass mass{source + ".tmp"}; Mass mass{source + ".tmp"_s};
if(!mass.updateAccount(_steamId)) { if(!mass.updateAccount(_account)) {
_lastError = mass.lastError(); _lastError = mass.lastError();
Utility::Directory::rm(source + ".tmp"); Utility::Directory::rm(source + ".tmp"_s);
return false; return false;
} }
} }
std::string dest = Utility::Directory::join(_saveDirectory, _hangars[hangar].filename()); Containers::String dest = Utility::Directory::join(_saveDirectory, _hangars[hangar].filename());
if(Utility::Directory::exists(dest)) { if(Utility::Directory::exists(dest)) {
Utility::Directory::rm(dest); Utility::Directory::rm(dest);
} }
if(!Utility::Directory::move(source + ".tmp", dest)) { if(!Utility::Directory::move(source + ".tmp"_s, dest)) {
_lastError = Utility::formatString("Couldn't move {} to hangar {:.2d}", staged_fn, hangar + 1); _lastError = Utility::formatString("Couldn't move {} to hangar {:.2d}", staged_fn, hangar + 1);
return false; return false;
} }
@ -104,7 +105,7 @@ auto MassManager::importMass(const std::string& staged_fn, Int hangar) -> bool {
auto MassManager::exportMass(Int hangar) -> bool { auto MassManager::exportMass(Int hangar) -> bool {
if(hangar < 0 || hangar >= 32) { if(hangar < 0 || hangar >= 32) {
_lastError = "Hangar out of range in MassManager::exportMass()"; _lastError = "Hangar out of range in MassManager::exportMass()"_s;
return false; return false;
} }
@ -113,9 +114,9 @@ auto MassManager::exportMass(Int hangar) -> bool {
return false; return false;
} }
std::string source = Utility::Directory::join(_saveDirectory, _hangars[hangar].filename()); Containers::String source = Utility::Directory::join(_saveDirectory, _hangars[hangar].filename());
std::string dest = Utility::Directory::join(_stagingAreaDirectory, Containers::String dest = Utility::Directory::join(_stagingAreaDirectory,
Utility::formatString("{}_{}.sav", *_hangars[hangar].name(), _steamId)); Utility::formatString("{}_{}.sav", _hangars[hangar].name(), _account));
if(!Utility::Directory::copy(source, dest)) { if(!Utility::Directory::copy(source, dest)) {
_lastError = Utility::formatString("Couldn't export data from hangar {:.2d} to {}", hangar, dest); _lastError = Utility::formatString("Couldn't export data from hangar {:.2d} to {}", hangar, dest);
@ -127,17 +128,17 @@ auto MassManager::exportMass(Int hangar) -> bool {
auto MassManager::moveMass(Int source, Int destination) -> bool { auto MassManager::moveMass(Int source, Int destination) -> bool {
if(source < 0 || source >= 32) { if(source < 0 || source >= 32) {
_lastError = "Source hangar out of range."; _lastError = "Source hangar out of range."_s;
return false; return false;
} }
if(destination < 0 || destination >= 32) { if(destination < 0 || destination >= 32) {
_lastError = "Destination hangar out of range."; _lastError = "Destination hangar out of range."_s;
return false; return false;
} }
std::string source_file = Utility::Directory::join(_saveDirectory, _hangars[source].filename()); Containers::String source_file = Utility::Directory::join(_saveDirectory, _hangars[source].filename());
std::string dest_file = Utility::Directory::join(_saveDirectory, _hangars[destination].filename()); Containers::String dest_file = Utility::Directory::join(_saveDirectory, _hangars[destination].filename());
Mass::State dest_state = _hangars[destination].state(); Mass::State dest_state = _hangars[destination].state();
switch(dest_state) { switch(dest_state) {
@ -147,14 +148,14 @@ auto MassManager::moveMass(Int source, Int destination) -> bool {
Utility::Directory::rm(dest_file); Utility::Directory::rm(dest_file);
break; break;
case Mass::State::Valid: case Mass::State::Valid:
Utility::Directory::move(dest_file, dest_file + ".tmp"); Utility::Directory::move(dest_file, dest_file + ".tmp"_s);
break; break;
} }
Utility::Directory::move(source_file, dest_file); Utility::Directory::move(source_file, dest_file);
if(dest_state == Mass::State::Valid) { if(dest_state == Mass::State::Valid) {
Utility::Directory::move(dest_file + ".tmp", source_file); Utility::Directory::move(dest_file + ".tmp"_s, source_file);
} }
return true; return true;
@ -162,7 +163,7 @@ auto MassManager::moveMass(Int source, Int destination) -> bool {
auto MassManager::deleteMass(Int hangar) -> bool { auto MassManager::deleteMass(Int hangar) -> bool {
if(hangar < 0 || hangar >= 32) { if(hangar < 0 || hangar >= 32) {
_lastError = "Hangar out of range."; _lastError = "Hangar out of range."_s;
return false; return false;
} }
@ -174,7 +175,7 @@ auto MassManager::deleteMass(Int hangar) -> bool {
return true; return true;
} }
auto MassManager::stagedMasses() -> std::map<std::string, std::string> const& { auto MassManager::stagedMasses() -> std::map<Containers::String, Containers::String> const& {
return _stagedMasses; return _stagedMasses;
} }
@ -182,31 +183,31 @@ void MassManager::refreshStagedMasses() {
_stagedMasses.clear(); _stagedMasses.clear();
using Utility::Directory::Flag; using Utility::Directory::Flag;
std::vector<std::string> file_list = Utility::Directory::list(_stagingAreaDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot); auto file_list = Utility::Directory::list(_stagingAreaDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot);
auto iter = std::remove_if(file_list.begin(), file_list.end(), [](std::string& file){ auto iter = std::remove_if(file_list.begin(), file_list.end(), [](std::string& file){
return !Utility::String::endsWith(file, ".sav"); return !Utility::String::endsWith(file, ".sav"_s);
}); });
file_list.erase(iter, file_list.end()); file_list.erase(iter, file_list.end());
for(const std::string& file : file_list) { for(auto& file : file_list) {
std::string name = *Mass::getNameFromFile(Utility::Directory::join(_stagingAreaDirectory, file)); auto name = Mass::getNameFromFile(Utility::Directory::join(_stagingAreaDirectory, file));
if(!name.empty()) { if(name) {
_stagedMasses[file] = name; _stagedMasses[file] = *name;
} }
} }
} }
auto MassManager::deleteStagedMass(const std::string& filename) -> bool { auto MassManager::deleteStagedMass(Containers::StringView filename) -> bool {
if(_stagedMasses.find(filename) == _stagedMasses.cend()) { if(_stagedMasses.find(filename) == _stagedMasses.cend()) {
_lastError = "The file " + filename + " couldn't be found in the list of staged M.A.S.S.es."; _lastError = "The file "_s + filename + " couldn't be found in the list of staged M.A.S.S.es."_s;
return false; return false;
} }
if(!Utility::Directory::rm(Utility::Directory::join(_stagingAreaDirectory, filename))) { if(!Utility::Directory::rm(Utility::Directory::join(_stagingAreaDirectory, filename))) {
_lastError = Utility::formatString("{} couldn't be deleted: {}", filename, std::strerror(errno)); _lastError = filename + " couldn't be deleted: " + std::strerror(errno);
return false; return false;
} }

View File

@ -17,9 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <map> #include <map>
#include <string>
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "../Mass/Mass.h" #include "../Mass/Mass.h"
@ -27,34 +28,34 @@ using namespace Corrade;
class MassManager { class MassManager {
public: public:
MassManager(const std::string& save_path, const std::string& steam_id, bool demo, const std::string& staging_dir); MassManager(Containers::StringView save_path, Containers::StringView account, bool demo, Containers::StringView staging_dir);
auto lastError() -> std::string const&; auto lastError() -> Containers::StringView;
auto hangar(int hangar) -> Mass&; auto hangar(int hangar) -> Mass&;
void refreshHangar(int hangar); void refreshHangar(int hangar);
auto importMass(const std::string& staged_fn, int hangar) -> bool; auto importMass(Containers::StringView staged_fn, int hangar) -> bool;
auto exportMass(int hangar) -> bool; auto exportMass(int hangar) -> bool;
auto moveMass(int source, int destination) -> bool; auto moveMass(int source, int destination) -> bool;
auto deleteMass(int hangar) -> bool; auto deleteMass(int hangar) -> bool;
auto stagedMasses() -> std::map<std::string, std::string> const&; auto stagedMasses() -> std::map<Containers::String, Containers::String> const&;
void refreshStagedMasses(); void refreshStagedMasses();
auto deleteStagedMass(const std::string& filename) -> bool; auto deleteStagedMass(Containers::StringView filename) -> bool;
private: private:
const std::string& _saveDirectory; Containers::StringView _saveDirectory;
const std::string& _steamId; Containers::StringView _account;
bool _demo; bool _demo;
std::string _lastError; Containers::String _lastError;
Containers::Array<Mass> _hangars; Containers::Array<Mass> _hangars;
const std::string& _stagingAreaDirectory; Containers::StringView _stagingAreaDirectory;
std::map<std::string, std::string> _stagedMasses; std::map<Containers::String, Containers::String> _stagedMasses;
}; };

View File

@ -18,6 +18,7 @@
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Utility/Directory.h> #include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
@ -30,13 +31,14 @@
#include "Profile.h" #include "Profile.h"
using namespace Corrade; using namespace Corrade;
using namespace Containers::Literals;
Profile::Profile(const std::string& path): Profile::Profile(Containers::StringView path):
_profile(path) _profile(path)
{ {
_filename = Utility::Directory::filename(path); _filename = Utility::Directory::filename(path);
if(Utility::String::beginsWith(_filename, "Demo")) { if(Utility::String::beginsWith(_filename, "Demo"_s)) {
_type = ProfileType::Demo; _type = ProfileType::Demo;
} }
else { else {
@ -45,13 +47,13 @@ Profile::Profile(const std::string& path):
auto account_prop = _profile.at<StringProperty>("Account"); auto account_prop = _profile.at<StringProperty>("Account");
if(!account_prop) { if(!account_prop) {
_lastError = "Couldn't find an account ID in " + _filename; _lastError = "Couldn't find an account ID in "_s + _filename;
_valid = false; _valid = false;
return; return;
} }
_account = account_prop->value; _account = account_prop->value;
if(Utility::String::beginsWith(_account, "PMCSlot")) { if(Utility::String::beginsWith(_account, "PMCSlot"_s)) {
_version = ProfileVersion::Normal; _version = ProfileVersion::Normal;
} }
else { else {
@ -65,11 +67,11 @@ auto Profile::valid() const -> bool {
return _valid; return _valid;
} }
auto Profile::lastError() const -> std::string const& { auto Profile::lastError() const -> Containers::StringView {
return _lastError; return _lastError;
} }
auto Profile::filename() const -> std::string const& { auto Profile::filename() const -> Containers::StringView {
return _filename; return _filename;
} }
@ -81,7 +83,7 @@ auto Profile::version() const -> ProfileVersion {
return _version; return _version;
} }
auto Profile::account() const -> std::string const& { auto Profile::account() const -> Containers::StringView {
return _account; return _account;
} }
@ -92,61 +94,61 @@ void Profile::refreshValues() {
return; return;
} }
auto name_prop = _profile.at<StringProperty>("CompanyName"); auto name_prop = _profile.at<StringProperty>("CompanyName"_s);
if(!name_prop) { if(!name_prop) {
_lastError = "No company name in " + _filename; _lastError = "No company name in "_s + _filename;
_valid = false; _valid = false;
return; return;
} }
_name = name_prop->value; _name = name_prop->value;
auto prop = _profile.at<IntProperty>("ActiveFrameSlot"); auto prop = _profile.at<IntProperty>("ActiveFrameSlot"_s);
_activeFrameSlot = prop ? prop->value : 0; _activeFrameSlot = prop ? prop->value : 0;
prop = _profile.at<IntProperty>("Credit"); prop = _profile.at<IntProperty>("Credit"_s);
_credits = prop ? prop->value : 0; _credits = prop ? prop->value : 0;
prop = _profile.at<IntProperty>("StoryProgress"); prop = _profile.at<IntProperty>("StoryProgress"_s);
_storyProgress = prop ? prop->value : 0; _storyProgress = prop ? prop->value : 0;
prop = _profile.at<IntProperty>("LastMissionID"); prop = _profile.at<IntProperty>("LastMissionID"_s);
_lastMissionId = prop ? prop->value : 0; _lastMissionId = prop ? prop->value : 0;
_verseSteel = getResource("ResourceMaterial", VerseSteel); _verseSteel = getResource("ResourceMaterial"_s, VerseSteel);
_undinium = getResource("ResourceMaterial", Undinium); _undinium = getResource("ResourceMaterial"_s, Undinium);
_necriumAlloy = getResource("ResourceMaterial", NecriumAlloy); _necriumAlloy = getResource("ResourceMaterial"_s, NecriumAlloy);
_lunarite = getResource("ResourceMaterial", Lunarite); _lunarite = getResource("ResourceMaterial"_s, Lunarite);
_asterite = getResource("ResourceMaterial", Asterite); _asterite = getResource("ResourceMaterial"_s, Asterite);
_ednil = getResource("ResourceMaterial", Ednil); _ednil = getResource("ResourceMaterial"_s, Ednil);
_nuflalt = getResource("ResourceMaterial", Nuflalt); _nuflalt = getResource("ResourceMaterial"_s, Nuflalt);
_aurelene = getResource("ResourceMaterial", Aurelene); _aurelene = getResource("ResourceMaterial"_s, Aurelene);
_soldus = getResource("ResourceMaterial", Soldus); _soldus = getResource("ResourceMaterial"_s, Soldus);
_synthesisedN = getResource("ResourceMaterial", SynthesisedN); _synthesisedN = getResource("ResourceMaterial"_s, SynthesisedN);
_alcarbonite = getResource("ResourceMaterial", Alcarbonite); _alcarbonite = getResource("ResourceMaterial"_s, Alcarbonite);
_keriphene = getResource("ResourceMaterial", Keriphene); _keriphene = getResource("ResourceMaterial"_s, Keriphene);
_nitinolCM = getResource("ResourceMaterial", NitinolCM); _nitinolCM = getResource("ResourceMaterial"_s, NitinolCM);
_quarkium = getResource("ResourceMaterial", Quarkium); _quarkium = getResource("ResourceMaterial"_s, Quarkium);
_alterene = getResource("ResourceMaterial", Alterene); _alterene = getResource("ResourceMaterial"_s, Alterene);
_mixedComposition = getResource("ResourceQuarkData", MixedComposition); _mixedComposition = getResource("ResourceQuarkData"_s, MixedComposition);
_voidResidue = getResource("ResourceQuarkData", VoidResidue); _voidResidue = getResource("ResourceQuarkData"_s, VoidResidue);
_muscularConstruction = getResource("ResourceQuarkData", MuscularConstruction); _muscularConstruction = getResource("ResourceQuarkData"_s, MuscularConstruction);
_mineralExoskeletology = getResource("ResourceQuarkData", MineralExoskeletology); _mineralExoskeletology = getResource("ResourceQuarkData"_s, MineralExoskeletology);
_carbonisedSkin = getResource("ResourceQuarkData", CarbonisedSkin); _carbonisedSkin = getResource("ResourceQuarkData"_s, CarbonisedSkin);
_valid = true; _valid = true;
} }
auto Profile::companyName() const -> std::string const& { auto Profile::companyName() const -> Containers::StringView {
return _name; return _name;
} }
auto Profile::renameCompany(const std::string& new_name) -> bool { auto Profile::renameCompany(Containers::StringView new_name) -> bool {
auto name_prop = _profile.at<StringProperty>("CompanyName"); auto name_prop = _profile.at<StringProperty>("CompanyName"_s);
if(!name_prop) { if(!name_prop) {
_lastError = "No company name in " + _filename; _lastError = "No company name in "_s + _filename;
_valid = false; _valid = false;
return false; return false;
} }
@ -170,11 +172,11 @@ auto Profile::credits() const -> Int {
} }
auto Profile::setCredits(Int amount) -> bool { auto Profile::setCredits(Int amount) -> bool {
auto credits_prop = _profile.at<IntProperty>("Credit"); auto credits_prop = _profile.at<IntProperty>("Credit"_s);
if(!credits_prop) { if(!credits_prop) {
credits_prop = new IntProperty; credits_prop = new IntProperty;
credits_prop->name.emplace("Credit"); credits_prop->name.emplace("Credit"_s);
_profile.appendProperty(IntProperty::ptr{credits_prop}); _profile.appendProperty(IntProperty::ptr{credits_prop});
} }
@ -193,11 +195,11 @@ auto Profile::storyProgress() const -> Int {
} }
auto Profile::setStoryProgress(Int progress) -> bool { auto Profile::setStoryProgress(Int progress) -> bool {
auto story_progress_prop = _profile.at<IntProperty>("StoryProgress"); auto story_progress_prop = _profile.at<IntProperty>("StoryProgress"_s);
if(!story_progress_prop) { if(!story_progress_prop) {
story_progress_prop = new IntProperty; story_progress_prop = new IntProperty;
story_progress_prop->name.emplace("StoryProgress"); story_progress_prop->name.emplace("StoryProgress"_s);
_profile.appendProperty(IntProperty::ptr{story_progress_prop}); _profile.appendProperty(IntProperty::ptr{story_progress_prop});
} }
@ -220,7 +222,7 @@ auto Profile::verseSteel() const -> Int {
} }
auto Profile::setVerseSteel(Int amount) -> bool { auto Profile::setVerseSteel(Int amount) -> bool {
return setResource("ResourceMaterial", VerseSteel, amount); return setResource("ResourceMaterial"_s, VerseSteel, amount);
} }
auto Profile::undinium() const -> Int { auto Profile::undinium() const -> Int {
@ -228,7 +230,7 @@ auto Profile::undinium() const -> Int {
} }
auto Profile::setUndinium(Int amount) -> bool { auto Profile::setUndinium(Int amount) -> bool {
return setResource("ResourceMaterial", Undinium, amount); return setResource("ResourceMaterial"_s, Undinium, amount);
} }
auto Profile::necriumAlloy() const -> Int { auto Profile::necriumAlloy() const -> Int {
@ -236,7 +238,7 @@ auto Profile::necriumAlloy() const -> Int {
} }
auto Profile::setNecriumAlloy(Int amount) -> bool { auto Profile::setNecriumAlloy(Int amount) -> bool {
return setResource("ResourceMaterial", NecriumAlloy, amount); return setResource("ResourceMaterial"_s, NecriumAlloy, amount);
} }
auto Profile::lunarite() const -> Int { auto Profile::lunarite() const -> Int {
@ -244,7 +246,7 @@ auto Profile::lunarite() const -> Int {
} }
auto Profile::setLunarite(Int amount) -> bool { auto Profile::setLunarite(Int amount) -> bool {
return setResource("ResourceMaterial", Lunarite, amount); return setResource("ResourceMaterial"_s, Lunarite, amount);
} }
auto Profile::asterite() const -> Int { auto Profile::asterite() const -> Int {
@ -252,7 +254,7 @@ auto Profile::asterite() const -> Int {
} }
auto Profile::setAsterite(Int amount) -> bool { auto Profile::setAsterite(Int amount) -> bool {
return setResource("ResourceMaterial", Asterite, amount); return setResource("ResourceMaterial"_s, Asterite, amount);
} }
auto Profile::ednil() const -> Int { auto Profile::ednil() const -> Int {
@ -260,7 +262,7 @@ auto Profile::ednil() const -> Int {
} }
auto Profile::setEdnil(Int amount) -> bool { auto Profile::setEdnil(Int amount) -> bool {
return setResource("ResourceMaterial", Ednil, amount); return setResource("ResourceMaterial"_s, Ednil, amount);
} }
auto Profile::nuflalt() const -> Int { auto Profile::nuflalt() const -> Int {
@ -268,7 +270,7 @@ auto Profile::nuflalt() const -> Int {
} }
auto Profile::setNuflalt(Int amount) -> bool { auto Profile::setNuflalt(Int amount) -> bool {
return setResource("ResourceMaterial", Nuflalt, amount); return setResource("ResourceMaterial"_s, Nuflalt, amount);
} }
auto Profile::aurelene() const -> Int { auto Profile::aurelene() const -> Int {
@ -276,7 +278,7 @@ auto Profile::aurelene() const -> Int {
} }
auto Profile::setAurelene(Int amount) -> bool { auto Profile::setAurelene(Int amount) -> bool {
return setResource("ResourceMaterial", Aurelene, amount); return setResource("ResourceMaterial"_s, Aurelene, amount);
} }
auto Profile::soldus() const -> Int { auto Profile::soldus() const -> Int {
@ -284,7 +286,7 @@ auto Profile::soldus() const -> Int {
} }
auto Profile::setSoldus(Int amount) -> bool { auto Profile::setSoldus(Int amount) -> bool {
return setResource("ResourceMaterial", Soldus, amount); return setResource("ResourceMaterial"_s, Soldus, amount);
} }
auto Profile::synthesisedN() const -> Int { auto Profile::synthesisedN() const -> Int {
@ -292,7 +294,7 @@ auto Profile::synthesisedN() const -> Int {
} }
auto Profile::setSynthesisedN(Int amount) -> bool { auto Profile::setSynthesisedN(Int amount) -> bool {
return setResource("ResourceMaterial", SynthesisedN, amount); return setResource("ResourceMaterial"_s, SynthesisedN, amount);
} }
auto Profile::alcarbonite() const -> Int { auto Profile::alcarbonite() const -> Int {
@ -300,7 +302,7 @@ auto Profile::alcarbonite() const -> Int {
} }
auto Profile::setAlcarbonite(Int amount) -> bool { auto Profile::setAlcarbonite(Int amount) -> bool {
return setResource("ResourceMaterial", Alcarbonite, amount); return setResource("ResourceMaterial"_s, Alcarbonite, amount);
} }
auto Profile::keriphene() const -> Int { auto Profile::keriphene() const -> Int {
@ -308,7 +310,7 @@ auto Profile::keriphene() const -> Int {
} }
auto Profile::setKeriphene(Int amount) -> bool { auto Profile::setKeriphene(Int amount) -> bool {
return setResource("ResourceMaterial", Keriphene, amount); return setResource("ResourceMaterial"_s, Keriphene, amount);
} }
auto Profile::nitinolCM() const -> Int { auto Profile::nitinolCM() const -> Int {
@ -316,7 +318,7 @@ auto Profile::nitinolCM() const -> Int {
} }
auto Profile::setNitinolCM(Int amount) -> bool { auto Profile::setNitinolCM(Int amount) -> bool {
return setResource("ResourceMaterial", NitinolCM, amount); return setResource("ResourceMaterial"_s, NitinolCM, amount);
} }
auto Profile::quarkium() const -> Int { auto Profile::quarkium() const -> Int {
@ -324,7 +326,7 @@ auto Profile::quarkium() const -> Int {
} }
auto Profile::setQuarkium(Int amount) -> bool { auto Profile::setQuarkium(Int amount) -> bool {
return setResource("ResourceMaterial", Quarkium, amount); return setResource("ResourceMaterial"_s, Quarkium, amount);
} }
auto Profile::alterene() const -> Int { auto Profile::alterene() const -> Int {
@ -332,7 +334,7 @@ auto Profile::alterene() const -> Int {
} }
auto Profile::setAlterene(Int amount) -> bool { auto Profile::setAlterene(Int amount) -> bool {
return setResource("ResourceMaterial", Alterene, amount); return setResource("ResourceMaterial"_s, Alterene, amount);
} }
auto Profile::mixedComposition() const -> Int { auto Profile::mixedComposition() const -> Int {
@ -340,7 +342,7 @@ auto Profile::mixedComposition() const -> Int {
} }
auto Profile::setMixedComposition(Int amount) -> bool { auto Profile::setMixedComposition(Int amount) -> bool {
return setResource("ResourceQuarkData", MixedComposition, amount); return setResource("ResourceQuarkData"_s, MixedComposition, amount);
} }
auto Profile::voidResidue() const -> Int { auto Profile::voidResidue() const -> Int {
@ -348,7 +350,7 @@ auto Profile::voidResidue() const -> Int {
} }
auto Profile::setVoidResidue(Int amount) -> bool { auto Profile::setVoidResidue(Int amount) -> bool {
return setResource("ResourceQuarkData", VoidResidue, amount); return setResource("ResourceQuarkData"_s, VoidResidue, amount);
} }
auto Profile::muscularConstruction() const -> Int { auto Profile::muscularConstruction() const -> Int {
@ -356,7 +358,7 @@ auto Profile::muscularConstruction() const -> Int {
} }
auto Profile::setMuscularConstruction(Int amount) -> bool { auto Profile::setMuscularConstruction(Int amount) -> bool {
return setResource("ResourceQuarkData", MuscularConstruction, amount); return setResource("ResourceQuarkData"_s, MuscularConstruction, amount);
} }
auto Profile::mineralExoskeletology() const -> Int { auto Profile::mineralExoskeletology() const -> Int {
@ -364,7 +366,7 @@ auto Profile::mineralExoskeletology() const -> Int {
} }
auto Profile::setMineralExoskeletology(Int amount) -> bool { auto Profile::setMineralExoskeletology(Int amount) -> bool {
return setResource("ResourceQuarkData", MineralExoskeletology, amount); return setResource("ResourceQuarkData"_s, MineralExoskeletology, amount);
} }
auto Profile::carbonisedSkin() const -> Int { auto Profile::carbonisedSkin() const -> Int {
@ -372,10 +374,10 @@ auto Profile::carbonisedSkin() const -> Int {
} }
auto Profile::setCarbonisedSkin(Int amount) -> bool { auto Profile::setCarbonisedSkin(Int amount) -> bool {
return setResource("ResourceQuarkData", CarbonisedSkin, amount); return setResource("ResourceQuarkData"_s, CarbonisedSkin, amount);
} }
auto Profile::getResource(const char* container, MaterialID id) -> Int { auto Profile::getResource(Containers::StringView container, MaterialID id) -> Int {
auto mats_prop = _profile.at<ArrayProperty>(container); auto mats_prop = _profile.at<ArrayProperty>(container);
if(!mats_prop) { if(!mats_prop) {
@ -391,11 +393,11 @@ auto Profile::getResource(const char* container, MaterialID id) -> Int {
return it != mats_prop->items.end() ? static_cast<ResourceItemValue*>(it->get())->quantity : 0; return it != mats_prop->items.end() ? static_cast<ResourceItemValue*>(it->get())->quantity : 0;
} }
auto Profile::setResource(const char* container, MaterialID id, Int amount) -> bool { auto Profile::setResource(Containers::StringView container, MaterialID id, Int amount) -> bool {
auto mats_prop = _profile.at<ArrayProperty>(container); auto mats_prop = _profile.at<ArrayProperty>(container);
if(!mats_prop) { if(!mats_prop) {
_lastError = "Couldn't find " + std::string{container} + " in " + _filename; _lastError = "Couldn't find "_s + container + " in "_s + _filename;
_valid = false; _valid = false;
return false; return false;
} }

View File

@ -16,7 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string> #include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Magnum.h> #include <Magnum/Magnum.h>
@ -24,6 +25,7 @@
#include "ResourceIDs.h" #include "ResourceIDs.h"
using namespace Corrade;
using namespace Magnum; using namespace Magnum;
enum class ProfileType : UnsignedByte { enum class ProfileType : UnsignedByte {
@ -38,24 +40,24 @@ enum class ProfileVersion : UnsignedByte {
class Profile { class Profile {
public: public:
explicit Profile(const std::string& path); explicit Profile(Containers::StringView path);
auto valid() const -> bool; auto valid() const -> bool;
auto lastError() const -> std::string const&; auto lastError() const -> Containers::StringView;
auto filename() const -> std::string const&; auto filename() const -> Containers::StringView;
auto type() const -> ProfileType; auto type() const -> ProfileType;
auto version() const -> ProfileVersion; auto version() const -> ProfileVersion;
auto account() const -> std::string const&; auto account() const -> Containers::StringView;
void refreshValues(); void refreshValues();
auto companyName() const -> std::string const&; auto companyName() const -> Containers::StringView;
auto renameCompany(const std::string& new_name) -> bool; auto renameCompany(Containers::StringView new_name) -> bool;
auto activeFrameSlot() const -> Int; auto activeFrameSlot() const -> Int;
@ -128,17 +130,17 @@ class Profile {
auto setCarbonisedSkin(Int amount) -> bool; auto setCarbonisedSkin(Int amount) -> bool;
private: private:
auto getResource(const char* container, MaterialID id) -> Int; auto getResource(Containers::StringView container, MaterialID id) -> Int;
auto setResource(const char* container, MaterialID id, Int amount) -> bool; auto setResource(Containers::StringView container, MaterialID id, Int amount) -> bool;
std::string _filename; Containers::String _filename;
ProfileType _type; ProfileType _type;
ProfileVersion _version; ProfileVersion _version;
UESaveFile _profile; UESaveFile _profile;
std::string _name; Containers::String _name;
Int _activeFrameSlot = 0; Int _activeFrameSlot = 0;
Int _credits = 0; Int _credits = 0;
Int _storyProgress = 0; Int _storyProgress = 0;
@ -168,8 +170,8 @@ class Profile {
Int _mineralExoskeletology = 0; Int _mineralExoskeletology = 0;
Int _carbonisedSkin = 0; Int _carbonisedSkin = 0;
std::string _account; Containers::String _account;
bool _valid = false; bool _valid = false;
std::string _lastError; Containers::String _lastError;
}; };

View File

@ -23,6 +23,7 @@
#include <Corrade/Containers/ScopeGuard.h> #include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Utility/Directory.h> #include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
@ -31,7 +32,9 @@
#include "ProfileManager.h" #include "ProfileManager.h"
ProfileManager::ProfileManager(const std::string& save_dir, const std::string& backup_dir): using namespace Containers::Literals;
ProfileManager::ProfileManager(Containers::StringView save_dir, Containers::StringView backup_dir):
_saveDirectory{save_dir}, _saveDirectory{save_dir},
_backupsDirectory{backup_dir} _backupsDirectory{backup_dir}
{ {
@ -42,7 +45,7 @@ auto ProfileManager::ready() const -> bool {
return _ready; return _ready;
} }
auto ProfileManager::lastError() -> std::string const& { auto ProfileManager::lastError() -> Containers::StringView {
return _lastError; return _lastError;
} }
@ -54,21 +57,21 @@ auto ProfileManager::refreshProfiles() -> bool {
_profiles = Containers::Array<Profile>{}; _profiles = Containers::Array<Profile>{};
using Utility::Directory::Flag; using Utility::Directory::Flag;
std::vector<std::string> files = Utility::Directory::list(_saveDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot); auto files = Utility::Directory::list(_saveDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot);
auto predicate = [](const std::string& file)->bool{ auto predicate = [](Containers::StringView file)->bool{
std::regex regex("(Demo)?Profile[0-9]{17}\\.sav", std::regex::nosubs); std::regex regex("(Demo)?Profile[0-9]{17}\\.sav", std::regex::nosubs);
std::cmatch m; std::cmatch m;
return !std::regex_match(file.c_str(), m, regex); return !std::regex_match(file.data(), m, regex);
}; };
files.erase(std::remove_if(files.begin(), files.end(), predicate), files.end()); files.erase(std::remove_if(files.begin(), files.end(), predicate), files.end());
for(const std::string& file : files) { for(const auto& file : files) {
Profile profile{Utility::Directory::join(_saveDirectory, file)}; Profile profile{Utility::Directory::join(_saveDirectory, file)};
if(!profile.valid()) { if(!profile.valid()) {
Utility::Warning{} << "Profile" << file.c_str() << "is invalid:" << profile.lastError().c_str(); Utility::Warning{} << "Profile"_s << file.c_str() << "is invalid:"_s << profile.lastError();
continue; continue;
} }
@ -76,7 +79,7 @@ auto ProfileManager::refreshProfiles() -> bool {
} }
if(_profiles.empty()) { if(_profiles.empty()) {
_lastError = "No valid profiles were found."; _lastError = "No valid profiles were found."_s;
return false; return false;
} }
@ -89,24 +92,24 @@ auto ProfileManager::getProfile(std::size_t index) -> Profile* {
auto ProfileManager::deleteProfile(std::size_t index, bool delete_builds) -> bool { auto ProfileManager::deleteProfile(std::size_t index, bool delete_builds) -> bool {
if(!Utility::Directory::rm(Utility::Directory::join(_saveDirectory, _profiles[index].filename()))) { if(!Utility::Directory::rm(Utility::Directory::join(_saveDirectory, _profiles[index].filename()))) {
_lastError = Utility::formatString("Couldn't delete {} (filename: {}).", _lastError = Utility::format("Couldn't delete {} (filename: {}).",
_profiles[index].companyName(), _profiles[index].companyName(),
_profiles[index].filename()); _profiles[index].filename());
refreshProfiles(); refreshProfiles();
return false; return false;
} }
if(delete_builds) { if(delete_builds) {
for(UnsignedByte i = 0; i < 32; ++i) { for(UnsignedByte i = 0; i < 32; ++i) {
std::string filename = Utility::formatString("{}Unit{:.2d}{}.sav", auto filename = Utility::format("{}Unit{:.2d}{}.sav",
_profiles[index].type() == ProfileType::Demo ? "Demo": "", _profiles[index].type() == ProfileType::Demo ? "Demo": "",
i, _profiles[index].account()); i, _profiles[index].account());
Utility::Directory::rm(Utility::Directory::join(_saveDirectory, filename)); Utility::Directory::rm(Utility::Directory::join(_saveDirectory, filename));
} }
} }
std::string file = _profiles[index].filename(); auto file = _profiles[index].filename();
auto it = std::remove_if(_profiles.begin(), _profiles.end(), [&file](Profile& profile){return profile.filename() == file;}); auto it = std::remove_if(_profiles.begin(), _profiles.end(), [&file](Profile& profile){ return profile.filename() == file; });
if(it != _profiles.end()) { if(it != _profiles.end()) {
arrayRemoveSuffix(_profiles, 1); arrayRemoveSuffix(_profiles, 1);
@ -119,10 +122,10 @@ auto ProfileManager::backupProfile(std::size_t index, bool backup_builds) -> boo
std::time_t timestamp = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::time_t timestamp = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm* time = std::localtime(&timestamp); std::tm* time = std::localtime(&timestamp);
std::string filename = Utility::formatString("{}_{}{:.2d}{:.2d}_{:.2d}{:.2d}{:.2d}.mbprofbackup", auto filename = Utility::format("{}_{}{:.2d}{:.2d}_{:.2d}{:.2d}{:.2d}.mbprofbackup",
Utility::String::replaceAll(_profiles[index].companyName(), " ", "_"), Utility::String::replaceAll(_profiles[index].companyName(), " ", "_"),
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec); time->tm_hour, time->tm_min, time->tm_sec);
int error_code = 0; int error_code = 0;
zip_error_t error; zip_error_t error;
@ -140,25 +143,24 @@ auto ProfileManager::backupProfile(std::size_t index, bool backup_builds) -> boo
return false; return false;
} }
if(zip_file_add(zip, _profiles[index].filename().c_str(), profile_source, ZIP_FL_ENC_UTF_8) == -1) { if(zip_file_add(zip, _profiles[index].filename().data(), profile_source, ZIP_FL_ENC_UTF_8) == -1) {
_lastError = zip_strerror(zip); _lastError = zip_strerror(zip);
zip_source_free(profile_source); zip_source_free(profile_source);
return false; return false;
} }
std::string comment = Utility::String::join({_profiles[index].companyName(), auto comment = "|"_s.join({_profiles[index].companyName(),
_profiles[index].type() == ProfileType::Demo ? "demo" : "full", _profiles[index].type() == ProfileType::Demo ? "demo"_s : "full"_s,
Utility::formatString("{}-{:.2d}-{:.2d}-{:.2d}-{:.2d}-{:.2d}", Utility::format("{}-{:.2d}-{:.2d}-{:.2d}-{:.2d}-{:.2d}",
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec) time->tm_hour, time->tm_min, time->tm_sec)});
}, '|'); zip_set_archive_comment(zip, comment.data(), comment.size());
zip_set_archive_comment(zip, comment.c_str(), comment.length());
if(backup_builds) { if(backup_builds) {
for(UnsignedByte i = 0; i < 32; ++i) { for(UnsignedByte i = 0; i < 32; ++i) {
std::string build_filename = Utility::formatString("{}Unit{:.2d}{}.sav", auto build_filename = Utility::format("{}Unit{:.2d}{}.sav",
_profiles[index].type() == ProfileType::Demo ? "Demo": "", _profiles[index].type() == ProfileType::Demo ? "Demo"_s : ""_s, i,
i, _profiles[index].account()); _profiles[index].account());
if(!Utility::Directory::exists(Utility::Directory::join(_saveDirectory, build_filename))) { if(!Utility::Directory::exists(Utility::Directory::join(_saveDirectory, build_filename))) {
continue; continue;
@ -170,7 +172,7 @@ auto ProfileManager::backupProfile(std::size_t index, bool backup_builds) -> boo
continue; continue;
} }
if(zip_file_add(zip, build_filename.c_str(), build_source, ZIP_FL_ENC_UTF_8) == -1) { if(zip_file_add(zip, build_filename.data(), build_source, ZIP_FL_ENC_UTF_8) == -1) {
zip_source_free(build_source); zip_source_free(build_source);
continue; continue;
} }
@ -197,8 +199,8 @@ void ProfileManager::refreshBackups() {
using Utility::Directory::Flag; using Utility::Directory::Flag;
std::vector<std::string> files = Utility::Directory::list(_backupsDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot); std::vector<std::string> files = Utility::Directory::list(_backupsDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot);
auto predicate = [](const std::string& file)->bool{ auto predicate = [](Containers::StringView file)->bool{
return !Utility::String::endsWith(file, ".mbprofbackup"); return !file.hasSuffix(".mbprofbackup"_s);
}; };
files.erase(std::remove_if(files.begin(), files.end(), predicate), files.end()); files.erase(std::remove_if(files.begin(), files.end(), predicate), files.end());
@ -217,40 +219,40 @@ void ProfileManager::refreshBackups() {
Containers::ScopeGuard guard{zip, zip_close}; Containers::ScopeGuard guard{zip, zip_close};
int comment_length; int comment_length;
const char* comment = zip_get_archive_comment(zip, &comment_length, ZIP_FL_UNCHANGED); Containers::StringView comment = zip_get_archive_comment(zip, &comment_length, ZIP_FL_UNCHANGED);
if(comment == nullptr) { if(comment == nullptr) {
continue; continue;
} }
auto info = Utility::String::split(comment, '|'); auto info = comment.split('|');
if(info.size() != 3) { if(info.size() != 3) {
continue; continue;
} }
backup.company = info.at(0); backup.company = info[0];
if(info.at(1) == "full") { if(info[1] == "full") {
backup.type = ProfileType::FullGame; backup.type = ProfileType::FullGame;
} }
else if(info.at(1) == "demo") { else if(info[1] == "demo") {
backup.type = ProfileType::Demo; backup.type = ProfileType::Demo;
} }
else { else {
continue; continue;
} }
auto ts = Utility::String::split(info.at(2), '-'); auto ts = info[2].split('-');
if(ts.size() != 6) { if(ts.size() != 6) {
continue; continue;
} }
backup.timestamp.year = std::stoi(ts.at(0)); backup.timestamp.year = std::stoi(ts[0]);
backup.timestamp.month = std::stoi(ts.at(1)); backup.timestamp.month = std::stoi(ts[1]);
backup.timestamp.day = std::stoi(ts.at(2)); backup.timestamp.day = std::stoi(ts[2]);
backup.timestamp.hour = std::stoi(ts.at(3)); backup.timestamp.hour = std::stoi(ts[3]);
backup.timestamp.minute = std::stoi(ts.at(4)); backup.timestamp.minute = std::stoi(ts[4]);
backup.timestamp.second = std::stoi(ts.at(5)); backup.timestamp.second = std::stoi(ts[5]);
Long num_entries = zip_get_num_entries(zip, ZIP_FL_UNCHANGED); Long num_entries = zip_get_num_entries(zip, ZIP_FL_UNCHANGED);
@ -274,7 +276,7 @@ auto ProfileManager::deleteBackup(std::size_t index) -> bool {
return false; return false;
} }
std::string file = _backups[index].filename; auto file = _backups[index].filename;
auto it = std::remove_if(_backups.begin(), _backups.end(), [&file](Backup& backup){return backup.filename == file;}); auto it = std::remove_if(_backups.begin(), _backups.end(), [&file](Backup& backup){return backup.filename == file;});
if(it != _backups.end()) { if(it != _backups.end()) {
@ -287,7 +289,7 @@ auto ProfileManager::deleteBackup(std::size_t index) -> bool {
auto ProfileManager::restoreBackup(std::size_t index) -> bool { auto ProfileManager::restoreBackup(std::size_t index) -> bool {
const Backup& backup = _backups[index]; const Backup& backup = _backups[index];
static const char* error_format = "Extraction of file {} failed: {}"; auto error_format = "Extraction of file {} failed: {}"_s;
int error_code = 0; int error_code = 0;
zip_t* zip = nullptr; zip_t* zip = nullptr;
@ -302,18 +304,18 @@ auto ProfileManager::restoreBackup(std::size_t index) -> bool {
Containers::ScopeGuard zip_guard{zip, zip_close}; Containers::ScopeGuard zip_guard{zip, zip_close};
for(const std::string& file : backup.includedFiles) { for(Containers::StringView file : backup.includedFiles) {
FILE* out = std::fopen(Utility::Directory::join(_saveDirectory, file).c_str(), "wb"); FILE* out = std::fopen(Utility::Directory::join(_saveDirectory, file).c_str(), "wb");
if(out == nullptr) { if(out == nullptr) {
_lastError = Utility::formatString(error_format, file, std::strerror(errno)); _lastError = Utility::formatString(error_format.data(), file, std::strerror(errno));
return false; return false;
} }
Containers::ScopeGuard out_guard{out, std::fclose}; Containers::ScopeGuard out_guard{out, std::fclose};
zip_file_t* zf = zip_fopen(zip, file.c_str(), ZIP_FL_ENC_GUESS); zip_file_t* zf = zip_fopen(zip, file.data(), ZIP_FL_ENC_GUESS);
if(zf == nullptr) { if(zf == nullptr) {
_lastError = Utility::formatString(error_format, file, zip_strerror(zip)); _lastError = Utility::format(error_format.data(), file, zip_strerror(zip));
return false; return false;
} }
@ -324,13 +326,13 @@ auto ProfileManager::restoreBackup(std::size_t index) -> bool {
Long bytes_read = 0; Long bytes_read = 0;
while((bytes_read = zip_fread(zf, buf.data(), buf.size())) > 0) { while((bytes_read = zip_fread(zf, buf.data(), buf.size())) > 0) {
if(std::fwrite(buf.data(), sizeof(char), bytes_read, out) < static_cast<std::size_t>(bytes_read)) { if(std::fwrite(buf.data(), sizeof(char), bytes_read, out) < static_cast<std::size_t>(bytes_read)) {
_lastError = Utility::formatString(error_format, file, "not enough bytes written."); _lastError = Utility::format(error_format.data(), file, "not enough bytes written.");
return false; return false;
} }
} }
if(bytes_read == -1) { if(bytes_read == -1) {
_lastError = Utility::formatString(error_format, file, "couldn't read bytes from archive."); _lastError = Utility::format(error_format.data(), file, "couldn't read bytes from archive.");
return false; return false;
} }
} }

View File

@ -19,14 +19,15 @@
#include <string> #include <string>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/String.h>
#include "../Profile/Profile.h" #include "../Profile/Profile.h"
using namespace Corrade; using namespace Corrade;
struct Backup { struct Backup {
std::string filename; Containers::String filename;
std::string company; Containers::String company;
ProfileType type; ProfileType type;
struct { struct {
int year; int year;
@ -36,15 +37,15 @@ struct Backup {
int minute; int minute;
int second; int second;
} timestamp; } timestamp;
Containers::Array<std::string> includedFiles; Containers::Array<Containers::String> includedFiles;
}; };
class ProfileManager { class ProfileManager {
public: public:
explicit ProfileManager(const std::string& save_dir, const std::string& backup_dir); explicit ProfileManager(Containers::StringView save_dir, Containers::StringView backup_dir);
auto ready() const -> bool; auto ready() const -> bool;
auto lastError() -> std::string const&; auto lastError() -> Containers::StringView;
auto profiles() -> Containers::ArrayView<Profile>; auto profiles() -> Containers::ArrayView<Profile>;
auto refreshProfiles() -> bool; auto refreshProfiles() -> bool;
@ -61,10 +62,10 @@ class ProfileManager {
private: private:
bool _ready = false; bool _ready = false;
std::string _lastError; Containers::String _lastError;
const std::string& _saveDirectory; Containers::StringView _saveDirectory;
const std::string& _backupsDirectory; Containers::StringView _backupsDirectory;
Containers::Array<Profile> _profiles; Containers::Array<Profile> _profiles;
Containers::Array<Backup> _backups; Containers::Array<Backup> _backups;

View File

@ -19,6 +19,7 @@
#include <cstring> #include <cstring>
#include <Corrade/Containers/ScopeGuard.h> #include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Utility/Directory.h> #include <Corrade/Utility/Directory.h>
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
@ -46,6 +47,8 @@
#include "../FontAwesome/IconsFontAwesome5.h" #include "../FontAwesome/IconsFontAwesome5.h"
#include "../FontAwesome/IconsFontAwesome5Brands.h" #include "../FontAwesome/IconsFontAwesome5Brands.h"
using namespace Containers::Literals;
extern const ImVec2 center_pivot = {0.5f, 0.5f}; extern const ImVec2 center_pivot = {0.5f, 0.5f};
#ifdef SAVETOOL_DEBUG_BUILD #ifdef SAVETOOL_DEBUG_BUILD
@ -58,19 +61,19 @@ SaveTool::SaveTool(const Arguments& arguments):
.setSize({960, 720})} .setSize({960, 720})}
{ {
#ifdef SAVETOOL_DEBUG_BUILD #ifdef SAVETOOL_DEBUG_BUILD
tweak.enable("", "../../"); tweak.enable(""_s, "../../"_s);
#endif #endif
if(SDL_VERSION_ATLEAST(2, 0, 5)) { if(SDL_VERSION_ATLEAST(2, 0, 5)) {
if(SDL_SetHintWithPriority(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1", SDL_HINT_OVERRIDE) == SDL_TRUE) { if(SDL_SetHintWithPriority(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1", SDL_HINT_OVERRIDE) == SDL_TRUE) {
Utility::Debug{} << "Clickthrough is available."; Utility::Debug{} << "Clickthrough is available."_s;
} }
else { else {
Utility::Warning{} << "Clickthrough is not available (hint couldn't be set)."; Utility::Warning{} << "Clickthrough is not available (hint couldn't be set)."_s;
} }
} }
else { else {
Utility::Warning{} << "Clickthrough is not available (SDL2 is too old)."; Utility::Warning{} << "Clickthrough is not available (SDL2 is too old)."_s;
} }
GL::Renderer::enable(GL::Renderer::Feature::Blending); GL::Renderer::enable(GL::Renderer::Feature::Blending);
@ -98,7 +101,7 @@ SaveTool::SaveTool(const Arguments& arguments):
_armouryDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "armoury"); _armouryDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "armoury");
_armoursDir = Utility::Directory::join(_armouryDir, "armours"); _armoursDir = Utility::Directory::join(_armouryDir, "armours");
_weaponsDir = Utility::Directory::join(_armouryDir, "weapons"); _weaponsDir = Utility::Directory::join(_armouryDir, "weapons");
_stylesDir = Utility::Directory::join(_armouryDir, "styles"); _stylesDir = Utility::Directory::join(_armouryDir, "styles");
if(!Utility::Directory::exists(_backupsDir)) { if(!Utility::Directory::exists(_backupsDir)) {
Utility::Directory::mkpath(_backupsDir); Utility::Directory::mkpath(_backupsDir);
@ -125,7 +128,7 @@ SaveTool::SaveTool(const Arguments& arguments):
} }
if(!findGameDataDirectory()) { if(!findGameDataDirectory()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.c_str(), window()); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
return; return;
} }
@ -145,8 +148,7 @@ SaveTool::SaveTool(const Arguments& arguments):
[](UnsignedInt interval, void* param)->UnsignedInt{ [](UnsignedInt interval, void* param)->UnsignedInt{
static_cast<SaveTool*>(param)->checkGameState(); static_cast<SaveTool*>(param)->checkGameState();
return interval; return interval;
}, }, this);
this);
if(_gameCheckTimerId == 0) { if(_gameCheckTimerId == 0) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", SDL_GetError(), window()); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", SDL_GetError(), window());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -170,7 +172,7 @@ SaveTool::SaveTool(const Arguments& arguments):
if(_checkUpdatesOnStartup) { if(_checkUpdatesOnStartup) {
_updateThread = std::thread{[this]{ checkForUpdates(); }}; _updateThread = std::thread{[this]{ checkForUpdates(); }};
_queue.addToast(Toast::Type::Default, "Checking for updates..."); _queue.addToast(Toast::Type::Default, "Checking for updates..."_s);
} }
if(GL::Context::current().isExtensionSupported<GL::Extensions::KHR::debug>() && if(GL::Context::current().isExtensionSupported<GL::Extensions::KHR::debug>() &&
@ -188,20 +190,20 @@ SaveTool::SaveTool(const Arguments& arguments):
SaveTool::~SaveTool() { SaveTool::~SaveTool() {
SDL_RemoveTimer(_gameCheckTimerId); SDL_RemoveTimer(_gameCheckTimerId);
_conf.setValue("cheat_mode", _cheatMode); _conf.setValue("cheat_mode"_s, _cheatMode);
_conf.setValue("unsafe_mode", _unsafeMode); _conf.setValue("unsafe_mode"_s, _unsafeMode);
_conf.setValue("startup_update_check", _checkUpdatesOnStartup); _conf.setValue("startup_update_check"_s, _checkUpdatesOnStartup);
_conf.setValue("skip_disclaimer", _skipDisclaimer); _conf.setValue("skip_disclaimer"_s, _skipDisclaimer);
switch(_framelimit) { switch(_framelimit) {
case Framelimit::Vsync: case Framelimit::Vsync:
_conf.setValue("frame_limit", "vsync"); _conf.setValue("frame_limit"_s, "vsync"_s);
break; break;
case Framelimit::HalfVsync: case Framelimit::HalfVsync:
_conf.setValue("frame_limit", "half_vsync"); _conf.setValue("frame_limit"_s, "half_vsync"_s);
break; break;
case Framelimit::FpsCap: case Framelimit::FpsCap:
_conf.setValue<UnsignedInt>("frame_limit", _fpsCap); _conf.setValue<UnsignedInt>("frame_limit"_s, _fpsCap);
break; break;
} }
@ -366,7 +368,7 @@ void SaveTool::initEvent(SDL_Event& event) {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
break; break;
case ProfileManagerFailure: case ProfileManagerFailure:
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising ProfileManager", _profileManager->lastError().c_str(), window()); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising ProfileManager", _profileManager->lastError().data(), window());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
break; break;
default: default:
@ -381,12 +383,12 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
delete static_cast<cpr::Response*>(event.user.data1); delete static_cast<cpr::Response*>(event.user.data1);
if(r.elapsed > 10.0) { if(r.elapsed > 10.0) {
_queue.addToast(Toast::Type::Error, "The request timed out."); _queue.addToast(Toast::Type::Error, "The request timed out."_s);
return; return;
} }
if(r.status_code != 200) { if(r.status_code != 200) {
_queue.addToast(Toast::Type::Error, Utility::formatString("The request failed with error code {}: {}", r.status_code, r.reason)); _queue.addToast(Toast::Type::Error, Utility::format("The request failed with error code {}: {}", r.status_code, r.reason));
return; return;
} }
@ -395,18 +397,18 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
json response = json::parse(r.text); json response = json::parse(r.text);
struct Version { struct Version {
explicit Version(const std::string& str) { explicit Version(Containers::StringView str) {
std::size_t start_point = 0; std::size_t start_point = 0;
if(str[0] == 'v') { if(str[0] == 'v') {
start_point++; start_point++;
} }
major = std::atoi(str.c_str() + start_point); auto components = Containers::StringView{str.data() + start_point, strlen(str.data() + start_point)}.split('.');
start_point = str.find('.', start_point) + 1;
minor = std::atoi(str.c_str() + start_point); major = std::strtol(components[0].data(), nullptr, 10);
start_point = str.find('.', start_point) + 1; minor = std::strtol(components[1].data(), nullptr, 10);
patch = std::atoi(str.c_str() + start_point); patch = std::strtol(components[2].data(), nullptr, 10);
} }
Int major; Int major;
Int minor; Int minor;
@ -419,8 +421,8 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
return ( major * 10000 + minor * 100 + patch) > return ( major * 10000 + minor * 100 + patch) >
(other.major * 10000 + other.minor * 100 + other.patch); (other.major * 10000 + other.minor * 100 + other.patch);
} }
operator std::string() const { operator Containers::String() const {
return Utility::formatString("{}.{}.{}", major, minor, patch); return Utility::format("{}.{}.{}", major, minor, patch);
} }
}; };
@ -431,21 +433,21 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
continue; continue;
} }
Version latest_ver{release["tag_name"]}; Version latest_ver{to_string(release["tag_name"])};
if(latest_ver > current_ver || (latest_ver == current_ver && Utility::String::endsWith(SAVETOOL_VERSION, "-pre"))) { if(latest_ver > current_ver || (latest_ver == current_ver && Utility::String::endsWith(SAVETOOL_VERSION, "-pre"))) {
_queue.addToast(Toast::Type::Warning, "Your version is out of date.\nCheck the settings for more information.", _queue.addToast(Toast::Type::Warning, "Your version is out of date.\nCheck the settings for more information."_s,
std::chrono::milliseconds{5000}); std::chrono::milliseconds{5000});
_updateAvailable = true; _updateAvailable = true;
_latestVersion = latest_ver; _latestVersion = latest_ver;
_releaseLink = release["html_url"]; _releaseLink = to_string(release["html_url"]);
_downloadLink = release["assets"][0]["browser_download_url"]; _downloadLink = to_string(release["assets"][0]["browser_download_url"]);
} }
else if(latest_ver == current_ver || (current_ver > latest_ver && Utility::String::endsWith(SAVETOOL_VERSION, "-pre"))) { else if(latest_ver == current_ver || (current_ver > latest_ver && Utility::String::endsWith(SAVETOOL_VERSION, "-pre"))) {
_queue.addToast(Toast::Type::Success, "The application is already up to date."); _queue.addToast(Toast::Type::Success, "The application is already up to date."_s);
} }
else if(current_ver > latest_ver) { else if(current_ver > latest_ver) {
_queue.addToast(Toast::Type::Warning, "Your version is more recent than the latest one in the repo. How???"); _queue.addToast(Toast::Type::Warning, "Your version is more recent than the latest one in the repo. How???"_s);
} }
break; break;
@ -453,40 +455,40 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
} }
void SaveTool::initialiseConfiguration() { void SaveTool::initialiseConfiguration() {
if(_conf.hasValue("cheat_mode")) { if(_conf.hasValue("cheat_mode"_s)) {
_cheatMode = _conf.value<bool>("cheat_mode"); _cheatMode = _conf.value<bool>("cheat_mode"_s);
} }
else { else {
_conf.setValue("cheat_mode", _cheatMode); _conf.setValue("cheat_mode"_s, _cheatMode);
} }
if(_conf.hasValue("unsafe_mode")) { if(_conf.hasValue("unsafe_mode"_s)) {
_unsafeMode = _conf.value<bool>("unsafe_mode"); _unsafeMode = _conf.value<bool>("unsafe_mode"_s);
} }
else { else {
_conf.setValue("unsafe_mode", _unsafeMode); _conf.setValue("unsafe_mode"_s, _unsafeMode);
} }
if(_conf.hasValue("startup_update_check")) { if(_conf.hasValue("startup_update_check"_s)) {
_checkUpdatesOnStartup = _conf.value<bool>("startup_update_check"); _checkUpdatesOnStartup = _conf.value<bool>("startup_update_check"_s);
} }
else { else {
_conf.setValue("startup_update_check", _checkUpdatesOnStartup); _conf.setValue("startup_update_check"_s, _checkUpdatesOnStartup);
} }
if(_conf.hasValue("skip_disclaimer")) { if(_conf.hasValue("skip_disclaimer"_s)) {
_skipDisclaimer = _conf.value<bool>("skip_disclaimer"); _skipDisclaimer = _conf.value<bool>("skip_disclaimer"_s);
} }
else { else {
_conf.setValue("skip_disclaimer", _skipDisclaimer); _conf.setValue("skip_disclaimer"_s, _skipDisclaimer);
} }
if(_conf.hasValue("frame_limit")) { if(_conf.hasValue("frame_limit"_s)) {
std::string frame_limit = _conf.value("frame_limit"); std::string frame_limit = _conf.value("frame_limit"_s);
if(frame_limit == "vsync") { if(frame_limit == "vsync"_s) {
_framelimit = Framelimit::Vsync; _framelimit = Framelimit::Vsync;
} }
else if(frame_limit == "half_vsync") { else if(frame_limit == "half_vsync"_s) {
_framelimit = Framelimit::HalfVsync; _framelimit = Framelimit::HalfVsync;
} }
else { else {
@ -495,7 +497,7 @@ void SaveTool::initialiseConfiguration() {
} }
} }
else { else {
_conf.setValue("frame_limit", "vsync"); _conf.setValue("frame_limit"_s, "vsync"_s);
} }
_conf.save(); _conf.save();
@ -506,7 +508,7 @@ void SaveTool::initialiseGui() {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
auto reg_font = _rs.getRaw("SourceSansPro-Regular.ttf"); auto reg_font = _rs.getRaw("SourceSansPro-Regular.ttf"_s);
ImFontConfig font_config; ImFontConfig font_config;
font_config.FontDataOwnedByAtlas = false; font_config.FontDataOwnedByAtlas = false;
std::strcpy(font_config.Name, "Source Sans Pro"); std::strcpy(font_config.Name, "Source Sans Pro");
@ -526,7 +528,7 @@ void SaveTool::initialiseGui() {
static const ImWchar brand_range[] = { ICON_MIN_FAB, ICON_MAX_FAB, 0 }; static const ImWchar brand_range[] = { ICON_MIN_FAB, ICON_MAX_FAB, 0 };
io.Fonts->AddFontFromMemoryTTF(const_cast<char*>(brand_font.data()), brand_font.size(), 16.0f, &icon_config, brand_range); io.Fonts->AddFontFromMemoryTTF(const_cast<char*>(brand_font.data()), brand_font.size(), 16.0f, &icon_config, brand_range);
auto mono_font = _rs.getRaw("SourceCodePro-Regular.ttf"); auto mono_font = _rs.getRaw("SourceCodePro-Regular.ttf"_s);
ImVector<ImWchar> range; ImVector<ImWchar> range;
ImFontGlyphRangesBuilder builder; ImFontGlyphRangesBuilder builder;
builder.AddRanges(io.Fonts->GetGlyphRangesDefault()); builder.AddRanges(io.Fonts->GetGlyphRangesDefault());
@ -566,14 +568,14 @@ auto SaveTool::findGameDataDirectory() -> bool {
Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree}; Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree};
if(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_NO_APPCONTAINER_REDIRECTION, nullptr, &localappdata_path) != S_OK) if(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_NO_APPCONTAINER_REDIRECTION, nullptr, &localappdata_path) != S_OK)
{ {
_lastError = "SHGetKnownFolderPath() failed in SaveTool::findGameDataDirectory()"; _lastError = "SHGetKnownFolderPath() failed in SaveTool::findGameDataDirectory()"_s;
return false; return false;
} }
_gameDataDir = Utility::Directory::join(Utility::Directory::fromNativeSeparators(Utility::Unicode::narrow(localappdata_path)), "MASS_Builder"); _gameDataDir = Utility::Directory::join(Utility::Directory::fromNativeSeparators(Utility::Unicode::narrow(localappdata_path)), "MASS_Builder");
if(!Utility::Directory::exists(_gameDataDir)) { if(!Utility::Directory::exists(_gameDataDir)) {
_lastError = _gameDataDir + " wasn't found. Make sure to play the game at least once."; _lastError = _gameDataDir + " wasn't found. Make sure to play the game at least once."_s;
return false; return false;
} }
@ -748,18 +750,18 @@ void SaveTool::drawGameState() {
} }
} }
void SaveTool::drawHelpMarker(const char* text, Float wrap_pos) { void SaveTool::drawHelpMarker(Containers::StringView text, Float wrap_pos) {
ImGui::TextUnformatted(ICON_FA_QUESTION_CIRCLE); ImGui::TextUnformatted(ICON_FA_QUESTION_CIRCLE);
drawTooltip(text, wrap_pos); drawTooltip(text, wrap_pos);
} }
void SaveTool::drawTooltip(const char* text, Float wrap_pos) { void SaveTool::drawTooltip(Containers::StringView text, Float wrap_pos) {
if(ImGui::IsItemHovered()){ if(ImGui::IsItemHovered()){
ImGui::BeginTooltip(); ImGui::BeginTooltip();
if(wrap_pos > 0.0f) { if(wrap_pos > 0.0f) {
ImGui::PushTextWrapPos(wrap_pos); ImGui::PushTextWrapPos(wrap_pos);
} }
ImGui::TextUnformatted(text); ImGui::TextUnformatted(text.data());
if(wrap_pos > 0.0f) { if(wrap_pos > 0.0f) {
ImGui::PopTextWrapPos(); ImGui::PopTextWrapPos();
} }
@ -767,8 +769,8 @@ void SaveTool::drawTooltip(const char* text, Float wrap_pos) {
} }
} }
void SaveTool::openUri(const std::string& uri) { void SaveTool::openUri(Containers::StringView uri) {
ShellExecuteW(nullptr, nullptr, Utility::Unicode::widen(uri).c_str(), nullptr, nullptr, SW_SHOWDEFAULT); ShellExecuteW(nullptr, nullptr, Utility::Unicode::widen(uri.data()).c_str(), nullptr, nullptr, SW_SHOWDEFAULT);
} }
void SaveTool::checkGameState() { void SaveTool::checkGameState() {

View File

@ -16,9 +16,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <thread> #include <thread>
#include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Utility/Configuration.h> #include <Corrade/Utility/Configuration.h>
#include <Corrade/Utility/Resource.h> #include <Corrade/Utility/Resource.h>
@ -43,6 +45,7 @@
#endif #endif
using namespace Corrade; using namespace Corrade;
using namespace Containers::Literals;
using namespace Magnum; using namespace Magnum;
class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener { class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener {
@ -106,11 +109,11 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
void drawGeneralInfo(); void drawGeneralInfo();
void drawResearchInventory(); void drawResearchInventory();
template<typename Getter, typename Setter> template<typename Getter, typename Setter>
void drawMaterialRow(const char* name, Int tier, Getter getter, Setter setter); void drawMaterialRow(Containers::StringView name, Int tier, Getter getter, Setter setter);
void drawUnavailableMaterialRow(const char* name, Int tier); void drawUnavailableMaterialRow(Containers::StringView name, Int tier);
void drawMassManager(); void drawMassManager();
auto drawDeleteMassPopup(int mass_index) -> ImGuiID; auto drawDeleteMassPopup(int mass_index) -> ImGuiID;
auto drawDeleteStagedMassPopup(const std::string& filename) -> ImGuiID; auto drawDeleteStagedMassPopup(Containers::StringView filename) -> ImGuiID;
void drawMassViewer(); void drawMassViewer();
void drawFrameInfo(); void drawFrameInfo();
@ -121,13 +124,14 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
void drawArmour(); void drawArmour();
void drawCustomArmourStyles(); void drawCustomArmourStyles();
void drawWeapons(); void drawWeapons();
void drawWeaponCategory(const char* name, Containers::ArrayView<Weapon> weapons_view, bool& dirty, const char* payload_type, const char* payload_tooltip); void drawWeaponCategory(Containers::StringView name, Containers::ArrayView<Weapon> weapons_view, bool& dirty,
Containers::StringView payload_type, Containers::StringView payload_tooltip);
void drawWeaponEditor(Weapon& weapon); void drawWeaponEditor(Weapon& weapon);
void drawGlobalStyles(); void drawGlobalStyles();
void drawTuning(); void drawTuning();
void drawDecalEditor(Decal& decal); void drawDecalEditor(Decal& decal);
void drawAccessoryEditor(Accessory& accessory, Containers::ArrayView<CustomStyle> style_view); void drawAccessoryEditor(Accessory& accessory, Containers::ArrayView<CustomStyle> style_view);
auto getStyleName(Int id, Containers::ArrayView<CustomStyle> view) -> const char*; auto getStyleName(Int id, Containers::ArrayView<CustomStyle> view) -> Containers::StringView;
enum DCSResult { enum DCSResult {
DCS_Fail, DCS_Fail,
@ -140,8 +144,8 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
void drawGameState(); void drawGameState();
// Convenience wrappers over ImGui stuff // Convenience wrappers over ImGui stuff
void drawHelpMarker(const char* text, Float wrap_pos = 0.0f); void drawHelpMarker(Containers::StringView text, Float wrap_pos = 0.0f);
void drawTooltip(const char* text, Float wrap_pos = 0.0f); void drawTooltip(Containers::StringView text, Float wrap_pos = 0.0f);
template<typename Functor, typename... Args> template<typename Functor, typename... Args>
auto drawUnsafeWidget(Functor func, Args... args) -> bool { auto drawUnsafeWidget(Functor func, Args... args) -> bool {
@ -163,7 +167,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
// Also, func should be a lambda if there are any default arguments, like ImGui::Button(), etc... // Also, func should be a lambda if there are any default arguments, like ImGui::Button(), etc...
template<typename... Args> template<typename... Args>
void drawUnsafeText(const char* text, Args... args) { // Alternative to the above, for ImGui::Text*() variants. void drawUnsafeText(Containers::StringView text, Args... args) { // Alternative to the above, for ImGui::Text*() variants.
if(!_unsafeMode && _gameState != GameState::NotRunning) { if(!_unsafeMode && _gameState != GameState::NotRunning) {
ImGui::TextDisabled(text, std::forward<Args>(args)...); ImGui::TextDisabled(text, std::forward<Args>(args)...);
} }
@ -173,19 +177,19 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
} }
template<typename... Args> template<typename... Args>
void drawAlignedText(const char* text, Args... args) { void drawAlignedText(Containers::StringView text, Args... args) {
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
ImGui::Text(text, std::forward<Args>(args)...); ImGui::Text(text.data(), std::forward<Args>(args)...);
} }
void openUri(const std::string& uri); void openUri(Containers::StringView uri);
void checkGameState(); void checkGameState();
void checkForUpdates(); void checkForUpdates();
Utility::Configuration _conf{"MassBuilderSaveTool.ini"}; Utility::Configuration _conf{"MassBuilderSaveTool.ini"_s};
Utility::Resource _rs{"assets"}; Utility::Resource _rs{"assets"_s};
// GUI-related members // GUI-related members
ImGuiIntegration::Context _imgui{NoCreate}; ImGuiIntegration::Context _imgui{NoCreate};
@ -213,22 +217,22 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
UnsignedInt _initEventId; UnsignedInt _initEventId;
UnsignedInt _updateEventId; UnsignedInt _updateEventId;
std::string _lastError; Containers::String _lastError;
std::string _gameDataDir; Containers::String _gameDataDir;
std::string _configDir; Containers::String _configDir;
std::string _saveDir; Containers::String _saveDir;
std::string _screenshotsDir; Containers::String _screenshotsDir;
std::string _backupsDir; Containers::String _backupsDir;
std::string _stagingDir; Containers::String _stagingDir;
std::string _armouryDir; Containers::String _armouryDir;
std::string _armoursDir; Containers::String _armoursDir;
std::string _weaponsDir; Containers::String _weaponsDir;
std::string _stylesDir; Containers::String _stylesDir;
enum class GameState : UnsignedByte { enum class GameState : UnsignedByte {
Unknown, NotRunning, Running Unknown, NotRunning, Running
} _gameState{GameState::Unknown}; } _gameState{GameState::Unknown};
SDL_TimerID _gameCheckTimerId = 0; SDL_TimerID _gameCheckTimerId = 0;
@ -260,9 +264,9 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
bool _unsafeMode{false}; bool _unsafeMode{false};
bool _updateAvailable{false}; bool _updateAvailable{false};
std::string _latestVersion; Containers::String _latestVersion;
std::string _releaseLink; Containers::String _releaseLink;
std::string _downloadLink; Containers::String _downloadLink;
bool _jointsDirty{false}; bool _jointsDirty{false};
bool _stylesDirty{false}; bool _stylesDirty{false};

View File

@ -43,7 +43,7 @@ void SaveTool::drawManager() {
} }
drawAlignedText("Current profile: %s (%s)", drawAlignedText("Current profile: %s (%s)",
_currentProfile->companyName().c_str(), _currentProfile->companyName(),
_currentProfile->type() == ProfileType::Demo ? "demo" : "full game"); _currentProfile->type() == ProfileType::Demo ? "demo" : "full game");
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button(ICON_FA_ARROW_LEFT " Back to profile manager")) { if(ImGui::Button(ICON_FA_ARROW_LEFT " Back to profile manager")) {
@ -220,7 +220,7 @@ void SaveTool::drawGeneralInfo() {
for(auto& c : name_buf) { for(auto& c : name_buf) {
c = '\0'; c = '\0';
} }
std::strncpy(name_buf.data(), _currentProfile->companyName().c_str(), 32); std::strncpy(name_buf.data(), _currentProfile->companyName().data(), 32);
ImGui::OpenPopup("name_edit"); ImGui::OpenPopup("name_edit");
} }
if(drawRenamePopup(name_buf)) { if(drawRenamePopup(name_buf)) {
@ -257,17 +257,17 @@ void SaveTool::drawGeneralInfo() {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
for(const auto& sp : story_progress) { for(const auto& sp : story_progress) {
if(ImGui::BeginMenu(sp.chapter)) { if(ImGui::BeginMenu(sp.chapter.data())) {
if(!sp.after) { if(!sp.after) {
if(ImGui::MenuItem(sp.point)) { if(ImGui::MenuItem(sp.point.data())) {
if(!_currentProfile->setStoryProgress(sp.id)) { if(!_currentProfile->setStoryProgress(sp.id)) {
_queue.addToast(Toast::Type::Error, _currentProfile->lastError()); _queue.addToast(Toast::Type::Error, _currentProfile->lastError());
} }
} }
} }
else { else {
if(ImGui::BeginMenu(sp.after)) { if(ImGui::BeginMenu(sp.after.data())) {
if(ImGui::MenuItem(sp.point)) { if(ImGui::MenuItem(sp.point.data())) {
if(!_currentProfile->setStoryProgress(sp.id)) { if(!_currentProfile->setStoryProgress(sp.id)) {
_queue.addToast(Toast::Type::Error, _currentProfile->lastError()); _queue.addToast(Toast::Type::Error, _currentProfile->lastError());
} }
@ -388,7 +388,7 @@ void SaveTool::drawResearchInventory() {
} }
template<typename Getter, typename Setter> template<typename Getter, typename Setter>
void SaveTool::drawMaterialRow(const char* name, Int tier, Getter getter, Setter setter) { void SaveTool::drawMaterialRow(Containers::StringView name, Int tier, Getter getter, Setter setter) {
static_assert(std::is_same<decltype(getter()), Int>::value, "getter doesn't return an Int, and/or doesn't take zero arguments."); static_assert(std::is_same<decltype(getter()), Int>::value, "getter doesn't return an Int, and/or doesn't take zero arguments.");
static_assert(std::is_same<decltype(setter(0)), bool>::value, "setter doesn't return a bool, and/or doesn't take a single Int as an argument."); static_assert(std::is_same<decltype(setter(0)), bool>::value, "setter doesn't return a bool, and/or doesn't take a single Int as an argument.");
@ -396,13 +396,13 @@ void SaveTool::drawMaterialRow(const char* name, Int tier, Getter getter, Setter
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("T%i", tier); ImGui::Text("T%i", tier);
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::TextUnformatted(name); ImGui::TextUnformatted(name.data());
ImGui::TableSetColumnIndex(2); ImGui::TableSetColumnIndex(2);
if(getter() != -1) { if(getter() != -1) {
ImGui::Text("%i", getter()); ImGui::Text("%i", getter());
if(_cheatMode) { if(_cheatMode) {
ImGui::TableSetColumnIndex(3); ImGui::TableSetColumnIndex(3);
ImGui::PushID(name); ImGui::PushID(name.data());
static Int var = 0; static Int var = 0;
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_EDIT)) { if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_EDIT)) {
(var) = getter(); (var) = getter();
@ -421,12 +421,12 @@ void SaveTool::drawMaterialRow(const char* name, Int tier, Getter getter, Setter
} }
} }
void SaveTool::drawUnavailableMaterialRow(const char* name, Int tier) { void SaveTool::drawUnavailableMaterialRow(Containers::StringView name, Int tier) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("T%i", tier); ImGui::Text("T%i", tier);
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::TextUnformatted(name); ImGui::TextUnformatted(name.data());
ImGui::TableSetColumnIndex(2); ImGui::TableSetColumnIndex(2);
ImGui::TextDisabled("Unavailable as of game version " SUPPORTED_GAME_VERSION); ImGui::TextDisabled("Unavailable as of game version " SUPPORTED_GAME_VERSION);
} }
@ -472,7 +472,7 @@ void SaveTool::drawMassManager() {
drag_drop_index = i; drag_drop_index = i;
ImGui::SetDragDropPayload("Mass", &drag_drop_index, sizeof(int)); ImGui::SetDragDropPayload("Mass", &drag_drop_index, sizeof(int));
ImGui::Text("%s - Hangar %.2d", (*_massManager->hangar(i).name()).c_str(), i + 1); ImGui::Text("%s - Hangar %.2d", _massManager->hangar(i).name().data(), i + 1);
ImGui::EndDragDropSource(); ImGui::EndDragDropSource();
} }
@ -518,7 +518,7 @@ void SaveTool::drawMassManager() {
ImGui::TextDisabled("<invalid>"); ImGui::TextDisabled("<invalid>");
break; break;
case Mass::State::Valid: case Mass::State::Valid:
ImGui::TextUnformatted((*_massManager->hangar(i).name()).c_str()); ImGui::TextUnformatted(_massManager->hangar(i).name().data());
break; break;
} }
@ -557,7 +557,7 @@ void SaveTool::drawMassManager() {
drawDeleteMassPopup(mass_to_delete); drawDeleteMassPopup(mass_to_delete);
static ImGuiID staged_mass_deletion_popup_ID = drawDeleteStagedMassPopup(""); static ImGuiID staged_mass_deletion_popup_ID = drawDeleteStagedMassPopup("");
static Containers::Reference<const std::string> staged_mass_to_delete{empty_str}; static Containers::StringView staged_mass_to_delete;
if(ImGui::BeginTable("##StagingArea", 2, if(ImGui::BeginTable("##StagingArea", 2,
ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersOuter|ImGuiTableFlags_RowBg)) ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersOuter|ImGuiTableFlags_RowBg))
@ -587,15 +587,15 @@ void SaveTool::drawMassManager() {
if(ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) { if(ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) {
ImGui::SetDragDropPayload("StagedMass", &(pair.first), sizeof(std::string)); ImGui::SetDragDropPayload("StagedMass", &(pair.first), sizeof(std::string));
ImGui::Text("%s - Staged", pair.second.c_str()); ImGui::Text("%s - Staged", pair.second.data());
ImGui::EndDragDropSource(); ImGui::EndDragDropSource();
} }
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::PushID(pair.first.c_str()); ImGui::PushID(pair.first.data());
if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) { if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
staged_mass_to_delete = Containers::Reference<const std::string>{pair.first}; staged_mass_to_delete = pair.first;
ImGui::OpenPopup(staged_mass_deletion_popup_ID); ImGui::OpenPopup(staged_mass_deletion_popup_ID);
} }
ImGui::PopID(); ImGui::PopID();
@ -622,7 +622,7 @@ void SaveTool::drawMassManager() {
ImGui::EndDragDropTarget(); ImGui::EndDragDropTarget();
} }
drawDeleteStagedMassPopup(staged_mass_to_delete.get()); drawDeleteStagedMassPopup(staged_mass_to_delete);
} }
auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID { auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID {
@ -651,7 +651,7 @@ auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID {
} }
else { else {
ImGui::Text("Are you sure you want to delete the M.A.S.S. named %s in hangar %.2i ? This operation is irreversible.", ImGui::Text("Are you sure you want to delete the M.A.S.S. named %s in hangar %.2i ? This operation is irreversible.",
(*_massManager->hangar(mass_index).name()).c_str(), mass_index + 1); _massManager->hangar(mass_index).name().data(), mass_index + 1);
} }
ImGui::PopTextWrapPos(); ImGui::PopTextWrapPos();
@ -681,7 +681,7 @@ auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID {
return 0; return 0;
} }
auto SaveTool::drawDeleteStagedMassPopup(const std::string& filename) -> ImGuiID { auto SaveTool::drawDeleteStagedMassPopup(Containers::StringView filename) -> ImGuiID {
if(!ImGui::BeginPopupModal("Confirmation##DeleteStagedMassConfirmation", nullptr, if(!ImGui::BeginPopupModal("Confirmation##DeleteStagedMassConfirmation", nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove)) ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
{ {
@ -690,7 +690,7 @@ auto SaveTool::drawDeleteStagedMassPopup(const std::string& filename) -> ImGuiID
ImGui::PushTextWrapPos(windowSize().x() * 0.40f); ImGui::PushTextWrapPos(windowSize().x() * 0.40f);
ImGui::Text("Are you sure you want to delete the staged M.A.S.S. named %s ? This operation is irreversible.", ImGui::Text("Are you sure you want to delete the staged M.A.S.S. named %s ? This operation is irreversible.",
_massManager->stagedMasses().at(filename).c_str()); _massManager->stagedMasses().at(filename).data());
ImGui::PopTextWrapPos(); ImGui::PopTextWrapPos();
if(ImGui::BeginTable("##DeleteStagedMassLayout", 2)) { if(ImGui::BeginTable("##DeleteStagedMassLayout", 2)) {

View File

@ -61,8 +61,8 @@ void SaveTool::drawMassViewer() {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("M.A.S.S.: %s", (*_currentMass->name()).c_str()); ImGui::Text("M.A.S.S.: %s", _currentMass->name().data());
drawTooltip(_currentMass->filename().c_str()); drawTooltip(_currentMass->filename());
ImGui::TableSetColumnIndex(2); ImGui::TableSetColumnIndex(2);
if(_currentMass->dirty()) { if(_currentMass->dirty()) {
@ -298,14 +298,14 @@ auto SaveTool::drawCustomStyle(CustomStyle& style) -> DCSResult {
} }
if(ImGui::BeginMenuBar()) { if(ImGui::BeginMenuBar()) {
ImGui::TextUnformatted(style.name.c_str()); ImGui::TextUnformatted(style.name.data());
static Containers::StaticArray<33, char> name_buf{ValueInit}; static Containers::StaticArray<33, char> name_buf{ValueInit};
if(ImGui::SmallButton(ICON_FA_EDIT " Rename")) { if(ImGui::SmallButton(ICON_FA_EDIT " Rename")) {
for(auto& c : name_buf) { for(auto& c : name_buf) {
c = '\0'; c = '\0';
} }
std::strncpy(name_buf.data(), style.name.c_str(), 32); std::strncpy(name_buf.data(), style.name.data(), 32);
ImGui::OpenPopup("name_edit"); ImGui::OpenPopup("name_edit");
} }
if(drawRenamePopup(name_buf)) { if(drawRenamePopup(name_buf)) {
@ -516,9 +516,9 @@ void SaveTool::drawAccessoryEditor(Accessory& accessory, Containers::ArrayView<C
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushMultiItemsWidths(2, ImGui::CalcItemWidth()); ImGui::PushMultiItemsWidths(2, ImGui::CalcItemWidth());
if(ImGui::BeginCombo("##Style1", getStyleName(accessory.styles[0], style_view))) { if(ImGui::BeginCombo("##Style1", getStyleName(accessory.styles[0], style_view).data())) {
for(const auto& style : style_names) { for(const auto& style : style_names) {
if(ImGui::Selectable(getStyleName(style.first, style_view), accessory.styles[0] == style.first)) { if(ImGui::Selectable(getStyleName(style.first, style_view).data(), accessory.styles[0] == style.first)) {
accessory.styles[0] = style.first; accessory.styles[0] = style.first;
} }
} }
@ -527,9 +527,9 @@ void SaveTool::drawAccessoryEditor(Accessory& accessory, Containers::ArrayView<C
} }
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
if(ImGui::BeginCombo("##Style2", getStyleName(accessory.styles[1], style_view))) { if(ImGui::BeginCombo("##Style2", getStyleName(accessory.styles[1], style_view).data())) {
for(const auto& style : style_names) { for(const auto& style : style_names) {
if(ImGui::Selectable(getStyleName(style.first, style_view), accessory.styles[1] == style.first)) { if(ImGui::Selectable(getStyleName(style.first, style_view).data(), accessory.styles[1] == style.first)) {
accessory.styles[1] = style.first; accessory.styles[1] = style.first;
} }
} }
@ -594,12 +594,12 @@ void SaveTool::drawAccessoryEditor(Accessory& accessory, Containers::ArrayView<C
ImGui::EndGroup(); ImGui::EndGroup();
} }
auto SaveTool::getStyleName(Int id, Containers::ArrayView<CustomStyle> view) -> const char* { auto SaveTool::getStyleName(Int id, Containers::ArrayView<CustomStyle> view) -> Containers::StringView {
if(id >= 0 && id <= 15) { if(id >= 0 && id <= 15) {
return view[id].name.c_str(); return view[id].name;
} }
else if(id >= 50 && id <= 65) { else if(id >= 50 && id <= 65) {
return _currentMass->globalStyles()[id - 50].name.c_str(); return _currentMass->globalStyles()[id - 50].name;
} }
else { else {
return style_names.at(id); return style_names.at(id);

View File

@ -35,10 +35,10 @@ void SaveTool::drawArmour() {
return; return;
} }
static const char* slot_labels[] = { static Containers::StringView slot_labels[] = {
#define c(enumerator, strenum, name) name, #define c(enumerator, strenum, name) name,
#include "../Maps/ArmourSlots.hpp" #include "../Maps/ArmourSlots.hpp"
#undef c #undef c
}; };
for(UnsignedInt i = 0; i < _currentMass->armourParts().size(); i++) { for(UnsignedInt i = 0; i < _currentMass->armourParts().size(); i++) {
@ -51,10 +51,10 @@ void SaveTool::drawArmour() {
std::memset(header, '\0', 129); std::memset(header, '\0', 129);
if(armour_sets.find(part.id) != armour_sets.cend()) { if(armour_sets.find(part.id) != armour_sets.cend()) {
std::snprintf(header, 128, "%s: %s###%u", slot_labels[UnsignedInt(part.slot)], armour_sets.at(part.id).name, UnsignedInt(part.slot)); std::snprintf(header, 128, "%s: %s###%u", slot_labels[UnsignedInt(part.slot)].data(), armour_sets.at(part.id).name.data(), UnsignedInt(part.slot));
} }
else { else {
std::snprintf(header, 128, "%s: %i###%u", slot_labels[UnsignedInt(part.slot)], part.id, UnsignedInt(part.slot)); std::snprintf(header, 128, "%s: %i###%u", slot_labels[UnsignedInt(part.slot)].data(), part.id, UnsignedInt(part.slot));
} }
if(ImGui::CollapsingHeader(header)) { if(ImGui::CollapsingHeader(header)) {
@ -62,9 +62,9 @@ void SaveTool::drawArmour() {
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() * 0.491f); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() * 0.491f);
if(ImGui::BeginListBox("##ChangePart")) { if(ImGui::BeginListBox("##ChangePart")) {
if(std::strncmp("Neck", slot_labels[UnsignedInt(part.slot)], 4) != 0) { if(std::strncmp("Neck", slot_labels[UnsignedInt(part.slot)].data(), 4) != 0) {
for(auto& set : armour_sets) { for(auto& set : armour_sets) {
if(ImGui::Selectable(set.second.name, set.first == part.id, ImGuiSelectableFlags_SpanAvailWidth)) { if(ImGui::Selectable(set.second.name.data(), set.first == part.id, ImGuiSelectableFlags_SpanAvailWidth)) {
part.id = set.first; part.id = set.first;
} }
} }
@ -75,7 +75,7 @@ void SaveTool::drawArmour() {
continue; continue;
} }
if(ImGui::Selectable(set.second.name, set.first == part.id, ImGuiSelectableFlags_SpanAvailWidth)) { if(ImGui::Selectable(set.second.name.data(), set.first == part.id, ImGuiSelectableFlags_SpanAvailWidth)) {
part.id = set.first; part.id = set.first;
} }
} }
@ -103,9 +103,9 @@ void SaveTool::drawArmour() {
ImGui::PushID(j); ImGui::PushID(j);
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() - 2.0f); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() - 2.0f);
if(ImGui::BeginCombo("##Style", getStyleName(part.styles[j], _currentMass->armourCustomStyles()))) { if(ImGui::BeginCombo("##Style", getStyleName(part.styles[j], _currentMass->armourCustomStyles()).data())) {
for(const auto& style : style_names) { for(const auto& style : style_names) {
if(ImGui::Selectable(getStyleName(style.first, _currentMass->armourCustomStyles()), part.styles[j] == style.first)) { if(ImGui::Selectable(getStyleName(style.first, _currentMass->armourCustomStyles()).data(), part.styles[j] == style.first)) {
part.styles[j] = style.first; part.styles[j] = style.first;
} }
} }

View File

@ -205,9 +205,9 @@ void SaveTool::drawFrameStyles() {
ImGui::PushID(i); ImGui::PushID(i);
if(ImGui::BeginCombo("##Style", getStyleName(_currentMass->frameStyles()[i], _currentMass->frameCustomStyles()))) { if(ImGui::BeginCombo("##Style", getStyleName(_currentMass->frameStyles()[i], _currentMass->frameCustomStyles()).data())) {
for(const auto& style : style_names) { for(const auto& style : style_names) {
if(ImGui::Selectable(getStyleName(style.first, _currentMass->frameCustomStyles()), _currentMass->frameStyles()[i] == style.first)) { if(ImGui::Selectable(getStyleName(style.first, _currentMass->frameCustomStyles()).data(), _currentMass->frameStyles()[i] == style.first)) {
_currentMass->frameStyles()[i] = style.first; _currentMass->frameStyles()[i] = style.first;
_stylesDirty = true; _stylesDirty = true;
} }

View File

@ -234,14 +234,14 @@ void SaveTool::drawWeapons() {
ImGui::EndGroup(); ImGui::EndGroup();
} }
void SaveTool::drawWeaponCategory(const char* name, Containers::ArrayView<Weapon> weapons_view, bool& dirty, void SaveTool::drawWeaponCategory(Containers::StringView name, Containers::ArrayView<Weapon> weapons_view, bool& dirty,
const char* payload_type, const char* payload_tooltip) Containers::StringView payload_type, Containers::StringView payload_tooltip)
{ {
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextUnformatted(name); ImGui::TextUnformatted(name.data());
ImGui::PushID(payload_type); ImGui::PushID(payload_type.data());
for(UnsignedInt i = 0; i < weapons_view.size(); i++) { for(UnsignedInt i = 0; i < weapons_view.size(); i++) {
auto& weapon = weapons_view[i]; auto& weapon = weapons_view[i];
@ -251,21 +251,21 @@ void SaveTool::drawWeaponCategory(const char* name, Containers::ArrayView<Weapon
ImGui::PushID(i); ImGui::PushID(i);
if(ImGui::Selectable(weapon.name.c_str(), _currentWeapon == &weapon)) { if(ImGui::Selectable(weapon.name.data(), _currentWeapon == &weapon)) {
_currentWeapon = &weapon; _currentWeapon = &weapon;
} }
if(ImGui::BeginDragDropSource()) { if(ImGui::BeginDragDropSource()) {
ImGui::SetDragDropPayload(payload_type, &i, sizeof(UnsignedInt)); ImGui::SetDragDropPayload(payload_type.data(), &i, sizeof(UnsignedInt));
if(ImGui::GetIO().KeyCtrl) { if(ImGui::GetIO().KeyCtrl) {
ImGui::Text("%s %i - %s (copy)", payload_tooltip, i + 1, weapon.name.c_str()); ImGui::Text("%s %i - %s (copy)", payload_tooltip.data(), i + 1, weapon.name.data());
} }
else { else {
ImGui::Text("%s %i - %s", payload_tooltip, i + 1, weapon.name.c_str()); ImGui::Text("%s %i - %s", payload_tooltip.data(), i + 1, weapon.name.data());
} }
ImGui::EndDragDropSource(); ImGui::EndDragDropSource();
} }
if(ImGui::BeginDragDropTarget()) { if(ImGui::BeginDragDropTarget()) {
if(const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(payload_type)) { if(const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(payload_type.data())) {
int index = *static_cast<int*>(payload->Data); int index = *static_cast<int*>(payload->Data);
if(!ImGui::GetIO().KeyCtrl) { if(!ImGui::GetIO().KeyCtrl) {
@ -302,13 +302,15 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) {
return; return;
} }
static const char* labels[] { static Containers::StringView labels[] {
#define c(enumerator, strenum, name) name, #define c(enumerator, strenum, name) name,
#include "../Maps/WeaponTypes.hpp" #include "../Maps/WeaponTypes.hpp"
#undef c #undef c
}; };
drawAlignedText("%s: %s", labels[UnsignedInt(weapon.type)], weapon.name.c_str()); //test
drawAlignedText("%s: %s", labels[UnsignedInt(weapon.type)], weapon.name.data());
ImGui::SameLine(); ImGui::SameLine();
@ -317,7 +319,7 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) {
for(auto& c : name_buf) { for(auto& c : name_buf) {
c = '\0'; c = '\0';
} }
std::strncpy(name_buf.data(), weapon.name.c_str(), 32); std::strncpy(name_buf.data(), weapon.name.data(), 32);
ImGui::OpenPopup("name_edit"); ImGui::OpenPopup("name_edit");
} }
if(drawRenamePopup(name_buf)) { if(drawRenamePopup(name_buf)) {
@ -425,9 +427,9 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) {
ImGui::PushID(i); ImGui::PushID(i);
if(ImGui::BeginCombo("##Style", getStyleName(part.styles[i], weapon.customStyles))) { if(ImGui::BeginCombo("##Style", getStyleName(part.styles[i], weapon.customStyles).data())) {
for(const auto& style: style_names) { for(const auto& style: style_names) {
if(ImGui::Selectable(getStyleName(style.first, weapon.customStyles), if(ImGui::Selectable(getStyleName(style.first, weapon.customStyles).data(),
part.styles[i] == style.first)) { part.styles[i] == style.first)) {
part.styles[i] = style.first; part.styles[i] = style.first;
} }

View File

@ -50,7 +50,7 @@ void SaveTool::drawProfileManager() {
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
if(ImGui::SmallButton("Refresh")) { if(ImGui::SmallButton("Refresh")) {
if(!_profileManager->refreshProfiles()) { if(!_profileManager->refreshProfiles()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error in ProfileManager", _profileManager->lastError().c_str(), window()); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error in ProfileManager", _profileManager->lastError().data(), window());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -81,7 +81,7 @@ void SaveTool::drawProfileManager() {
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::PushID(i); ImGui::PushID(i);
if(ImGui::Selectable(_profileManager->profiles()[i].companyName().c_str(), false, if(ImGui::Selectable(_profileManager->profiles()[i].companyName().data(), false,
ImGuiSelectableFlags_SpanAllColumns|ImGuiSelectableFlags_AllowItemOverlap)) ImGuiSelectableFlags_SpanAllColumns|ImGuiSelectableFlags_AllowItemOverlap))
{ {
_currentProfile = _profileManager->getProfile(i); _currentProfile = _profileManager->getProfile(i);
@ -132,7 +132,7 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID {
{ {
ImGui::PushTextWrapPos(windowSize().x() * 0.40f); ImGui::PushTextWrapPos(windowSize().x() * 0.40f);
ImGui::Text("Are you sure you want to restore the %s backup from %.4i-%.2i-%.2i %.2i:%.2i:%.2i ? Any existing data will be overwritten.", ImGui::Text("Are you sure you want to restore the %s backup from %.4i-%.2i-%.2i %.2i:%.2i:%.2i ? Any existing data will be overwritten.",
_profileManager->backups()[backup_index].company.c_str(), _profileManager->backups()[backup_index].company.data(),
_profileManager->backups()[backup_index].timestamp.year, _profileManager->backups()[backup_index].timestamp.year,
_profileManager->backups()[backup_index].timestamp.month, _profileManager->backups()[backup_index].timestamp.month,
_profileManager->backups()[backup_index].timestamp.day, _profileManager->backups()[backup_index].timestamp.day,
@ -171,7 +171,7 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID {
{ {
ImGui::PushTextWrapPos(windowSize().x() * 0.40f); ImGui::PushTextWrapPos(windowSize().x() * 0.40f);
ImGui::Text("Are you sure you want to delete the %s backup from %.4i-%.2i-%.2i %.2i:%.2i:%.2i ? This operation is irreversible.", ImGui::Text("Are you sure you want to delete the %s backup from %.4i-%.2i-%.2i %.2i:%.2i:%.2i ? This operation is irreversible.",
_profileManager->backups()[backup_index].company.c_str(), _profileManager->backups()[backup_index].company.data(),
_profileManager->backups()[backup_index].timestamp.year, _profileManager->backups()[backup_index].timestamp.year,
_profileManager->backups()[backup_index].timestamp.month, _profileManager->backups()[backup_index].timestamp.month,
_profileManager->backups()[backup_index].timestamp.day, _profileManager->backups()[backup_index].timestamp.day,
@ -249,11 +249,11 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::TextUnformatted(_profileManager->backups()[i].company.c_str()); ImGui::TextUnformatted(_profileManager->backups()[i].company.data());
if(ImGui::IsItemHovered()) { if(ImGui::IsItemHovered()) {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
for(const auto& file : _profileManager->backups()[i].includedFiles) { for(const auto& file : _profileManager->backups()[i].includedFiles) {
ImGui::TextUnformatted(file.c_str()); ImGui::TextUnformatted(file.data());
} }
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
@ -361,7 +361,7 @@ auto SaveTool::drawDeleteProfilePopup(std::size_t profile_index) -> ImGuiID {
ImGui::PushTextWrapPos(windowSize().x() * 0.40f); ImGui::PushTextWrapPos(windowSize().x() * 0.40f);
ImGui::Text("Are you sure you want to delete the %s %s profile ? This operation is irreversible.", ImGui::Text("Are you sure you want to delete the %s %s profile ? This operation is irreversible.",
_profileManager->profiles()[profile_index].companyName().c_str(), _profileManager->profiles()[profile_index].companyName().data(),
_profileManager->profiles()[profile_index].type() == ProfileType::Demo ? "demo" : "full game"); _profileManager->profiles()[profile_index].type() == ProfileType::Demo ? "demo" : "full game");
ImGui::PopTextWrapPos(); ImGui::PopTextWrapPos();

View File

@ -17,6 +17,7 @@
#include "SaveTool.h" #include "SaveTool.h"
#include <Corrade/version.h> #include <Corrade/version.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/version.h> #include <Magnum/version.h>
#include <Magnum/versionIntegration.h> #include <Magnum/versionIntegration.h>
@ -57,7 +58,7 @@ void SaveTool::drawAbout() {
ImGui::TextWrapped("This application, made for the M.A.S.S. Builder community by Guillaume Jacquemin (aka William JCM), " ImGui::TextWrapped("This application, made for the M.A.S.S. Builder community by Guillaume Jacquemin (aka William JCM), "
"is a rewrite of the wxWidgets-powered M.A.S.S. Builder Save Tool (formerly known as wxMASSManager)."); "is a rewrite of the wxWidgets-powered M.A.S.S. Builder Save Tool (formerly known as wxMASSManager).");
const char* repo = "https://williamjcm.ovh/git/williamjcm/MassBuilderSaveTool"; auto repo = "https://williamjcm.ovh/git/williamjcm/MassBuilderSaveTool";
drawAlignedText(ICON_FA_GIT_ALT " %s", repo); drawAlignedText(ICON_FA_GIT_ALT " %s", repo);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -74,9 +75,9 @@ void SaveTool::drawAbout() {
ImGui::TextWrapped("This application is made available under the terms of the GNU General Public License, version 3, the full text of which is available below:"); ImGui::TextWrapped("This application is made available under the terms of the GNU General Public License, version 3, the full text of which is available below:");
if(ImGui::BeginChild("##GPL", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##GPL", {0.0f, windowSize().y() * 0.3f}, true)) {
static const auto licence = _rs.get("COPYING"); static auto licence = _rs.getRaw("COPYING");
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(licence.c_str()); ImGui::TextUnformatted(licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -89,7 +90,7 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("Corrade", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("Corrade", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::Text("Version used: %s", CORRADE_VERSION_STRING); ImGui::Text("Version used: %s", CORRADE_VERSION_STRING);
const char* corrade_website = "https://magnum.graphics/corrade"; auto corrade_website = "https://magnum.graphics/corrade";
drawAlignedText(ICON_FA_GLOBE " %s", corrade_website); drawAlignedText(ICON_FA_GLOBE " %s", corrade_website);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -102,10 +103,10 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Licence: MIT"); ImGui::TextUnformatted("Licence: MIT");
static const auto corrade_licence = _rs.get("COPYING.Corrade"); static auto corrade_licence = _rs.getRaw("COPYING.Corrade");
if(ImGui::BeginChild("##CorradeLicence", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##CorradeLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(corrade_licence.c_str()); ImGui::TextUnformatted(corrade_licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -117,7 +118,7 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Versions used:"); ImGui::TextUnformatted("Versions used:");
ImGui::BulletText("Magnum: %s", MAGNUM_VERSION_STRING); ImGui::BulletText("Magnum: %s", MAGNUM_VERSION_STRING);
ImGui::BulletText("Integration: %s", MAGNUMINTEGRATION_VERSION_STRING); ImGui::BulletText("Integration: %s", MAGNUMINTEGRATION_VERSION_STRING);
const char* magnum_website = "https://magnum.graphics"; auto magnum_website = "https://magnum.graphics";
drawAlignedText(ICON_FA_GLOBE " %s", magnum_website); drawAlignedText(ICON_FA_GLOBE " %s", magnum_website);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -130,10 +131,10 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Licence: MIT"); ImGui::TextUnformatted("Licence: MIT");
static const auto magnum_licence = _rs.get("COPYING.Magnum"); static auto magnum_licence = _rs.getRaw("COPYING.Magnum");
if(ImGui::BeginChild("##MagnumLicence", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##MagnumLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(magnum_licence.c_str()); ImGui::TextUnformatted(magnum_licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -143,7 +144,7 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("Dear ImGui", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("Dear ImGui", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::Text("Version used: %s", IMGUI_VERSION); ImGui::Text("Version used: %s", IMGUI_VERSION);
const char* imgui_repo = "https://github.com/ocornut/imgui"; auto imgui_repo = "https://github.com/ocornut/imgui";
drawAlignedText(ICON_FA_GITHUB " %s", imgui_repo); drawAlignedText(ICON_FA_GITHUB " %s", imgui_repo);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -156,10 +157,10 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Licence: MIT"); ImGui::TextUnformatted("Licence: MIT");
static const auto imgui_licence = _rs.get("LICENSE.ImGui"); static auto imgui_licence = _rs.getRaw("LICENSE.ImGui");
if(ImGui::BeginChild("##ImGuiLicence", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##ImGuiLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(imgui_licence.c_str()); ImGui::TextUnformatted(imgui_licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -169,7 +170,7 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("Simple DirectMedia Layer (SDL) 2", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("Simple DirectMedia Layer (SDL) 2", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::Text("Version used: %i.%i.%i", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL); ImGui::Text("Version used: %i.%i.%i", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
const char* sdl_website = "https://www.libsdl.org/"; auto sdl_website = "https://www.libsdl.org/";
drawAlignedText(ICON_FA_GLOBE " %s", sdl_website); drawAlignedText(ICON_FA_GLOBE " %s", sdl_website);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -182,10 +183,10 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Licence: zlib"); ImGui::TextUnformatted("Licence: zlib");
static const auto sdl_licence = _rs.get("LICENSE.SDL"); static auto sdl_licence = _rs.getRaw("LICENSE.SDL");
if(ImGui::BeginChild("##SDLLicence", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##SDLLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(sdl_licence.c_str()); ImGui::TextUnformatted(sdl_licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -195,7 +196,7 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("libzip", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("libzip", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::Text("Version used: %s", LIBZIP_VERSION); ImGui::Text("Version used: %s", LIBZIP_VERSION);
const char* libzip_website = "https://libzip.org/"; auto libzip_website = "https://libzip.org/";
drawAlignedText(ICON_FA_GLOBE " %s", libzip_website); drawAlignedText(ICON_FA_GLOBE " %s", libzip_website);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -208,10 +209,10 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Licence: 3-clause BSD"); ImGui::TextUnformatted("Licence: 3-clause BSD");
static const auto libzip_licence = _rs.get("LICENSE.libzip"); static auto libzip_licence = _rs.getRaw("LICENSE.libzip");
if(ImGui::BeginChild("##libzipLicence", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##libzipLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(libzip_licence.c_str()); ImGui::TextUnformatted(libzip_licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -220,11 +221,11 @@ void SaveTool::drawAbout() {
} }
if(ImGui::TreeNodeEx("Entropia File System Watcher (efsw)", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("Entropia File System Watcher (efsw)", ImGuiTreeNodeFlags_SpanAvailWidth)) {
const char* efsw_repo = "https://github.com/SpartanJ/efsw"; auto efsw_repo = "https://github.com/SpartanJ/efsw";
drawAlignedText(ICON_FA_GITHUB " %s", efsw_repo); drawAlignedText(ICON_FA_GITHUB " %s", efsw_repo);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(efsw_repo); ImGui::SetClipboardText(efsw_repo.data());
} }
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Open in browser")) { if(ImGui::Button("Open in browser")) {
@ -233,10 +234,10 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Licence: MIT"); ImGui::TextUnformatted("Licence: MIT");
static const auto efsw_licence = _rs.get("LICENSE.efsw"); static auto efsw_licence = _rs.getRaw("LICENSE.efsw");
if(ImGui::BeginChild("##efswLicence", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##efswLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(efsw_licence.c_str()); ImGui::TextUnformatted(efsw_licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -245,7 +246,7 @@ void SaveTool::drawAbout() {
} }
if(ImGui::TreeNodeEx("C++ Requests (cpr)", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("C++ Requests (cpr)", ImGuiTreeNodeFlags_SpanAvailWidth)) {
const char* cpr_website = "https://whoshuu.github.io/cpr/"; auto cpr_website = "https://whoshuu.github.io/cpr/";
drawAlignedText(ICON_FA_GLOBE " %s", cpr_website); drawAlignedText(ICON_FA_GLOBE " %s", cpr_website);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -258,10 +259,10 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Licence: MIT"); ImGui::TextUnformatted("Licence: MIT");
static const auto cpr_licence = _rs.get("LICENSE.cpr"); static auto cpr_licence = _rs.getRaw("LICENSE.cpr");
if(ImGui::BeginChild("##cprLicence", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##cprLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(cpr_licence.c_str()); ImGui::TextUnformatted(cpr_licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -270,7 +271,7 @@ void SaveTool::drawAbout() {
} }
if(ImGui::TreeNodeEx("JSON for Modern C++ (aka json.hpp)", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("JSON for Modern C++ (aka json.hpp)", ImGuiTreeNodeFlags_SpanAvailWidth)) {
const char* json_website = "https://json.nlohmann.me/"; auto json_website = "https://json.nlohmann.me/";
drawAlignedText(ICON_FA_GLOBE " %s", json_website); drawAlignedText(ICON_FA_GLOBE " %s", json_website);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -283,10 +284,10 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Licence: MIT"); ImGui::TextUnformatted("Licence: MIT");
static const auto json_licence = _rs.get("LICENSE.json"); static auto json_licence = _rs.getRaw("LICENSE.json");
if(ImGui::BeginChild("##jsonLicence", {0.0f, windowSize().y() * 0.3f}, true)) { if(ImGui::BeginChild("##jsonLicence", {0.0f, windowSize().y() * 0.3f}, true)) {
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ImGui::TextUnformatted(json_licence.c_str()); ImGui::TextUnformatted(json_licence);
ImGui::PopFont(); ImGui::PopFont();
} }
ImGui::EndChild(); ImGui::EndChild();
@ -296,7 +297,7 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("Font Awesome", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("Font Awesome", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::TextUnformatted("Version used: 5.15.3"); ImGui::TextUnformatted("Version used: 5.15.3");
const char* fa_website = "https://fontawesome.com/"; auto fa_website = "https://fontawesome.com/";
drawAlignedText(ICON_FA_GLOBE " %s", fa_website); drawAlignedText(ICON_FA_GLOBE " %s", fa_website);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {
@ -313,7 +314,7 @@ void SaveTool::drawAbout() {
} }
if(ImGui::TreeNodeEx("IconFontCppHeaders", ImGuiTreeNodeFlags_SpanAvailWidth)) { if(ImGui::TreeNodeEx("IconFontCppHeaders", ImGuiTreeNodeFlags_SpanAvailWidth)) {
const char* icon_repo = "https://github.com/juliettef/IconFontCppHeaders"; auto icon_repo = "https://github.com/juliettef/IconFontCppHeaders";
drawAlignedText(ICON_FA_GITHUB " %s", icon_repo); drawAlignedText(ICON_FA_GITHUB " %s", icon_repo);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) { if(ImGui::Button("Copy to clipboard")) {

View File

@ -117,7 +117,7 @@ void SaveTool::drawMainMenu() {
} }
if(_updateAvailable) { if(_updateAvailable) {
drawAlignedText("Version %s is available.", _latestVersion.c_str()); drawAlignedText("Version %s is available.", _latestVersion.data());
if(ImGui::Button(ICON_FA_FILE_SIGNATURE " Release notes")) { if(ImGui::Button(ICON_FA_FILE_SIGNATURE " Release notes")) {
openUri(_releaseLink); openUri(_releaseLink);
} }

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/Format.h>
#include <Magnum/Math/Functions.h> #include <Magnum/Math/Functions.h>
@ -24,7 +24,7 @@
#include "ToastQueue.h" #include "ToastQueue.h"
using namespace Corrade; using namespace Containers::Literals;
constexpr UnsignedInt success_colour = 0xff67d23bu; constexpr UnsignedInt success_colour = 0xff67d23bu;
constexpr UnsignedInt info_colour = 0xffcc832fu; constexpr UnsignedInt info_colour = 0xffcc832fu;
@ -36,7 +36,7 @@ constexpr Float base_opacity = 1.0f;
constexpr Vector2 padding{20.0f, 20.0f}; constexpr Vector2 padding{20.0f, 20.0f};
constexpr Float toast_spacing = 10.0f; constexpr Float toast_spacing = 10.0f;
Toast::Toast(Type type, const std::string& message, std::chrono::milliseconds timeout): Toast::Toast(Type type, Containers::StringView message, std::chrono::milliseconds timeout):
_type{type}, _message{message}, _timeout{timeout}, _creationTime{std::chrono::steady_clock::now()} _type{type}, _message{message}, _timeout{timeout}, _creationTime{std::chrono::steady_clock::now()}
{ {
_phaseTrack = Animation::Track<UnsignedInt, Phase>{{ _phaseTrack = Animation::Track<UnsignedInt, Phase>{{
@ -51,7 +51,7 @@ auto Toast::type() -> Type {
return _type; return _type;
} }
auto Toast::message() -> const std::string& { auto Toast::message() -> Containers::StringView {
return _message; return _message;
} }
@ -89,7 +89,7 @@ void ToastQueue::addToast(Toast&& toast) {
_toasts.push_back(std::move(toast)); _toasts.push_back(std::move(toast));
} }
void ToastQueue::addToast(Toast::Type type, const std::string& message, std::chrono::milliseconds timeout) { void ToastQueue::addToast(Toast::Type type, Containers::StringView message, std::chrono::milliseconds timeout) {
_toasts.emplace_back(type, message, timeout); _toasts.emplace_back(type, message, timeout);
} }
@ -104,14 +104,14 @@ void ToastQueue::draw(Vector2i viewport_size) {
continue; continue;
} }
std::string win_id = Utility::formatString("##Toast{}", i); Containers::String win_id = Utility::format("##Toast{}", i);
Float opacity = base_opacity * current->opacity(); Float opacity = base_opacity * current->opacity();
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, opacity); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, opacity);
ImGui::SetNextWindowPos({viewport_size.x() - padding.x(), viewport_size.y() - padding.y() - height}, ImGuiCond_Always, {1.0f, 1.0f}); ImGui::SetNextWindowPos({viewport_size.x() - padding.x(), viewport_size.y() - padding.y() - height}, ImGuiCond_Always, {1.0f, 1.0f});
if(ImGui::Begin(win_id.c_str(), nullptr, if(ImGui::Begin(win_id.data(), nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoDecoration| ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoDecoration|
ImGuiWindowFlags_NoInputs|ImGuiWindowFlags_NoNav|ImGuiWindowFlags_NoFocusOnAppearing)) ImGuiWindowFlags_NoInputs|ImGuiWindowFlags_NoNav|ImGuiWindowFlags_NoFocusOnAppearing))
{ {
@ -142,11 +142,11 @@ void ToastQueue::draw(Vector2i viewport_size) {
ImGui::SameLine(); ImGui::SameLine();
} }
if(current->message().length() > 127) { if(current->message().size() > 127) {
ImGui::TextColored(colour, "%.*s...", 127, current->message().c_str()); ImGui::TextColored(colour, "%.*s...", 127, current->message().data());
} }
else { else {
ImGui::TextColored(colour, current->message().c_str()); ImGui::TextColored(colour, current->message().data());
} }
height += ImGui::GetWindowHeight() + toast_spacing; height += ImGui::GetWindowHeight() + toast_spacing;

View File

@ -17,12 +17,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <chrono> #include <chrono>
#include <string>
#include <vector> #include <vector>
#include <Corrade/Containers/String.h>
#include <Magnum/Magnum.h> #include <Magnum/Magnum.h>
#include <Magnum/Animation/Track.h> #include <Magnum/Animation/Track.h>
using namespace Corrade;
using namespace Magnum; using namespace Magnum;
class Toast { class Toast {
@ -35,7 +37,7 @@ class Toast {
FadeIn, Wait, FadeOut, TimedOut FadeIn, Wait, FadeOut, TimedOut
}; };
explicit Toast(Type type, const std::string& message, explicit Toast(Type type, Containers::StringView message,
std::chrono::milliseconds timeout = std::chrono::milliseconds{3000}); std::chrono::milliseconds timeout = std::chrono::milliseconds{3000});
Toast(const Toast& other) = delete; Toast(const Toast& other) = delete;
@ -46,7 +48,7 @@ class Toast {
auto type() -> Type; auto type() -> Type;
auto message() -> std::string const&; auto message() -> Containers::StringView;
auto timeout() -> std::chrono::milliseconds; auto timeout() -> std::chrono::milliseconds;
@ -60,7 +62,7 @@ class Toast {
private: private:
Type _type{Type::Default}; Type _type{Type::Default};
std::string _message; Containers::StringView _message;
std::chrono::milliseconds _timeout; std::chrono::milliseconds _timeout;
std::chrono::steady_clock::time_point _creationTime; std::chrono::steady_clock::time_point _creationTime;
Animation::Track<UnsignedInt, Phase> _phaseTrack; Animation::Track<UnsignedInt, Phase> _phaseTrack;
@ -70,7 +72,7 @@ class ToastQueue {
public: public:
void addToast(Toast&& toast); void addToast(Toast&& toast);
void addToast(Toast::Type type, const std::string& message, void addToast(Toast::Type type, Containers::StringView message,
std::chrono::milliseconds timeout = std::chrono::milliseconds{3000}); std::chrono::milliseconds timeout = std::chrono::milliseconds{3000});
void draw(Vector2i viewport_size); void draw(Vector2i viewport_size);

View File

@ -16,15 +16,16 @@
#include <cstring> #include <cstring>
#include <string> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/String.h>
#include "BinaryReader.h" #include "BinaryReader.h"
BinaryReader::BinaryReader(const std::string& filename) { BinaryReader::BinaryReader(Containers::StringView filename) {
_file = std::fopen(filename.c_str(), "rb"); _file = std::fopen(filename.data(), "rb");
if(!_file) { if(!_file) {
Utility::Error{} << "Couldn't open" << filename.c_str() << "for reading:\n" Utility::Error{} << "Couldn't open" << filename << "for reading:\n"
<< std::strerror(errno); << std::strerror(errno);
} }
} }
@ -106,16 +107,15 @@ auto BinaryReader::readArray(Containers::Array<char>& array, std::size_t count)
return std::fread(array.data(), sizeof(char), count, _file) == count; return std::fread(array.data(), sizeof(char), count, _file) == count;
} }
auto BinaryReader::readUEString(std::string& str) -> bool { auto BinaryReader::readUEString(Containers::String& str) -> bool {
UnsignedInt length = 0; UnsignedInt length = 0;
if(!readUnsignedInt(length) || length == 0) { if(!readUnsignedInt(length) || length == 0) {
return false; return false;
} }
str = std::string{}; str = Containers::String{ValueInit, length - 1};
str.resize(length - 1);
return std::fread(&str[0], sizeof(char), length, _file) == length; return std::fread(str.data(), sizeof(char), length, _file) == length;
} }
auto BinaryReader::peekChar() -> Int { auto BinaryReader::peekChar() -> Int {

View File

@ -18,9 +18,9 @@
#include <cstdio> #include <cstdio>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Containers.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
#include <Corrade/Utility/StlForwardString.h> #include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h> #include <Magnum/Types.h>
@ -29,7 +29,7 @@ using namespace Magnum;
class BinaryReader { class BinaryReader {
public: public:
explicit BinaryReader(const std::string& filename); explicit BinaryReader(Containers::StringView filename);
~BinaryReader(); ~BinaryReader();
auto open() -> bool; auto open() -> bool;
@ -63,7 +63,7 @@ class BinaryReader {
return std::fread(array.data(), sizeof(char), S, _file) == S; return std::fread(array.data(), sizeof(char), S, _file) == S;
} }
auto readUEString(std::string& str) -> bool; auto readUEString(Containers::String& str) -> bool;
auto peekChar() -> Int; auto peekChar() -> Int;

View File

@ -16,14 +16,14 @@
#include <cstring> #include <cstring>
#include <string>
#include "BinaryWriter.h" #include "BinaryWriter.h"
BinaryWriter::BinaryWriter(const std::string& filename) { using namespace Containers::Literals;
_file = std::fopen(filename.c_str(), "wb");
BinaryWriter::BinaryWriter(Containers::StringView filename) {
_file = std::fopen(filename.data(), "wb");
if(!_file) { if(!_file) {
Utility::Error{} << "Couldn't open" << filename.c_str() << "for reading:\n" Utility::Error{} << "Couldn't open"_s << filename << "for reading:\n"_s
<< std::strerror(errno); << std::strerror(errno);
} }
} }
@ -114,24 +114,25 @@ auto BinaryWriter::writeArray(Containers::ArrayView<const char> array) -> bool {
return std::fwrite(array.data(), sizeof(char), array.size(), _file) == array.size(); return std::fwrite(array.data(), sizeof(char), array.size(), _file) == array.size();
} }
auto BinaryWriter::writeUEString(const std::string& str) -> bool { auto BinaryWriter::writeUEString(Containers::StringView str) -> bool {
if(str.length() > UINT32_MAX) { if(str.size() > UINT32_MAX) {
Utility::Error{} << "BinaryWriter::writeUEString(): string is too big."; Utility::Error{} << "BinaryWriter::writeUEString(): string is too big."_s;
return false; return false;
} }
writeUnsignedInt(static_cast<UnsignedInt>(str.length()) + 1); writeUnsignedInt(static_cast<UnsignedInt>(str.size()) + 1);
if(str.length() > 0) { if(str.size() > 0) {
std::size_t count = std::fwrite(&str[0], sizeof(char), str.length(), _file); std::size_t count = std::fwrite(str.data(), sizeof(char), str.size(), _file);
if(count != str.length()) { if(count != str.size()) {
return false; return false;
} }
} }
return writeChar('\0'); return writeChar('\0');
} }
auto BinaryWriter::writeUEStringToArray(const std::string& value) -> UnsignedLong { auto BinaryWriter::writeUEStringToArray(Containers::StringView value) -> UnsignedLong {
Containers::ArrayView<const char> view{value.c_str(), value.length()}; return writeValueToArray<UnsignedInt>(UnsignedInt(value.size()) + 1u) +
return writeValueToArray<UnsignedInt>(UnsignedInt(value.length()) + 1u) + writeDataToArray(view) + writeValueToArray<char>('\0'); writeDataToArray(Containers::ArrayView<const char>{value}) +
writeValueToArray<char>('\0');
} }

View File

@ -21,7 +21,7 @@
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
#include <Corrade/Utility/StlForwardString.h> #include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h> #include <Magnum/Types.h>
@ -30,7 +30,7 @@ using namespace Magnum;
class BinaryWriter { class BinaryWriter {
public: public:
explicit BinaryWriter(const std::string& filename); explicit BinaryWriter(Containers::StringView filename);
~BinaryWriter(); ~BinaryWriter();
BinaryWriter(const BinaryWriter& other) = delete; BinaryWriter(const BinaryWriter& other) = delete;
@ -71,7 +71,7 @@ class BinaryWriter {
return std::fwrite(array.data(), sizeof(char), S, _file) == S; return std::fwrite(array.data(), sizeof(char), S, _file) == S;
} }
auto writeUEString(const std::string& str) -> bool; auto writeUEString(Containers::StringView str) -> bool;
template<typename T, typename U = std::conditional_t<std::is_trivially_copyable<T>::value, T, T&>> template<typename T, typename U = std::conditional_t<std::is_trivially_copyable<T>::value, T, T&>>
auto writeValueToArray(U value) -> UnsignedLong { auto writeValueToArray(U value) -> UnsignedLong {
@ -79,7 +79,7 @@ class BinaryWriter {
return writeDataToArray(view); return writeDataToArray(view);
} }
auto writeUEStringToArray(const std::string& value) -> UnsignedLong; auto writeUEStringToArray(Containers::StringView value) -> UnsignedLong;
template<typename T> template<typename T>
void writeValueToArrayAt(T& value, UnsignedLong position) { void writeValueToArrayAt(T& value, UnsignedLong position) {

View File

@ -23,18 +23,18 @@
#include "Debug.h" #include "Debug.h"
Utility::Debug& operator<<(Utility::Debug& debug, const ArrayProperty* prop) { Utility::Debug& operator<<(Utility::Debug& debug, const ArrayProperty* prop) {
return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << return debug << (*prop->name) << Utility::Debug::nospace << ":" <<
prop->propertyType.c_str() << "of" << prop->items.size() << prop->itemType.c_str(); prop->propertyType << "of" << prop->items.size() << prop->itemType;
} }
Utility::Debug& operator<<(Utility::Debug& debug, const SetProperty* prop) { Utility::Debug& operator<<(Utility::Debug& debug, const SetProperty* prop) {
return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << return debug << (*prop->name) << Utility::Debug::nospace << ":" <<
prop->propertyType.c_str() << "of" << prop->items.size() << prop->itemType.c_str(); prop->propertyType << "of" << prop->items.size() << prop->itemType;
} }
Utility::Debug& operator<<(Utility::Debug& debug, const GenericStructProperty* prop) { Utility::Debug& operator<<(Utility::Debug& debug, const GenericStructProperty* prop) {
debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << debug << (*prop->name) << Utility::Debug::nospace << ":" <<
prop->structType.c_str() << "(" << Utility::Debug::nospace << prop->propertyType.c_str() << Utility::Debug::nospace << prop->structType << "(" << Utility::Debug::nospace << prop->propertyType << Utility::Debug::nospace <<
") Contents:"; ") Contents:";
for(const auto& item : prop->properties) { for(const auto& item : prop->properties) {
debug << "\n " << Utility::Debug::nospace << item.get(); debug << "\n " << Utility::Debug::nospace << item.get();
@ -48,8 +48,8 @@ Utility::Debug& operator<<(Utility::Debug& debug, const StructProperty* prop) {
return debug << cast; return debug << cast;
} }
return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << return debug << (*prop->name) << Utility::Debug::nospace << ":" <<
prop->structType.c_str() << "(" << Utility::Debug::nospace << prop->propertyType.c_str() << Utility::Debug::nospace << ")"; prop->structType << "(" << Utility::Debug::nospace << prop->propertyType << Utility::Debug::nospace << ")";
} }
Utility::Debug& operator<<(Utility::Debug& debug, const UnrealPropertyBase* prop) { Utility::Debug& operator<<(Utility::Debug& debug, const UnrealPropertyBase* prop) {
@ -72,5 +72,5 @@ Utility::Debug& operator<<(Utility::Debug& debug, const UnrealPropertyBase* prop
} }
} }
return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << prop->propertyType.c_str(); return debug << (*prop->name) << Utility::Debug::nospace << ":" << prop->propertyType;
} }

View File

@ -42,7 +42,6 @@
#include "PropertySerialiser.h" #include "PropertySerialiser.h"
PropertySerialiser::PropertySerialiser() { PropertySerialiser::PropertySerialiser() {
arrayAppend(_serialisers, Containers::pointer<ArrayPropertySerialiser>()); arrayAppend(_serialisers, Containers::pointer<ArrayPropertySerialiser>());
arrayAppend(_serialisers, Containers::pointer<BoolPropertySerialiser>()); arrayAppend(_serialisers, Containers::pointer<BoolPropertySerialiser>());
@ -71,7 +70,7 @@ auto PropertySerialiser::read(BinaryReader& reader) -> UnrealPropertyBase::ptr {
return nullptr; return nullptr;
} }
std::string name; Containers::String name;
if(!reader.readUEString(name)) { if(!reader.readUEString(name)) {
return nullptr; return nullptr;
} }
@ -80,7 +79,7 @@ auto PropertySerialiser::read(BinaryReader& reader) -> UnrealPropertyBase::ptr {
return Containers::pointer<NoneProperty>(); return Containers::pointer<NoneProperty>();
} }
std::string type; Containers::String type;
if(!reader.readUEString(type)) { if(!reader.readUEString(type)) {
return nullptr; return nullptr;
} }
@ -93,7 +92,8 @@ auto PropertySerialiser::read(BinaryReader& reader) -> UnrealPropertyBase::ptr {
return deserialise(std::move(name), std::move(type), value_length, reader); return deserialise(std::move(name), std::move(type), value_length, reader);
} }
auto PropertySerialiser::readItem(BinaryReader& reader, std::string type, UnsignedLong value_length, std::string name) -> UnrealPropertyBase::ptr { auto PropertySerialiser::readItem(BinaryReader& reader, Containers::String type, UnsignedLong value_length,
Containers::String name) -> UnrealPropertyBase::ptr {
if(reader.peekChar() < 0 || reader.eof()) { if(reader.peekChar() < 0 || reader.eof()) {
return nullptr; return nullptr;
} }
@ -101,7 +101,9 @@ auto PropertySerialiser::readItem(BinaryReader& reader, std::string type, Unsign
return deserialise(std::move(name), std::move(type), value_length, reader); return deserialise(std::move(name), std::move(type), value_length, reader);
} }
auto PropertySerialiser::readSet(BinaryReader& reader, const std::string& item_type, UnsignedInt count) -> Containers::Array<UnrealPropertyBase::ptr> { auto PropertySerialiser::readSet(BinaryReader& reader, Containers::StringView item_type,
UnsignedInt count) -> Containers::Array<UnrealPropertyBase::ptr>
{
if(reader.peekChar() < 0 || reader.eof()) { if(reader.peekChar() < 0 || reader.eof()) {
return nullptr; return nullptr;
} }
@ -111,12 +113,12 @@ auto PropertySerialiser::readSet(BinaryReader& reader, const std::string& item_t
Containers::Array<UnrealPropertyBase::ptr> array; Containers::Array<UnrealPropertyBase::ptr> array;
if(serialiser) { if(serialiser) {
std::string name; Containers::String name;
if(!reader.readUEString(name)) { if(!reader.readUEString(name)) {
return nullptr; return nullptr;
} }
std::string type; Containers::String type;
if(!reader.readUEString(type)) { if(!reader.readUEString(type)) {
return nullptr; return nullptr;
} }
@ -144,7 +146,7 @@ auto PropertySerialiser::readSet(BinaryReader& reader, const std::string& item_t
return array; return array;
} }
auto PropertySerialiser::deserialise(std::string name, std::string type, UnsignedLong value_length, auto PropertySerialiser::deserialise(Containers::String name, Containers::String type, UnsignedLong value_length,
BinaryReader& reader) -> UnrealPropertyBase::ptr BinaryReader& reader) -> UnrealPropertyBase::ptr
{ {
UnrealPropertyBase::ptr prop; UnrealPropertyBase::ptr prop;
@ -167,8 +169,8 @@ auto PropertySerialiser::deserialise(std::string name, std::string type, Unsigne
return prop; return prop;
} }
auto PropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, const std::string& item_type, UnsignedLong& bytes_written, auto PropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, Containers::StringView item_type,
BinaryWriter& writer) -> bool UnsignedLong& bytes_written, BinaryWriter& writer) -> bool
{ {
auto serialiser = getSerialiser(item_type); auto serialiser = getSerialiser(item_type);
if(!serialiser) { if(!serialiser) {
@ -200,7 +202,7 @@ auto PropertySerialiser::write(UnrealPropertyBase::ptr& prop, UnsignedLong& byte
return ret; return ret;
} }
auto PropertySerialiser::writeItem(UnrealPropertyBase::ptr& prop, const std::string& item_type, auto PropertySerialiser::writeItem(UnrealPropertyBase::ptr& prop, Containers::StringView item_type,
UnsignedLong& bytes_written, BinaryWriter& writer) -> bool UnsignedLong& bytes_written, BinaryWriter& writer) -> bool
{ {
if(prop->name == "None" && prop->propertyType == "NoneProperty" && dynamic_cast<NoneProperty*>(prop.get())) { if(prop->name == "None" && prop->propertyType == "NoneProperty" && dynamic_cast<NoneProperty*>(prop.get())) {
@ -211,8 +213,9 @@ auto PropertySerialiser::writeItem(UnrealPropertyBase::ptr& prop, const std::str
return serialise(prop, item_type, bytes_written, writer); return serialise(prop, item_type, bytes_written, writer);
} }
auto PropertySerialiser::writeSet(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type, auto PropertySerialiser::writeSet(Containers::ArrayView<UnrealPropertyBase::ptr> props,
UnsignedLong& bytes_written, BinaryWriter& writer) -> bool Containers::StringView item_type, UnsignedLong& bytes_written,
BinaryWriter& writer) -> bool
{ {
auto serialiser = getCollectionSerialiser(item_type); auto serialiser = getCollectionSerialiser(item_type);
if(serialiser) { if(serialiser) {
@ -229,9 +232,9 @@ auto PropertySerialiser::writeSet(Containers::ArrayView<UnrealPropertyBase::ptr>
} }
} }
auto PropertySerialiser::getSerialiser(const std::string& item_type) -> AbstractUnrealPropertySerialiser* { auto PropertySerialiser::getSerialiser(Containers::StringView item_type) -> AbstractUnrealPropertySerialiser* {
for(auto& item : _serialisers) { for(auto& item : _serialisers) {
for(const std::string& serialiser_type : item->types()) { for(Containers::StringView serialiser_type : item->types()) {
if(item_type == serialiser_type) { if(item_type == serialiser_type) {
return item.get(); return item.get();
} }
@ -241,9 +244,9 @@ auto PropertySerialiser::getSerialiser(const std::string& item_type) -> Abstract
return nullptr; return nullptr;
} }
auto PropertySerialiser::getCollectionSerialiser(const std::string& item_type) -> AbstractUnrealCollectionPropertySerialiser* { auto PropertySerialiser::getCollectionSerialiser(Containers::StringView item_type) -> AbstractUnrealCollectionPropertySerialiser* {
for(auto& item : _collectionSerialisers) { for(auto& item : _collectionSerialisers) {
for(const std::string& serialiser_type : item->types()) { for(Containers::StringView serialiser_type : item->types()) {
if(item_type == serialiser_type) { if(item_type == serialiser_type) {
return item.get(); return item.get();
} }

View File

@ -17,6 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "Serialisers/AbstractUnrealPropertySerialiser.h" #include "Serialisers/AbstractUnrealPropertySerialiser.h"
#include "Serialisers/AbstractUnrealCollectionPropertySerialiser.h" #include "Serialisers/AbstractUnrealCollectionPropertySerialiser.h"
@ -33,18 +35,23 @@ class PropertySerialiser {
PropertySerialiser(); PropertySerialiser();
auto read(BinaryReader& reader) -> UnrealPropertyBase::ptr; auto read(BinaryReader& reader) -> UnrealPropertyBase::ptr;
auto readItem(BinaryReader& reader, std::string type, UnsignedLong value_length, std::string name) -> UnrealPropertyBase::ptr; auto readItem(BinaryReader& reader, Containers::String type, UnsignedLong value_length,
auto readSet(BinaryReader& reader, const std::string& item_type, UnsignedInt count) -> Containers::Array<UnrealPropertyBase::ptr>; Containers::String name) -> UnrealPropertyBase::ptr;
auto deserialise(std::string name, std::string type, UnsignedLong value_length, BinaryReader& reader) -> UnrealPropertyBase::ptr; auto readSet(BinaryReader& reader, Containers::StringView item_type, UnsignedInt count) -> Containers::Array<UnrealPropertyBase::ptr>;
auto deserialise(Containers::String name, Containers::String type, UnsignedLong value_length,
BinaryReader& reader) -> UnrealPropertyBase::ptr;
auto serialise(UnrealPropertyBase::ptr& prop, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool; auto serialise(UnrealPropertyBase::ptr& prop, Containers::StringView item_type, UnsignedLong& bytes_written,
BinaryWriter& writer) -> bool;
auto write(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool; auto write(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool;
auto writeItem(UnrealPropertyBase::ptr& prop, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool; auto writeItem(UnrealPropertyBase::ptr& prop, Containers::StringView item_type, UnsignedLong& bytes_written,
auto writeSet(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool; BinaryWriter& writer) -> bool;
auto writeSet(Containers::ArrayView<UnrealPropertyBase::ptr> props, Containers::StringView item_type,
UnsignedLong& bytes_written, BinaryWriter& writer) -> bool;
private: private:
auto getSerialiser(const std::string& item_type) -> AbstractUnrealPropertySerialiser*; auto getSerialiser(Containers::StringView item_type) -> AbstractUnrealPropertySerialiser*;
auto getCollectionSerialiser(const std::string& item_type) -> AbstractUnrealCollectionPropertySerialiser*; auto getCollectionSerialiser(Containers::StringView item_type) -> AbstractUnrealCollectionPropertySerialiser*;
Containers::Array<AbstractUnrealPropertySerialiser::ptr> _serialisers; Containers::Array<AbstractUnrealPropertySerialiser::ptr> _serialisers;
Containers::Array<AbstractUnrealCollectionPropertySerialiser::ptr> _collectionSerialisers; Containers::Array<AbstractUnrealCollectionPropertySerialiser::ptr> _collectionSerialisers;

View File

@ -16,11 +16,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h> #include <Magnum/Types.h>
@ -39,9 +38,12 @@ class AbstractUnrealCollectionPropertySerialiser {
virtual ~AbstractUnrealCollectionPropertySerialiser() = default; virtual ~AbstractUnrealCollectionPropertySerialiser() = default;
virtual auto types() -> Containers::ArrayView<const std::string> = 0; virtual auto types() -> Containers::ArrayView<const Containers::StringView> = 0;
virtual auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> = 0; virtual auto deserialise(Containers::StringView name, Containers::StringView type,
UnsignedLong value_length, UnsignedInt count, BinaryReader& reader,
PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> = 0;
virtual auto serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0; virtual auto serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, Containers::StringView item_type,
UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0;
}; };

View File

@ -16,10 +16,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h> #include <Magnum/Types.h>
@ -38,9 +37,11 @@ class AbstractUnrealPropertySerialiser {
virtual ~AbstractUnrealPropertySerialiser() = default; virtual ~AbstractUnrealPropertySerialiser() = default;
virtual auto types() -> Containers::ArrayView<const std::string> = 0; virtual auto types() -> Containers::ArrayView<const Containers::StringView> = 0;
virtual auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr = 0; virtual auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr = 0;
virtual auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0; virtual auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool = 0;
}; };

View File

@ -16,11 +16,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h> #include <Magnum/Types.h>
@ -38,9 +37,10 @@ class AbstractUnrealStructSerialiser {
virtual ~AbstractUnrealStructSerialiser() = default; virtual ~AbstractUnrealStructSerialiser() = default;
virtual auto supportsType(const std::string& type) -> bool = 0; virtual auto supportsType(Containers::StringView type) -> bool = 0;
virtual auto deserialise(BinaryReader& reader) -> UnrealPropertyBase::ptr = 0; virtual auto deserialise(BinaryReader& reader) -> UnrealPropertyBase::ptr = 0;
virtual auto serialise(UnrealPropertyBase::ptr& structProp, BinaryWriter& writer, UnsignedLong& bytes_written) -> bool = 0; virtual auto serialise(UnrealPropertyBase::ptr& structProp, BinaryWriter& writer,
UnsignedLong& bytes_written) -> bool = 0;
}; };

View File

@ -14,16 +14,19 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/String.h>
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../PropertySerialiser.h" #include "../PropertySerialiser.h"
#include "ArrayPropertySerialiser.h" #include "ArrayPropertySerialiser.h"
auto ArrayPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto ArrayPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
std::string item_type; Containers::String item_type;
if(!reader.readUEString(item_type)) { if(!reader.readUEString(item_type)) {
return nullptr; return nullptr;
} }

View File

@ -16,15 +16,24 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/ArrayProperty.h" #include "../Types/ArrayProperty.h"
using namespace Corrade;
using namespace Magnum;
class ArrayPropertySerialiser : public UnrealPropertySerialiser<ArrayProperty> { class ArrayPropertySerialiser : public UnrealPropertySerialiser<ArrayProperty> {
public: public:
using ptr = Containers::Pointer<ArrayPropertySerialiser>; using ptr = Containers::Pointer<ArrayPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,13 +19,15 @@
#include "BoolPropertySerialiser.h" #include "BoolPropertySerialiser.h"
auto BoolPropertySerialiser::types() -> Containers::ArrayView<const std::string> { auto BoolPropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> {
static const Containers::Array<std::string> types{InPlaceInit, {"BoolProperty"}}; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"BoolProperty"_s}};
return types; return types;
} }
auto BoolPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, auto BoolPropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
if(value_length != 0) { if(value_length != 0) {
return nullptr; return nullptr;

View File

@ -16,17 +16,24 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/StringView.h>
#include "AbstractUnrealPropertySerialiser.h" #include "AbstractUnrealPropertySerialiser.h"
#include "../Types/BoolProperty.h" #include "../Types/BoolProperty.h"
using namespace Corrade;
class BoolPropertySerialiser : public AbstractUnrealPropertySerialiser { class BoolPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<BoolPropertySerialiser>; using ptr = Containers::Pointer<BoolPropertySerialiser>;
auto types() -> Containers::ArrayView<const std::string> override; auto types() -> Containers::ArrayView<const Containers::StringView> override;
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,13 +19,15 @@
#include "BytePropertySerialiser.h" #include "BytePropertySerialiser.h"
auto BytePropertySerialiser::types() -> Containers::ArrayView<const std::string> { auto BytePropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> {
static const Containers::Array<std::string> types{InPlaceInit, {"ByteProperty"}}; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"ByteProperty"_s}};
return types; return types;
} }
auto BytePropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, auto BytePropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<ByteProperty>(); auto prop = Containers::pointer<ByteProperty>();

View File

@ -16,6 +16,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/StringView.h>
#include "AbstractUnrealPropertySerialiser.h" #include "AbstractUnrealPropertySerialiser.h"
#include "../Types/ByteProperty.h" #include "../Types/ByteProperty.h"
@ -24,9 +27,11 @@ class BytePropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<BytePropertySerialiser>; using ptr = Containers::Pointer<BytePropertySerialiser>;
auto types() -> Containers::ArrayView<const std::string> override; auto types() -> Containers::ArrayView<const Containers::StringView> override;
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,8 +19,9 @@
#include "ColourPropertySerialiser.h" #include "ColourPropertySerialiser.h"
auto ColourPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto ColourPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<ColourStructProperty>(); auto prop = Containers::pointer<ColourStructProperty>();

View File

@ -16,15 +16,21 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/ColourStructProperty.h" #include "../Types/ColourStructProperty.h"
using namespace Corrade;
class ColourPropertySerialiser : public UnrealPropertySerialiser<ColourStructProperty> { class ColourPropertySerialiser : public UnrealPropertySerialiser<ColourStructProperty> {
public: public:
using ptr = Containers::Pointer<ColourPropertySerialiser>; using ptr = Containers::Pointer<ColourPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,8 +19,9 @@
#include "DateTimePropertySerialiser.h" #include "DateTimePropertySerialiser.h"
auto DateTimePropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto DateTimePropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<DateTimeStructProperty>(); auto prop = Containers::pointer<DateTimeStructProperty>();

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/DateTimeStructProperty.h" #include "../Types/DateTimeStructProperty.h"
@ -25,6 +27,8 @@ class DateTimePropertySerialiser : public UnrealPropertySerialiser<DateTimeStruc
using ptr = Containers::Pointer<DateTimePropertySerialiser>; using ptr = Containers::Pointer<DateTimePropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,13 +19,15 @@
#include "EnumPropertySerialiser.h" #include "EnumPropertySerialiser.h"
auto EnumPropertySerialiser::types() -> Containers::ArrayView<const std::string> { auto EnumPropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> {
static const Containers::Array<std::string> types{InPlaceInit, {"EnumProperty"}}; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"EnumProperty"_s}};
return types; return types;
} }
auto EnumPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, auto EnumPropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<EnumProperty>(); auto prop = Containers::pointer<EnumProperty>();

View File

@ -16,6 +16,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/StringView.h>
#include "AbstractUnrealPropertySerialiser.h" #include "AbstractUnrealPropertySerialiser.h"
#include "../Types/EnumProperty.h" #include "../Types/EnumProperty.h"
@ -24,9 +27,11 @@ class EnumPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<EnumPropertySerialiser>; using ptr = Containers::Pointer<EnumPropertySerialiser>;
auto types() -> Containers::ArrayView<const std::string> override; auto types() -> Containers::ArrayView<const Containers::StringView> override;
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,13 +19,16 @@
#include "FloatPropertySerialiser.h" #include "FloatPropertySerialiser.h"
auto FloatPropertySerialiser::types() -> Containers::ArrayView<const std::string> {
static const Containers::Array<std::string> types{InPlaceInit, {"FloatProperty"}}; auto FloatPropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> {
using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"FloatProperty"_s}};
return types; return types;
} }
auto FloatPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, auto FloatPropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<FloatProperty>(); auto prop = Containers::pointer<FloatProperty>();

View File

@ -16,6 +16,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/StringView.h>
#include "AbstractUnrealPropertySerialiser.h" #include "AbstractUnrealPropertySerialiser.h"
#include "../Types/FloatProperty.h" #include "../Types/FloatProperty.h"
@ -24,9 +27,11 @@ class FloatPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<FloatPropertySerialiser>; using ptr = Containers::Pointer<FloatPropertySerialiser>;
auto types() -> Containers::ArrayView<const std::string> override; auto types() -> Containers::ArrayView<const Containers::StringView> override;
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,13 +19,16 @@
#include "GuidPropertySerialiser.h" #include "GuidPropertySerialiser.h"
auto GuidPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, using namespace Containers::Literals;
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
auto GuidPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<GuidStructProperty>(); auto prop = Containers::pointer<GuidStructProperty>();
if(!reader.readStaticArray(prop->guid)) { if(!reader.readStaticArray(prop->guid)) {
Utility::Error{} << "Couldn't read guid in" << __func__; Utility::Error{} << "Couldn't read GUID in"_s << __func__;
return nullptr; return nullptr;
} }

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/GuidStructProperty.h" #include "../Types/GuidStructProperty.h"
@ -25,7 +27,8 @@ class GuidPropertySerialiser : public UnrealPropertySerialiser<GuidStructPropert
using ptr = Containers::Pointer<GuidPropertySerialiser>; using ptr = Containers::Pointer<GuidPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,8 +19,9 @@
#include "IntPropertySerialiser.h" #include "IntPropertySerialiser.h"
auto IntPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto IntPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<IntProperty>(); auto prop = Containers::pointer<IntProperty>();

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/IntProperty.h" #include "../Types/IntProperty.h"
@ -25,6 +27,8 @@ class IntPropertySerialiser : public UnrealPropertySerialiser<IntProperty> {
using ptr = Containers::Pointer<IntPropertySerialiser>; using ptr = Containers::Pointer<IntPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -22,8 +22,11 @@
#include "MapPropertySerialiser.h" #include "MapPropertySerialiser.h"
auto MapPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, using namespace Containers::Literals;
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
auto MapPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<MapProperty>(); auto prop = Containers::pointer<MapProperty>();
@ -58,7 +61,7 @@ auto MapPropertySerialiser::deserialiseProperty(const std::string& name, const s
for(UnsignedInt i = 0; i < count; i++) { for(UnsignedInt i = 0; i < count; i++) {
MapProperty::KeyValuePair pair; MapProperty::KeyValuePair pair;
if(prop->keyType == "IntProperty" || prop->keyType == "StrProperty") { if(prop->keyType == "IntProperty"_s || prop->keyType == "StrProperty"_s) {
pair.key = serialiser.readItem(reader, prop->keyType, -1, name); pair.key = serialiser.readItem(reader, prop->keyType, -1, name);
if(pair.key == nullptr) { if(pair.key == nullptr) {
return nullptr; return nullptr;
@ -69,19 +72,19 @@ auto MapPropertySerialiser::deserialiseProperty(const std::string& name, const s
} }
UnrealPropertyBase::ptr value_item; UnrealPropertyBase::ptr value_item;
if(prop->valueType == "StructProperty") { if(prop->valueType == "StructProperty"_s) {
while((value_item = serialiser.read(reader)) != nullptr) { while((value_item = serialiser.read(reader)) != nullptr) {
arrayAppend(pair.values, std::move(value_item)); arrayAppend(pair.values, std::move(value_item));
if(pair.values.back()->name == "None" && if(pair.values.back()->name == "None"_s &&
pair.values.back()->propertyType == "NoneProperty" && pair.values.back()->propertyType == "NoneProperty"_s &&
dynamic_cast<NoneProperty*>(pair.values.back().get()) != nullptr) dynamic_cast<NoneProperty*>(pair.values.back().get()) != nullptr)
{ {
break; break;
} }
} }
} }
else if(prop->valueType == "ByteProperty") { else if(prop->valueType == "ByteProperty"_s) {
if((value_item = serialiser.readItem(reader, prop->valueType, -1, name)) == nullptr) { if((value_item = serialiser.readItem(reader, prop->valueType, -1, name)) == nullptr) {
return nullptr; return nullptr;
} }
@ -121,7 +124,7 @@ auto MapPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns
} }
for(auto& value : pair.values) { for(auto& value : pair.values) {
if(map_prop->valueType == "StructProperty") { if(map_prop->valueType == "StructProperty"_s) {
if(!serialiser.write(value, dummy_bytes_written, writer)) { if(!serialiser.write(value, dummy_bytes_written, writer)) {
return false; return false;
} }

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/MapProperty.h" #include "../Types/MapProperty.h"
@ -25,6 +27,8 @@ class MapPropertySerialiser : public UnrealPropertySerialiser<MapProperty> {
using ptr = Containers::Pointer<MapPropertySerialiser>; using ptr = Containers::Pointer<MapPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -23,17 +23,20 @@
#include "ResourcePropertySerialiser.h" #include "ResourcePropertySerialiser.h"
auto ResourcePropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, using namespace Containers::Literals;
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
auto ResourcePropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<ResourceItemValue>(); auto prop = Containers::pointer<ResourceItemValue>();
std::string str; Containers::String str;
if(!reader.readUEString(str) || str != "ID_4_AAE08F17428E229EC7A2209F51081A21") { if(!reader.readUEString(str) || str != "ID_4_AAE08F17428E229EC7A2209F51081A21"_s) {
return nullptr; return nullptr;
} }
if(!reader.readUEString(str) || str != "IntProperty") { if(!reader.readUEString(str) || str != "IntProperty"_s) {
return nullptr; return nullptr;
} }
@ -50,11 +53,11 @@ auto ResourcePropertySerialiser::deserialiseProperty(const std::string& name, co
return nullptr; return nullptr;
} }
if(!reader.readUEString(str) || str != "Quantity_3_560F09B5485C365D3041888910019CE3") { if(!reader.readUEString(str) || str != "Quantity_3_560F09B5485C365D3041888910019CE3"_s) {
return nullptr; return nullptr;
} }
if(!reader.readUEString(str) || str != "IntProperty") { if(!reader.readUEString(str) || str != "IntProperty"_s) {
return nullptr; return nullptr;
} }
@ -70,7 +73,7 @@ auto ResourcePropertySerialiser::deserialiseProperty(const std::string& name, co
return nullptr; return nullptr;
} }
if(!reader.readUEString(str) || str != "None") { if(!reader.readUEString(str) || str != "None"_s) {
return nullptr; return nullptr;
} }
@ -85,19 +88,19 @@ auto ResourcePropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop
return false; return false;
} }
bytes_written += writer.writeUEStringToArray("ID_4_AAE08F17428E229EC7A2209F51081A21") + bytes_written += writer.writeUEStringToArray("ID_4_AAE08F17428E229EC7A2209F51081A21"_s) +
writer.writeUEStringToArray("IntProperty") + writer.writeUEStringToArray("IntProperty"_s) +
writer.writeValueToArray<UnsignedLong>(4ull) + writer.writeValueToArray<UnsignedLong>(4ull) +
writer.writeValueToArray<char>('\0') + writer.writeValueToArray<char>('\0') +
writer.writeValueToArray<Int>(res_prop->id); writer.writeValueToArray<Int>(res_prop->id);
bytes_written += writer.writeUEStringToArray("Quantity_3_560F09B5485C365D3041888910019CE3") + bytes_written += writer.writeUEStringToArray("Quantity_3_560F09B5485C365D3041888910019CE3"_s) +
writer.writeUEStringToArray("IntProperty") + writer.writeUEStringToArray("IntProperty"_s) +
writer.writeValueToArray<UnsignedLong>(4ull) + writer.writeValueToArray<UnsignedLong>(4ull) +
writer.writeValueToArray<char>('\0') + writer.writeValueToArray<char>('\0') +
writer.writeValueToArray<Int>(res_prop->quantity); writer.writeValueToArray<Int>(res_prop->quantity);
bytes_written += writer.writeUEStringToArray("None"); bytes_written += writer.writeUEStringToArray("None"_s);
return true; return true;
} }

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/ResourceItemValue.h" #include "../Types/ResourceItemValue.h"
@ -25,6 +27,8 @@ class ResourcePropertySerialiser : public UnrealPropertySerialiser<ResourceItemV
using ptr = Containers::Pointer<ResourcePropertySerialiser>; using ptr = Containers::Pointer<ResourcePropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,8 +19,9 @@
#include "RotatorPropertySerialiser.h" #include "RotatorPropertySerialiser.h"
auto RotatorPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto RotatorPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<RotatorStructProperty>(); auto prop = Containers::pointer<RotatorStructProperty>();

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/RotatorStructProperty.h" #include "../Types/RotatorStructProperty.h"
@ -25,6 +27,8 @@ class RotatorPropertySerialiser : public UnrealPropertySerialiser<RotatorStructP
using ptr = Containers::Pointer<RotatorPropertySerialiser>; using ptr = Containers::Pointer<RotatorPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -20,10 +20,11 @@
#include "SetPropertySerialiser.h" #include "SetPropertySerialiser.h"
auto SetPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto SetPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
std::string item_type; Containers::String item_type;
if(!reader.readUEString(item_type)) { if(!reader.readUEString(item_type)) {
return nullptr; return nullptr;
} }

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/SetProperty.h" #include "../Types/SetProperty.h"
@ -25,6 +27,8 @@ class SetPropertySerialiser : public UnrealPropertySerialiser<SetProperty> {
using ptr = Containers::Pointer<SetPropertySerialiser>; using ptr = Containers::Pointer<SetPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,13 +19,17 @@
#include "StringPropertySerialiser.h" #include "StringPropertySerialiser.h"
auto StringPropertySerialiser::types() -> Containers::ArrayView<const std::string> { auto StringPropertySerialiser::types() -> Containers::ArrayView<const Containers::StringView> {
static const Containers::Array<std::string> types{InPlaceInit, {"NameProperty", "StrProperty", "SoftObjectProperty", "ObjectProperty"}}; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit,
{"NameProperty"_s, "StrProperty"_s,
"SoftObjectProperty"_s, "ObjectProperty"_s}};
return types; return types;
} }
auto StringPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, auto StringPropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<StringProperty>(type); auto prop = Containers::pointer<StringProperty>(type);

View File

@ -16,6 +16,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/StringView.h>
#include "AbstractUnrealPropertySerialiser.h" #include "AbstractUnrealPropertySerialiser.h"
#include "../Types/StringProperty.h" #include "../Types/StringProperty.h"
@ -24,9 +27,11 @@ class StringPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<StringPropertySerialiser>; using ptr = Containers::Pointer<StringPropertySerialiser>;
auto types() -> Containers::ArrayView<const std::string> override; auto types() -> Containers::ArrayView<const Containers::StringView> override;
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/String.h>
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "../PropertySerialiser.h" #include "../PropertySerialiser.h"
@ -23,15 +25,16 @@
#include "StructSerialiser.h" #include "StructSerialiser.h"
auto StructSerialiser::types() -> Containers::ArrayView<const std::string> { auto StructSerialiser::types() -> Containers::ArrayView<const Containers::StringView> {
static const Containers::Array<std::string> types{InPlaceInit, {"StructProperty"}}; using namespace Containers::Literals;
static const Containers::Array<Containers::StringView> types{InPlaceInit, {"StructProperty"_s}};
return types; return types;
} }
auto StructSerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, auto StructSerialiser::deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr>
{ {
std::string item_type; Containers::String item_type;
if(!reader.readUEString(item_type)) { if(!reader.readUEString(item_type)) {
return nullptr; return nullptr;
} }
@ -76,10 +79,10 @@ auto StructSerialiser::deserialise(const std::string& name, const std::string& t
return array; return array;
} }
auto StructSerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, auto StructSerialiser::deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
std::string item_type; Containers::String item_type;
if(!reader.readUEString(item_type)) { if(!reader.readUEString(item_type)) {
return nullptr; return nullptr;
} }
@ -110,7 +113,7 @@ auto StructSerialiser::deserialise(const std::string& name, const std::string& t
return prop; return prop;
} }
auto StructSerialiser::serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type, auto StructSerialiser::serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, Containers::StringView item_type,
UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool
{ {
bytes_written += writer.writeUEStringToArray(*(props.front()->name)); bytes_written += writer.writeUEStringToArray(*(props.front()->name));
@ -176,7 +179,7 @@ auto StructSerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& by
return true; return true;
} }
auto StructSerialiser::readStructValue(const std::string& name, const std::string& type, UnsignedLong value_length, auto StructSerialiser::readStructValue(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> StructProperty::ptr BinaryReader& reader, PropertySerialiser& serialiser) -> StructProperty::ptr
{ {
auto st_prop = Containers::pointer<GenericStructProperty>(); auto st_prop = Containers::pointer<GenericStructProperty>();

View File

@ -16,6 +16,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/StringView.h>
#include "AbstractUnrealCollectionPropertySerialiser.h" #include "AbstractUnrealCollectionPropertySerialiser.h"
#include "AbstractUnrealPropertySerialiser.h" #include "AbstractUnrealPropertySerialiser.h"
#include "AbstractUnrealStructSerialiser.h" #include "AbstractUnrealStructSerialiser.h"
@ -26,20 +29,20 @@ class StructSerialiser : public AbstractUnrealPropertySerialiser, public Abstrac
public: public:
using ptr = Containers::Pointer<StructSerialiser>; using ptr = Containers::Pointer<StructSerialiser>;
auto types() -> Containers::ArrayView<const std::string> override; auto types() -> Containers::ArrayView<const Containers::StringView> override;
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, UnsignedInt count, auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> override; UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array<UnrealPropertyBase::ptr> override;
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, const std::string& item_type, UnsignedLong& bytes_written, auto serialise(Containers::ArrayView<UnrealPropertyBase::ptr> props, Containers::StringView item_type,
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override;
private: private:
auto readStructValue(const std::string& name, const std::string& type, UnsignedLong value_length, auto readStructValue(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> StructProperty::ptr; BinaryReader& reader, PropertySerialiser& serialiser) -> StructProperty::ptr;
auto writeStructValue(StructProperty* prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool; auto writeStructValue(StructProperty* prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool;
}; };

View File

@ -14,13 +14,16 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/String.h>
#include "../BinaryReader.h" #include "../BinaryReader.h"
#include "../BinaryWriter.h" #include "../BinaryWriter.h"
#include "TextPropertySerialiser.h" #include "TextPropertySerialiser.h"
auto TextPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto TextPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<TextProperty>(); auto prop = Containers::pointer<TextProperty>();
@ -49,7 +52,7 @@ auto TextPropertySerialiser::deserialiseProperty(const std::string& name, const
auto interval = reader.position() - start_position; auto interval = reader.position() - start_position;
do { do {
std::string str; Containers::String str;
if(!reader.readUEString(str)) { if(!reader.readUEString(str)) {
return nullptr; return nullptr;

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/TextProperty.h" #include "../Types/TextProperty.h"
@ -25,6 +27,8 @@ class TextPropertySerialiser : public UnrealPropertySerialiser<TextProperty> {
using ptr = Containers::Pointer<TextPropertySerialiser>; using ptr = Containers::Pointer<TextPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -18,6 +18,10 @@
#include <type_traits> #include <type_traits>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/StringView.h>
#include "AbstractUnrealPropertySerialiser.h" #include "AbstractUnrealPropertySerialiser.h"
#include "../Types/StructProperty.h" #include "../Types/StructProperty.h"
@ -28,31 +32,38 @@ class UnrealPropertySerialiser : public AbstractUnrealPropertySerialiser {
public: public:
using ptr = Containers::Pointer<UnrealPropertySerialiser<T>>; using ptr = Containers::Pointer<UnrealPropertySerialiser<T>>;
auto types() -> Containers::ArrayView<const std::string> override { auto types() -> Containers::ArrayView<const Containers::StringView> override {
static const Containers::Array<std::string> types = []{ static const Containers::Array<Containers::StringView> types = []{
Containers::Array<std::string> array; Containers::Array<Containers::StringView> array;
Containers::Pointer<T> p(new T); Containers::Pointer<T> p(new T);
if(std::is_base_of<StructProperty, T>::value) { if(std::is_base_of<StructProperty, T>::value) {
array = Containers::Array<std::string>{InPlaceInit, {dynamic_cast<StructProperty*>(p.get())->structType}}; array = Containers::Array<Containers::StringView>{InPlaceInit, {dynamic_cast<StructProperty*>(p.get())->structType}};
} }
else { else {
array = Containers::Array<std::string>{InPlaceInit, {p->propertyType}}; array = Containers::Array<Containers::StringView>{InPlaceInit, {p->propertyType}};
} }
return array; return array;
}(); }();
return types; return types;
} }
auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override { auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override
{
return deserialiseProperty(name, type, value_length, reader, serialiser); return deserialiseProperty(name, type, value_length, reader, serialiser);
} }
auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override { auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override
{
return serialiseProperty(prop, bytes_written, writer, serialiser); return serialiseProperty(prop, bytes_written, writer, serialiser);
} }
private: private:
virtual auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> typename UnrealPropertyBase::ptr = 0; virtual auto deserialiseProperty(Containers::StringView name, Containers::StringView type,
UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> typename UnrealPropertyBase::ptr = 0;
virtual auto serialiseProperty(typename UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0; virtual auto serialiseProperty(typename UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written,
BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0;
}; };

View File

@ -19,8 +19,9 @@
#include "Vector2DPropertySerialiser.h" #include "Vector2DPropertySerialiser.h"
auto Vector2DPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto Vector2DPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<Vector2DStructProperty>(); auto prop = Containers::pointer<Vector2DStructProperty>();

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/Vector2DStructProperty.h" #include "../Types/Vector2DStructProperty.h"
@ -25,6 +27,8 @@ class Vector2DPropertySerialiser : public UnrealPropertySerialiser<Vector2DStruc
using ptr = Containers::Pointer<Vector2DPropertySerialiser>; using ptr = Containers::Pointer<Vector2DPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -19,8 +19,9 @@
#include "VectorPropertySerialiser.h" #include "VectorPropertySerialiser.h"
auto VectorPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, auto VectorPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type,
BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr UnsignedLong value_length, BinaryReader& reader,
PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr
{ {
auto prop = Containers::pointer<VectorStructProperty>(); auto prop = Containers::pointer<VectorStructProperty>();

View File

@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertySerialiser.h" #include "UnrealPropertySerialiser.h"
#include "../Types/VectorStructProperty.h" #include "../Types/VectorStructProperty.h"
@ -25,6 +27,8 @@ class VectorPropertySerialiser : public UnrealPropertySerialiser<VectorStructPro
using ptr = Containers::Pointer<VectorPropertySerialiser>; using ptr = Containers::Pointer<VectorPropertySerialiser>;
private: private:
auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length,
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override;
auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer,
PropertySerialiser& serialiser) -> bool override;
}; };

View File

@ -17,6 +17,9 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertyBase.h" #include "UnrealPropertyBase.h"
@ -24,7 +27,8 @@ struct ArrayProperty : public UnrealPropertyBase {
using ptr = Containers::Pointer<ArrayProperty>; using ptr = Containers::Pointer<ArrayProperty>;
ArrayProperty() { ArrayProperty() {
propertyType = "ArrayProperty"; using namespace Containers::Literals;
propertyType = "ArrayProperty"_s;
} }
template<typename T> template<typename T>
@ -37,6 +41,6 @@ struct ArrayProperty : public UnrealPropertyBase {
return static_cast<T*>(items[index].get()); return static_cast<T*>(items[index].get());
} }
std::string itemType; Containers::String itemType;
Containers::Array<UnrealPropertyBase::ptr> items; Containers::Array<UnrealPropertyBase::ptr> items;
}; };

View File

@ -16,12 +16,18 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealProperty.h" #include "UnrealProperty.h"
using namespace Corrade;
struct BoolProperty : public UnrealProperty<bool> { struct BoolProperty : public UnrealProperty<bool> {
using ptr = Containers::Pointer<BoolProperty>; using ptr = Containers::Pointer<BoolProperty>;
BoolProperty() { BoolProperty() {
propertyType = "BoolProperty"; using namespace Containers::Literals;
propertyType = "BoolProperty"_s;
} }
}; };

View File

@ -17,17 +17,23 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealProperty.h" #include "UnrealProperty.h"
using namespace Corrade;
struct ByteProperty : public UnrealProperty<Containers::Array<char>> { struct ByteProperty : public UnrealProperty<Containers::Array<char>> {
using ptr = Containers::Pointer<ByteProperty>; using ptr = Containers::Pointer<ByteProperty>;
ByteProperty() { ByteProperty() {
propertyType = "ByteProperty"; using namespace Containers::Literals;
propertyType = "ByteProperty"_s;
} }
// For some reason, M.A.S.S. Builder stores EnumProperties as ByteProperties. Ugh... // For some reason, M.A.S.S. Builder stores EnumProperties as ByteProperties. Ugh...
std::string enumType; Containers::String enumType;
std::string enumValue; Containers::String enumValue;
}; };

View File

@ -16,12 +16,18 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include "StructProperty.h" #include "StructProperty.h"
using namespace Corrade;
struct ColourStructProperty : public StructProperty { struct ColourStructProperty : public StructProperty {
using ptr = Containers::Pointer<ColourStructProperty>; using ptr = Containers::Pointer<ColourStructProperty>;
ColourStructProperty() { ColourStructProperty() {
structType = "LinearColor"; using namespace Containers::Literals;
structType = "LinearColor"_s;
} }
Float r = 0.0f, g = 0.0f, b = 0.0f, a = 0.0f; Float r = 0.0f, g = 0.0f, b = 0.0f, a = 0.0f;
}; };

View File

@ -16,13 +16,22 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h>
#include "StructProperty.h" #include "StructProperty.h"
using namespace Corrade;
using namespace Magnum;
struct DateTimeStructProperty : public StructProperty { struct DateTimeStructProperty : public StructProperty {
using ptr = Containers::Pointer<DateTimeStructProperty>; using ptr = Containers::Pointer<DateTimeStructProperty>;
DateTimeStructProperty() { DateTimeStructProperty() {
structType = "DateTime"; using namespace Containers::Literals;
structType = "DateTime"_s;
} }
UnsignedLong timestamp = 0; UnsignedLong timestamp = 0;

View File

@ -16,14 +16,21 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealProperty.h" #include "UnrealProperty.h"
struct EnumProperty : public UnrealProperty<std::string> { using namespace Corrade;
struct EnumProperty : public UnrealProperty<Containers::String> {
using ptr = Containers::Pointer<EnumProperty>; using ptr = Containers::Pointer<EnumProperty>;
EnumProperty() { EnumProperty() {
propertyType = "EnumProperty"; using namespace Containers::Literals;
propertyType = "EnumProperty"_s;
} }
std::string enumType; Containers::String enumType;
}; };

View File

@ -16,12 +16,21 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h>
#include "UnrealProperty.h" #include "UnrealProperty.h"
using namespace Corrade;
using namespace Magnum;
struct FloatProperty : public UnrealProperty<Float> { struct FloatProperty : public UnrealProperty<Float> {
using ptr = Containers::Pointer<FloatProperty>; using ptr = Containers::Pointer<FloatProperty>;
FloatProperty() { FloatProperty() {
propertyType = "FloatProperty"; using namespace Containers::Literals;
propertyType = "FloatProperty"_s;
} }
}; };

View File

@ -16,18 +16,22 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <algorithm> #include <type_traits>
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include "StructProperty.h" #include "StructProperty.h"
using namespace Corrade;
struct GenericStructProperty : public StructProperty { struct GenericStructProperty : public StructProperty {
using ptr = Containers::Pointer<GenericStructProperty>; using ptr = Containers::Pointer<GenericStructProperty>;
template<typename T> template<typename T>
std::enable_if_t<std::is_base_of<UnrealPropertyBase, T>::value, T*> std::enable_if_t<std::is_base_of<UnrealPropertyBase, T>::value, T*>
at(const std::string& name) { at(Containers::StringView name) {
for(auto& item : properties) { for(auto& item : properties) {
if(item->name == name) { if(item->name == name) {
return static_cast<T*>(item.get()); return static_cast<T*>(item.get());
@ -38,7 +42,7 @@ struct GenericStructProperty : public StructProperty {
template<typename T> template<typename T>
std::enable_if_t<std::is_base_of<UnrealPropertyBase, T>::value, typename T::ptr> std::enable_if_t<std::is_base_of<UnrealPropertyBase, T>::value, typename T::ptr>
atMove(const std::string& name) { atMove(Containers::StringView name) {
for(auto& item : properties) { for(auto& item : properties) {
if(item && item->name == name) { if(item && item->name == name) {
return Containers::Pointer<T>{static_cast<T*>(item.release())}; return Containers::Pointer<T>{static_cast<T*>(item.release())};

View File

@ -16,15 +16,20 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/StringView.h>
#include "StructProperty.h" #include "StructProperty.h"
using namespace Corrade;
struct GuidStructProperty : public StructProperty { struct GuidStructProperty : public StructProperty {
using ptr = Containers::Pointer<GuidStructProperty>; using ptr = Containers::Pointer<GuidStructProperty>;
GuidStructProperty() { GuidStructProperty() {
structType = "Guid"; using namespace Containers::Literals;
structType = "Guid"_s;
} }
Containers::StaticArray<16, char> guid{ValueInit}; Containers::StaticArray<16, char> guid{ValueInit};

View File

@ -16,12 +16,18 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealProperty.h" #include "UnrealProperty.h"
using namespace Corrade;
struct IntProperty : public UnrealProperty<Int> { struct IntProperty : public UnrealProperty<Int> {
using ptr = Containers::Pointer<IntProperty>; using ptr = Containers::Pointer<IntProperty>;
IntProperty() { IntProperty() {
propertyType = "IntProperty"; using namespace Containers::Literals;
propertyType = "IntProperty"_s;
} }
}; };

View File

@ -16,17 +16,24 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertyBase.h" #include "UnrealPropertyBase.h"
using namespace Corrade;
struct MapProperty : public UnrealPropertyBase { struct MapProperty : public UnrealPropertyBase {
using ptr = Containers::Pointer<MapProperty>; using ptr = Containers::Pointer<MapProperty>;
MapProperty() { MapProperty() {
propertyType = "MapProperty"; using namespace Containers::Literals;
propertyType = "MapProperty"_s;
} }
std::string keyType; Containers::String keyType;
std::string valueType; Containers::String valueType;
struct KeyValuePair { struct KeyValuePair {
UnrealPropertyBase::ptr key; UnrealPropertyBase::ptr key;

View File

@ -16,13 +16,19 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertyBase.h" #include "UnrealPropertyBase.h"
using namespace Corrade;
struct NoneProperty : UnrealPropertyBase { struct NoneProperty : UnrealPropertyBase {
using ptr = Containers::Pointer<NoneProperty>; using ptr = Containers::Pointer<NoneProperty>;
NoneProperty() { NoneProperty() {
name.emplace("None"); using namespace Containers::Literals;
propertyType = "NoneProperty"; name.emplace("None"_s);
propertyType = "NoneProperty"_s;
} }
}; };

View File

@ -16,13 +16,22 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h>
#include "StructProperty.h" #include "StructProperty.h"
using namespace Corrade;
using namespace Magnum;
struct ResourceItemValue : public StructProperty { struct ResourceItemValue : public StructProperty {
using ptr = Containers::Pointer<ResourceItemValue>; using ptr = Containers::Pointer<ResourceItemValue>;
ResourceItemValue() { ResourceItemValue() {
structType = "sttResourceItemValue"; using namespace Containers::Literals;
structType = "sttResourceItemValue"_s;
structGuid = Containers::StaticArray<16, char>{'\xB7', '\xA7', '\x77', '\xAB', '\xD3', '\x1B', '\xA6', '\x43', '\xAF', '\x42', '\xE5', '\x9E', '\xBF', '\xFD', '\x37', '\x55'}; structGuid = Containers::StaticArray<16, char>{'\xB7', '\xA7', '\x77', '\xAB', '\xD3', '\x1B', '\xA6', '\x43', '\xAF', '\x42', '\xE5', '\x9E', '\xBF', '\xFD', '\x37', '\x55'};
} }

View File

@ -16,13 +16,22 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Types.h>
#include "StructProperty.h" #include "StructProperty.h"
using namespace Corrade;
using namespace Magnum;
struct RotatorStructProperty : public StructProperty { struct RotatorStructProperty : public StructProperty {
using ptr = Containers::Pointer<RotatorStructProperty>; using ptr = Containers::Pointer<RotatorStructProperty>;
RotatorStructProperty() { RotatorStructProperty() {
structType = "Rotator"; using namespace Containers::Literals;
structType = "Rotator"_s;
} }
Float x = 0.0f, y = 0.0f, z = 0.0f; Float x = 0.0f, y = 0.0f, z = 0.0f;

View File

@ -17,14 +17,20 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertyBase.h" #include "UnrealPropertyBase.h"
using namespace Corrade;
struct SetProperty : public UnrealPropertyBase { struct SetProperty : public UnrealPropertyBase {
using ptr = Containers::Pointer<SetProperty>; using ptr = Containers::Pointer<SetProperty>;
SetProperty() { SetProperty() {
propertyType = "SetProperty"; using namespace Containers::Literals;
propertyType = "SetProperty"_s;
} }
auto at(std::size_t index) -> UnrealPropertyBase* { auto at(std::size_t index) -> UnrealPropertyBase* {
@ -35,6 +41,6 @@ struct SetProperty : public UnrealPropertyBase {
return items[index].get(); return items[index].get();
} }
std::string itemType; Containers::String itemType;
Containers::Array<UnrealPropertyBase::ptr> items; Containers::Array<UnrealPropertyBase::ptr> items;
}; };

View File

@ -16,12 +16,19 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealProperty.h" #include "UnrealProperty.h"
struct StringProperty : public UnrealProperty<std::string> { using namespace Corrade;
using namespace Containers::Literals;
struct StringProperty : public UnrealProperty<Containers::String> {
using ptr = Containers::Pointer<StringProperty>; using ptr = Containers::Pointer<StringProperty>;
explicit StringProperty(const std::string& type = "StrProperty") { explicit StringProperty(Containers::StringView type = "StrProperty"_s) {
propertyType = type; propertyType = type;
} }
}; };

View File

@ -16,17 +16,23 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealPropertyBase.h" #include "UnrealPropertyBase.h"
using namespace Corrade;
struct StructProperty : public UnrealPropertyBase { struct StructProperty : public UnrealPropertyBase {
using ptr = Containers::Pointer<StructProperty>; using ptr = Containers::Pointer<StructProperty>;
StructProperty() { StructProperty() {
std::string propertyType = "StructProperty"; using namespace Containers::Literals;
propertyType = "StructProperty"_s;
} }
Containers::StaticArray<16, char> structGuid{ValueInit}; Containers::StaticArray<16, char> structGuid{ValueInit};
std::string structType; Containers::String structType;
}; };

View File

@ -16,16 +16,24 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "UnrealProperty.h" #include "UnrealProperty.h"
struct TextProperty : public UnrealProperty<std::string> { using namespace Corrade;
struct TextProperty : public UnrealProperty<Containers::String> {
using ptr = Containers::Pointer<TextProperty>; using ptr = Containers::Pointer<TextProperty>;
TextProperty() { TextProperty() {
propertyType = "TextProperty"; using namespace Containers::Literals;
propertyType = "TextProperty"_s;
} }
Containers::Array<char> flags; Containers::Array<char> flags;
char id = 0; char id = 0;
Containers::Array<std::string> data; Containers::Array<Containers::String> data;
}; };

View File

@ -16,8 +16,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Pointer.h>
#include "UnrealPropertyBase.h" #include "UnrealPropertyBase.h"
using namespace Corrade;
template<typename T> template<typename T>
struct UnrealProperty : public UnrealPropertyBase { struct UnrealProperty : public UnrealPropertyBase {
using ptr = Containers::Pointer<UnrealProperty<T>>; using ptr = Containers::Pointer<UnrealProperty<T>>;

View File

@ -16,10 +16,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
#include <Corrade/Containers/Optional.h> #include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/String.h>
#include <Magnum/Types.h> #include <Magnum/Types.h>
@ -31,7 +30,7 @@ struct UnrealPropertyBase {
virtual ~UnrealPropertyBase() = default; virtual ~UnrealPropertyBase() = default;
Containers::Optional<std::string> name = Containers::NullOpt; Containers::Optional<Containers::String> name = Containers::NullOpt;
std::string propertyType; Containers::String propertyType;
UnsignedLong valueLength = 0; UnsignedLong valueLength = 0;
}; };

Some files were not shown because too many files have changed in this diff Show More