diff --git a/src/Maps/Accessories.h b/src/Maps/Accessories.h index 3f41ccc..76d116e 100644 --- a/src/Maps/Accessories.h +++ b/src/Maps/Accessories.h @@ -18,53 +18,57 @@ #include +#include + #include +using namespace Corrade; +using namespace Containers::Literals; using namespace Magnum; -static const std::map accessories { +static const std::map accessories { // Primitives - {1, "Cube (S)"}, - {2, "Pentagon (S)"}, - {3, "Hexagon (S)"}, - {4, "Cylinder (S)"}, - {5, "Sphere (S)"}, - {6, "TriPyramid (S)"}, - {7, "SquPyramid (S)"}, - {8, "PenPyramid (S)"}, - {9, "HexPyramid (S)"}, - {10, "Cone (S)"}, - {11, "SquStick (S)"}, - {12, "PenStick (S)"}, - {13, "HexStick (S)"}, - {14, "CycStick (S)"}, - {15, "Capsule (S)"}, - {16, "Decal Pad 01 (S)"}, - {17, "Decal Pad 02 (S)"}, - {18, "Decal Pad 03 (S)"}, - {19, "Decal Pad 04 (S)"}, - {20, "Decal Pad 05 (S)"}, + {1, "Cube (S)"_s}, + {2, "Pentagon (S)"_s}, + {3, "Hexagon (S)"_s}, + {4, "Cylinder (S)"_s}, + {5, "Sphere (S)"_s}, + {6, "TriPyramid (S)"_s}, + {7, "SquPyramid (S)"_s}, + {8, "PenPyramid (S)"_s}, + {9, "HexPyramid (S)"_s}, + {10, "Cone (S)"_s}, + {11, "SquStick (S)"_s}, + {12, "PenStick (S)"_s}, + {13, "HexStick (S)"_s}, + {14, "CycStick (S)"_s}, + {15, "Capsule (S)"_s}, + {16, "Decal Pad 01 (S)"_s}, + {17, "Decal Pad 02 (S)"_s}, + {18, "Decal Pad 03 (S)"_s}, + {19, "Decal Pad 04 (S)"_s}, + {20, "Decal Pad 05 (S)"_s}, - {51, "SquBevel (S)"}, - {52, "TriBevel (S)"}, - {53, "PenBevel (S)"}, - {54, "HexBevel (S)"}, - {55, "CycBevel (S)"}, - {56, "RecBevel (S)"}, - {57, "DaiBevel (S)"}, - {58, "MonBevel (S)"}, - {59, "CofBevel (S)"}, - {60, "JevBevel (S)"}, - {61, "SquEmboss (S)"}, - {62, "TriEmboss (S)"}, - {63, "PenEmboss (S)"}, - {64, "HexEmboss (S)"}, - {65, "CycEmboss (S)"}, - {66, "RecEmboss (S)"}, - {67, "DaiEmboss (S)"}, - {68, "MonEmboss (S)"}, - {69, "CofEmboss (S)"}, - {70, "JevEmboss (S)"}, + {51, "SquBevel (S)"_s}, + {52, "TriBevel (S)"_s}, + {53, "PenBevel (S)"_s}, + {54, "HexBevel (S)"_s}, + {55, "CycBevel (S)"_s}, + {56, "RecBevel (S)"_s}, + {57, "DaiBevel (S)"_s}, + {58, "MonBevel (S)"_s}, + {59, "CofBevel (S)"_s}, + {60, "JevBevel (S)"_s}, + {61, "SquEmboss (S)"_s}, + {62, "TriEmboss (S)"_s}, + {63, "PenEmboss (S)"_s}, + {64, "HexEmboss (S)"_s}, + {65, "CycEmboss (S)"_s}, + {66, "RecEmboss (S)"_s}, + {67, "DaiEmboss (S)"_s}, + {68, "MonEmboss (S)"_s}, + {69, "CofEmboss (S)"_s}, + {70, "JevEmboss (S)"_s}, // Armours diff --git a/src/Maps/ArmourSets.h b/src/Maps/ArmourSets.h index 24d46bd..bc4311f 100644 --- a/src/Maps/ArmourSets.h +++ b/src/Maps/ArmourSets.h @@ -18,34 +18,38 @@ #include +#include + #include +using namespace Corrade; +using namespace Containers::Literals; using namespace Magnum; struct ArmourSet { - const char* name; + Containers::StringView name; bool neck_compatible; }; static const std::map armour_sets { - {-1, {"", true}}, - {0, {"Vanguard", true}}, - {1, {"Assault Mk.I", true}}, - {2, {"Assault Mk.II", false}}, - {3, {"Assault Mk.III", false}}, - {7, {"Titan 001", true}}, - {8, {"Titan 002", false}}, - {9, {"Titan 003", false}}, - {13, {"Blitz X", true}}, - {14, {"Blitz EX", false}}, - {15, {"Blitz EXS", false}}, - {16, {"Kaiser S-R0", true}}, - {17, {"Kaiser S-R1", false}}, - {18, {"Kaiser S-R2", false}}, - {19, {"Hammerfall MG-A", true}}, - {20, {"Hammerfall MG-S", false}}, - {21, {"Hammerfall MG-X", false}}, - {22, {"Panzer S-UC", true}}, - {23, {"Panzer L-UC", false}}, - {24, {"Panzer H-UC", false}}, + {-1, {""_s, true}}, + {0, {"Vanguard"_s, true}}, + {1, {"Assault Mk.I"_s, true}}, + {2, {"Assault Mk.II"_s, false}}, + {3, {"Assault Mk.III"_s, false}}, + {7, {"Titan 001"_s, true}}, + {8, {"Titan 002"_s, false}}, + {9, {"Titan 003"_s, false}}, + {13, {"Blitz X"_s, true}}, + {14, {"Blitz EX"_s, false}}, + {15, {"Blitz EXS"_s, false}}, + {16, {"Kaiser S-R0"_s, true}}, + {17, {"Kaiser S-R1"_s, false}}, + {18, {"Kaiser S-R2"_s, false}}, + {19, {"Hammerfall MG-A"_s, true}}, + {20, {"Hammerfall MG-S"_s, false}}, + {21, {"Hammerfall MG-X"_s, false}}, + {22, {"Panzer S-UC"_s, true}}, + {23, {"Panzer L-UC"_s, false}}, + {24, {"Panzer H-UC"_s, false}}, }; diff --git a/src/Maps/ArmourSlots.hpp b/src/Maps/ArmourSlots.hpp index 3004a65..73f7393 100644 --- a/src/Maps/ArmourSlots.hpp +++ b/src/Maps/ArmourSlots.hpp @@ -15,42 +15,42 @@ // along with this program. If not, see . #ifdef c -c(Face, "enuArmorSlots::NewEnumerator0", "Face") -c(UpperHead, "enuArmorSlots::NewEnumerator1", "Upper head") -c(LowerHead, "enuArmorSlots::NewEnumerator2", "Lower head") -c(Neck, "enuArmorSlots::NewEnumerator3", "Neck") -c(UpperBody, "enuArmorSlots::NewEnumerator4", "Upper body") -c(MiddleBody, "enuArmorSlots::NewEnumerator5", "Middle body") -c(LowerBody, "enuArmorSlots::NewEnumerator6", "Lower body") -c(FrontWaist, "enuArmorSlots::NewEnumerator7", "Front waist") -c(LeftFrontSkirt, "enuArmorSlots::NewEnumerator8", "Left front skirt") -c(RightFrontSkirt, "enuArmorSlots::NewEnumerator9", "Right front skirt") -c(LeftSideSkirt, "enuArmorSlots::NewEnumerator10", "Left side skirt") -c(RightSideSkirt, "enuArmorSlots::NewEnumerator11", "Right side skirt") -c(LeftBackSkirt, "enuArmorSlots::NewEnumerator12", "Left back skirt") -c(RightBackSkirt, "enuArmorSlots::NewEnumerator13", "Right back skirt") -c(BackWaist, "enuArmorSlots::NewEnumerator14", "Back waist") -c(LeftShoulder, "enuArmorSlots::NewEnumerator15", "Left shoulder") -c(RightShoulder, "enuArmorSlots::NewEnumerator16", "Right shoulder") -c(LeftUpperArm, "enuArmorSlots::NewEnumerator17", "Left upper arm") -c(RightUpperArm, "enuArmorSlots::NewEnumerator18", "Right upper arm") -c(LeftElbow, "enuArmorSlots::NewEnumerator19", "Left elbow") -c(RightElbow, "enuArmorSlots::NewEnumerator20", "Right elbow") -c(LeftLowerArm, "enuArmorSlots::NewEnumerator21", "Left lower arm") -c(RightLowerArm, "enuArmorSlots::NewEnumerator22", "Right lower arm") -c(Backpack, "enuArmorSlots::NewEnumerator23", "Backpack") -c(LeftHand, "enuArmorSlots::NewEnumerator24", "Left hand") -c(RightHand, "enuArmorSlots::NewEnumerator25", "Right hand") -c(LeftUpperLeg, "enuArmorSlots::NewEnumerator26", "Left upper leg") -c(RightUpperLeg, "enuArmorSlots::NewEnumerator27", "Right upper leg") -c(LeftKnee, "enuArmorSlots::NewEnumerator28", "Left knee") -c(RightKnee, "enuArmorSlots::NewEnumerator29", "Right knee") -c(LeftLowerLeg, "enuArmorSlots::NewEnumerator30", "Left lower leg") -c(RightLowerLeg, "enuArmorSlots::NewEnumerator31", "Right lower leg") -c(LeftAnkle, "enuArmorSlots::NewEnumerator32", "Left ankle") -c(RightAnkle, "enuArmorSlots::NewEnumerator33", "Right ankle") -c(LeftHeel, "enuArmorSlots::NewEnumerator34", "Left heel") -c(RightHeel, "enuArmorSlots::NewEnumerator35", "Right heel") -c(LeftFoot, "enuArmorSlots::NewEnumerator36", "Left foot") -c(RightFoot, "enuArmorSlots::NewEnumerator37", "Right foot") +c(Face, "enuArmorSlots::NewEnumerator0"_s, "Face"_s) +c(UpperHead, "enuArmorSlots::NewEnumerator1"_s, "Upper head"_s) +c(LowerHead, "enuArmorSlots::NewEnumerator2"_s, "Lower head"_s) +c(Neck, "enuArmorSlots::NewEnumerator3"_s, "Neck"_s) +c(UpperBody, "enuArmorSlots::NewEnumerator4"_s, "Upper body"_s) +c(MiddleBody, "enuArmorSlots::NewEnumerator5"_s, "Middle body"_s) +c(LowerBody, "enuArmorSlots::NewEnumerator6"_s, "Lower body"_s) +c(FrontWaist, "enuArmorSlots::NewEnumerator7"_s, "Front waist"_s) +c(LeftFrontSkirt, "enuArmorSlots::NewEnumerator8"_s, "Left front skirt"_s) +c(RightFrontSkirt, "enuArmorSlots::NewEnumerator9"_s, "Right front skirt"_s) +c(LeftSideSkirt, "enuArmorSlots::NewEnumerator10"_s, "Left side skirt"_s) +c(RightSideSkirt, "enuArmorSlots::NewEnumerator11"_s, "Right side skirt"_s) +c(LeftBackSkirt, "enuArmorSlots::NewEnumerator12"_s, "Left back skirt"_s) +c(RightBackSkirt, "enuArmorSlots::NewEnumerator13"_s, "Right back skirt"_s) +c(BackWaist, "enuArmorSlots::NewEnumerator14"_s, "Back waist"_s) +c(LeftShoulder, "enuArmorSlots::NewEnumerator15"_s, "Left shoulder"_s) +c(RightShoulder, "enuArmorSlots::NewEnumerator16"_s, "Right shoulder"_s) +c(LeftUpperArm, "enuArmorSlots::NewEnumerator17"_s, "Left upper arm"_s) +c(RightUpperArm, "enuArmorSlots::NewEnumerator18"_s, "Right upper arm"_s) +c(LeftElbow, "enuArmorSlots::NewEnumerator19"_s, "Left elbow"_s) +c(RightElbow, "enuArmorSlots::NewEnumerator20"_s, "Right elbow"_s) +c(LeftLowerArm, "enuArmorSlots::NewEnumerator21"_s, "Left lower arm"_s) +c(RightLowerArm, "enuArmorSlots::NewEnumerator22"_s, "Right lower arm"_s) +c(Backpack, "enuArmorSlots::NewEnumerator23"_s, "Backpack"_s) +c(LeftHand, "enuArmorSlots::NewEnumerator24"_s, "Left hand"_s) +c(RightHand, "enuArmorSlots::NewEnumerator25"_s, "Right hand"_s) +c(LeftUpperLeg, "enuArmorSlots::NewEnumerator26"_s, "Left upper leg"_s) +c(RightUpperLeg, "enuArmorSlots::NewEnumerator27"_s, "Right upper leg"_s) +c(LeftKnee, "enuArmorSlots::NewEnumerator28"_s, "Left knee"_s) +c(RightKnee, "enuArmorSlots::NewEnumerator29"_s, "Right knee"_s) +c(LeftLowerLeg, "enuArmorSlots::NewEnumerator30"_s, "Left lower leg"_s) +c(RightLowerLeg, "enuArmorSlots::NewEnumerator31"_s, "Right lower leg"_s) +c(LeftAnkle, "enuArmorSlots::NewEnumerator32"_s, "Left ankle"_s) +c(RightAnkle, "enuArmorSlots::NewEnumerator33"_s, "Right ankle"_s) +c(LeftHeel, "enuArmorSlots::NewEnumerator34"_s, "Left heel"_s) +c(RightHeel, "enuArmorSlots::NewEnumerator35"_s, "Right heel"_s) +c(LeftFoot, "enuArmorSlots::NewEnumerator36"_s, "Left foot"_s) +c(RightFoot, "enuArmorSlots::NewEnumerator37"_s, "Right foot"_s) #endif diff --git a/src/Maps/DamageTypes.hpp b/src/Maps/DamageTypes.hpp index 5665f65..edfdaad 100644 --- a/src/Maps/DamageTypes.hpp +++ b/src/Maps/DamageTypes.hpp @@ -15,10 +15,10 @@ // along with this program. If not, see . #ifdef c -c(Physical, "enuDamageProperty::NewEnumerator0") -c(Piercing, "enuDamageProperty::NewEnumerator1") -c(Heat, "enuDamageProperty::NewEnumerator2") -c(Freeze, "enuDamageProperty::NewEnumerator3") -c(Shock, "enuDamageProperty::NewEnumerator4") -c(Plasma, "enuDamageProperty::NewEnumerator5") +c(Physical, "enuDamageProperty::NewEnumerator0"_s) +c(Piercing, "enuDamageProperty::NewEnumerator1"_s) +c(Heat, "enuDamageProperty::NewEnumerator2"_s) +c(Freeze, "enuDamageProperty::NewEnumerator3"_s) +c(Shock, "enuDamageProperty::NewEnumerator4"_s) +c(Plasma, "enuDamageProperty::NewEnumerator5"_s) #endif diff --git a/src/Maps/EffectColourModes.hpp b/src/Maps/EffectColourModes.hpp index 7df0077..9e18866 100644 --- a/src/Maps/EffectColourModes.hpp +++ b/src/Maps/EffectColourModes.hpp @@ -15,6 +15,6 @@ // along with this program. If not, see . #ifdef c -c(Default, "enuWeaponEffectColorMode::NewEnumerator0") -c(Custom, "enuWeaponEffectColorMode::NewEnumerator1") +c(Default, "enuWeaponEffectColorMode::NewEnumerator0"_s) +c(Custom, "enuWeaponEffectColorMode::NewEnumerator1"_s) #endif diff --git a/src/Maps/LastMissionId.h b/src/Maps/LastMissionId.h index 165fbb1..03b407e 100644 --- a/src/Maps/LastMissionId.h +++ b/src/Maps/LastMissionId.h @@ -18,31 +18,39 @@ #include -static const std::map mission_id_map {{ +#include + +#include + +using namespace Corrade; +using namespace Containers::Literals; +using namespace Magnum; + +static const std::map mission_id_map {{ // Story missions - {0x0064, "Mission 1 - Training"}, - {0x0065, "Mission 2 - Patrol Operation"}, - {0x0066, "Mission 3 - Fusion Cells in the Snow"}, - {0x0067, "Mission 4 - Earning Changes"}, - {0x0068, "Mission 5 - Unexpected Coordination"}, - {0x0069, "Mission 6 - Empowering Void"}, - {0x006A, "Mission 7 - Logisitics Obstacles"}, - {0x006B, "Mission 8 - Wrath of the Wastelands"}, - {0x006C, "Mission 9 - Suspicious Originator"}, - {0x006D, "Mission 10 - Researchers Data Recovery"}, - {0x006E, "Mission 11 - Tempestuous Sector"}, - {0x006F, "Mission 12 - Clashes of Metal"}, - {0x0070, "Mission 13 - The Sandstorm Glutton"}, - {0x0071, "Mission 14 - An Icy Investigation"}, + {0x0064, "Mission 1 - Training"_s}, + {0x0065, "Mission 2 - Patrol Operation"_s}, + {0x0066, "Mission 3 - Fusion Cells in the Snow"_s}, + {0x0067, "Mission 4 - Earning Changes"_s}, + {0x0068, "Mission 5 - Unexpected Coordination"_s}, + {0x0069, "Mission 6 - Empowering Void"_s}, + {0x006A, "Mission 7 - Logisitics Obstacles"_s}, + {0x006B, "Mission 8 - Wrath of the Wastelands"_s}, + {0x006C, "Mission 9 - Suspicious Originator"_s}, + {0x006D, "Mission 10 - Researchers Data Recovery"_s}, + {0x006E, "Mission 11 - Tempestuous Sector"_s}, + {0x006F, "Mission 12 - Clashes of Metal"_s}, + {0x0070, "Mission 13 - The Sandstorm Glutton"_s}, + {0x0071, "Mission 14 - An Icy Investigation"_s}, // Hunting grounds - {0x00C8, "Hunt 1 - Desert Pathway Safety"}, - {0x00C9, "Hunt 2 - Snowfield Custodian"}, - {0x00CA, "Hunt 3 - Abandoned Valley Raid"}, - {0x00CB, "Hunt 4 - Depths of the Machineries"}, + {0x00C8, "Hunt 1 - Desert Pathway Safety"_s}, + {0x00C9, "Hunt 2 - Snowfield Custodian"_s}, + {0x00CA, "Hunt 3 - Abandoned Valley Raid"_s}, + {0x00CB, "Hunt 4 - Depths of the Machineries"_s}, // Challenges - {0x012C, "Challenge 1 - Redline Battlefront"}, - {0x0140, "Challenge 2 - Void Convergence"}, - {0x0190, "Challenge 3 - Gates of Ascension"} + {0x012C, "Challenge 1 - Redline Battlefront"_s}, + {0x0140, "Challenge 2 - Void Convergence"_s}, + {0x0190, "Challenge 3 - Gates of Ascension"_s} }}; diff --git a/src/Maps/StoryProgress.h b/src/Maps/StoryProgress.h index 6bb1742..98d9010 100644 --- a/src/Maps/StoryProgress.h +++ b/src/Maps/StoryProgress.h @@ -17,78 +17,85 @@ // along with this program. If not, see . #include +#include + +#include + +using namespace Corrade; +using namespace Containers::Literals; +using namespace Magnum; struct StoryProgressPoint { Int id; - const char* chapter; - const char* point; - const char* after = nullptr; + Containers::StringView chapter; + Containers::StringView point; + Containers::StringView after = nullptr; }; static const Corrade::Containers::Array story_progress { InPlaceInit, { - {0x0000, "Chapter 1", "Chapter start (company isn't named yet)"}, - {0x0064, "Chapter 1", "First time in the hangar"}, - {0x0065, "Chapter 1", "After 1st meeting with Quin in mission section"}, - {0x0066, "Chapter 1", "Talking with Reina and Quin in hangar", "After training"}, - {0x0067, "Chapter 1", "Returned to hangar", "After training"}, - {0x0068, "Chapter 1", "Talked with Quin in development section", "After training"}, - {0x0069, "Chapter 1", "Talked with Waltz in armour section", "After training"}, - {0x00C8, "Chapter 1", "Talked with Kael in tuning section", "After training"}, - {0x00C9, "Chapter 1", "Got mission 2 briefing", "After training"}, - {0x012C, "Chapter 1", "Talking with Reina", "After mission 2"}, - {0x012D, "Chapter 1", "Returned to hangar", "After mission 2"}, - {0x012E, "Chapter 1", "Talked with Kael in tuning section", "After mission 2"}, - {0x012F, "Chapter 1", "Talked with Reina in hangar", "After mission 2"}, - {0x0130, "Chapter 1", "Got mission 3 briefing", "After mission 2"}, - {0x0190, "Chapter 1", "Talking with Reina", "After mission 3"}, - {0x0191, "Chapter 1", "Returned to hangar", "After mission 3"}, - {0x0192, "Chapter 1", "Talked with Waltz in armour section", "After mission 3"}, - {0x0193, "Chapter 1", "Got mission 4 briefing", "After mission 3"}, - {0x01F4, "Chapter 1", "Talking with Reina", "After mission 4"}, - {0x01F5, "Chapter 1", "Returned to hangar", "After mission 4"}, - {0x01F6, "Chapter 1", "Talked with Waltz in armour section", "After mission 4"}, - {0x01F7, "Chapter 1", "Talked with Reina in hangar", "After mission 4"}, - {0x01F8, "Chapter 1", "Got mission 5 and hunt 1 briefing", "After mission 4"}, - {0x0258, "Chapter 1", "Meeting Neon and Aine", "After mission 5"}, - {0x0259, "Chapter 1", "Returned to hangar", "After mission 5"}, - {0x025A, "Chapter 1", "Got mission 6 briefing", "After mission 5"}, - {0x02BC, "Chapter 1", "Talking with Reina", "After mission 6"}, - {0x02BD, "Chapter 1", "Returned to hangar", "After mission 6"}, - {0x02BE, "Chapter 1", "Got hunt 2 briefing", "After mission 6"}, - {0x02BF, "Chapter 1", "Met Ellenier", "After mission 6"}, - {0x02C0, "Chapter 1", "Got mission 7 briefing", "After mission 6"}, - {0x0320, "Chapter 1", "Talking with Nier", "After mission 7"}, - {0x0321, "Chapter 1", "Returned to hangar", "After mission 7"}, - {0x0322, "Chapter 1", "Talked with Quin, Reina, and Nier in development section", "After mission 7"}, - {0x0323, "Chapter 1", "Got mission 8 briefing", "After mission 7"}, - {0x0384, "Chapter 1", "Talking with crew in hangar", "After mission 8"}, - {0x0385, "Chapter 1", "Returned to hangar", "After mission 8"}, - {0x0386, "Chapter 1", "Got hunt 3 briefing", "After mission 8"}, - {0x0387, "Chapter 1", "Talked with Reina, Nier, and Quin in development section", "After mission 8"}, + {0x0000, "Chapter 1"_s, "Chapter start (company isn't named yet)"_s}, + {0x0064, "Chapter 1"_s, "First time in the hangar"_s}, + {0x0065, "Chapter 1"_s, "After 1st meeting with Quin in mission section"_s}, + {0x0066, "Chapter 1"_s, "Talking with Reina and Quin in hangar"_s, "After training"_s}, + {0x0067, "Chapter 1"_s, "Returned to hangar"_s, "After training"_s}, + {0x0068, "Chapter 1"_s, "Talked with Quin in development section"_s, "After training"_s}, + {0x0069, "Chapter 1"_s, "Talked with Waltz in armour section"_s, "After training"_s}, + {0x00C8, "Chapter 1"_s, "Talked with Kael in tuning section"_s, "After training"_s}, + {0x00C9, "Chapter 1"_s, "Got mission 2 briefing"_s, "After training"_s}, + {0x012C, "Chapter 1"_s, "Talking with Reina"_s, "After mission 2"_s}, + {0x012D, "Chapter 1"_s, "Returned to hangar"_s, "After mission 2"_s}, + {0x012E, "Chapter 1"_s, "Talked with Kael in tuning section"_s, "After mission 2"_s}, + {0x012F, "Chapter 1"_s, "Talked with Reina in hangar"_s, "After mission 2"_s}, + {0x0130, "Chapter 1"_s, "Got mission 3 briefing"_s, "After mission 2"_s}, + {0x0190, "Chapter 1"_s, "Talking with Reina"_s, "After mission 3"_s}, + {0x0191, "Chapter 1"_s, "Returned to hangar"_s, "After mission 3"_s}, + {0x0192, "Chapter 1"_s, "Talked with Waltz in armour section"_s, "After mission 3"_s}, + {0x0193, "Chapter 1"_s, "Got mission 4 briefing"_s, "After mission 3"_s}, + {0x01F4, "Chapter 1"_s, "Talking with Reina"_s, "After mission 4"_s}, + {0x01F5, "Chapter 1"_s, "Returned to hangar"_s, "After mission 4"_s}, + {0x01F6, "Chapter 1"_s, "Talked with Waltz in armour section"_s, "After mission 4"_s}, + {0x01F7, "Chapter 1"_s, "Talked with Reina in hangar"_s, "After mission 4"_s}, + {0x01F8, "Chapter 1"_s, "Got mission 5 and hunt 1 briefing"_s, "After mission 4"_s}, + {0x0258, "Chapter 1"_s, "Meeting Neon and Aine"_s, "After mission 5"_s}, + {0x0259, "Chapter 1"_s, "Returned to hangar"_s, "After mission 5"_s}, + {0x025A, "Chapter 1"_s, "Got mission 6 briefing"_s, "After mission 5"_s}, + {0x02BC, "Chapter 1"_s, "Talking with Reina"_s, "After mission 6"_s}, + {0x02BD, "Chapter 1"_s, "Returned to hangar"_s, "After mission 6"_s}, + {0x02BE, "Chapter 1"_s, "Got hunt 2 briefing"_s, "After mission 6"_s}, + {0x02BF, "Chapter 1"_s, "Met Ellenier"_s, "After mission 6"_s}, + {0x02C0, "Chapter 1"_s, "Got mission 7 briefing"_s, "After mission 6"_s}, + {0x0320, "Chapter 1"_s, "Talking with Nier"_s, "After mission 7"_s}, + {0x0321, "Chapter 1"_s, "Returned to hangar"_s, "After mission 7"_s}, + {0x0322, "Chapter 1"_s, "Talked with Quin, Reina, and Nier in development section"_s, "After mission 7"_s}, + {0x0323, "Chapter 1"_s, "Got mission 8 briefing"_s, "After mission 7"_s}, + {0x0384, "Chapter 1"_s, "Talking with crew in hangar"_s, "After mission 8"_s}, + {0x0385, "Chapter 1"_s, "Returned to hangar"_s, "After mission 8"_s}, + {0x0386, "Chapter 1"_s, "Got hunt 3 briefing"_s, "After mission 8"_s}, + {0x0387, "Chapter 1"_s, "Talked with Reina, Nier, and Quin in development section"_s, "After mission 8"_s}, - {0x0388, "Chapter 2", "Chapter start"}, - {0x0389, "Chapter 2", "Got mission 9 briefing"}, - {0x03E8, "Chapter 2", "Talking with Reina in hangar", "After mission 9"}, - {0x03E9, "Chapter 2", "Returned to hangar", "After mission 9"}, - {0x03EA, "Chapter 2", "Talked with crew in armour section", "After mission 9"}, - {0x03EB, "Chapter 2", "Got mission 10 briefing", "After mission 9"}, - {0x044C, "Chapter 2", "Talking with Reina in hangar", "After mission 10"}, - {0x044D, "Chapter 2", "Returned to hangar", "After mission 10"}, - {0x044E, "Chapter 2", "Got mission 11 briefing", "After mission 10"}, - {0x04B0, "Chapter 2", "Talking with Reina and Nier in hangar", "After mission 11"}, - {0x04B1, "Chapter 2", "Returned to hangar", "After mission 11"}, - {0x04B2, "Chapter 2", "Got mission 12 briefing", "After mission 11"}, - {0x0514, "Chapter 2", "Talking with Reina and Waltz in hangar", "After mission 12"}, - {0x0515, "Chapter 2", "Returned to hangar", "After mission 12"}, - {0x0516, "Chapter 2", "Got hunt 4 and mission 13 briefing", "After mission 12"}, - {0x0578, "Chapter 2", "Talking with Reina in hangar", "After mission 13"}, - {0x0579, "Chapter 2", "Returned to hangar", "After mission 13"}, - {0x057A, "Chapter 2", "Talked with Reina in development section", "After mission 13"}, - {0x057B, "Chapter 2", "Got briefing for challenges 1, 2, and 3", "After mission 13"}, - {0x057C, "Chapter 2", "Talked with Reina about device", "After mission 13"}, - {0x057D, "Chapter 2", "Got mission 14 briefing", "After mission 13"}, + {0x0388, "Chapter 2"_s, "Chapter start"_s}, + {0x0389, "Chapter 2"_s, "Got mission 9 briefing"_s}, + {0x03E8, "Chapter 2"_s, "Talking with Reina in hangar"_s, "After mission 9"_s}, + {0x03E9, "Chapter 2"_s, "Returned to hangar"_s, "After mission 9"_s}, + {0x03EA, "Chapter 2"_s, "Talked with crew in armour section"_s, "After mission 9"_s}, + {0x03EB, "Chapter 2"_s, "Got mission 10 briefing"_s, "After mission 9"_s}, + {0x044C, "Chapter 2"_s, "Talking with Reina in hangar"_s, "After mission 10"_s}, + {0x044D, "Chapter 2"_s, "Returned to hangar"_s, "After mission 10"_s}, + {0x044E, "Chapter 2"_s, "Got mission 11 briefing"_s, "After mission 10"_s}, + {0x04B0, "Chapter 2"_s, "Talking with Reina and Nier in hangar"_s, "After mission 11"_s}, + {0x04B1, "Chapter 2"_s, "Returned to hangar"_s, "After mission 11"_s}, + {0x04B2, "Chapter 2"_s, "Got mission 12 briefing"_s, "After mission 11"_s}, + {0x0514, "Chapter 2"_s, "Talking with Reina and Waltz in hangar"_s, "After mission 12"_s}, + {0x0515, "Chapter 2"_s, "Returned to hangar"_s, "After mission 12"_s}, + {0x0516, "Chapter 2"_s, "Got hunt 4 and mission 13 briefing"_s, "After mission 12"_s}, + {0x0578, "Chapter 2"_s, "Talking with Reina in hangar"_s, "After mission 13"_s}, + {0x0579, "Chapter 2"_s, "Returned to hangar"_s, "After mission 13"_s}, + {0x057A, "Chapter 2"_s, "Talked with Reina in development section"_s, "After mission 13"_s}, + {0x057B, "Chapter 2"_s, "Got briefing for challenges 1, 2, and 3"_s, "After mission 13"_s}, + {0x057C, "Chapter 2"_s, "Talked with Reina about device"_s, "After mission 13"_s}, + {0x057D, "Chapter 2"_s, "Got mission 14 briefing"_s, "After mission 13"_s}, } }; diff --git a/src/Maps/StyleNames.h b/src/Maps/StyleNames.h index 048509a..e62188f 100644 --- a/src/Maps/StyleNames.h +++ b/src/Maps/StyleNames.h @@ -18,175 +18,179 @@ #include +#include + #include +using namespace Corrade; +using namespace Containers::Literals; using namespace Magnum; -extern const std::map style_names +extern const std::map style_names #ifdef STYLENAMES_DEFINITION { - {0, "Custom Style 1"}, - {1, "Custom Style 2"}, - {2, "Custom Style 3"}, - {3, "Custom Style 4"}, - {4, "Custom Style 5"}, - {5, "Custom Style 6"}, - {6, "Custom Style 7"}, - {7, "Custom Style 8"}, - {8, "Custom Style 9"}, - {9, "Custom Style 10"}, - {10, "Custom Style 11"}, - {11, "Custom Style 12"}, - {12, "Custom Style 13"}, - {13, "Custom Style 14"}, - {14, "Custom Style 15"}, - {15, "Custom Style 16"}, + {0, "Custom Style 1"_s}, + {1, "Custom Style 2"_s}, + {2, "Custom Style 3"_s}, + {3, "Custom Style 4"_s}, + {4, "Custom Style 5"_s}, + {5, "Custom Style 6"_s}, + {6, "Custom Style 7"_s}, + {7, "Custom Style 8"_s}, + {8, "Custom Style 9"_s}, + {9, "Custom Style 10"_s}, + {10, "Custom Style 11"_s}, + {11, "Custom Style 12"_s}, + {12, "Custom Style 13"_s}, + {13, "Custom Style 14"_s}, + {14, "Custom Style 15"_s}, + {15, "Custom Style 16"_s}, - {50, "Global Style 1"}, - {51, "Global Style 2"}, - {52, "Global Style 3"}, - {53, "Global Style 4"}, - {54, "Global Style 5"}, - {55, "Global Style 6"}, - {56, "Global Style 7"}, - {57, "Global Style 8"}, - {58, "Global Style 9"}, - {59, "Global Style 10"}, - {60, "Global Style 11"}, - {61, "Global Style 12"}, - {62, "Global Style 13"}, - {63, "Global Style 14"}, - {64, "Global Style 15"}, - {65, "Global Style 16"}, + {50, "Global Style 1"_s}, + {51, "Global Style 2"_s}, + {52, "Global Style 3"_s}, + {53, "Global Style 4"_s}, + {54, "Global Style 5"_s}, + {55, "Global Style 6"_s}, + {56, "Global Style 7"_s}, + {57, "Global Style 8"_s}, + {58, "Global Style 9"_s}, + {59, "Global Style 10"_s}, + {60, "Global Style 11"_s}, + {61, "Global Style 12"_s}, + {62, "Global Style 13"_s}, + {63, "Global Style 14"_s}, + {64, "Global Style 15"_s}, + {65, "Global Style 16"_s}, - {100, "Iron"}, - {101, "Silver"}, - {102, "Gold"}, - {103, "Bronze"}, - {104, "Copper"}, - {105, "Nickel"}, - {106, "Cobalt"}, - {107, "Aluminium"}, - {108, "Titanium"}, - {109, "Platinum"}, - {110, "Gun Metal"}, - {111, "White"}, - {112, "White Metal"}, - {113, "White Gloss"}, - {114, "Grey"}, - {115, "Grey Metal"}, - {116, "Grey Gloss"}, - {117, "Dark Grey"}, - {118, "Dark Grey Metal"}, - {119, "Dark Grey Gloss"}, - {120, "Black"}, - {121, "Black Metal"}, - {122, "Black Gloss"}, - {123, "Red"}, - {124, "Red Metal"}, - {125, "Red Gloss"}, - {126, "Dark Red"}, - {127, "Dark Red Metal"}, - {128, "Dark Red Gloss"}, - {129, "Orange"}, - {130, "Orange Metal"}, - {131, "Orange Gloss"}, - {132, "Dark Orange"}, - {133, "Dark Orange Metal"}, - {134, "Dark Orange Gloss"}, - {135, "Yellow"}, - {136, "Yellow Metal"}, - {137, "Yellow Gloss"}, - {138, "Brown"}, - {139, "Brown Metal"}, - {140, "Brown Gloss"}, - {141, "Dark Brown"}, - {142, "Dark Brown Metal"}, - {143, "Dark Brown Gloss"}, - {144, "Leafgreen"}, - {145, "Leafgreen Metal"}, - {146, "Leafgreen Gloss"}, - {147, "Military Green"}, - {148, "Military Green Metal"}, - {149, "Military Green Gloss"}, - {150, "Green"}, - {151, "Green Metal"}, - {152, "Green Gloss"}, - {153, "Dark Green"}, - {154, "Dark Green Metal"}, - {155, "Dark Green Gloss"}, - {156, "Teal"}, - {157, "Teal Metal"}, - {158, "Teal Gloss"}, - {159, "Cyan"}, - {160, "Cyan Metal"}, - {161, "Cyan Gloss"}, - {162, "Blue"}, - {163, "Blue Metal"}, - {164, "Blue Gloss"}, - {165, "Blue Sky"}, - {166, "Blue Sky Metal"}, - {167, "Blue Sky Gloss"}, - {168, "Dark Blue"}, - {169, "Dark Blue Metal"}, - {170, "Dark Blue Gloss"}, - {171, "Purple"}, - {172, "Purple Metal"}, - {173, "Purple Gloss"}, - {174, "Dark Purple"}, - {175, "Dark Purple Metal"}, - {176, "Dark Purple Gloss"}, - {177, "Pink"}, - {178, "Pink Metal"}, - {179, "Pink Gloss"}, - {180, "Rosy Brown"}, - {181, "Rosy Brown Metal"}, - {182, "Rosy Brown Gloss"}, - {183, "Ivory"}, - {184, "Ivory Metal"}, - {185, "Ivory Gloss"}, - {186, "Slate Brown"}, - {187, "Slate Brown Metal"}, - {188, "Slate Brown Gloss"}, - {189, "Slate Green"}, - {190, "Slate Green Metal"}, - {191, "Slate Green Gloss"}, - {192, "Slate Blue"}, - {193, "Slate Blue Metal"}, - {194, "Slate Blue Gloss"}, - {195, "Slate Purple"}, - {196, "Slate Purple Metal"}, - {197, "Slate Purple Gloss"}, - {198, "White Glow"}, - {199, "White Radiance"}, - {200, "Red Glow"}, - {201, "Red Radiance"}, - {202, "Orange Glow"}, - {203, "Orange Radiance"}, - {204, "Yellow Glow"}, - {205, "Yellow Radiance"}, - {206, "Leafgreen Glow"}, - {207, "Leafgreen Radiance"}, - {208, "Green Glow"}, - {209, "Green Radiance"}, - {210, "Teal Glow"}, - {211, "Teal Radiance"}, - {212, "Cyan Glow"}, - {213, "Cyan Radiance"}, - {214, "Blue Glow"}, - {215, "Blue Radiance"}, - {216, "Purple Glow"}, - {217, "Purple Radiance"}, - {218, "Pink Glow"}, - {219, "Pink Radiance"}, - {220, "Grey Camo"}, - {221, "Dark Grey Camo"}, - {222, "Green Camo"}, - {223, "Dark Green Camo"}, - {224, "Brown Camo"}, - {225, "Dark Brown Camo"}, - {226, "Blue Camo"}, - {227, "Dark Blue Camo"}, + {100, "Iron"_s}, + {101, "Silver"_s}, + {102, "Gold"_s}, + {103, "Bronze"_s}, + {104, "Copper"_s}, + {105, "Nickel"_s}, + {106, "Cobalt"_s}, + {107, "Aluminium"_s}, + {108, "Titanium"_s}, + {109, "Platinum"_s}, + {110, "Gun Metal"_s}, + {111, "White"_s}, + {112, "White Metal"_s}, + {113, "White Gloss"_s}, + {114, "Grey"_s}, + {115, "Grey Metal"_s}, + {116, "Grey Gloss"_s}, + {117, "Dark Grey"_s}, + {118, "Dark Grey Metal"_s}, + {119, "Dark Grey Gloss"_s}, + {120, "Black"_s}, + {121, "Black Metal"_s}, + {122, "Black Gloss"_s}, + {123, "Red"_s}, + {124, "Red Metal"_s}, + {125, "Red Gloss"_s}, + {126, "Dark Red"_s}, + {127, "Dark Red Metal"_s}, + {128, "Dark Red Gloss"_s}, + {129, "Orange"_s}, + {130, "Orange Metal"_s}, + {131, "Orange Gloss"_s}, + {132, "Dark Orange"_s}, + {133, "Dark Orange Metal"_s}, + {134, "Dark Orange Gloss"_s}, + {135, "Yellow"_s}, + {136, "Yellow Metal"_s}, + {137, "Yellow Gloss"_s}, + {138, "Brown"_s}, + {139, "Brown Metal"_s}, + {140, "Brown Gloss"_s}, + {141, "Dark Brown"_s}, + {142, "Dark Brown Metal"_s}, + {143, "Dark Brown Gloss"_s}, + {144, "Leafgreen"_s}, + {145, "Leafgreen Metal"_s}, + {146, "Leafgreen Gloss"_s}, + {147, "Military Green"_s}, + {148, "Military Green Metal"_s}, + {149, "Military Green Gloss"_s}, + {150, "Green"_s}, + {151, "Green Metal"_s}, + {152, "Green Gloss"_s}, + {153, "Dark Green"_s}, + {154, "Dark Green Metal"_s}, + {155, "Dark Green Gloss"_s}, + {156, "Teal"_s}, + {157, "Teal Metal"_s}, + {158, "Teal Gloss"_s}, + {159, "Cyan"_s}, + {160, "Cyan Metal"_s}, + {161, "Cyan Gloss"_s}, + {162, "Blue"_s}, + {163, "Blue Metal"_s}, + {164, "Blue Gloss"_s}, + {165, "Blue Sky"_s}, + {166, "Blue Sky Metal"_s}, + {167, "Blue Sky Gloss"_s}, + {168, "Dark Blue"_s}, + {169, "Dark Blue Metal"_s}, + {170, "Dark Blue Gloss"_s}, + {171, "Purple"_s}, + {172, "Purple Metal"_s}, + {173, "Purple Gloss"_s}, + {174, "Dark Purple"_s}, + {175, "Dark Purple Metal"_s}, + {176, "Dark Purple Gloss"_s}, + {177, "Pink"_s}, + {178, "Pink Metal"_s}, + {179, "Pink Gloss"_s}, + {180, "Rosy Brown"_s}, + {181, "Rosy Brown Metal"_s}, + {182, "Rosy Brown Gloss"_s}, + {183, "Ivory"_s}, + {184, "Ivory Metal"_s}, + {185, "Ivory Gloss"_s}, + {186, "Slate Brown"_s}, + {187, "Slate Brown Metal"_s}, + {188, "Slate Brown Gloss"_s}, + {189, "Slate Green"_s}, + {190, "Slate Green Metal"_s}, + {191, "Slate Green Gloss"_s}, + {192, "Slate Blue"_s}, + {193, "Slate Blue Metal"_s}, + {194, "Slate Blue Gloss"_s}, + {195, "Slate Purple"_s}, + {196, "Slate Purple Metal"_s}, + {197, "Slate Purple Gloss"_s}, + {198, "White Glow"_s}, + {199, "White Radiance"_s}, + {200, "Red Glow"_s}, + {201, "Red Radiance"_s}, + {202, "Orange Glow"_s}, + {203, "Orange Radiance"_s}, + {204, "Yellow Glow"_s}, + {205, "Yellow Radiance"_s}, + {206, "Leafgreen Glow"_s}, + {207, "Leafgreen Radiance"_s}, + {208, "Green Glow"_s}, + {209, "Green Radiance"_s}, + {210, "Teal Glow"_s}, + {211, "Teal Radiance"_s}, + {212, "Cyan Glow"_s}, + {213, "Cyan Radiance"_s}, + {214, "Blue Glow"_s}, + {215, "Blue Radiance"_s}, + {216, "Purple Glow"_s}, + {217, "Purple Radiance"_s}, + {218, "Pink Glow"_s}, + {219, "Pink Radiance"_s}, + {220, "Grey Camo"_s}, + {221, "Dark Grey Camo"_s}, + {222, "Green Camo"_s}, + {223, "Dark Green Camo"_s}, + {224, "Brown Camo"_s}, + {225, "Dark Brown Camo"_s}, + {226, "Blue Camo"_s}, + {227, "Dark Blue Camo"_s}, } #endif ; diff --git a/src/Maps/WeaponTypes.hpp b/src/Maps/WeaponTypes.hpp index baa31d6..9ef7858 100644 --- a/src/Maps/WeaponTypes.hpp +++ b/src/Maps/WeaponTypes.hpp @@ -15,10 +15,10 @@ // along with this program. If not, see . #ifdef c -c(Melee, "enuWeaponTypes::NewEnumerator0", "Melee weapon") -c(BulletShooter, "enuWeaponTypes::NewEnumerator1", "Bullet shooter") -c(EnergyShooter, "enuWeaponTypes::NewEnumerator2", "Energy shooter") -c(BulletLauncher, "enuWeaponTypes::NewEnumerator3", "Bullet launcher") -c(EnergyLauncher, "enuWeaponTypes::NewEnumerator4", "Energy launcher") -c(Shield, "enuWeaponTypes::NewEnumerator5", "Shield") +c(Melee, "enuWeaponTypes::NewEnumerator0"_s, "Melee weapon"_s) +c(BulletShooter, "enuWeaponTypes::NewEnumerator1"_s, "Bullet shooter"_s) +c(EnergyShooter, "enuWeaponTypes::NewEnumerator2"_s, "Energy shooter"_s) +c(BulletLauncher, "enuWeaponTypes::NewEnumerator3"_s, "Bullet launcher"_s) +c(EnergyLauncher, "enuWeaponTypes::NewEnumerator4"_s, "Energy launcher"_s) +c(Shield, "enuWeaponTypes::NewEnumerator5"_s, "Shield"_s) #endif diff --git a/src/Mass/ArmourPart.h b/src/Mass/ArmourPart.h index 7246b89..90287f2 100644 --- a/src/Mass/ArmourPart.h +++ b/src/Mass/ArmourPart.h @@ -16,8 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include diff --git a/src/Mass/CustomStyle.h b/src/Mass/CustomStyle.h index cee5cf9..7fcc9c3 100644 --- a/src/Mass/CustomStyle.h +++ b/src/Mass/CustomStyle.h @@ -16,16 +16,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include +#include #include #include #include +using namespace Corrade; using namespace Magnum; struct CustomStyle { - std::string name; + Containers::String name; Color4 colour{0.0f}; Float metallic = 0.5f; Float gloss = 0.5f; diff --git a/src/Mass/Decal.h b/src/Mass/Decal.h index 487f813..3758b75 100644 --- a/src/Mass/Decal.h +++ b/src/Mass/Decal.h @@ -16,8 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include #include diff --git a/src/Mass/Mass.cpp b/src/Mass/Mass.cpp index 38bdf2c..c608027 100644 --- a/src/Mass/Mass.cpp +++ b/src/Mass/Mass.cpp @@ -15,8 +15,10 @@ // along with this program. If not, see . #include +#include #include +#include #include #include "../UESaveFile/Types/ArrayProperty.h" @@ -33,6 +35,8 @@ #include "Mass.h" +using namespace Containers::Literals; + Mass::Mass(const std::string& path) { _folder = Utility::Directory::path(path); _filename = Utility::Directory::filename(path); @@ -40,38 +44,38 @@ Mass::Mass(const std::string& path) { refreshValues(); } -auto Mass::lastError() -> std::string const& { +auto Mass::lastError() -> Containers::StringView { return _lastError; } -auto Mass::getNameFromFile(const std::string& path) -> Containers::Optional { +auto Mass::getNameFromFile(Containers::StringView path) -> Containers::Optional { if(!Utility::Directory::exists(path)) { - Utility::Error{} << path.c_str() << "couldn't be found."; + Utility::Error{} << path << "couldn't be found."_s; return Containers::NullOpt; } UESaveFile mass{path}; if(!mass.valid()) { - Utility::Error{} << "The unit file seems to be corrupt."; + Utility::Error{} << "The unit file seems to be corrupt."_s; return Containers::NullOpt; } - auto unit_data = mass.at("UnitData"); + auto unit_data = mass.at("UnitData"_s); if(!unit_data) { - Utility::Error{} << "Couldn't find unit data in the file."; + Utility::Error{} << "Couldn't find unit data in the file."_s; return Containers::NullOpt; } - auto name_prop = unit_data->at("Name_45_A037C5D54E53456407BDF091344529BB"); + auto name_prop = unit_data->at("Name_45_A037C5D54E53456407BDF091344529BB"_s); if(!name_prop) { - Utility::Error{} << "Couldn't find the name in the file."; + Utility::Error{} << "Couldn't find the name in the file."_s; return Containers::NullOpt; } - return name_prop->value; + return {name_prop->value}; } void Mass::refreshValues() { @@ -108,7 +112,7 @@ void Mass::refreshValues() { return; } - _name = name_prop->value; + _name = {name_prop->value}; getJointSliders(); if(_state == State::Invalid) { @@ -191,34 +195,39 @@ void Mass::refreshValues() { _state = State::Valid; } -auto Mass::filename() -> std::string const&{ +auto Mass::filename() -> Containers::StringView { return _filename; } -auto Mass::name() -> Containers::Optional const& { - return _name; +auto Mass::name() -> Containers::StringView { + return *_name; } -auto Mass::setName(std::string new_name) -> bool { - _name = new_name; +auto Mass::setName(Containers::StringView new_name) -> bool { + _name = {new_name}; - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return false; } - auto name_prop = unit_data->at("Name_45_A037C5D54E53456407BDF091344529BB"); + auto name_prop = unit_data->at("Name_45_A037C5D54E53456407BDF091344529BB"_s); if(!name_prop) { _state = State::Invalid; return false; } - name_prop->value = std::move(new_name); + name_prop->value = new_name; - return _mass->saveToFile(); + if(!_mass->saveToFile()) { + _lastError = _mass->lastError(); + return false; + } + + return true; } auto Mass::state() -> State { @@ -238,130 +247,130 @@ auto Mass::jointSliders() -> Joints& { } void Mass::getJointSliders() { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return; } - auto frame_prop = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"); + auto frame_prop = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); if(!frame_prop) { _state = State::Invalid; return; } - auto length = frame_prop->at("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"); + auto length = frame_prop->at("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"_s); _frame.joints.neck = (length ? length->value : 0.0f); - length = frame_prop->at("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"); + length = frame_prop->at("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"_s); _frame.joints.body = (length ? length->value : 0.0f); - length = frame_prop->at("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"); + length = frame_prop->at("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"_s); _frame.joints.shoulders = (length ? length->value : 0.0f); - length = frame_prop->at("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"); + length = frame_prop->at("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"_s); _frame.joints.hips = (length ? length->value : 0.0f); - length = frame_prop->at("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"); + length = frame_prop->at("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"_s); _frame.joints.upperArms = (length ? length->value : 0.0f); - length = frame_prop->at("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"); + length = frame_prop->at("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"_s); _frame.joints.lowerArms = (length ? length->value : 0.0f); - length = frame_prop->at("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"); + length = frame_prop->at("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"_s); _frame.joints.upperLegs = (length ? length->value : 0.0f); - length = frame_prop->at("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"); + length = frame_prop->at("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"_s); _frame.joints.lowerLegs = (length ? length->value : 0.0f); } auto Mass::writeJointSliders() -> bool { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; - _lastError = "No unit data in " + _filename; + _lastError = "No unit data in "_s + _filename; return false; } - auto frame_prop = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"); + auto frame_prop = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); if(!frame_prop) { _state = State::Invalid; - _lastError = "No frame data in " + _filename; + _lastError = "No frame data in "_s + _filename; return false; } Containers::Array temp; - auto length = frame_prop->atMove("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"); + auto length = frame_prop->atMove("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"_s); if(_frame.joints.neck != 0.0f) { if(!length) { length.emplace(); - length->name.emplace("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"); + length->name.emplace("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"_s); } length->value = _frame.joints.neck; arrayAppend(temp, std::move(length)); } - length = frame_prop->atMove("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"); + length = frame_prop->atMove("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"_s); if(_frame.joints.body != 0.0f) { if(!length) { length.emplace(); - length->name.emplace("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"); + length->name.emplace("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"_s); } length->value = _frame.joints.body; arrayAppend(temp, std::move(length)); } - length = frame_prop->atMove("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"); + length = frame_prop->atMove("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"_s); if(_frame.joints.shoulders != 0.0f) { if(!length) { length.emplace(); - length->name.emplace("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"); + length->name.emplace("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"_s); } length->value = _frame.joints.shoulders; arrayAppend(temp, std::move(length)); } - length = frame_prop->atMove("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"); + length = frame_prop->atMove("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"_s); if(_frame.joints.upperArms != 0.0f) { if(!length) { length.emplace(); - length->name.emplace("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"); + length->name.emplace("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"_s); } length->value = _frame.joints.upperArms; arrayAppend(temp, std::move(length)); } - length = frame_prop->atMove("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"); + length = frame_prop->atMove("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"_s); if(_frame.joints.lowerArms != 0.0f) { if(!length) { length.emplace(); - length->name.emplace("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"); + length->name.emplace("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"_s); } length->value = _frame.joints.lowerArms; arrayAppend(temp, std::move(length)); } - length = frame_prop->atMove("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"); + length = frame_prop->atMove("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"_s); if(_frame.joints.hips != 0.0f) { if(!length) { length.emplace(); - length->name.emplace("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"); + length->name.emplace("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"_s); } length->value = _frame.joints.hips; arrayAppend(temp, std::move(length)); } - length = frame_prop->atMove("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"); + length = frame_prop->atMove("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"_s); if(_frame.joints.upperLegs != 0.0f) { if(!length) { length.emplace(); - length->name.emplace("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"); + length->name.emplace("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"_s); } length->value = _frame.joints.upperLegs; arrayAppend(temp, std::move(length)); } - length = frame_prop->atMove("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"); + length = frame_prop->atMove("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"_s); if(_frame.joints.lowerLegs != 0.0f) { if(!length) { length.emplace(); - length->name.emplace("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"); + length->name.emplace("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"_s); } length->value = _frame.joints.lowerLegs; arrayAppend(temp, std::move(length)); @@ -386,19 +395,19 @@ auto Mass::frameStyles() -> Containers::ArrayView { } void Mass::getFrameStyles() { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return; } - auto frame_prop = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"); + auto frame_prop = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); if(!frame_prop) { _state = State::Invalid; return; } - auto frame_styles = frame_prop->at("Styles_32_00A3B3284B37F1E7819458844A20EB48"); + auto frame_styles = frame_prop->at("Styles_32_00A3B3284B37F1E7819458844A20EB48"_s); if(!frame_styles) { _state = State::Invalid; return; @@ -415,24 +424,24 @@ void Mass::getFrameStyles() { } auto Mass::writeFrameStyles() -> bool { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; - _lastError = "No unit data in " + _filename; + _lastError = "No unit data in "_s + _filename; return false; } - auto frame = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"); + auto frame = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); if(!frame) { _state = State::Invalid; - _lastError = "No frame data in " + _filename; + _lastError = "No frame data in "_s + _filename; return false; } - auto frame_styles = frame->at("Styles_32_00A3B3284B37F1E7819458844A20EB48"); + auto frame_styles = frame->at("Styles_32_00A3B3284B37F1E7819458844A20EB48"_s); if(!frame_styles) { _state = State::Invalid; - _lastError = "No frame styles in " + _filename; + _lastError = "No frame styles in "_s + _filename; return false; } @@ -453,19 +462,19 @@ auto Mass::eyeFlareColour() -> Color4& { } void Mass::getEyeFlareColour() { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return; } - auto frame_prop = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"); + auto frame_prop = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); if(!frame_prop) { _state = State::Invalid; return; } - auto eye_flare_prop = frame_prop->at("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"); + auto eye_flare_prop = frame_prop->at("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"_s); if(!eye_flare_prop) { _state = State::Invalid; return; @@ -475,24 +484,24 @@ void Mass::getEyeFlareColour() { } auto Mass::writeEyeFlareColour() -> bool { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; - _lastError = "No unit data in " + _filename; + _lastError = "No unit data in "_s + _filename; return false; } - auto frame = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"); + auto frame = unit_data->at("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); if(!frame) { _state = State::Invalid; - _lastError = "No frame data in " + _filename; + _lastError = "No frame data in "_s + _filename; return false; } - auto eye_flare_prop = frame->at("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"); + auto eye_flare_prop = frame->at("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"_s); if(!eye_flare_prop) { _state = State::Invalid; - _lastError = "No eye flare property in " + _filename; + _lastError = "No eye flare property in "_s + _filename; return false; } @@ -514,13 +523,13 @@ auto Mass::frameCustomStyles() -> Containers::ArrayView { } void Mass::getFrameCustomStyles() { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return; } - auto frame_styles = unit_data->at("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"); + auto frame_styles = unit_data->at("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"_s); if(!frame_styles) { _state = State::Invalid; return; @@ -536,21 +545,21 @@ void Mass::getFrameCustomStyles() { auto Mass::writeFrameCustomStyle(UnsignedLong index) -> bool { if(index > _frame.customStyles.size()) { - _lastError = "Style index out of range."; + _lastError = "Style index out of range."_s; return false; } - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; - _lastError = "No unit data in " + _filename; + _lastError = "No unit data in "_s + _filename; return false; } - auto frame_styles = unit_data->at("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"); + auto frame_styles = unit_data->at("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"_s); if(!frame_styles) { _state = State::Invalid; - _lastError = "No frame styles in " + _filename; + _lastError = "No frame styles in "_s + _filename; return false; } @@ -562,13 +571,13 @@ auto Mass::armourParts() -> Containers::ArrayView { } void Mass::getArmourParts() { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return; } - auto armour_array = unit_data->at("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"); + auto armour_array = unit_data->at("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"_s); if(!armour_array) { _state = State::Invalid; return; @@ -583,18 +592,18 @@ void Mass::getArmourParts() { auto part_prop = armour_array->at(i); auto& part = _armour.parts[i]; - auto& armour_slot = part_prop->at("Slot_3_408BA56F4C9605C7E805CF91B642249C")->enumValue; + auto& armour_slot = part_prop->at("Slot_3_408BA56F4C9605C7E805CF91B642249C"_s)->enumValue; #define c(enumerator, strenum, name) if(armour_slot == (strenum)) { part.slot = ArmourSlot::enumerator; } else #include "../Maps/ArmourSlots.hpp" #undef c { _state = State::Invalid; - Utility::Warning{} << "Invalid armour slot enum value in getArmourParts()."; + Utility::Warning{} << "Invalid armour slot enum value in getArmourParts()."_s; } - part.id = part_prop->at("ID_5_ACD101864D3481DE96EDACACC09BDD25")->value; + part.id = part_prop->at("ID_5_ACD101864D3481DE96EDACACC09BDD25"_s)->value; - auto part_styles = part_prop->at("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"); + auto part_styles = part_prop->at("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"_s); if(!part_styles) { _state = State::Invalid; return; @@ -609,7 +618,7 @@ void Mass::getArmourParts() { part.styles[j] = part_styles->at(j)->value; } - auto decals_array = part_prop->at("Decals_42_F358794A4F18497970F56BA9627D3603"); + auto decals_array = part_prop->at("Decals_42_F358794A4F18497970F56BA9627D3603"_s); if(!decals_array) { _state = State::Invalid; return; @@ -619,7 +628,7 @@ void Mass::getArmourParts() { getDecals(part.decals, decals_array); - auto accs_array = part_prop->at("Accessories_52_D902DD4241FA0050C2529596255153F3"); + auto accs_array = part_prop->at("Accessories_52_D902DD4241FA0050C2529596255153F3"_s); if(!accs_array) { part.accessories = Containers::Array{}; continue; @@ -636,11 +645,11 @@ void Mass::getArmourParts() { auto Mass::writeArmourPart(ArmourSlot slot) -> bool { auto& part = *std::find_if(_armour.parts.begin(), _armour.parts.end(), [&slot](const ArmourPart& part){ return slot == part.slot; }); - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); - auto armour_array = unit_data->at("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"); + auto armour_array = unit_data->at("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"_s); - const char* slot_str = nullptr; + Containers::StringView slot_str = nullptr; switch(slot) { #define c(enumerator, strenum, name) case ArmourSlot::enumerator: \ slot_str = strenum; \ @@ -653,16 +662,16 @@ auto Mass::writeArmourPart(ArmourSlot slot) -> bool { for(UnsignedInt i = 0; i < armour_array->items.size(); i++) { part_prop = armour_array->at(i); - if(slot_str != part_prop->at("Slot_3_408BA56F4C9605C7E805CF91B642249C")->value) { + if(slot_str != part_prop->at("Slot_3_408BA56F4C9605C7E805CF91B642249C"_s)->value) { part_prop = nullptr; } } if(!part_prop) { - _lastError = "Couldn't find the armour part for slot "; + auto prefix = "Couldn't find the armour part for slot "_s; switch(slot) { - #define c(enumerator, strenum, name) case ArmourSlot::enumerator: \ - _lastError += "ArmourSlot::" #enumerator "."; \ + #define c(enumerator, strenum, name) case ArmourSlot::enumerator: \ + _lastError = prefix + "ArmourSlot::" #enumerator "."_s; \ break; #include "../Maps/ArmourSlots.hpp" #undef c @@ -670,18 +679,18 @@ auto Mass::writeArmourPart(ArmourSlot slot) -> bool { return false; } - part_prop->at("ID_5_ACD101864D3481DE96EDACACC09BDD25")->value = part.id; + part_prop->at("ID_5_ACD101864D3481DE96EDACACC09BDD25"_s)->value = part.id; - auto part_styles = part_prop->at("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"); + auto part_styles = part_prop->at("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"_s); for(UnsignedInt i = 0; i < part.styles.size(); i++) { part_styles->at(i)->value = part.styles[i]; } - auto decals_array = part_prop->at("Decals_42_F358794A4F18497970F56BA9627D3603"); + auto decals_array = part_prop->at("Decals_42_F358794A4F18497970F56BA9627D3603"_s); writeDecals(part.decals, decals_array); if(part.accessories.size() != 0) { - auto accs_array = part_prop->at("Accessories_52_D902DD4241FA0050C2529596255153F3"); + auto accs_array = part_prop->at("Accessories_52_D902DD4241FA0050C2529596255153F3"_s); writeAccessories(part.accessories, accs_array); } @@ -698,13 +707,13 @@ auto Mass::armourCustomStyles() -> Containers::ArrayView { } void Mass::getArmourCustomStyles() { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return; } - auto armour_styles = unit_data->at("ArmorStyle_42_E2F6AC3647788CB366BD469B3B7E899E"); + auto armour_styles = unit_data->at("ArmorStyle_42_E2F6AC3647788CB366BD469B3B7E899E"_s); if(!armour_styles) { _state = State::Invalid; return; @@ -720,20 +729,20 @@ void Mass::getArmourCustomStyles() { auto Mass::writeArmourCustomStyle(UnsignedLong index) -> bool { if(index > _armour.customStyles.size()) { - _lastError = "Style index out of range."; + _lastError = "Style index out of range."_s; return false; } - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; - _lastError = "Couldn't find unit data in " + _filename; + _lastError = "Couldn't find unit data in "_s + _filename; return false; } - auto armour_styles = unit_data->at("ArmorStyle_42_E2F6AC3647788CB366BD469B3B7E899E"); + auto armour_styles = unit_data->at("ArmorStyle_42_E2F6AC3647788CB366BD469B3B7E899E"_s); if(!armour_styles) { - _lastError = "Couldn't find armour custom styles in " + _filename; + _lastError = "Couldn't find armour custom styles in "_s + _filename; _state = State::Invalid; return false; } @@ -746,11 +755,11 @@ auto Mass::meleeWeapons() -> Containers::ArrayView { } void Mass::getMeleeWeapons() { - getWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7", _weapons.melee); + getWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7"_s, _weapons.melee); } auto Mass::writeMeleeWeapons() -> bool { - return writeWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7", _weapons.melee); + return writeWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7"_s, _weapons.melee); } auto Mass::shields() -> Containers::ArrayView { @@ -758,11 +767,11 @@ auto Mass::shields() -> Containers::ArrayView { } void Mass::getShields() { - getWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E", _weapons.shields); + getWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E"_s, _weapons.shields); } auto Mass::writeShields() -> bool { - return writeWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E", _weapons.shields); + return writeWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E"_s, _weapons.shields); } auto Mass::bulletShooters() -> Containers::ArrayView { @@ -770,11 +779,11 @@ auto Mass::bulletShooters() -> Containers::ArrayView { } void Mass::getBulletShooters() { - getWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED", _weapons.bulletShooters); + getWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED"_s, _weapons.bulletShooters); } auto Mass::writeBulletShooters() -> bool { - return writeWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED", _weapons.bulletShooters); + return writeWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED"_s, _weapons.bulletShooters); } auto Mass::energyShooters() -> Containers::ArrayView { @@ -782,11 +791,11 @@ auto Mass::energyShooters() -> Containers::ArrayView { } void Mass::getEnergyShooters() { - getWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99", _weapons.energyShooters); + getWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99"_s, _weapons.energyShooters); } auto Mass::writeEnergyShooters() -> bool { - return writeWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99", _weapons.energyShooters); + return writeWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99"_s, _weapons.energyShooters); } auto Mass::bulletLaunchers() -> Containers::ArrayView { @@ -794,11 +803,11 @@ auto Mass::bulletLaunchers() -> Containers::ArrayView { } void Mass::getBulletLaunchers() { - getWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E", _weapons.bulletLaunchers); + getWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E"_s, _weapons.bulletLaunchers); } auto Mass::writeBulletLaunchers() -> bool { - return writeWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E", _weapons.bulletLaunchers); + return writeWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E"_s, _weapons.bulletLaunchers); } auto Mass::energyLaunchers() -> Containers::ArrayView { @@ -806,11 +815,11 @@ auto Mass::energyLaunchers() -> Containers::ArrayView { } void Mass::getEnergyLaunchers() { - getWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995", _weapons.energyLaunchers); + getWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995"_s, _weapons.energyLaunchers); } auto Mass::writeEnergyLaunchers() -> bool { - return writeWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995", _weapons.energyLaunchers); + return writeWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995"_s, _weapons.energyLaunchers); } auto Mass::globalStyles() -> Containers::ArrayView { @@ -818,13 +827,13 @@ auto Mass::globalStyles() -> Containers::ArrayView { } void Mass::getGlobalStyles() { - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return; } - auto global_styles = unit_data->at("GlobalStyles_57_6A681C114035241F7BDAAE9B43A8BF1B"); + auto global_styles = unit_data->at("GlobalStyles_57_6A681C114035241F7BDAAE9B43A8BF1B"_s); if(!global_styles) { _globalStyles = Containers::Array{0}; return; @@ -839,21 +848,21 @@ void Mass::getGlobalStyles() { auto Mass::writeGlobalStyle(UnsignedLong index) -> bool { if(index > _globalStyles.size()) { - _lastError = "Global style index out of range"; + _lastError = "Global style index out of range"_s; return false; } - auto unit_data = _mass->at("UnitData"); + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; - _lastError = "No unit data found in " + _filename; + _lastError = "No unit data found in "_s + _filename; return false; } - auto global_styles = unit_data->at("GlobalStyles_57_6A681C114035241F7BDAAE9B43A8BF1B"); + auto global_styles = unit_data->at("GlobalStyles_57_6A681C114035241F7BDAAE9B43A8BF1B"_s); if(!global_styles) { _state = State::Invalid; - _lastError = "No global styles found in " + _filename; + _lastError = "No global styles found in "_s + _filename; return false; } @@ -861,17 +870,17 @@ auto Mass::writeGlobalStyle(UnsignedLong index) -> bool { } void Mass::getTuning() { - getTuningCategory("Engine", _tuning.engineId, "Gears", _tuning.gearIds); + getTuningCategory("Engine"_s, _tuning.engineId, "Gears"_s, _tuning.gearIds); if(_state == State::Invalid) { return; } - getTuningCategory("OS", _tuning.osId, "Modules", _tuning.moduleIds); + getTuningCategory("OS"_s, _tuning.osId, "Modules"_s, _tuning.moduleIds); if(_state == State::Invalid) { return; } - getTuningCategory("Architect", _tuning.archId, "Techs", _tuning.techIds); + getTuningCategory("Architect"_s, _tuning.archId, "Techs"_s, _tuning.techIds); if(_state == State::Invalid) { return; } @@ -901,17 +910,17 @@ auto Mass::techs() -> Containers::ArrayView { return _tuning.techIds; } -auto Mass::account() -> const std::string& { +auto Mass::account() -> Containers::StringView { return _account; } -auto Mass::updateAccount(const std::string& new_account) -> bool { +auto Mass::updateAccount(Containers::StringView new_account) -> bool { _account = new_account; - auto account = _mass->at("Account"); + auto account = _mass->at("Account"_s); if(!account) { _state = State::Invalid; - _lastError = "Couldn't find the account property."; + _lastError = "Couldn't find the account property."_s; return false; } @@ -930,52 +939,52 @@ void Mass::getCustomStyles(Containers::ArrayView styles, ArrayPrope auto style_prop = style_array->at(i); auto& style = styles[i]; - style.name = style_prop->at("Name_27_1532115A46EF2B2FA283908DF561A86B")->value; - auto colour_prop = style_prop->at("Color_5_F0D383DF40474C9464AE48A0984A212E"); + style.name = style_prop->at("Name_27_1532115A46EF2B2FA283908DF561A86B"_s)->value; + auto colour_prop = style_prop->at("Color_5_F0D383DF40474C9464AE48A0984A212E"_s); style.colour = Color4{colour_prop->r, colour_prop->g, colour_prop->b, colour_prop->a}; - style.metallic = style_prop->at("Metallic_10_0A4CD1E4482CBF41CA61D0A856DE90B9")->value; - style.gloss = style_prop->at("Gloss_11_9769599842CC275A401C4282A236E240")->value; + style.metallic = style_prop->at("Metallic_10_0A4CD1E4482CBF41CA61D0A856DE90B9"_s)->value; + style.gloss = style_prop->at("Gloss_11_9769599842CC275A401C4282A236E240"_s)->value; style.glow = colour_prop->a == 0.0f ? false : true; - style.patternId = style_prop->at("PatternID_14_516DB85641DAF8ECFD2920BE2BDF1311")->value; - style.opacity = style_prop->at("Opacity_30_53BD060B4DFCA1C92302D6A0F7831131")->value; + style.patternId = style_prop->at("PatternID_14_516DB85641DAF8ECFD2920BE2BDF1311"_s)->value; + style.opacity = style_prop->at("Opacity_30_53BD060B4DFCA1C92302D6A0F7831131"_s)->value; style.offset = Vector2{ - style_prop->at("OffsetX_23_70FC2E814C64BBB82452748D2AF9CD48")->value, - style_prop->at("OffsetY_24_5E1F866C4C054D9B2EE337ADC180C17F")->value + style_prop->at("OffsetX_23_70FC2E814C64BBB82452748D2AF9CD48"_s)->value, + style_prop->at("OffsetY_24_5E1F866C4C054D9B2EE337ADC180C17F"_s)->value }; - style.rotation = style_prop->at("Rotation_25_EC2DFAD84AD0A6BD3FA841ACD52EDD6D")->value; - style.scale = style_prop->at("Scale_26_19DF0708409262183E1247B317137671")->value; + style.rotation = style_prop->at("Rotation_25_EC2DFAD84AD0A6BD3FA841ACD52EDD6D"_s)->value; + style.scale = style_prop->at("Scale_26_19DF0708409262183E1247B317137671"_s)->value; } } auto Mass::setCustomStyle(const CustomStyle& style, UnsignedLong index, ArrayProperty* style_array) -> bool { if(!style_array) { - _lastError = "Mass::setCustomStyle(): style_array is null."; + _lastError = "Mass::setCustomStyle(): style_array is null."_s; return false; } auto style_prop = style_array->at(index); if(!style_prop) { - _lastError = "Style index is out of range in " + _filename; + _lastError = "Style index is out of range in "_s + _filename; return false; } - style_prop->at("Name_27_1532115A46EF2B2FA283908DF561A86B")->value = style.name; - auto colour_prop = style_prop->at("Color_5_F0D383DF40474C9464AE48A0984A212E"); + style_prop->at("Name_27_1532115A46EF2B2FA283908DF561A86B"_s)->value = style.name; + auto colour_prop = style_prop->at("Color_5_F0D383DF40474C9464AE48A0984A212E"_s); colour_prop->r = style.colour.r(); colour_prop->g = style.colour.g(); colour_prop->b = style.colour.b(); colour_prop->a = style.glow ? 1.0f : 0.0f; - style_prop->at("Metallic_10_0A4CD1E4482CBF41CA61D0A856DE90B9")->value = style.metallic; - style_prop->at("Gloss_11_9769599842CC275A401C4282A236E240")->value = style.gloss; + style_prop->at("Metallic_10_0A4CD1E4482CBF41CA61D0A856DE90B9"_s)->value = style.metallic; + style_prop->at("Gloss_11_9769599842CC275A401C4282A236E240"_s)->value = style.gloss; - style_prop->at("PatternID_14_516DB85641DAF8ECFD2920BE2BDF1311")->value = style.patternId; - style_prop->at("Opacity_30_53BD060B4DFCA1C92302D6A0F7831131")->value = style.opacity; - style_prop->at("OffsetX_23_70FC2E814C64BBB82452748D2AF9CD48")->value = style.offset.x(); - style_prop->at("OffsetY_24_5E1F866C4C054D9B2EE337ADC180C17F")->value = style.offset.y(); - style_prop->at("Rotation_25_EC2DFAD84AD0A6BD3FA841ACD52EDD6D")->value = style.rotation; - style_prop->at("Scale_26_19DF0708409262183E1247B317137671")->value = style.scale; + style_prop->at("PatternID_14_516DB85641DAF8ECFD2920BE2BDF1311"_s)->value = style.patternId; + style_prop->at("Opacity_30_53BD060B4DFCA1C92302D6A0F7831131"_s)->value = style.opacity; + style_prop->at("OffsetX_23_70FC2E814C64BBB82452748D2AF9CD48"_s)->value = style.offset.x(); + style_prop->at("OffsetY_24_5E1F866C4C054D9B2EE337ADC180C17F"_s)->value = style.offset.y(); + style_prop->at("Rotation_25_EC2DFAD84AD0A6BD3FA841ACD52EDD6D"_s)->value = style.rotation; + style_prop->at("Scale_26_19DF0708409262183E1247B317137671"_s)->value = style.scale; if(!_mass->saveToFile()) { _lastError = _mass->lastError(); @@ -990,21 +999,21 @@ void Mass::getDecals(Containers::ArrayView decals, ArrayProperty* decal_a auto decal_prop = decal_array->at(i); auto& decal = decals[i]; - decal.id = decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value; - auto colour_prop = decal_prop->at("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"); + decal.id = decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9"_s)->value; + auto colour_prop = decal_prop->at("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"_s); decal.colour = Color4{colour_prop->r, colour_prop->g, colour_prop->b, colour_prop->a}; - auto pos_prop = decal_prop->at("Position_41_022C8FE84E1AAFE587261E88F2C72250"); + auto pos_prop = decal_prop->at("Position_41_022C8FE84E1AAFE587261E88F2C72250"_s); decal.position = Vector3{pos_prop->x, pos_prop->y, pos_prop->z}; - auto u_prop = decal_prop->at("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"); + auto u_prop = decal_prop->at("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"_s); decal.uAxis = Vector3{u_prop->x, u_prop->y, u_prop->z}; - auto v_prop = decal_prop->at("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"); + auto v_prop = decal_prop->at("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"_s); decal.vAxis = Vector3{v_prop->x, v_prop->y, v_prop->z}; - auto offset_prop = decal_prop->at("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"); + auto offset_prop = decal_prop->at("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"_s); decal.offset = Vector2{offset_prop->x, offset_prop->y}; - decal.scale = decal_prop->at("Scale_32_959D1C2747AFD8D62808468235CBBA40")->value; - decal.rotation = decal_prop->at("Rotation_27_12D7C314493D203D5C2326A03C5F910F")->value; - decal.flip = decal_prop->at("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1")->value; - decal.wrap = decal_prop->at("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62")->value; + decal.scale = decal_prop->at("Scale_32_959D1C2747AFD8D62808468235CBBA40"_s)->value; + decal.rotation = decal_prop->at("Rotation_27_12D7C314493D203D5C2326A03C5F910F"_s)->value; + decal.flip = decal_prop->at("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1"_s)->value; + decal.wrap = decal_prop->at("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62"_s)->value; } } @@ -1013,31 +1022,31 @@ void Mass::writeDecals(Containers::ArrayView decals, ArrayProperty* decal auto decal_prop = decal_array->at(i); auto& decal = decals[i]; - decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id; - auto colour_prop = decal_prop->at("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"); + decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9"_s)->value = decal.id; + auto colour_prop = decal_prop->at("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"_s); colour_prop->r = decal.colour.r(); colour_prop->g = decal.colour.g(); colour_prop->b = decal.colour.b(); colour_prop->a = decal.colour.a(); - auto pos_prop = decal_prop->at("Position_41_022C8FE84E1AAFE587261E88F2C72250"); + auto pos_prop = decal_prop->at("Position_41_022C8FE84E1AAFE587261E88F2C72250"_s); pos_prop->x = decal.position.x(); pos_prop->y = decal.position.y(); pos_prop->z = decal.position.z(); - auto u_prop = decal_prop->at("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"); + auto u_prop = decal_prop->at("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"_s); u_prop->x = decal.uAxis.x(); u_prop->y = decal.uAxis.y(); u_prop->z = decal.uAxis.z(); - auto v_prop = decal_prop->at("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"); + auto v_prop = decal_prop->at("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"_s); v_prop->x = decal.vAxis.x(); v_prop->y = decal.vAxis.y(); v_prop->z = decal.vAxis.z(); - auto offset_prop = decal_prop->at("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"); + auto offset_prop = decal_prop->at("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"_s); offset_prop->x = decal.offset.x(); offset_prop->y = decal.offset.y(); - decal_prop->at("Scale_32_959D1C2747AFD8D62808468235CBBA40")->value = decal.scale; - decal_prop->at("Rotation_27_12D7C314493D203D5C2326A03C5F910F")->value = decal.rotation; - decal_prop->at("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1")->value = decal.flip; - decal_prop->at("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62")->value = decal.wrap; + decal_prop->at("Scale_32_959D1C2747AFD8D62808468235CBBA40"_s)->value = decal.scale; + decal_prop->at("Rotation_27_12D7C314493D203D5C2326A03C5F910F"_s)->value = decal.rotation; + decal_prop->at("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1"_s)->value = decal.flip; + decal_prop->at("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62"_s)->value = decal.wrap; } } @@ -1046,21 +1055,21 @@ void Mass::getAccessories(Containers::ArrayView accessories, ArrayPro auto acc_prop = accessory_array->at(i); auto& accessory = accessories[i]; - accessory.attachIndex = acc_prop->at("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20")->value; - accessory.id = acc_prop->at("ID_4_5757B32647BAE263266259B8A7DFFFC1")->value; - auto acc_styles = acc_prop->at("Styles_7_91DEB0F24E24D13FC9472882C11D0DFD"); + accessory.attachIndex = acc_prop->at("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value; + accessory.id = acc_prop->at("ID_4_5757B32647BAE263266259B8A7DFFFC1"_s)->value; + auto acc_styles = acc_prop->at("Styles_7_91DEB0F24E24D13FC9472882C11D0DFD"_s); for(UnsignedInt j = 0; j < acc_styles->items.size(); j++) { accessory.styles[j] = acc_styles->at(j)->value; } - auto rel_pos_prop = acc_prop->at("RelativePosition_14_BE8FB2A94074F34B3EDA6683B227D3A1"); + auto rel_pos_prop = acc_prop->at("RelativePosition_14_BE8FB2A94074F34B3EDA6683B227D3A1"_s); accessory.relativePosition = Vector3{rel_pos_prop->x, rel_pos_prop->y, rel_pos_prop->z}; - auto rel_pos_offset_prop = acc_prop->at("RelativePositionOffset_15_98FD0CE74E44BBAFC2D46FB4CA4E0ED6"); + auto rel_pos_offset_prop = acc_prop->at("RelativePositionOffset_15_98FD0CE74E44BBAFC2D46FB4CA4E0ED6"_s); accessory.relativePositionOffset = Vector3{rel_pos_offset_prop->x, rel_pos_offset_prop->y, rel_pos_offset_prop->z}; - auto rel_rot_prop = acc_prop->at("RelativeRotation_20_C78C73274E6E78E7878F8C98ECA342C0"); + auto rel_rot_prop = acc_prop->at("RelativeRotation_20_C78C73274E6E78E7878F8C98ECA342C0"_s); accessory.relativeRotation = Vector3{rel_rot_prop->x, rel_rot_prop->y, rel_rot_prop->z}; - auto rel_rot_offset_prop = acc_prop->at("RelativeRotationOffset_21_E07FA0EC46728B7BA763C6861249ABAA"); + auto rel_rot_offset_prop = acc_prop->at("RelativeRotationOffset_21_E07FA0EC46728B7BA763C6861249ABAA"_s); accessory.relativeRotationOffset = Vector3{rel_rot_offset_prop->x, rel_rot_offset_prop->y, rel_rot_offset_prop->z}; - auto local_scale_prop = acc_prop->at("LocalScale_24_DC2D93A742A41A46E7E61D988F15ED53"); + auto local_scale_prop = acc_prop->at("LocalScale_24_DC2D93A742A41A46E7E61D988F15ED53"_s); accessory.localScale = Vector3{local_scale_prop->x, local_scale_prop->y, local_scale_prop->z}; } } @@ -1070,37 +1079,37 @@ void Mass::writeAccessories(Containers::ArrayView accessories, ArrayP auto acc_prop = accs_array->at(i); auto& accessory = accessories[i]; - acc_prop->at("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20")->value = accessory.attachIndex; - acc_prop->at("ID_4_5757B32647BAE263266259B8A7DFFFC1")->value = accessory.id; - auto acc_styles = acc_prop->at("Styles_7_91DEB0F24E24D13FC9472882C11D0DFD"); + acc_prop->at("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value = accessory.attachIndex; + acc_prop->at("ID_4_5757B32647BAE263266259B8A7DFFFC1"_s)->value = accessory.id; + auto acc_styles = acc_prop->at("Styles_7_91DEB0F24E24D13FC9472882C11D0DFD"_s); for(UnsignedInt j = 0; j < acc_styles->items.size(); j++) { acc_styles->at(j)->value = accessory.styles[j]; } - auto rel_pos_prop = acc_prop->at("RelativePosition_14_BE8FB2A94074F34B3EDA6683B227D3A1"); + auto rel_pos_prop = acc_prop->at("RelativePosition_14_BE8FB2A94074F34B3EDA6683B227D3A1"_s); rel_pos_prop->x = accessory.relativePosition.x(); rel_pos_prop->y = accessory.relativePosition.y(); rel_pos_prop->z = accessory.relativePosition.z(); - auto rel_pos_offset_prop = acc_prop->at("RelativePositionOffset_15_98FD0CE74E44BBAFC2D46FB4CA4E0ED6"); + auto rel_pos_offset_prop = acc_prop->at("RelativePositionOffset_15_98FD0CE74E44BBAFC2D46FB4CA4E0ED6"_s); rel_pos_offset_prop->x = accessory.relativePositionOffset.x(); rel_pos_offset_prop->y = accessory.relativePositionOffset.y(); rel_pos_offset_prop->z = accessory.relativePositionOffset.z(); - auto rel_rot_prop = acc_prop->at("RelativeRotation_20_C78C73274E6E78E7878F8C98ECA342C0"); + auto rel_rot_prop = acc_prop->at("RelativeRotation_20_C78C73274E6E78E7878F8C98ECA342C0"_s); rel_rot_prop->x = accessory.relativeRotation.x(); rel_rot_prop->y = accessory.relativeRotation.y(); rel_rot_prop->z = accessory.relativeRotation.z(); - auto rel_rot_offset_prop = acc_prop->at("RelativeRotationOffset_21_E07FA0EC46728B7BA763C6861249ABAA"); + auto rel_rot_offset_prop = acc_prop->at("RelativeRotationOffset_21_E07FA0EC46728B7BA763C6861249ABAA"_s); rel_rot_offset_prop->x = accessory.relativeRotationOffset.x(); rel_rot_offset_prop->y = accessory.relativeRotationOffset.y(); rel_rot_offset_prop->z = accessory.relativeRotationOffset.z(); - auto local_scale_prop = acc_prop->at("LocalScale_24_DC2D93A742A41A46E7E61D988F15ED53"); + auto local_scale_prop = acc_prop->at("LocalScale_24_DC2D93A742A41A46E7E61D988F15ED53"_s); local_scale_prop->x = accessory.localScale.x(); local_scale_prop->y = accessory.localScale.y(); local_scale_prop->z = accessory.localScale.z(); } } -void Mass::getWeaponType(const char* prop_name, Containers::ArrayView weapon_array) { - auto unit_data = _mass->at("UnitData"); +void Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView weapon_array) { + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; return; @@ -1121,38 +1130,38 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView we auto weapon_prop = prop->at(i); auto& weapon = weapon_array[i]; - weapon.name = weapon_prop->at("Name_13_7BF0D31F4E50C50C47231BB36A485D92")->value; - auto& weapon_type = weapon_prop->at("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976")->enumValue; + weapon.name = weapon_prop->at("Name_13_7BF0D31F4E50C50C47231BB36A485D92"_s)->value; + auto& weapon_type = weapon_prop->at("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976"_s)->enumValue; #define c(enumerator, strenum, name) if(weapon_type == (strenum)) { weapon.type = WeaponType::enumerator; } else #include "../Maps/WeaponTypes.hpp" #undef c { _state = State::Invalid; - Utility::Warning{} << "Invalid weapon type enum value in getWeaponType()."; + Utility::Warning{} << "Invalid weapon type enum value in getWeaponType()."_s; } - auto parts_prop = weapon_prop->at("Element_6_8E4617CC4B2C1F1490435599784EC6E0"); + auto parts_prop = weapon_prop->at("Element_6_8E4617CC4B2C1F1490435599784EC6E0"_s); weapon.parts = Containers::Array{ValueInit, parts_prop->items.size()}; for(UnsignedInt j = 0; j < parts_prop->items.size(); j++) { auto part_prop = parts_prop->at(j); auto& part = weapon.parts[j]; - part.id = part_prop->at("ID_2_A74D75434308158E5926178822DD28EE")->value; + part.id = part_prop->at("ID_2_A74D75434308158E5926178822DD28EE"_s)->value; - auto part_styles = part_prop->at("Styles_17_994C97C34A90667BE5B716BFD0B97588"); + auto part_styles = part_prop->at("Styles_17_994C97C34A90667BE5B716BFD0B97588"_s); for(UnsignedInt k = 0; k < part_styles->items.size(); k++) { part.styles[k] = part_styles->at(k)->value; } - auto part_decals = part_prop->at("Decals_13_8B81112B453D7230C0CDE982185E14F1"); + auto part_decals = part_prop->at("Decals_13_8B81112B453D7230C0CDE982185E14F1"_s); if(part_decals->items.size() != part.decals.size()) { part.decals = Containers::Array{part_decals->items.size()}; } getDecals(part.decals, part_decals); - auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"); + auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"_s); if(!part_accs) { part.accessories = Containers::Array{0}; continue; @@ -1164,7 +1173,7 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView we getAccessories(part.accessories, part_accs); } - auto custom_styles = weapon_prop->at("Styles_10_8C3C82444B986AD7A99595AD4985912D"); + auto custom_styles = weapon_prop->at("Styles_10_8C3C82444B986AD7A99595AD4985912D"_s); if(!custom_styles) { _state = State::Invalid; return; @@ -1177,47 +1186,47 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView we getCustomStyles(weapon.customStyles, custom_styles); - weapon.attached = weapon_prop->at("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value; - auto& damage_type = weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue; + weapon.attached = weapon_prop->at("Attach_15_D00AABBD4AD6A04778D56D81E51927B3"_s)->value; + auto& damage_type = weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83"_s)->enumValue; #define c(enumerator, strenum) if(damage_type == (strenum)) { weapon.damageType = DamageType::enumerator; } else #include "../Maps/DamageTypes.hpp" #undef c { _state = State::Invalid; - Utility::Warning{} << "Invalid damage type enum value in getWeaponType()."; + Utility::Warning{} << "Invalid damage type enum value in getWeaponType()."_s; } - weapon.dualWield = weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value; - auto& effect_colour_mode = weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue; + weapon.dualWield = weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222"_s)->value; + auto& effect_colour_mode = weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014"_s)->enumValue; #define c(enumerator, strenum) if(effect_colour_mode == (strenum)) { weapon.effectColourMode = EffectColourMode::enumerator; } else #include "../Maps/EffectColourModes.hpp" #undef c { _state = State::Invalid; - Utility::Warning{} << "Invalid effect colour mode in getWeaponType()."; + Utility::Warning{} << "Invalid effect colour mode in getWeaponType()."_s; } - auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"); + auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"_s); weapon.effectColour = Color4{effect_colour->r, effect_colour->g, effect_colour->b, effect_colour->a}; } } -auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView weapon_array) -> bool { - auto unit_data = _mass->at("UnitData"); +auto Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView weapon_array) -> bool { + auto unit_data = _mass->at("UnitData"_s); if(!unit_data) { _state = State::Invalid; - _lastError = "No unit data in " + _filename; + _lastError = "No unit data in "_s + _filename; return false; } auto prop = unit_data->at(prop_name); if(!prop) { _state = State::Invalid; - _lastError = std::string{prop_name} + " not found in " + _filename; + _lastError = prop_name + " not found in "_s + _filename; return false; } if(prop->items.size() != weapon_array.size()) { _state = State::Invalid; - _lastError = "Weapon type array size mismatch."; + _lastError = "Weapon type array size mismatch."_s; return false; } @@ -1225,19 +1234,19 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView auto weapon_prop = prop->at(i); auto& weapon = weapon_array[i]; - weapon_prop->at("Name_13_7BF0D31F4E50C50C47231BB36A485D92")->value = weapon.name; + weapon_prop->at("Name_13_7BF0D31F4E50C50C47231BB36A485D92"_s)->value = weapon.name; switch(weapon.type) { - #define c(enumerator, strenum, name) case WeaponType::enumerator: weapon_prop->at("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976")->enumValue = strenum; break; + #define c(enumerator, strenum, name) case WeaponType::enumerator: weapon_prop->at("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976"_s)->enumValue = strenum; break; #include "../Maps/WeaponTypes.hpp" #undef c default: - Utility::Warning{} << "Invalid weapon type enum value in writeWeaponType()."; + Utility::Warning{} << "Invalid weapon type enum value in writeWeaponType()."_s; } - auto parts_prop = weapon_prop->at("Element_6_8E4617CC4B2C1F1490435599784EC6E0"); + auto parts_prop = weapon_prop->at("Element_6_8E4617CC4B2C1F1490435599784EC6E0"_s); if(parts_prop->items.size() != weapon.parts.size()) { _state = State::Invalid; - _lastError = "Weapon parts array size mismatch."; + _lastError = "Weapon parts array size mismatch."_s; return false; } @@ -1245,40 +1254,40 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView auto part_prop = parts_prop->at(j); auto& part = weapon.parts[j]; - part_prop->at("ID_2_A74D75434308158E5926178822DD28EE")->value = part.id; + part_prop->at("ID_2_A74D75434308158E5926178822DD28EE"_s)->value = part.id; - auto part_styles = part_prop->at("Styles_17_994C97C34A90667BE5B716BFD0B97588"); + auto part_styles = part_prop->at("Styles_17_994C97C34A90667BE5B716BFD0B97588"_s); for(UnsignedInt k = 0; k < part_styles->items.size(); k++) { part_styles->at(k)->value = part.styles[k]; } - auto part_decals = part_prop->at("Decals_13_8B81112B453D7230C0CDE982185E14F1"); + auto part_decals = part_prop->at("Decals_13_8B81112B453D7230C0CDE982185E14F1"_s); writeDecals(part.decals, part_decals); - auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"); + auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"_s); if(!part_accs) { continue; } if(part_accs->items.size() != part.accessories.size()) { _state = State::Invalid; - _lastError = "Accessories array size mismatch."; + _lastError = "Accessories array size mismatch."_s; return false; } writeAccessories(part.accessories, part_accs); } - auto custom_styles = weapon_prop->at("Styles_10_8C3C82444B986AD7A99595AD4985912D"); + auto custom_styles = weapon_prop->at("Styles_10_8C3C82444B986AD7A99595AD4985912D"_s); if(!custom_styles) { _state = State::Invalid; - _lastError = "No custom styles found for weapon."; + _lastError = "No custom styles found for weapon."_s; return false; } if(custom_styles->items.size() != weapon.customStyles.size()) { _state = State::Invalid; - _lastError = "Custom styles array size mismatch."; + _lastError = "Custom styles array size mismatch."_s; return false; } @@ -1286,25 +1295,25 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView setCustomStyle(weapon.customStyles[j], j, custom_styles); } - weapon_prop->at("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value = weapon.attached; + weapon_prop->at("Attach_15_D00AABBD4AD6A04778D56D81E51927B3"_s)->value = weapon.attached; switch(weapon.damageType) { - #define c(enumerator, strenum) case DamageType::enumerator: weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue = strenum; break; + #define c(enumerator, strenum) case DamageType::enumerator: weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83"_s)->enumValue = strenum; break; #include "../Maps/DamageTypes.hpp" #undef c default: - Utility::Warning{} << "Unknown damage type enum value in writeWeaponType()."; + Utility::Warning{} << "Unknown damage type enum value in writeWeaponType()."_s; } - weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value = weapon.dualWield; + weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222"_s)->value = weapon.dualWield; switch(weapon.effectColourMode) { - #define c(enumerator, enumstr) case EffectColourMode::enumerator: \ - weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue = enumstr; \ + #define c(enumerator, enumstr) case EffectColourMode::enumerator: \ + weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014"_s)->enumValue = enumstr; \ break; #include "../Maps/EffectColourModes.hpp" #undef c default: - Utility::Warning{} << "Unknown effect colour mode in writeWeaponType()."; + Utility::Warning{} << "Unknown effect colour mode in writeWeaponType()."_s; } - auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"); + auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"_s); effect_colour->r = weapon.effectColour.r(); effect_colour->g = weapon.effectColour.g(); effect_colour->b = weapon.effectColour.b(); @@ -1319,8 +1328,8 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView return true; } -void Mass::getTuningCategory(const char* big_node_prop_name, Int& big_node_id, - const char* small_nodes_prop_name, Containers::ArrayView small_nodes_ids) +void Mass::getTuningCategory(Containers::StringView big_node_prop_name, Int& big_node_id, + Containers::StringView small_nodes_prop_name, Containers::ArrayView small_nodes_ids) { auto node_id = _mass->at(big_node_prop_name); if(!node_id) { diff --git a/src/Mass/Mass.h b/src/Mass/Mass.h index 3edfc3c..2c138bc 100644 --- a/src/Mass/Mass.h +++ b/src/Mass/Mass.h @@ -16,11 +16,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include #include +#include +#include #include #include @@ -56,16 +56,16 @@ class Mass { Mass(Mass&&) = default; Mass& operator=(Mass&&) = default; - auto lastError() -> std::string const&; + auto lastError() -> Containers::StringView; - static auto getNameFromFile(const std::string& path) -> Containers::Optional; + static auto getNameFromFile(Containers::StringView path) -> Containers::Optional; void refreshValues(); - auto filename() -> std::string const&; + auto filename() -> Containers::StringView; - auto name() -> Containers::Optional const&; - auto setName(std::string new_name) -> bool; + auto name() -> Containers::StringView; + auto setName(Containers::StringView new_name) -> bool; auto state() -> State; @@ -135,8 +135,8 @@ class Mass { auto architecture() -> Int&; auto techs() -> Containers::ArrayView; - auto account() -> std::string const&; - auto updateAccount(const std::string& new_account) -> bool; + auto account() -> Containers::StringView; + auto updateAccount(Containers::StringView new_account) -> bool; private: void getCustomStyles(Containers::ArrayView styles, ArrayProperty* style_array); @@ -148,37 +148,33 @@ class Mass { void getAccessories(Containers::ArrayView accessories, ArrayProperty* accessory_array); void writeAccessories(Containers::ArrayView accessories, ArrayProperty* accs_array); - void getWeaponType(const char* prop_name, Containers::ArrayView weapon_array); - auto writeWeaponType(const char* prop_name, Containers::ArrayView weapon_array) -> bool; + void getWeaponType(Containers::StringView prop_name, Containers::ArrayView weapon_array); + auto writeWeaponType(Containers::StringView prop_name, Containers::ArrayView weapon_array) -> bool; - void getTuningCategory(const char* big_node_prop_name, Int& big_node_id, - const char* small_nodes_prop_name, Containers::ArrayView small_nodes_ids); + void getTuningCategory(Containers::StringView big_node_prop_name, Int& big_node_id, + Containers::StringView small_nodes_prop_name, Containers::ArrayView small_nodes_ids); Containers::Optional _mass; - std::string _lastError; + Containers::String _lastError; - std::string _folder; - std::string _filename; + Containers::String _folder; + Containers::String _filename; State _state = State::Empty; bool _dirty = false; - Containers::Optional _name = Containers::NullOpt; + Containers::Optional _name = Containers::NullOpt; struct { Joints joints{}; - Containers::StaticArray<4, Int> styles{ValueInit}; - Color4 eyeFlare{0.0f}; - Containers::StaticArray<16, CustomStyle> customStyles; } _frame; struct { Containers::StaticArray<38, ArmourPart> parts; - Containers::StaticArray<16, CustomStyle> customStyles; } _armour; @@ -204,5 +200,5 @@ class Mass { Containers::StaticArray<7, Int> techIds; } _tuning; - std::string _account; + Containers::String _account; }; diff --git a/src/Mass/Weapon.h b/src/Mass/Weapon.h index 660de20..bcbdff6 100644 --- a/src/Mass/Weapon.h +++ b/src/Mass/Weapon.h @@ -16,10 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include +#include #include #include @@ -62,7 +61,7 @@ struct Weapon { Weapon(Weapon&& other) = default; Weapon& operator=(Weapon&& other) = default; - std::string name; + Containers::String name; WeaponType type = WeaponType::Melee; Containers::Array parts; Containers::StaticArray<16, CustomStyle> customStyles{ValueInit}; diff --git a/src/MassManager/MassManager.cpp b/src/MassManager/MassManager.cpp index 22b18bf..7fda7d4 100644 --- a/src/MassManager/MassManager.cpp +++ b/src/MassManager/MassManager.cpp @@ -19,22 +19,23 @@ #include #include #include +#include #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}, - _steamId{steam_id}, + _account{account}, _demo{demo}, _stagingAreaDirectory{staging_dir} { Containers::arrayReserve(_hangars, 32); - std::string mass_filename = ""; + Containers::String mass_filename = ""; 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}); } @@ -45,7 +46,7 @@ MassManager::MassManager(const std::string& save_path, const std::string& steam_ refreshStagedMasses(); } -auto MassManager::lastError() -> std::string const& { +auto MassManager::lastError() -> Containers::StringView { return _lastError; } @@ -58,43 +59,43 @@ void MassManager::refreshHangar(Int hangar) { return; } - std::string mass_filename = - Utility::Directory::join(_saveDirectory, Utility::formatString("{}Unit{:.2d}{}.sav", _demo ? "Demo" : "", hangar, _steamId)); + Containers::String mass_filename = + Utility::Directory::join(_saveDirectory, Utility::formatString("{}Unit{:.2d}{}.sav", _demo ? "Demo" : "", hangar, _account)); _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) { - _lastError = "Hangar out of range in MassManager::importMass()"; + _lastError = "Hangar out of range in MassManager::importMass()"_s; return false; } auto it = _stagedMasses.find(staged_fn); 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; } - std::string source = Utility::Directory::join(_stagingAreaDirectory, staged_fn); - Utility::Directory::copy(source, source + ".tmp"); + Containers::String source = Utility::Directory::join(_stagingAreaDirectory, staged_fn); + Utility::Directory::copy(source, source + ".tmp"_s); { - Mass mass{source + ".tmp"}; - if(!mass.updateAccount(_steamId)) { + Mass mass{source + ".tmp"_s}; + if(!mass.updateAccount(_account)) { _lastError = mass.lastError(); - Utility::Directory::rm(source + ".tmp"); + Utility::Directory::rm(source + ".tmp"_s); 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)) { 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); return false; } @@ -104,7 +105,7 @@ auto MassManager::importMass(const std::string& staged_fn, Int hangar) -> bool { auto MassManager::exportMass(Int hangar) -> bool { if(hangar < 0 || hangar >= 32) { - _lastError = "Hangar out of range in MassManager::exportMass()"; + _lastError = "Hangar out of range in MassManager::exportMass()"_s; return false; } @@ -113,9 +114,9 @@ auto MassManager::exportMass(Int hangar) -> bool { return false; } - std::string source = Utility::Directory::join(_saveDirectory, _hangars[hangar].filename()); - std::string dest = Utility::Directory::join(_stagingAreaDirectory, - Utility::formatString("{}_{}.sav", *_hangars[hangar].name(), _steamId)); + Containers::String source = Utility::Directory::join(_saveDirectory, _hangars[hangar].filename()); + Containers::String dest = Utility::Directory::join(_stagingAreaDirectory, + Utility::formatString("{}_{}.sav", _hangars[hangar].name(), _account)); if(!Utility::Directory::copy(source, 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 { if(source < 0 || source >= 32) { - _lastError = "Source hangar out of range."; + _lastError = "Source hangar out of range."_s; return false; } if(destination < 0 || destination >= 32) { - _lastError = "Destination hangar out of range."; + _lastError = "Destination hangar out of range."_s; return false; } - std::string source_file = Utility::Directory::join(_saveDirectory, _hangars[source].filename()); - std::string dest_file = Utility::Directory::join(_saveDirectory, _hangars[destination].filename()); + Containers::String source_file = Utility::Directory::join(_saveDirectory, _hangars[source].filename()); + Containers::String dest_file = Utility::Directory::join(_saveDirectory, _hangars[destination].filename()); Mass::State dest_state = _hangars[destination].state(); switch(dest_state) { @@ -147,14 +148,14 @@ auto MassManager::moveMass(Int source, Int destination) -> bool { Utility::Directory::rm(dest_file); break; case Mass::State::Valid: - Utility::Directory::move(dest_file, dest_file + ".tmp"); + Utility::Directory::move(dest_file, dest_file + ".tmp"_s); break; } Utility::Directory::move(source_file, dest_file); 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; @@ -162,7 +163,7 @@ auto MassManager::moveMass(Int source, Int destination) -> bool { auto MassManager::deleteMass(Int hangar) -> bool { if(hangar < 0 || hangar >= 32) { - _lastError = "Hangar out of range."; + _lastError = "Hangar out of range."_s; return false; } @@ -174,7 +175,7 @@ auto MassManager::deleteMass(Int hangar) -> bool { return true; } -auto MassManager::stagedMasses() -> std::map const& { +auto MassManager::stagedMasses() -> std::map const& { return _stagedMasses; } @@ -182,31 +183,31 @@ void MassManager::refreshStagedMasses() { _stagedMasses.clear(); using Utility::Directory::Flag; - std::vector 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){ - return !Utility::String::endsWith(file, ".sav"); + return !Utility::String::endsWith(file, ".sav"_s); }); file_list.erase(iter, file_list.end()); - for(const std::string& file : file_list) { - std::string name = *Mass::getNameFromFile(Utility::Directory::join(_stagingAreaDirectory, file)); + for(auto& file : file_list) { + auto name = Mass::getNameFromFile(Utility::Directory::join(_stagingAreaDirectory, file)); - if(!name.empty()) { - _stagedMasses[file] = name; + if(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()) { - _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; } 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; } diff --git a/src/MassManager/MassManager.h b/src/MassManager/MassManager.h index fbfee37..ccda973 100644 --- a/src/MassManager/MassManager.h +++ b/src/MassManager/MassManager.h @@ -17,9 +17,10 @@ // along with this program. If not, see . #include -#include #include +#include +#include #include "../Mass/Mass.h" @@ -27,34 +28,34 @@ using namespace Corrade; class MassManager { 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&; 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 moveMass(int source, int destination) -> bool; auto deleteMass(int hangar) -> bool; - auto stagedMasses() -> std::map const&; + auto stagedMasses() -> std::map const&; void refreshStagedMasses(); - auto deleteStagedMass(const std::string& filename) -> bool; + auto deleteStagedMass(Containers::StringView filename) -> bool; private: - const std::string& _saveDirectory; - const std::string& _steamId; + Containers::StringView _saveDirectory; + Containers::StringView _account; bool _demo; - std::string _lastError; + Containers::String _lastError; Containers::Array _hangars; - const std::string& _stagingAreaDirectory; + Containers::StringView _stagingAreaDirectory; - std::map _stagedMasses; + std::map _stagedMasses; }; diff --git a/src/Profile/Profile.cpp b/src/Profile/Profile.cpp index 6913153..d956d98 100644 --- a/src/Profile/Profile.cpp +++ b/src/Profile/Profile.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -30,13 +31,14 @@ #include "Profile.h" using namespace Corrade; +using namespace Containers::Literals; -Profile::Profile(const std::string& path): +Profile::Profile(Containers::StringView path): _profile(path) { _filename = Utility::Directory::filename(path); - if(Utility::String::beginsWith(_filename, "Demo")) { + if(Utility::String::beginsWith(_filename, "Demo"_s)) { _type = ProfileType::Demo; } else { @@ -45,13 +47,13 @@ Profile::Profile(const std::string& path): auto account_prop = _profile.at("Account"); if(!account_prop) { - _lastError = "Couldn't find an account ID in " + _filename; + _lastError = "Couldn't find an account ID in "_s + _filename; _valid = false; return; } _account = account_prop->value; - if(Utility::String::beginsWith(_account, "PMCSlot")) { + if(Utility::String::beginsWith(_account, "PMCSlot"_s)) { _version = ProfileVersion::Normal; } else { @@ -65,11 +67,11 @@ auto Profile::valid() const -> bool { return _valid; } -auto Profile::lastError() const -> std::string const& { +auto Profile::lastError() const -> Containers::StringView { return _lastError; } -auto Profile::filename() const -> std::string const& { +auto Profile::filename() const -> Containers::StringView { return _filename; } @@ -81,7 +83,7 @@ auto Profile::version() const -> ProfileVersion { return _version; } -auto Profile::account() const -> std::string const& { +auto Profile::account() const -> Containers::StringView { return _account; } @@ -92,61 +94,61 @@ void Profile::refreshValues() { return; } - auto name_prop = _profile.at("CompanyName"); + auto name_prop = _profile.at("CompanyName"_s); if(!name_prop) { - _lastError = "No company name in " + _filename; + _lastError = "No company name in "_s + _filename; _valid = false; return; } _name = name_prop->value; - auto prop = _profile.at("ActiveFrameSlot"); + auto prop = _profile.at("ActiveFrameSlot"_s); _activeFrameSlot = prop ? prop->value : 0; - prop = _profile.at("Credit"); + prop = _profile.at("Credit"_s); _credits = prop ? prop->value : 0; - prop = _profile.at("StoryProgress"); + prop = _profile.at("StoryProgress"_s); _storyProgress = prop ? prop->value : 0; - prop = _profile.at("LastMissionID"); + prop = _profile.at("LastMissionID"_s); _lastMissionId = prop ? prop->value : 0; - _verseSteel = getResource("ResourceMaterial", VerseSteel); - _undinium = getResource("ResourceMaterial", Undinium); - _necriumAlloy = getResource("ResourceMaterial", NecriumAlloy); - _lunarite = getResource("ResourceMaterial", Lunarite); - _asterite = getResource("ResourceMaterial", Asterite); + _verseSteel = getResource("ResourceMaterial"_s, VerseSteel); + _undinium = getResource("ResourceMaterial"_s, Undinium); + _necriumAlloy = getResource("ResourceMaterial"_s, NecriumAlloy); + _lunarite = getResource("ResourceMaterial"_s, Lunarite); + _asterite = getResource("ResourceMaterial"_s, Asterite); - _ednil = getResource("ResourceMaterial", Ednil); - _nuflalt = getResource("ResourceMaterial", Nuflalt); - _aurelene = getResource("ResourceMaterial", Aurelene); - _soldus = getResource("ResourceMaterial", Soldus); - _synthesisedN = getResource("ResourceMaterial", SynthesisedN); + _ednil = getResource("ResourceMaterial"_s, Ednil); + _nuflalt = getResource("ResourceMaterial"_s, Nuflalt); + _aurelene = getResource("ResourceMaterial"_s, Aurelene); + _soldus = getResource("ResourceMaterial"_s, Soldus); + _synthesisedN = getResource("ResourceMaterial"_s, SynthesisedN); - _alcarbonite = getResource("ResourceMaterial", Alcarbonite); - _keriphene = getResource("ResourceMaterial", Keriphene); - _nitinolCM = getResource("ResourceMaterial", NitinolCM); - _quarkium = getResource("ResourceMaterial", Quarkium); - _alterene = getResource("ResourceMaterial", Alterene); + _alcarbonite = getResource("ResourceMaterial"_s, Alcarbonite); + _keriphene = getResource("ResourceMaterial"_s, Keriphene); + _nitinolCM = getResource("ResourceMaterial"_s, NitinolCM); + _quarkium = getResource("ResourceMaterial"_s, Quarkium); + _alterene = getResource("ResourceMaterial"_s, Alterene); - _mixedComposition = getResource("ResourceQuarkData", MixedComposition); - _voidResidue = getResource("ResourceQuarkData", VoidResidue); - _muscularConstruction = getResource("ResourceQuarkData", MuscularConstruction); - _mineralExoskeletology = getResource("ResourceQuarkData", MineralExoskeletology); - _carbonisedSkin = getResource("ResourceQuarkData", CarbonisedSkin); + _mixedComposition = getResource("ResourceQuarkData"_s, MixedComposition); + _voidResidue = getResource("ResourceQuarkData"_s, VoidResidue); + _muscularConstruction = getResource("ResourceQuarkData"_s, MuscularConstruction); + _mineralExoskeletology = getResource("ResourceQuarkData"_s, MineralExoskeletology); + _carbonisedSkin = getResource("ResourceQuarkData"_s, CarbonisedSkin); _valid = true; } -auto Profile::companyName() const -> std::string const& { +auto Profile::companyName() const -> Containers::StringView { return _name; } -auto Profile::renameCompany(const std::string& new_name) -> bool { - auto name_prop = _profile.at("CompanyName"); +auto Profile::renameCompany(Containers::StringView new_name) -> bool { + auto name_prop = _profile.at("CompanyName"_s); if(!name_prop) { - _lastError = "No company name in " + _filename; + _lastError = "No company name in "_s + _filename; _valid = false; return false; } @@ -170,11 +172,11 @@ auto Profile::credits() const -> Int { } auto Profile::setCredits(Int amount) -> bool { - auto credits_prop = _profile.at("Credit"); + auto credits_prop = _profile.at("Credit"_s); if(!credits_prop) { credits_prop = new IntProperty; - credits_prop->name.emplace("Credit"); + credits_prop->name.emplace("Credit"_s); _profile.appendProperty(IntProperty::ptr{credits_prop}); } @@ -193,11 +195,11 @@ auto Profile::storyProgress() const -> Int { } auto Profile::setStoryProgress(Int progress) -> bool { - auto story_progress_prop = _profile.at("StoryProgress"); + auto story_progress_prop = _profile.at("StoryProgress"_s); if(!story_progress_prop) { 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}); } @@ -220,7 +222,7 @@ auto Profile::verseSteel() const -> Int { } auto Profile::setVerseSteel(Int amount) -> bool { - return setResource("ResourceMaterial", VerseSteel, amount); + return setResource("ResourceMaterial"_s, VerseSteel, amount); } auto Profile::undinium() const -> Int { @@ -228,7 +230,7 @@ auto Profile::undinium() const -> Int { } auto Profile::setUndinium(Int amount) -> bool { - return setResource("ResourceMaterial", Undinium, amount); + return setResource("ResourceMaterial"_s, Undinium, amount); } auto Profile::necriumAlloy() const -> Int { @@ -236,7 +238,7 @@ auto Profile::necriumAlloy() const -> Int { } auto Profile::setNecriumAlloy(Int amount) -> bool { - return setResource("ResourceMaterial", NecriumAlloy, amount); + return setResource("ResourceMaterial"_s, NecriumAlloy, amount); } auto Profile::lunarite() const -> Int { @@ -244,7 +246,7 @@ auto Profile::lunarite() const -> Int { } auto Profile::setLunarite(Int amount) -> bool { - return setResource("ResourceMaterial", Lunarite, amount); + return setResource("ResourceMaterial"_s, Lunarite, amount); } auto Profile::asterite() const -> Int { @@ -252,7 +254,7 @@ auto Profile::asterite() const -> Int { } auto Profile::setAsterite(Int amount) -> bool { - return setResource("ResourceMaterial", Asterite, amount); + return setResource("ResourceMaterial"_s, Asterite, amount); } auto Profile::ednil() const -> Int { @@ -260,7 +262,7 @@ auto Profile::ednil() const -> Int { } auto Profile::setEdnil(Int amount) -> bool { - return setResource("ResourceMaterial", Ednil, amount); + return setResource("ResourceMaterial"_s, Ednil, amount); } auto Profile::nuflalt() const -> Int { @@ -268,7 +270,7 @@ auto Profile::nuflalt() const -> Int { } auto Profile::setNuflalt(Int amount) -> bool { - return setResource("ResourceMaterial", Nuflalt, amount); + return setResource("ResourceMaterial"_s, Nuflalt, amount); } auto Profile::aurelene() const -> Int { @@ -276,7 +278,7 @@ auto Profile::aurelene() const -> Int { } auto Profile::setAurelene(Int amount) -> bool { - return setResource("ResourceMaterial", Aurelene, amount); + return setResource("ResourceMaterial"_s, Aurelene, amount); } auto Profile::soldus() const -> Int { @@ -284,7 +286,7 @@ auto Profile::soldus() const -> Int { } auto Profile::setSoldus(Int amount) -> bool { - return setResource("ResourceMaterial", Soldus, amount); + return setResource("ResourceMaterial"_s, Soldus, amount); } auto Profile::synthesisedN() const -> Int { @@ -292,7 +294,7 @@ auto Profile::synthesisedN() const -> Int { } auto Profile::setSynthesisedN(Int amount) -> bool { - return setResource("ResourceMaterial", SynthesisedN, amount); + return setResource("ResourceMaterial"_s, SynthesisedN, amount); } auto Profile::alcarbonite() const -> Int { @@ -300,7 +302,7 @@ auto Profile::alcarbonite() const -> Int { } auto Profile::setAlcarbonite(Int amount) -> bool { - return setResource("ResourceMaterial", Alcarbonite, amount); + return setResource("ResourceMaterial"_s, Alcarbonite, amount); } auto Profile::keriphene() const -> Int { @@ -308,7 +310,7 @@ auto Profile::keriphene() const -> Int { } auto Profile::setKeriphene(Int amount) -> bool { - return setResource("ResourceMaterial", Keriphene, amount); + return setResource("ResourceMaterial"_s, Keriphene, amount); } auto Profile::nitinolCM() const -> Int { @@ -316,7 +318,7 @@ auto Profile::nitinolCM() const -> Int { } auto Profile::setNitinolCM(Int amount) -> bool { - return setResource("ResourceMaterial", NitinolCM, amount); + return setResource("ResourceMaterial"_s, NitinolCM, amount); } auto Profile::quarkium() const -> Int { @@ -324,7 +326,7 @@ auto Profile::quarkium() const -> Int { } auto Profile::setQuarkium(Int amount) -> bool { - return setResource("ResourceMaterial", Quarkium, amount); + return setResource("ResourceMaterial"_s, Quarkium, amount); } auto Profile::alterene() const -> Int { @@ -332,7 +334,7 @@ auto Profile::alterene() const -> Int { } auto Profile::setAlterene(Int amount) -> bool { - return setResource("ResourceMaterial", Alterene, amount); + return setResource("ResourceMaterial"_s, Alterene, amount); } auto Profile::mixedComposition() const -> Int { @@ -340,7 +342,7 @@ auto Profile::mixedComposition() const -> Int { } auto Profile::setMixedComposition(Int amount) -> bool { - return setResource("ResourceQuarkData", MixedComposition, amount); + return setResource("ResourceQuarkData"_s, MixedComposition, amount); } auto Profile::voidResidue() const -> Int { @@ -348,7 +350,7 @@ auto Profile::voidResidue() const -> Int { } auto Profile::setVoidResidue(Int amount) -> bool { - return setResource("ResourceQuarkData", VoidResidue, amount); + return setResource("ResourceQuarkData"_s, VoidResidue, amount); } auto Profile::muscularConstruction() const -> Int { @@ -356,7 +358,7 @@ auto Profile::muscularConstruction() const -> Int { } auto Profile::setMuscularConstruction(Int amount) -> bool { - return setResource("ResourceQuarkData", MuscularConstruction, amount); + return setResource("ResourceQuarkData"_s, MuscularConstruction, amount); } auto Profile::mineralExoskeletology() const -> Int { @@ -364,7 +366,7 @@ auto Profile::mineralExoskeletology() const -> Int { } auto Profile::setMineralExoskeletology(Int amount) -> bool { - return setResource("ResourceQuarkData", MineralExoskeletology, amount); + return setResource("ResourceQuarkData"_s, MineralExoskeletology, amount); } auto Profile::carbonisedSkin() const -> Int { @@ -372,10 +374,10 @@ auto Profile::carbonisedSkin() const -> Int { } 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(container); if(!mats_prop) { @@ -391,11 +393,11 @@ auto Profile::getResource(const char* container, MaterialID id) -> Int { return it != mats_prop->items.end() ? static_cast(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(container); if(!mats_prop) { - _lastError = "Couldn't find " + std::string{container} + " in " + _filename; + _lastError = "Couldn't find "_s + container + " in "_s + _filename; _valid = false; return false; } diff --git a/src/Profile/Profile.h b/src/Profile/Profile.h index b65ea6a..4da0a3d 100644 --- a/src/Profile/Profile.h +++ b/src/Profile/Profile.h @@ -16,7 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include +#include +#include #include @@ -24,6 +25,7 @@ #include "ResourceIDs.h" +using namespace Corrade; using namespace Magnum; enum class ProfileType : UnsignedByte { @@ -38,24 +40,24 @@ enum class ProfileVersion : UnsignedByte { class Profile { public: - explicit Profile(const std::string& path); + explicit Profile(Containers::StringView path); 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 version() const -> ProfileVersion; - auto account() const -> std::string const&; + auto account() const -> Containers::StringView; void refreshValues(); - auto companyName() const -> std::string const&; - auto renameCompany(const std::string& new_name) -> bool; + auto companyName() const -> Containers::StringView; + auto renameCompany(Containers::StringView new_name) -> bool; auto activeFrameSlot() const -> Int; @@ -128,17 +130,17 @@ class Profile { auto setCarbonisedSkin(Int amount) -> bool; private: - auto getResource(const char* container, MaterialID id) -> Int; - auto setResource(const char* container, MaterialID id, Int amount) -> bool; + auto getResource(Containers::StringView container, MaterialID id) -> Int; + auto setResource(Containers::StringView container, MaterialID id, Int amount) -> bool; - std::string _filename; + Containers::String _filename; ProfileType _type; ProfileVersion _version; UESaveFile _profile; - std::string _name; + Containers::String _name; Int _activeFrameSlot = 0; Int _credits = 0; Int _storyProgress = 0; @@ -168,8 +170,8 @@ class Profile { Int _mineralExoskeletology = 0; Int _carbonisedSkin = 0; - std::string _account; + Containers::String _account; - bool _valid = false; - std::string _lastError; + bool _valid = false; + Containers::String _lastError; }; diff --git a/src/ProfileManager/ProfileManager.cpp b/src/ProfileManager/ProfileManager.cpp index 38d69cf..a97cc22 100644 --- a/src/ProfileManager/ProfileManager.cpp +++ b/src/ProfileManager/ProfileManager.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -31,7 +32,9 @@ #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}, _backupsDirectory{backup_dir} { @@ -42,7 +45,7 @@ auto ProfileManager::ready() const -> bool { return _ready; } -auto ProfileManager::lastError() -> std::string const& { +auto ProfileManager::lastError() -> Containers::StringView { return _lastError; } @@ -54,21 +57,21 @@ auto ProfileManager::refreshProfiles() -> bool { _profiles = Containers::Array{}; using Utility::Directory::Flag; - std::vector 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::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()); - for(const std::string& file : files) { + for(const auto& file : files) { Profile profile{Utility::Directory::join(_saveDirectory, file)}; 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; } @@ -76,7 +79,7 @@ auto ProfileManager::refreshProfiles() -> bool { } if(_profiles.empty()) { - _lastError = "No valid profiles were found."; + _lastError = "No valid profiles were found."_s; 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 { if(!Utility::Directory::rm(Utility::Directory::join(_saveDirectory, _profiles[index].filename()))) { - _lastError = Utility::formatString("Couldn't delete {} (filename: {}).", - _profiles[index].companyName(), - _profiles[index].filename()); + _lastError = Utility::format("Couldn't delete {} (filename: {}).", + _profiles[index].companyName(), + _profiles[index].filename()); refreshProfiles(); return false; } if(delete_builds) { for(UnsignedByte i = 0; i < 32; ++i) { - std::string filename = Utility::formatString("{}Unit{:.2d}{}.sav", - _profiles[index].type() == ProfileType::Demo ? "Demo": "", - i, _profiles[index].account()); + auto filename = Utility::format("{}Unit{:.2d}{}.sav", + _profiles[index].type() == ProfileType::Demo ? "Demo": "", + i, _profiles[index].account()); Utility::Directory::rm(Utility::Directory::join(_saveDirectory, filename)); } } - std::string file = _profiles[index].filename(); - auto it = std::remove_if(_profiles.begin(), _profiles.end(), [&file](Profile& profile){return profile.filename() == file;}); + auto file = _profiles[index].filename(); + auto it = std::remove_if(_profiles.begin(), _profiles.end(), [&file](Profile& profile){ return profile.filename() == file; }); if(it != _profiles.end()) { 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::tm* time = std::localtime(×tamp); - std::string filename = Utility::formatString("{}_{}{:.2d}{:.2d}_{:.2d}{:.2d}{:.2d}.mbprofbackup", - Utility::String::replaceAll(_profiles[index].companyName(), " ", "_"), - time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec); + auto filename = Utility::format("{}_{}{:.2d}{:.2d}_{:.2d}{:.2d}{:.2d}.mbprofbackup", + Utility::String::replaceAll(_profiles[index].companyName(), " ", "_"), + time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, + time->tm_hour, time->tm_min, time->tm_sec); int error_code = 0; zip_error_t error; @@ -140,25 +143,24 @@ auto ProfileManager::backupProfile(std::size_t index, bool backup_builds) -> boo 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); zip_source_free(profile_source); return false; } - std::string comment = Utility::String::join({_profiles[index].companyName(), - _profiles[index].type() == ProfileType::Demo ? "demo" : "full", - Utility::formatString("{}-{:.2d}-{:.2d}-{:.2d}-{:.2d}-{:.2d}", - time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec) - }, '|'); - zip_set_archive_comment(zip, comment.c_str(), comment.length()); + auto comment = "|"_s.join({_profiles[index].companyName(), + _profiles[index].type() == ProfileType::Demo ? "demo"_s : "full"_s, + Utility::format("{}-{:.2d}-{:.2d}-{:.2d}-{:.2d}-{:.2d}", + time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, + time->tm_hour, time->tm_min, time->tm_sec)}); + zip_set_archive_comment(zip, comment.data(), comment.size()); if(backup_builds) { for(UnsignedByte i = 0; i < 32; ++i) { - std::string build_filename = Utility::formatString("{}Unit{:.2d}{}.sav", - _profiles[index].type() == ProfileType::Demo ? "Demo": "", - i, _profiles[index].account()); + auto build_filename = Utility::format("{}Unit{:.2d}{}.sav", + _profiles[index].type() == ProfileType::Demo ? "Demo"_s : ""_s, i, + _profiles[index].account()); if(!Utility::Directory::exists(Utility::Directory::join(_saveDirectory, build_filename))) { continue; @@ -170,7 +172,7 @@ auto ProfileManager::backupProfile(std::size_t index, bool backup_builds) -> boo 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); continue; } @@ -197,8 +199,8 @@ void ProfileManager::refreshBackups() { using Utility::Directory::Flag; std::vector files = Utility::Directory::list(_backupsDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot); - auto predicate = [](const std::string& file)->bool{ - return !Utility::String::endsWith(file, ".mbprofbackup"); + auto predicate = [](Containers::StringView file)->bool{ + return !file.hasSuffix(".mbprofbackup"_s); }; 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}; 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) { continue; } - auto info = Utility::String::split(comment, '|'); + auto info = comment.split('|'); if(info.size() != 3) { continue; } - backup.company = info.at(0); + backup.company = info[0]; - if(info.at(1) == "full") { + if(info[1] == "full") { backup.type = ProfileType::FullGame; } - else if(info.at(1) == "demo") { + else if(info[1] == "demo") { backup.type = ProfileType::Demo; } else { continue; } - auto ts = Utility::String::split(info.at(2), '-'); + auto ts = info[2].split('-'); if(ts.size() != 6) { continue; } - backup.timestamp.year = std::stoi(ts.at(0)); - backup.timestamp.month = std::stoi(ts.at(1)); - backup.timestamp.day = std::stoi(ts.at(2)); - backup.timestamp.hour = std::stoi(ts.at(3)); - backup.timestamp.minute = std::stoi(ts.at(4)); - backup.timestamp.second = std::stoi(ts.at(5)); + backup.timestamp.year = std::stoi(ts[0]); + backup.timestamp.month = std::stoi(ts[1]); + backup.timestamp.day = std::stoi(ts[2]); + backup.timestamp.hour = std::stoi(ts[3]); + backup.timestamp.minute = std::stoi(ts[4]); + backup.timestamp.second = std::stoi(ts[5]); 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; } - 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;}); if(it != _backups.end()) { @@ -287,7 +289,7 @@ auto ProfileManager::deleteBackup(std::size_t index) -> bool { auto ProfileManager::restoreBackup(std::size_t index) -> bool { 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; zip_t* zip = nullptr; @@ -302,18 +304,18 @@ auto ProfileManager::restoreBackup(std::size_t index) -> bool { 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"); if(out == nullptr) { - _lastError = Utility::formatString(error_format, file, std::strerror(errno)); + _lastError = Utility::formatString(error_format.data(), file, std::strerror(errno)); return false; } 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) { - _lastError = Utility::formatString(error_format, file, zip_strerror(zip)); + _lastError = Utility::format(error_format.data(), file, zip_strerror(zip)); return false; } @@ -324,13 +326,13 @@ auto ProfileManager::restoreBackup(std::size_t index) -> bool { Long bytes_read = 0; while((bytes_read = zip_fread(zf, buf.data(), buf.size())) > 0) { if(std::fwrite(buf.data(), sizeof(char), bytes_read, out) < static_cast(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; } } 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; } } diff --git a/src/ProfileManager/ProfileManager.h b/src/ProfileManager/ProfileManager.h index db9887a..0fe9e11 100644 --- a/src/ProfileManager/ProfileManager.h +++ b/src/ProfileManager/ProfileManager.h @@ -19,14 +19,15 @@ #include #include +#include #include "../Profile/Profile.h" using namespace Corrade; struct Backup { - std::string filename; - std::string company; + Containers::String filename; + Containers::String company; ProfileType type; struct { int year; @@ -36,15 +37,15 @@ struct Backup { int minute; int second; } timestamp; - Containers::Array includedFiles; + Containers::Array includedFiles; }; class ProfileManager { 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 lastError() -> std::string const&; + auto lastError() -> Containers::StringView; auto profiles() -> Containers::ArrayView; auto refreshProfiles() -> bool; @@ -61,10 +62,10 @@ class ProfileManager { private: bool _ready = false; - std::string _lastError; + Containers::String _lastError; - const std::string& _saveDirectory; - const std::string& _backupsDirectory; + Containers::StringView _saveDirectory; + Containers::StringView _backupsDirectory; Containers::Array _profiles; Containers::Array _backups; diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index 3b2a23f..9d7b1f4 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -46,6 +47,8 @@ #include "../FontAwesome/IconsFontAwesome5.h" #include "../FontAwesome/IconsFontAwesome5Brands.h" +using namespace Containers::Literals; + extern const ImVec2 center_pivot = {0.5f, 0.5f}; #ifdef SAVETOOL_DEBUG_BUILD @@ -58,19 +61,19 @@ SaveTool::SaveTool(const Arguments& arguments): .setSize({960, 720})} { #ifdef SAVETOOL_DEBUG_BUILD - tweak.enable("", "../../"); + tweak.enable(""_s, "../../"_s); #endif if(SDL_VERSION_ATLEAST(2, 0, 5)) { 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 { - Utility::Warning{} << "Clickthrough is not available (hint couldn't be set)."; + Utility::Warning{} << "Clickthrough is not available (hint couldn't be set)."_s; } } 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); @@ -98,7 +101,7 @@ SaveTool::SaveTool(const Arguments& arguments): _armouryDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "armoury"); _armoursDir = Utility::Directory::join(_armouryDir, "armours"); _weaponsDir = Utility::Directory::join(_armouryDir, "weapons"); - _stylesDir = Utility::Directory::join(_armouryDir, "styles"); + _stylesDir = Utility::Directory::join(_armouryDir, "styles"); if(!Utility::Directory::exists(_backupsDir)) { Utility::Directory::mkpath(_backupsDir); @@ -125,7 +128,7 @@ SaveTool::SaveTool(const Arguments& arguments): } 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); return; } @@ -145,8 +148,7 @@ SaveTool::SaveTool(const Arguments& arguments): [](UnsignedInt interval, void* param)->UnsignedInt{ static_cast(param)->checkGameState(); return interval; - }, - this); + }, this); if(_gameCheckTimerId == 0) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", SDL_GetError(), window()); exit(EXIT_FAILURE); @@ -170,7 +172,7 @@ SaveTool::SaveTool(const Arguments& arguments): if(_checkUpdatesOnStartup) { _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() && @@ -188,20 +190,20 @@ SaveTool::SaveTool(const Arguments& arguments): SaveTool::~SaveTool() { SDL_RemoveTimer(_gameCheckTimerId); - _conf.setValue("cheat_mode", _cheatMode); - _conf.setValue("unsafe_mode", _unsafeMode); - _conf.setValue("startup_update_check", _checkUpdatesOnStartup); - _conf.setValue("skip_disclaimer", _skipDisclaimer); + _conf.setValue("cheat_mode"_s, _cheatMode); + _conf.setValue("unsafe_mode"_s, _unsafeMode); + _conf.setValue("startup_update_check"_s, _checkUpdatesOnStartup); + _conf.setValue("skip_disclaimer"_s, _skipDisclaimer); switch(_framelimit) { case Framelimit::Vsync: - _conf.setValue("frame_limit", "vsync"); + _conf.setValue("frame_limit"_s, "vsync"_s); break; case Framelimit::HalfVsync: - _conf.setValue("frame_limit", "half_vsync"); + _conf.setValue("frame_limit"_s, "half_vsync"_s); break; case Framelimit::FpsCap: - _conf.setValue("frame_limit", _fpsCap); + _conf.setValue("frame_limit"_s, _fpsCap); break; } @@ -366,7 +368,7 @@ void SaveTool::initEvent(SDL_Event& event) { ImGui::CloseCurrentPopup(); break; 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); break; default: @@ -381,12 +383,12 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { delete static_cast(event.user.data1); 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; } 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; } @@ -395,18 +397,18 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { json response = json::parse(r.text); struct Version { - explicit Version(const std::string& str) { + explicit Version(Containers::StringView str) { std::size_t start_point = 0; if(str[0] == 'v') { start_point++; } - major = std::atoi(str.c_str() + start_point); - start_point = str.find('.', start_point) + 1; - minor = std::atoi(str.c_str() + start_point); - start_point = str.find('.', start_point) + 1; - patch = std::atoi(str.c_str() + start_point); + auto components = Containers::StringView{str.data() + start_point, strlen(str.data() + start_point)}.split('.'); + + major = std::strtol(components[0].data(), nullptr, 10); + minor = std::strtol(components[1].data(), nullptr, 10); + patch = std::strtol(components[2].data(), nullptr, 10); } Int major; Int minor; @@ -419,8 +421,8 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { return ( major * 10000 + minor * 100 + patch) > (other.major * 10000 + other.minor * 100 + other.patch); } - operator std::string() const { - return Utility::formatString("{}.{}.{}", major, minor, patch); + operator Containers::String() const { + return Utility::format("{}.{}.{}", major, minor, patch); } }; @@ -431,21 +433,21 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { 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"))) { - _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}); _updateAvailable = true; _latestVersion = latest_ver; - _releaseLink = release["html_url"]; - _downloadLink = release["assets"][0]["browser_download_url"]; + _releaseLink = to_string(release["html_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"))) { - _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) { - _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; @@ -453,40 +455,40 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { } void SaveTool::initialiseConfiguration() { - if(_conf.hasValue("cheat_mode")) { - _cheatMode = _conf.value("cheat_mode"); + if(_conf.hasValue("cheat_mode"_s)) { + _cheatMode = _conf.value("cheat_mode"_s); } else { - _conf.setValue("cheat_mode", _cheatMode); + _conf.setValue("cheat_mode"_s, _cheatMode); } - if(_conf.hasValue("unsafe_mode")) { - _unsafeMode = _conf.value("unsafe_mode"); + if(_conf.hasValue("unsafe_mode"_s)) { + _unsafeMode = _conf.value("unsafe_mode"_s); } else { - _conf.setValue("unsafe_mode", _unsafeMode); + _conf.setValue("unsafe_mode"_s, _unsafeMode); } - if(_conf.hasValue("startup_update_check")) { - _checkUpdatesOnStartup = _conf.value("startup_update_check"); + if(_conf.hasValue("startup_update_check"_s)) { + _checkUpdatesOnStartup = _conf.value("startup_update_check"_s); } else { - _conf.setValue("startup_update_check", _checkUpdatesOnStartup); + _conf.setValue("startup_update_check"_s, _checkUpdatesOnStartup); } - if(_conf.hasValue("skip_disclaimer")) { - _skipDisclaimer = _conf.value("skip_disclaimer"); + if(_conf.hasValue("skip_disclaimer"_s)) { + _skipDisclaimer = _conf.value("skip_disclaimer"_s); } else { - _conf.setValue("skip_disclaimer", _skipDisclaimer); + _conf.setValue("skip_disclaimer"_s, _skipDisclaimer); } - if(_conf.hasValue("frame_limit")) { - std::string frame_limit = _conf.value("frame_limit"); - if(frame_limit == "vsync") { + if(_conf.hasValue("frame_limit"_s)) { + std::string frame_limit = _conf.value("frame_limit"_s); + if(frame_limit == "vsync"_s) { _framelimit = Framelimit::Vsync; } - else if(frame_limit == "half_vsync") { + else if(frame_limit == "half_vsync"_s) { _framelimit = Framelimit::HalfVsync; } else { @@ -495,7 +497,7 @@ void SaveTool::initialiseConfiguration() { } } else { - _conf.setValue("frame_limit", "vsync"); + _conf.setValue("frame_limit"_s, "vsync"_s); } _conf.save(); @@ -506,7 +508,7 @@ void SaveTool::initialiseGui() { ImGuiIO& io = ImGui::GetIO(); - auto reg_font = _rs.getRaw("SourceSansPro-Regular.ttf"); + auto reg_font = _rs.getRaw("SourceSansPro-Regular.ttf"_s); ImFontConfig font_config; font_config.FontDataOwnedByAtlas = false; 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 }; io.Fonts->AddFontFromMemoryTTF(const_cast(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 range; ImFontGlyphRangesBuilder builder; builder.AddRanges(io.Fonts->GetGlyphRangesDefault()); @@ -566,14 +568,14 @@ auto SaveTool::findGameDataDirectory() -> bool { Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree}; 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; } _gameDataDir = Utility::Directory::join(Utility::Directory::fromNativeSeparators(Utility::Unicode::narrow(localappdata_path)), "MASS_Builder"); 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; } @@ -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); 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()){ ImGui::BeginTooltip(); if(wrap_pos > 0.0f) { ImGui::PushTextWrapPos(wrap_pos); } - ImGui::TextUnformatted(text); + ImGui::TextUnformatted(text.data()); if(wrap_pos > 0.0f) { ImGui::PopTextWrapPos(); } @@ -767,8 +769,8 @@ void SaveTool::drawTooltip(const char* text, Float wrap_pos) { } } -void SaveTool::openUri(const std::string& uri) { - ShellExecuteW(nullptr, nullptr, Utility::Unicode::widen(uri).c_str(), nullptr, nullptr, SW_SHOWDEFAULT); +void SaveTool::openUri(Containers::StringView uri) { + ShellExecuteW(nullptr, nullptr, Utility::Unicode::widen(uri.data()).c_str(), nullptr, nullptr, SW_SHOWDEFAULT); } void SaveTool::checkGameState() { diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index b871df8..437d15e 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -16,9 +16,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include #include #include +#include #include #include @@ -43,6 +45,7 @@ #endif using namespace Corrade; +using namespace Containers::Literals; using namespace Magnum; class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener { @@ -106,11 +109,11 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener void drawGeneralInfo(); void drawResearchInventory(); template - void drawMaterialRow(const char* name, Int tier, Getter getter, Setter setter); - void drawUnavailableMaterialRow(const char* name, Int tier); + void drawMaterialRow(Containers::StringView name, Int tier, Getter getter, Setter setter); + void drawUnavailableMaterialRow(Containers::StringView name, Int tier); void drawMassManager(); auto drawDeleteMassPopup(int mass_index) -> ImGuiID; - auto drawDeleteStagedMassPopup(const std::string& filename) -> ImGuiID; + auto drawDeleteStagedMassPopup(Containers::StringView filename) -> ImGuiID; void drawMassViewer(); void drawFrameInfo(); @@ -121,13 +124,14 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener void drawArmour(); void drawCustomArmourStyles(); void drawWeapons(); - void drawWeaponCategory(const char* name, Containers::ArrayView weapons_view, bool& dirty, const char* payload_type, const char* payload_tooltip); + void drawWeaponCategory(Containers::StringView name, Containers::ArrayView weapons_view, bool& dirty, + Containers::StringView payload_type, Containers::StringView payload_tooltip); void drawWeaponEditor(Weapon& weapon); void drawGlobalStyles(); void drawTuning(); void drawDecalEditor(Decal& decal); void drawAccessoryEditor(Accessory& accessory, Containers::ArrayView style_view); - auto getStyleName(Int id, Containers::ArrayView view) -> const char*; + auto getStyleName(Int id, Containers::ArrayView view) -> Containers::StringView; enum DCSResult { DCS_Fail, @@ -140,8 +144,8 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener void drawGameState(); // Convenience wrappers over ImGui stuff - void drawHelpMarker(const char* text, Float wrap_pos = 0.0f); - void drawTooltip(const char* text, Float wrap_pos = 0.0f); + void drawHelpMarker(Containers::StringView text, Float wrap_pos = 0.0f); + void drawTooltip(Containers::StringView text, Float wrap_pos = 0.0f); template 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... template - 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) { ImGui::TextDisabled(text, std::forward(args)...); } @@ -173,19 +177,19 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener } template - void drawAlignedText(const char* text, Args... args) { + void drawAlignedText(Containers::StringView text, Args... args) { ImGui::AlignTextToFramePadding(); - ImGui::Text(text, std::forward(args)...); + ImGui::Text(text.data(), std::forward(args)...); } - void openUri(const std::string& uri); + void openUri(Containers::StringView uri); void checkGameState(); void checkForUpdates(); - Utility::Configuration _conf{"MassBuilderSaveTool.ini"}; - Utility::Resource _rs{"assets"}; + Utility::Configuration _conf{"MassBuilderSaveTool.ini"_s}; + Utility::Resource _rs{"assets"_s}; // GUI-related members ImGuiIntegration::Context _imgui{NoCreate}; @@ -213,22 +217,22 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener UnsignedInt _initEventId; UnsignedInt _updateEventId; - std::string _lastError; + Containers::String _lastError; - std::string _gameDataDir; - std::string _configDir; - std::string _saveDir; - std::string _screenshotsDir; + Containers::String _gameDataDir; + Containers::String _configDir; + Containers::String _saveDir; + Containers::String _screenshotsDir; - std::string _backupsDir; - std::string _stagingDir; - std::string _armouryDir; - std::string _armoursDir; - std::string _weaponsDir; - std::string _stylesDir; + Containers::String _backupsDir; + Containers::String _stagingDir; + Containers::String _armouryDir; + Containers::String _armoursDir; + Containers::String _weaponsDir; + Containers::String _stylesDir; enum class GameState : UnsignedByte { - Unknown, NotRunning, Running + Unknown, NotRunning, Running } _gameState{GameState::Unknown}; SDL_TimerID _gameCheckTimerId = 0; @@ -260,9 +264,9 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener bool _unsafeMode{false}; bool _updateAvailable{false}; - std::string _latestVersion; - std::string _releaseLink; - std::string _downloadLink; + Containers::String _latestVersion; + Containers::String _releaseLink; + Containers::String _downloadLink; bool _jointsDirty{false}; bool _stylesDirty{false}; diff --git a/src/SaveTool/SaveTool_MainManager.cpp b/src/SaveTool/SaveTool_MainManager.cpp index d949984..fd8a97a 100644 --- a/src/SaveTool/SaveTool_MainManager.cpp +++ b/src/SaveTool/SaveTool_MainManager.cpp @@ -43,7 +43,7 @@ void SaveTool::drawManager() { } drawAlignedText("Current profile: %s (%s)", - _currentProfile->companyName().c_str(), + _currentProfile->companyName(), _currentProfile->type() == ProfileType::Demo ? "demo" : "full game"); ImGui::SameLine(); if(ImGui::Button(ICON_FA_ARROW_LEFT " Back to profile manager")) { @@ -220,7 +220,7 @@ void SaveTool::drawGeneralInfo() { for(auto& c : name_buf) { 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"); } if(drawRenamePopup(name_buf)) { @@ -257,17 +257,17 @@ void SaveTool::drawGeneralInfo() { ImGui::CloseCurrentPopup(); } for(const auto& sp : story_progress) { - if(ImGui::BeginMenu(sp.chapter)) { + if(ImGui::BeginMenu(sp.chapter.data())) { if(!sp.after) { - if(ImGui::MenuItem(sp.point)) { + if(ImGui::MenuItem(sp.point.data())) { if(!_currentProfile->setStoryProgress(sp.id)) { _queue.addToast(Toast::Type::Error, _currentProfile->lastError()); } } } else { - if(ImGui::BeginMenu(sp.after)) { - if(ImGui::MenuItem(sp.point)) { + if(ImGui::BeginMenu(sp.after.data())) { + if(ImGui::MenuItem(sp.point.data())) { if(!_currentProfile->setStoryProgress(sp.id)) { _queue.addToast(Toast::Type::Error, _currentProfile->lastError()); } @@ -388,7 +388,7 @@ void SaveTool::drawResearchInventory() { } template -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::value, "getter doesn't return an Int, and/or doesn't take zero arguments."); static_assert(std::is_same::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::Text("T%i", tier); ImGui::TableSetColumnIndex(1); - ImGui::TextUnformatted(name); + ImGui::TextUnformatted(name.data()); ImGui::TableSetColumnIndex(2); if(getter() != -1) { ImGui::Text("%i", getter()); if(_cheatMode) { ImGui::TableSetColumnIndex(3); - ImGui::PushID(name); + ImGui::PushID(name.data()); static Int var = 0; if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_EDIT)) { (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::TableSetColumnIndex(0); ImGui::Text("T%i", tier); ImGui::TableSetColumnIndex(1); - ImGui::TextUnformatted(name); + ImGui::TextUnformatted(name.data()); ImGui::TableSetColumnIndex(2); ImGui::TextDisabled("Unavailable as of game version " SUPPORTED_GAME_VERSION); } @@ -472,7 +472,7 @@ void SaveTool::drawMassManager() { drag_drop_index = i; 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(); } @@ -518,7 +518,7 @@ void SaveTool::drawMassManager() { ImGui::TextDisabled(""); break; case Mass::State::Valid: - ImGui::TextUnformatted((*_massManager->hangar(i).name()).c_str()); + ImGui::TextUnformatted(_massManager->hangar(i).name().data()); break; } @@ -557,7 +557,7 @@ void SaveTool::drawMassManager() { drawDeleteMassPopup(mass_to_delete); static ImGuiID staged_mass_deletion_popup_ID = drawDeleteStagedMassPopup(""); - static Containers::Reference staged_mass_to_delete{empty_str}; + static Containers::StringView staged_mass_to_delete; if(ImGui::BeginTable("##StagingArea", 2, ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersOuter|ImGuiTableFlags_RowBg)) @@ -587,15 +587,15 @@ void SaveTool::drawMassManager() { if(ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) { 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::TableSetColumnIndex(1); - ImGui::PushID(pair.first.c_str()); + ImGui::PushID(pair.first.data()); if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) { - staged_mass_to_delete = Containers::Reference{pair.first}; + staged_mass_to_delete = pair.first; ImGui::OpenPopup(staged_mass_deletion_popup_ID); } ImGui::PopID(); @@ -622,7 +622,7 @@ void SaveTool::drawMassManager() { ImGui::EndDragDropTarget(); } - drawDeleteStagedMassPopup(staged_mass_to_delete.get()); + drawDeleteStagedMassPopup(staged_mass_to_delete); } auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID { @@ -651,7 +651,7 @@ auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID { } else { 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(); @@ -681,7 +681,7 @@ auto SaveTool::drawDeleteMassPopup(int mass_index) -> ImGuiID { return 0; } -auto SaveTool::drawDeleteStagedMassPopup(const std::string& filename) -> ImGuiID { +auto SaveTool::drawDeleteStagedMassPopup(Containers::StringView filename) -> ImGuiID { if(!ImGui::BeginPopupModal("Confirmation##DeleteStagedMassConfirmation", nullptr, 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::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(); if(ImGui::BeginTable("##DeleteStagedMassLayout", 2)) { diff --git a/src/SaveTool/SaveTool_MassViewer.cpp b/src/SaveTool/SaveTool_MassViewer.cpp index 578b2e9..0941440 100644 --- a/src/SaveTool/SaveTool_MassViewer.cpp +++ b/src/SaveTool/SaveTool_MassViewer.cpp @@ -61,8 +61,8 @@ void SaveTool::drawMassViewer() { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::Text("M.A.S.S.: %s", (*_currentMass->name()).c_str()); - drawTooltip(_currentMass->filename().c_str()); + ImGui::Text("M.A.S.S.: %s", _currentMass->name().data()); + drawTooltip(_currentMass->filename()); ImGui::TableSetColumnIndex(2); if(_currentMass->dirty()) { @@ -298,14 +298,14 @@ auto SaveTool::drawCustomStyle(CustomStyle& style) -> DCSResult { } if(ImGui::BeginMenuBar()) { - ImGui::TextUnformatted(style.name.c_str()); + ImGui::TextUnformatted(style.name.data()); static Containers::StaticArray<33, char> name_buf{ValueInit}; if(ImGui::SmallButton(ICON_FA_EDIT " Rename")) { for(auto& c : name_buf) { 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"); } if(drawRenamePopup(name_buf)) { @@ -516,9 +516,9 @@ void SaveTool::drawAccessoryEditor(Accessory& accessory, Containers::ArrayView view) -> const char* { +auto SaveTool::getStyleName(Int id, Containers::ArrayView view) -> Containers::StringView { if(id >= 0 && id <= 15) { - return view[id].name.c_str(); + return view[id].name; } else if(id >= 50 && id <= 65) { - return _currentMass->globalStyles()[id - 50].name.c_str(); + return _currentMass->globalStyles()[id - 50].name; } else { return style_names.at(id); diff --git a/src/SaveTool/SaveTool_MassViewer_Armour.cpp b/src/SaveTool/SaveTool_MassViewer_Armour.cpp index a3120ad..27313f7 100644 --- a/src/SaveTool/SaveTool_MassViewer_Armour.cpp +++ b/src/SaveTool/SaveTool_MassViewer_Armour.cpp @@ -35,10 +35,10 @@ void SaveTool::drawArmour() { return; } - static const char* slot_labels[] = { -#define c(enumerator, strenum, name) name, -#include "../Maps/ArmourSlots.hpp" -#undef c + static Containers::StringView slot_labels[] = { + #define c(enumerator, strenum, name) name, + #include "../Maps/ArmourSlots.hpp" + #undef c }; for(UnsignedInt i = 0; i < _currentMass->armourParts().size(); i++) { @@ -51,10 +51,10 @@ void SaveTool::drawArmour() { std::memset(header, '\0', 129); 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 { - 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)) { @@ -62,9 +62,9 @@ void SaveTool::drawArmour() { ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() * 0.491f); 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) { - 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; } } @@ -75,7 +75,7 @@ void SaveTool::drawArmour() { 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; } } @@ -103,9 +103,9 @@ void SaveTool::drawArmour() { ImGui::PushID(j); 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) { - 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; } } diff --git a/src/SaveTool/SaveTool_MassViewer_Frame.cpp b/src/SaveTool/SaveTool_MassViewer_Frame.cpp index 8aae76f..8a2907b 100644 --- a/src/SaveTool/SaveTool_MassViewer_Frame.cpp +++ b/src/SaveTool/SaveTool_MassViewer_Frame.cpp @@ -205,9 +205,9 @@ void SaveTool::drawFrameStyles() { 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) { - 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; _stylesDirty = true; } diff --git a/src/SaveTool/SaveTool_MassViewer_Weapons.cpp b/src/SaveTool/SaveTool_MassViewer_Weapons.cpp index afac126..aa58626 100644 --- a/src/SaveTool/SaveTool_MassViewer_Weapons.cpp +++ b/src/SaveTool/SaveTool_MassViewer_Weapons.cpp @@ -234,14 +234,14 @@ void SaveTool::drawWeapons() { ImGui::EndGroup(); } -void SaveTool::drawWeaponCategory(const char* name, Containers::ArrayView weapons_view, bool& dirty, - const char* payload_type, const char* payload_tooltip) +void SaveTool::drawWeaponCategory(Containers::StringView name, Containers::ArrayView weapons_view, bool& dirty, + Containers::StringView payload_type, Containers::StringView payload_tooltip) { ImGui::TableNextRow(ImGuiTableRowFlags_Headers); 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++) { auto& weapon = weapons_view[i]; @@ -251,21 +251,21 @@ void SaveTool::drawWeaponCategory(const char* name, Containers::ArrayView(payload->Data); if(!ImGui::GetIO().KeyCtrl) { @@ -302,13 +302,15 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { return; } - static const char* labels[] { -#define c(enumerator, strenum, name) name, -#include "../Maps/WeaponTypes.hpp" -#undef c + static Containers::StringView labels[] { + #define c(enumerator, strenum, name) name, + #include "../Maps/WeaponTypes.hpp" + #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(); @@ -317,7 +319,7 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { for(auto& c : name_buf) { 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"); } if(drawRenamePopup(name_buf)) { @@ -425,9 +427,9 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { 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) { - 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; } diff --git a/src/SaveTool/SaveTool_ProfileManager.cpp b/src/SaveTool/SaveTool_ProfileManager.cpp index d501d1b..4752bf1 100644 --- a/src/SaveTool/SaveTool_ProfileManager.cpp +++ b/src/SaveTool/SaveTool_ProfileManager.cpp @@ -50,7 +50,7 @@ void SaveTool::drawProfileManager() { ImGui::TableSetColumnIndex(1); if(ImGui::SmallButton("Refresh")) { 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); } } @@ -81,7 +81,7 @@ void SaveTool::drawProfileManager() { ImGui::TableSetColumnIndex(0); 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)) { _currentProfile = _profileManager->getProfile(i); @@ -132,7 +132,7 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID { { 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.", - _profileManager->backups()[backup_index].company.c_str(), + _profileManager->backups()[backup_index].company.data(), _profileManager->backups()[backup_index].timestamp.year, _profileManager->backups()[backup_index].timestamp.month, _profileManager->backups()[backup_index].timestamp.day, @@ -171,7 +171,7 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID { { 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.", - _profileManager->backups()[backup_index].company.c_str(), + _profileManager->backups()[backup_index].company.data(), _profileManager->backups()[backup_index].timestamp.year, _profileManager->backups()[backup_index].timestamp.month, _profileManager->backups()[backup_index].timestamp.day, @@ -249,11 +249,11 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::TextUnformatted(_profileManager->backups()[i].company.c_str()); + ImGui::TextUnformatted(_profileManager->backups()[i].company.data()); if(ImGui::IsItemHovered()) { ImGui::BeginTooltip(); for(const auto& file : _profileManager->backups()[i].includedFiles) { - ImGui::TextUnformatted(file.c_str()); + ImGui::TextUnformatted(file.data()); } ImGui::EndTooltip(); } @@ -361,7 +361,7 @@ auto SaveTool::drawDeleteProfilePopup(std::size_t profile_index) -> ImGuiID { ImGui::PushTextWrapPos(windowSize().x() * 0.40f); 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"); ImGui::PopTextWrapPos(); diff --git a/src/SaveTool/SaveTool_drawAbout.cpp b/src/SaveTool/SaveTool_drawAbout.cpp index c5fa7ea..975a269 100644 --- a/src/SaveTool/SaveTool_drawAbout.cpp +++ b/src/SaveTool/SaveTool_drawAbout.cpp @@ -17,6 +17,7 @@ #include "SaveTool.h" #include +#include #include #include @@ -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), " "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); ImGui::SameLine(); 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:"); 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::TextUnformatted(licence.c_str()); + ImGui::TextUnformatted(licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -89,7 +90,7 @@ void SaveTool::drawAbout() { if(ImGui::TreeNodeEx("Corrade", ImGuiTreeNodeFlags_SpanAvailWidth)) { 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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { @@ -102,10 +103,10 @@ void SaveTool::drawAbout() { 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)) { ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(corrade_licence.c_str()); + ImGui::TextUnformatted(corrade_licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -117,7 +118,7 @@ void SaveTool::drawAbout() { ImGui::TextUnformatted("Versions used:"); ImGui::BulletText("Magnum: %s", MAGNUM_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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { @@ -130,10 +131,10 @@ void SaveTool::drawAbout() { 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)) { ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(magnum_licence.c_str()); + ImGui::TextUnformatted(magnum_licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -143,7 +144,7 @@ void SaveTool::drawAbout() { if(ImGui::TreeNodeEx("Dear ImGui", ImGuiTreeNodeFlags_SpanAvailWidth)) { 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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { @@ -156,10 +157,10 @@ void SaveTool::drawAbout() { 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)) { ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(imgui_licence.c_str()); + ImGui::TextUnformatted(imgui_licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -169,7 +170,7 @@ void SaveTool::drawAbout() { 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); - const char* sdl_website = "https://www.libsdl.org/"; + auto sdl_website = "https://www.libsdl.org/"; drawAlignedText(ICON_FA_GLOBE " %s", sdl_website); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { @@ -182,10 +183,10 @@ void SaveTool::drawAbout() { 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)) { ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(sdl_licence.c_str()); + ImGui::TextUnformatted(sdl_licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -195,7 +196,7 @@ void SaveTool::drawAbout() { if(ImGui::TreeNodeEx("libzip", ImGuiTreeNodeFlags_SpanAvailWidth)) { 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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { @@ -208,10 +209,10 @@ void SaveTool::drawAbout() { 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)) { ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(libzip_licence.c_str()); + ImGui::TextUnformatted(libzip_licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -220,11 +221,11 @@ void SaveTool::drawAbout() { } 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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { - ImGui::SetClipboardText(efsw_repo); + ImGui::SetClipboardText(efsw_repo.data()); } ImGui::SameLine(); if(ImGui::Button("Open in browser")) { @@ -233,10 +234,10 @@ void SaveTool::drawAbout() { 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)) { ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(efsw_licence.c_str()); + ImGui::TextUnformatted(efsw_licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -245,7 +246,7 @@ void SaveTool::drawAbout() { } 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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { @@ -258,10 +259,10 @@ void SaveTool::drawAbout() { 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)) { ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(cpr_licence.c_str()); + ImGui::TextUnformatted(cpr_licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -270,7 +271,7 @@ void SaveTool::drawAbout() { } 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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { @@ -283,10 +284,10 @@ void SaveTool::drawAbout() { 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)) { ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]); - ImGui::TextUnformatted(json_licence.c_str()); + ImGui::TextUnformatted(json_licence); ImGui::PopFont(); } ImGui::EndChild(); @@ -296,7 +297,7 @@ void SaveTool::drawAbout() { if(ImGui::TreeNodeEx("Font Awesome", ImGuiTreeNodeFlags_SpanAvailWidth)) { 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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { @@ -313,7 +314,7 @@ void SaveTool::drawAbout() { } 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); ImGui::SameLine(); if(ImGui::Button("Copy to clipboard")) { diff --git a/src/SaveTool/SaveTool_drawMainMenu.cpp b/src/SaveTool/SaveTool_drawMainMenu.cpp index 92abb24..07ce855 100644 --- a/src/SaveTool/SaveTool_drawMainMenu.cpp +++ b/src/SaveTool/SaveTool_drawMainMenu.cpp @@ -117,7 +117,7 @@ void SaveTool::drawMainMenu() { } 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")) { openUri(_releaseLink); } diff --git a/src/ToastQueue/ToastQueue.cpp b/src/ToastQueue/ToastQueue.cpp index ec2113d..52c80f1 100644 --- a/src/ToastQueue/ToastQueue.cpp +++ b/src/ToastQueue/ToastQueue.cpp @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include +#include #include @@ -24,7 +24,7 @@ #include "ToastQueue.h" -using namespace Corrade; +using namespace Containers::Literals; constexpr UnsignedInt success_colour = 0xff67d23bu; constexpr UnsignedInt info_colour = 0xffcc832fu; @@ -36,7 +36,7 @@ constexpr Float base_opacity = 1.0f; constexpr Vector2 padding{20.0f, 20.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()} { _phaseTrack = Animation::Track{{ @@ -51,7 +51,7 @@ auto Toast::type() -> Type { return _type; } -auto Toast::message() -> const std::string& { +auto Toast::message() -> Containers::StringView { return _message; } @@ -89,7 +89,7 @@ void ToastQueue::addToast(Toast&& 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); } @@ -104,14 +104,14 @@ void ToastQueue::draw(Vector2i viewport_size) { continue; } - std::string win_id = Utility::formatString("##Toast{}", i); + Containers::String win_id = Utility::format("##Toast{}", i); Float opacity = base_opacity * current->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}); - if(ImGui::Begin(win_id.c_str(), nullptr, + if(ImGui::Begin(win_id.data(), nullptr, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoDecoration| ImGuiWindowFlags_NoInputs|ImGuiWindowFlags_NoNav|ImGuiWindowFlags_NoFocusOnAppearing)) { @@ -142,11 +142,11 @@ void ToastQueue::draw(Vector2i viewport_size) { ImGui::SameLine(); } - if(current->message().length() > 127) { - ImGui::TextColored(colour, "%.*s...", 127, current->message().c_str()); + if(current->message().size() > 127) { + ImGui::TextColored(colour, "%.*s...", 127, current->message().data()); } else { - ImGui::TextColored(colour, current->message().c_str()); + ImGui::TextColored(colour, current->message().data()); } height += ImGui::GetWindowHeight() + toast_spacing; diff --git a/src/ToastQueue/ToastQueue.h b/src/ToastQueue/ToastQueue.h index d309833..bf9e7de 100644 --- a/src/ToastQueue/ToastQueue.h +++ b/src/ToastQueue/ToastQueue.h @@ -17,12 +17,14 @@ // along with this program. If not, see . #include -#include #include +#include + #include #include +using namespace Corrade; using namespace Magnum; class Toast { @@ -35,7 +37,7 @@ class Toast { 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}); Toast(const Toast& other) = delete; @@ -46,7 +48,7 @@ class Toast { auto type() -> Type; - auto message() -> std::string const&; + auto message() -> Containers::StringView; auto timeout() -> std::chrono::milliseconds; @@ -60,7 +62,7 @@ class Toast { private: Type _type{Type::Default}; - std::string _message; + Containers::StringView _message; std::chrono::milliseconds _timeout; std::chrono::steady_clock::time_point _creationTime; Animation::Track _phaseTrack; @@ -70,7 +72,7 @@ class ToastQueue { public: 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}); void draw(Vector2i viewport_size); diff --git a/src/UESaveFile/BinaryReader.cpp b/src/UESaveFile/BinaryReader.cpp index a34486e..0f0599e 100644 --- a/src/UESaveFile/BinaryReader.cpp +++ b/src/UESaveFile/BinaryReader.cpp @@ -16,15 +16,16 @@ #include -#include +#include +#include #include "BinaryReader.h" -BinaryReader::BinaryReader(const std::string& filename) { - _file = std::fopen(filename.c_str(), "rb"); +BinaryReader::BinaryReader(Containers::StringView filename) { + _file = std::fopen(filename.data(), "rb"); 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); } } @@ -106,16 +107,15 @@ auto BinaryReader::readArray(Containers::Array& array, std::size_t 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; if(!readUnsignedInt(length) || length == 0) { return false; } - str = std::string{}; - str.resize(length - 1); + str = Containers::String{ValueInit, 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 { diff --git a/src/UESaveFile/BinaryReader.h b/src/UESaveFile/BinaryReader.h index 5a11280..d43df8a 100644 --- a/src/UESaveFile/BinaryReader.h +++ b/src/UESaveFile/BinaryReader.h @@ -18,9 +18,9 @@ #include -#include +#include #include -#include +#include #include @@ -29,7 +29,7 @@ using namespace Magnum; class BinaryReader { public: - explicit BinaryReader(const std::string& filename); + explicit BinaryReader(Containers::StringView filename); ~BinaryReader(); auto open() -> bool; @@ -63,7 +63,7 @@ class BinaryReader { 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; diff --git a/src/UESaveFile/BinaryWriter.cpp b/src/UESaveFile/BinaryWriter.cpp index 64e6b24..1d1c482 100644 --- a/src/UESaveFile/BinaryWriter.cpp +++ b/src/UESaveFile/BinaryWriter.cpp @@ -16,14 +16,14 @@ #include -#include - #include "BinaryWriter.h" -BinaryWriter::BinaryWriter(const std::string& filename) { - _file = std::fopen(filename.c_str(), "wb"); +using namespace Containers::Literals; + +BinaryWriter::BinaryWriter(Containers::StringView filename) { + _file = std::fopen(filename.data(), "wb"); 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); } } @@ -114,24 +114,25 @@ auto BinaryWriter::writeArray(Containers::ArrayView array) -> bool { return std::fwrite(array.data(), sizeof(char), array.size(), _file) == array.size(); } -auto BinaryWriter::writeUEString(const std::string& str) -> bool { - if(str.length() > UINT32_MAX) { - Utility::Error{} << "BinaryWriter::writeUEString(): string is too big."; +auto BinaryWriter::writeUEString(Containers::StringView str) -> bool { + if(str.size() > UINT32_MAX) { + Utility::Error{} << "BinaryWriter::writeUEString(): string is too big."_s; return false; } - writeUnsignedInt(static_cast(str.length()) + 1); + writeUnsignedInt(static_cast(str.size()) + 1); - if(str.length() > 0) { - std::size_t count = std::fwrite(&str[0], sizeof(char), str.length(), _file); - if(count != str.length()) { + if(str.size() > 0) { + std::size_t count = std::fwrite(str.data(), sizeof(char), str.size(), _file); + if(count != str.size()) { return false; } } return writeChar('\0'); } -auto BinaryWriter::writeUEStringToArray(const std::string& value) -> UnsignedLong { - Containers::ArrayView view{value.c_str(), value.length()}; - return writeValueToArray(UnsignedInt(value.length()) + 1u) + writeDataToArray(view) + writeValueToArray('\0'); +auto BinaryWriter::writeUEStringToArray(Containers::StringView value) -> UnsignedLong { + return writeValueToArray(UnsignedInt(value.size()) + 1u) + + writeDataToArray(Containers::ArrayView{value}) + + writeValueToArray('\0'); } diff --git a/src/UESaveFile/BinaryWriter.h b/src/UESaveFile/BinaryWriter.h index ac73f1a..efdc4ed 100644 --- a/src/UESaveFile/BinaryWriter.h +++ b/src/UESaveFile/BinaryWriter.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include @@ -30,7 +30,7 @@ using namespace Magnum; class BinaryWriter { public: - explicit BinaryWriter(const std::string& filename); + explicit BinaryWriter(Containers::StringView filename); ~BinaryWriter(); BinaryWriter(const BinaryWriter& other) = delete; @@ -71,7 +71,7 @@ class BinaryWriter { return std::fwrite(array.data(), sizeof(char), S, _file) == S; } - auto writeUEString(const std::string& str) -> bool; + auto writeUEString(Containers::StringView str) -> bool; template::value, T, T&>> auto writeValueToArray(U value) -> UnsignedLong { @@ -79,7 +79,7 @@ class BinaryWriter { return writeDataToArray(view); } - auto writeUEStringToArray(const std::string& value) -> UnsignedLong; + auto writeUEStringToArray(Containers::StringView value) -> UnsignedLong; template void writeValueToArrayAt(T& value, UnsignedLong position) { diff --git a/src/UESaveFile/Debug.cpp b/src/UESaveFile/Debug.cpp index c11568e..31bc2ab 100644 --- a/src/UESaveFile/Debug.cpp +++ b/src/UESaveFile/Debug.cpp @@ -23,18 +23,18 @@ #include "Debug.h" Utility::Debug& operator<<(Utility::Debug& debug, const ArrayProperty* prop) { - return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << - prop->propertyType.c_str() << "of" << prop->items.size() << prop->itemType.c_str(); + return debug << (*prop->name) << Utility::Debug::nospace << ":" << + prop->propertyType << "of" << prop->items.size() << prop->itemType; } Utility::Debug& operator<<(Utility::Debug& debug, const SetProperty* prop) { - return debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << - prop->propertyType.c_str() << "of" << prop->items.size() << prop->itemType.c_str(); + return debug << (*prop->name) << Utility::Debug::nospace << ":" << + prop->propertyType << "of" << prop->items.size() << prop->itemType; } Utility::Debug& operator<<(Utility::Debug& debug, const GenericStructProperty* prop) { - debug << (*prop->name).c_str() << Utility::Debug::nospace << ":" << - prop->structType.c_str() << "(" << Utility::Debug::nospace << prop->propertyType.c_str() << Utility::Debug::nospace << + debug << (*prop->name) << Utility::Debug::nospace << ":" << + prop->structType << "(" << Utility::Debug::nospace << prop->propertyType << Utility::Debug::nospace << ") Contents:"; for(const auto& item : prop->properties) { 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 << (*prop->name).c_str() << Utility::Debug::nospace << ":" << - prop->structType.c_str() << "(" << Utility::Debug::nospace << prop->propertyType.c_str() << Utility::Debug::nospace << ")"; + return debug << (*prop->name) << Utility::Debug::nospace << ":" << + prop->structType << "(" << Utility::Debug::nospace << prop->propertyType << Utility::Debug::nospace << ")"; } 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; } diff --git a/src/UESaveFile/PropertySerialiser.cpp b/src/UESaveFile/PropertySerialiser.cpp index 830e78a..7e98562 100644 --- a/src/UESaveFile/PropertySerialiser.cpp +++ b/src/UESaveFile/PropertySerialiser.cpp @@ -42,7 +42,6 @@ #include "PropertySerialiser.h" - PropertySerialiser::PropertySerialiser() { arrayAppend(_serialisers, Containers::pointer()); arrayAppend(_serialisers, Containers::pointer()); @@ -71,7 +70,7 @@ auto PropertySerialiser::read(BinaryReader& reader) -> UnrealPropertyBase::ptr { return nullptr; } - std::string name; + Containers::String name; if(!reader.readUEString(name)) { return nullptr; } @@ -80,7 +79,7 @@ auto PropertySerialiser::read(BinaryReader& reader) -> UnrealPropertyBase::ptr { return Containers::pointer(); } - std::string type; + Containers::String type; if(!reader.readUEString(type)) { return nullptr; } @@ -93,7 +92,8 @@ auto PropertySerialiser::read(BinaryReader& reader) -> UnrealPropertyBase::ptr { 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()) { 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); } -auto PropertySerialiser::readSet(BinaryReader& reader, const std::string& item_type, UnsignedInt count) -> Containers::Array { +auto PropertySerialiser::readSet(BinaryReader& reader, Containers::StringView item_type, + UnsignedInt count) -> Containers::Array +{ if(reader.peekChar() < 0 || reader.eof()) { return nullptr; } @@ -111,12 +113,12 @@ auto PropertySerialiser::readSet(BinaryReader& reader, const std::string& item_t Containers::Array array; if(serialiser) { - std::string name; + Containers::String name; if(!reader.readUEString(name)) { return nullptr; } - std::string type; + Containers::String type; if(!reader.readUEString(type)) { return nullptr; } @@ -144,7 +146,7 @@ auto PropertySerialiser::readSet(BinaryReader& reader, const std::string& item_t 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 { UnrealPropertyBase::ptr prop; @@ -167,8 +169,8 @@ auto PropertySerialiser::deserialise(std::string name, std::string type, Unsigne return prop; } -auto PropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, const std::string& item_type, UnsignedLong& bytes_written, - BinaryWriter& writer) -> bool +auto PropertySerialiser::serialise(UnrealPropertyBase::ptr& prop, Containers::StringView item_type, + UnsignedLong& bytes_written, BinaryWriter& writer) -> bool { auto serialiser = getSerialiser(item_type); if(!serialiser) { @@ -200,7 +202,7 @@ auto PropertySerialiser::write(UnrealPropertyBase::ptr& prop, UnsignedLong& byte 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 { if(prop->name == "None" && prop->propertyType == "NoneProperty" && dynamic_cast(prop.get())) { @@ -211,8 +213,9 @@ auto PropertySerialiser::writeItem(UnrealPropertyBase::ptr& prop, const std::str return serialise(prop, item_type, bytes_written, writer); } -auto PropertySerialiser::writeSet(Containers::ArrayView props, const std::string& item_type, - UnsignedLong& bytes_written, BinaryWriter& writer) -> bool +auto PropertySerialiser::writeSet(Containers::ArrayView props, + Containers::StringView item_type, UnsignedLong& bytes_written, + BinaryWriter& writer) -> bool { auto serialiser = getCollectionSerialiser(item_type); if(serialiser) { @@ -229,9 +232,9 @@ auto PropertySerialiser::writeSet(Containers::ArrayView } } -auto PropertySerialiser::getSerialiser(const std::string& item_type) -> AbstractUnrealPropertySerialiser* { +auto PropertySerialiser::getSerialiser(Containers::StringView item_type) -> AbstractUnrealPropertySerialiser* { for(auto& item : _serialisers) { - for(const std::string& serialiser_type : item->types()) { + for(Containers::StringView serialiser_type : item->types()) { if(item_type == serialiser_type) { return item.get(); } @@ -241,9 +244,9 @@ auto PropertySerialiser::getSerialiser(const std::string& item_type) -> Abstract return nullptr; } -auto PropertySerialiser::getCollectionSerialiser(const std::string& item_type) -> AbstractUnrealCollectionPropertySerialiser* { +auto PropertySerialiser::getCollectionSerialiser(Containers::StringView item_type) -> AbstractUnrealCollectionPropertySerialiser* { for(auto& item : _collectionSerialisers) { - for(const std::string& serialiser_type : item->types()) { + for(Containers::StringView serialiser_type : item->types()) { if(item_type == serialiser_type) { return item.get(); } diff --git a/src/UESaveFile/PropertySerialiser.h b/src/UESaveFile/PropertySerialiser.h index 546cd72..7f753eb 100644 --- a/src/UESaveFile/PropertySerialiser.h +++ b/src/UESaveFile/PropertySerialiser.h @@ -17,6 +17,8 @@ // along with this program. If not, see . #include +#include +#include #include "Serialisers/AbstractUnrealPropertySerialiser.h" #include "Serialisers/AbstractUnrealCollectionPropertySerialiser.h" @@ -33,18 +35,23 @@ class PropertySerialiser { PropertySerialiser(); auto read(BinaryReader& reader) -> UnrealPropertyBase::ptr; - auto readItem(BinaryReader& reader, std::string type, UnsignedLong value_length, std::string name) -> UnrealPropertyBase::ptr; - auto readSet(BinaryReader& reader, const std::string& item_type, UnsignedInt count) -> Containers::Array; - auto deserialise(std::string name, std::string type, UnsignedLong value_length, BinaryReader& reader) -> UnrealPropertyBase::ptr; + auto readItem(BinaryReader& reader, Containers::String type, UnsignedLong value_length, + Containers::String name) -> UnrealPropertyBase::ptr; + auto readSet(BinaryReader& reader, Containers::StringView item_type, UnsignedInt count) -> Containers::Array; + 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 writeItem(UnrealPropertyBase::ptr& prop, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool; - auto writeSet(Containers::ArrayView props, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer) -> bool; + auto writeItem(UnrealPropertyBase::ptr& prop, Containers::StringView item_type, UnsignedLong& bytes_written, + BinaryWriter& writer) -> bool; + auto writeSet(Containers::ArrayView props, Containers::StringView item_type, + UnsignedLong& bytes_written, BinaryWriter& writer) -> bool; private: - auto getSerialiser(const std::string& item_type) -> AbstractUnrealPropertySerialiser*; - auto getCollectionSerialiser(const std::string& item_type) -> AbstractUnrealCollectionPropertySerialiser*; + auto getSerialiser(Containers::StringView item_type) -> AbstractUnrealPropertySerialiser*; + auto getCollectionSerialiser(Containers::StringView item_type) -> AbstractUnrealCollectionPropertySerialiser*; Containers::Array _serialisers; Containers::Array _collectionSerialisers; diff --git a/src/UESaveFile/Serialisers/AbstractUnrealCollectionPropertySerialiser.h b/src/UESaveFile/Serialisers/AbstractUnrealCollectionPropertySerialiser.h index c672495..4e43baa 100644 --- a/src/UESaveFile/Serialisers/AbstractUnrealCollectionPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/AbstractUnrealCollectionPropertySerialiser.h @@ -16,11 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include #include +#include #include @@ -39,9 +38,12 @@ class AbstractUnrealCollectionPropertySerialiser { virtual ~AbstractUnrealCollectionPropertySerialiser() = default; - virtual auto types() -> Containers::ArrayView = 0; + virtual auto types() -> Containers::ArrayView = 0; - virtual auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array = 0; + virtual auto deserialise(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, UnsignedInt count, BinaryReader& reader, + PropertySerialiser& serialiser) -> Containers::Array = 0; - virtual auto serialise(Containers::ArrayView props, const std::string& item_type, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0; + virtual auto serialise(Containers::ArrayView props, Containers::StringView item_type, + UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool = 0; }; diff --git a/src/UESaveFile/Serialisers/AbstractUnrealPropertySerialiser.h b/src/UESaveFile/Serialisers/AbstractUnrealPropertySerialiser.h index 21c42eb..d4da220 100644 --- a/src/UESaveFile/Serialisers/AbstractUnrealPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/AbstractUnrealPropertySerialiser.h @@ -16,10 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include +#include #include @@ -38,9 +37,11 @@ class AbstractUnrealPropertySerialiser { virtual ~AbstractUnrealPropertySerialiser() = default; - virtual auto types() -> Containers::ArrayView = 0; + virtual auto types() -> Containers::ArrayView = 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; }; diff --git a/src/UESaveFile/Serialisers/AbstractUnrealStructSerialiser.h b/src/UESaveFile/Serialisers/AbstractUnrealStructSerialiser.h index 0d8d003..7e62fc6 100644 --- a/src/UESaveFile/Serialisers/AbstractUnrealStructSerialiser.h +++ b/src/UESaveFile/Serialisers/AbstractUnrealStructSerialiser.h @@ -16,11 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include #include +#include #include @@ -38,9 +37,10 @@ class AbstractUnrealStructSerialiser { 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 serialise(UnrealPropertyBase::ptr& structProp, BinaryWriter& writer, UnsignedLong& bytes_written) -> bool = 0; + virtual auto serialise(UnrealPropertyBase::ptr& structProp, BinaryWriter& writer, + UnsignedLong& bytes_written) -> bool = 0; }; diff --git a/src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp b/src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp index 7bb6196..7852587 100644 --- a/src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/ArrayPropertySerialiser.cpp @@ -14,16 +14,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "../PropertySerialiser.h" #include "ArrayPropertySerialiser.h" -auto ArrayPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto ArrayPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { - std::string item_type; + Containers::String item_type; if(!reader.readUEString(item_type)) { return nullptr; } diff --git a/src/UESaveFile/Serialisers/ArrayPropertySerialiser.h b/src/UESaveFile/Serialisers/ArrayPropertySerialiser.h index b5c2530..f9b0334 100644 --- a/src/UESaveFile/Serialisers/ArrayPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/ArrayPropertySerialiser.h @@ -16,15 +16,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + +#include + #include "UnrealPropertySerialiser.h" #include "../Types/ArrayProperty.h" +using namespace Corrade; +using namespace Magnum; + class ArrayPropertySerialiser : public UnrealPropertySerialiser { public: using ptr = Containers::Pointer; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp b/src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp index ee1c4fa..2bc40b9 100644 --- a/src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/BoolPropertySerialiser.cpp @@ -19,13 +19,15 @@ #include "BoolPropertySerialiser.h" -auto BoolPropertySerialiser::types() -> Containers::ArrayView { - static const Containers::Array types{InPlaceInit, {"BoolProperty"}}; +auto BoolPropertySerialiser::types() -> Containers::ArrayView { + using namespace Containers::Literals; + static const Containers::Array types{InPlaceInit, {"BoolProperty"_s}}; return types; } -auto BoolPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto BoolPropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { if(value_length != 0) { return nullptr; diff --git a/src/UESaveFile/Serialisers/BoolPropertySerialiser.h b/src/UESaveFile/Serialisers/BoolPropertySerialiser.h index 373fca0..e3e602a 100644 --- a/src/UESaveFile/Serialisers/BoolPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/BoolPropertySerialiser.h @@ -16,17 +16,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "AbstractUnrealPropertySerialiser.h" #include "../Types/BoolProperty.h" +using namespace Corrade; + class BoolPropertySerialiser : public AbstractUnrealPropertySerialiser { public: using ptr = Containers::Pointer; - auto types() -> Containers::ArrayView override; + auto types() -> Containers::ArrayView 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; }; diff --git a/src/UESaveFile/Serialisers/BytePropertySerialiser.cpp b/src/UESaveFile/Serialisers/BytePropertySerialiser.cpp index 96ad39f..7534d69 100644 --- a/src/UESaveFile/Serialisers/BytePropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/BytePropertySerialiser.cpp @@ -19,13 +19,15 @@ #include "BytePropertySerialiser.h" -auto BytePropertySerialiser::types() -> Containers::ArrayView { - static const Containers::Array types{InPlaceInit, {"ByteProperty"}}; +auto BytePropertySerialiser::types() -> Containers::ArrayView { + using namespace Containers::Literals; + static const Containers::Array types{InPlaceInit, {"ByteProperty"_s}}; return types; } -auto BytePropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto BytePropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/BytePropertySerialiser.h b/src/UESaveFile/Serialisers/BytePropertySerialiser.h index cdf5fbe..b698352 100644 --- a/src/UESaveFile/Serialisers/BytePropertySerialiser.h +++ b/src/UESaveFile/Serialisers/BytePropertySerialiser.h @@ -16,6 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "AbstractUnrealPropertySerialiser.h" #include "../Types/ByteProperty.h" @@ -24,9 +27,11 @@ class BytePropertySerialiser : public AbstractUnrealPropertySerialiser { public: using ptr = Containers::Pointer; - auto types() -> Containers::ArrayView override; + auto types() -> Containers::ArrayView 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; }; diff --git a/src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp b/src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp index a263311..a7bc6e6 100644 --- a/src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/ColourPropertySerialiser.cpp @@ -19,8 +19,9 @@ #include "ColourPropertySerialiser.h" -auto ColourPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto ColourPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/ColourPropertySerialiser.h b/src/UESaveFile/Serialisers/ColourPropertySerialiser.h index 5a6cbab..d14dd1f 100644 --- a/src/UESaveFile/Serialisers/ColourPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/ColourPropertySerialiser.h @@ -16,15 +16,21 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/ColourStructProperty.h" +using namespace Corrade; + class ColourPropertySerialiser : public UnrealPropertySerialiser { public: using ptr = Containers::Pointer; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp b/src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp index b06db6e..7a26a6f 100644 --- a/src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/DateTimePropertySerialiser.cpp @@ -19,8 +19,9 @@ #include "DateTimePropertySerialiser.h" -auto DateTimePropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto DateTimePropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/DateTimePropertySerialiser.h b/src/UESaveFile/Serialisers/DateTimePropertySerialiser.h index abaf5e2..51db914 100644 --- a/src/UESaveFile/Serialisers/DateTimePropertySerialiser.h +++ b/src/UESaveFile/Serialisers/DateTimePropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/DateTimeStructProperty.h" @@ -25,6 +27,8 @@ class DateTimePropertySerialiser : public UnrealPropertySerialiser; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp b/src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp index 7ee43d8..942f076 100644 --- a/src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/EnumPropertySerialiser.cpp @@ -19,13 +19,15 @@ #include "EnumPropertySerialiser.h" -auto EnumPropertySerialiser::types() -> Containers::ArrayView { - static const Containers::Array types{InPlaceInit, {"EnumProperty"}}; +auto EnumPropertySerialiser::types() -> Containers::ArrayView { + using namespace Containers::Literals; + static const Containers::Array types{InPlaceInit, {"EnumProperty"_s}}; return types; } -auto EnumPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto EnumPropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/EnumPropertySerialiser.h b/src/UESaveFile/Serialisers/EnumPropertySerialiser.h index d41c628..ec28c3c 100644 --- a/src/UESaveFile/Serialisers/EnumPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/EnumPropertySerialiser.h @@ -16,6 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "AbstractUnrealPropertySerialiser.h" #include "../Types/EnumProperty.h" @@ -24,9 +27,11 @@ class EnumPropertySerialiser : public AbstractUnrealPropertySerialiser { public: using ptr = Containers::Pointer; - auto types() -> Containers::ArrayView override; + auto types() -> Containers::ArrayView 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; }; diff --git a/src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp b/src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp index 06ce073..c9f8ed5 100644 --- a/src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/FloatPropertySerialiser.cpp @@ -19,13 +19,16 @@ #include "FloatPropertySerialiser.h" -auto FloatPropertySerialiser::types() -> Containers::ArrayView { - static const Containers::Array types{InPlaceInit, {"FloatProperty"}}; + +auto FloatPropertySerialiser::types() -> Containers::ArrayView { + using namespace Containers::Literals; + static const Containers::Array types{InPlaceInit, {"FloatProperty"_s}}; return types; } -auto FloatPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto FloatPropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/FloatPropertySerialiser.h b/src/UESaveFile/Serialisers/FloatPropertySerialiser.h index 34a96b0..91b94f0 100644 --- a/src/UESaveFile/Serialisers/FloatPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/FloatPropertySerialiser.h @@ -16,6 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "AbstractUnrealPropertySerialiser.h" #include "../Types/FloatProperty.h" @@ -24,9 +27,11 @@ class FloatPropertySerialiser : public AbstractUnrealPropertySerialiser { public: using ptr = Containers::Pointer; - auto types() -> Containers::ArrayView override; + auto types() -> Containers::ArrayView 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; }; diff --git a/src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp b/src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp index 8576c34..35d9ad4 100644 --- a/src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/GuidPropertySerialiser.cpp @@ -19,13 +19,16 @@ #include "GuidPropertySerialiser.h" -auto GuidPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +using namespace Containers::Literals; + +auto GuidPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); if(!reader.readStaticArray(prop->guid)) { - Utility::Error{} << "Couldn't read guid in" << __func__; + Utility::Error{} << "Couldn't read GUID in"_s << __func__; return nullptr; } diff --git a/src/UESaveFile/Serialisers/GuidPropertySerialiser.h b/src/UESaveFile/Serialisers/GuidPropertySerialiser.h index c8ade5e..33f7d8c 100644 --- a/src/UESaveFile/Serialisers/GuidPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/GuidPropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/GuidStructProperty.h" @@ -25,7 +27,8 @@ class GuidPropertySerialiser : public UnrealPropertySerialiser; 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; - 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; }; diff --git a/src/UESaveFile/Serialisers/IntPropertySerialiser.cpp b/src/UESaveFile/Serialisers/IntPropertySerialiser.cpp index c5b3e4e..ecc7bc3 100644 --- a/src/UESaveFile/Serialisers/IntPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/IntPropertySerialiser.cpp @@ -19,8 +19,9 @@ #include "IntPropertySerialiser.h" -auto IntPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto IntPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/IntPropertySerialiser.h b/src/UESaveFile/Serialisers/IntPropertySerialiser.h index 1301f05..4dc9f88 100644 --- a/src/UESaveFile/Serialisers/IntPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/IntPropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/IntProperty.h" @@ -25,6 +27,8 @@ class IntPropertySerialiser : public UnrealPropertySerialiser { using ptr = Containers::Pointer; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/MapPropertySerialiser.cpp b/src/UESaveFile/Serialisers/MapPropertySerialiser.cpp index b1a6046..0305e2f 100644 --- a/src/UESaveFile/Serialisers/MapPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/MapPropertySerialiser.cpp @@ -22,8 +22,11 @@ #include "MapPropertySerialiser.h" -auto MapPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +using namespace Containers::Literals; + +auto MapPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); @@ -58,7 +61,7 @@ auto MapPropertySerialiser::deserialiseProperty(const std::string& name, const s for(UnsignedInt i = 0; i < count; i++) { 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); if(pair.key == nullptr) { return nullptr; @@ -69,19 +72,19 @@ auto MapPropertySerialiser::deserialiseProperty(const std::string& name, const s } UnrealPropertyBase::ptr value_item; - if(prop->valueType == "StructProperty") { + if(prop->valueType == "StructProperty"_s) { while((value_item = serialiser.read(reader)) != nullptr) { arrayAppend(pair.values, std::move(value_item)); - if(pair.values.back()->name == "None" && - pair.values.back()->propertyType == "NoneProperty" && + if(pair.values.back()->name == "None"_s && + pair.values.back()->propertyType == "NoneProperty"_s && dynamic_cast(pair.values.back().get()) != nullptr) { break; } } } - else if(prop->valueType == "ByteProperty") { + else if(prop->valueType == "ByteProperty"_s) { if((value_item = serialiser.readItem(reader, prop->valueType, -1, name)) == nullptr) { return nullptr; } @@ -121,7 +124,7 @@ auto MapPropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop, Uns } for(auto& value : pair.values) { - if(map_prop->valueType == "StructProperty") { + if(map_prop->valueType == "StructProperty"_s) { if(!serialiser.write(value, dummy_bytes_written, writer)) { return false; } diff --git a/src/UESaveFile/Serialisers/MapPropertySerialiser.h b/src/UESaveFile/Serialisers/MapPropertySerialiser.h index cbe1402..e8ebaba 100644 --- a/src/UESaveFile/Serialisers/MapPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/MapPropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/MapProperty.h" @@ -25,6 +27,8 @@ class MapPropertySerialiser : public UnrealPropertySerialiser { using ptr = Containers::Pointer; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp index 44a83d0..0362e63 100644 --- a/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.cpp @@ -23,17 +23,20 @@ #include "ResourcePropertySerialiser.h" -auto ResourcePropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +using namespace Containers::Literals; + +auto ResourcePropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); - std::string str; - if(!reader.readUEString(str) || str != "ID_4_AAE08F17428E229EC7A2209F51081A21") { + Containers::String str; + if(!reader.readUEString(str) || str != "ID_4_AAE08F17428E229EC7A2209F51081A21"_s) { return nullptr; } - if(!reader.readUEString(str) || str != "IntProperty") { + if(!reader.readUEString(str) || str != "IntProperty"_s) { return nullptr; } @@ -50,11 +53,11 @@ auto ResourcePropertySerialiser::deserialiseProperty(const std::string& name, co return nullptr; } - if(!reader.readUEString(str) || str != "Quantity_3_560F09B5485C365D3041888910019CE3") { + if(!reader.readUEString(str) || str != "Quantity_3_560F09B5485C365D3041888910019CE3"_s) { return nullptr; } - if(!reader.readUEString(str) || str != "IntProperty") { + if(!reader.readUEString(str) || str != "IntProperty"_s) { return nullptr; } @@ -70,7 +73,7 @@ auto ResourcePropertySerialiser::deserialiseProperty(const std::string& name, co return nullptr; } - if(!reader.readUEString(str) || str != "None") { + if(!reader.readUEString(str) || str != "None"_s) { return nullptr; } @@ -85,19 +88,19 @@ auto ResourcePropertySerialiser::serialiseProperty(UnrealPropertyBase::ptr& prop return false; } - bytes_written += writer.writeUEStringToArray("ID_4_AAE08F17428E229EC7A2209F51081A21") + - writer.writeUEStringToArray("IntProperty") + + bytes_written += writer.writeUEStringToArray("ID_4_AAE08F17428E229EC7A2209F51081A21"_s) + + writer.writeUEStringToArray("IntProperty"_s) + writer.writeValueToArray(4ull) + writer.writeValueToArray('\0') + writer.writeValueToArray(res_prop->id); - bytes_written += writer.writeUEStringToArray("Quantity_3_560F09B5485C365D3041888910019CE3") + - writer.writeUEStringToArray("IntProperty") + + bytes_written += writer.writeUEStringToArray("Quantity_3_560F09B5485C365D3041888910019CE3"_s) + + writer.writeUEStringToArray("IntProperty"_s) + writer.writeValueToArray(4ull) + writer.writeValueToArray('\0') + writer.writeValueToArray(res_prop->quantity); - bytes_written += writer.writeUEStringToArray("None"); + bytes_written += writer.writeUEStringToArray("None"_s); return true; } diff --git a/src/UESaveFile/Serialisers/ResourcePropertySerialiser.h b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.h index e32439b..bccd012 100644 --- a/src/UESaveFile/Serialisers/ResourcePropertySerialiser.h +++ b/src/UESaveFile/Serialisers/ResourcePropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/ResourceItemValue.h" @@ -25,6 +27,8 @@ class ResourcePropertySerialiser : public UnrealPropertySerialiser; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp b/src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp index b69633e..4e95409 100644 --- a/src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/RotatorPropertySerialiser.cpp @@ -19,8 +19,9 @@ #include "RotatorPropertySerialiser.h" -auto RotatorPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto RotatorPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/RotatorPropertySerialiser.h b/src/UESaveFile/Serialisers/RotatorPropertySerialiser.h index 1f05573..eec73c9 100644 --- a/src/UESaveFile/Serialisers/RotatorPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/RotatorPropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/RotatorStructProperty.h" @@ -25,6 +27,8 @@ class RotatorPropertySerialiser : public UnrealPropertySerialiser; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp b/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp index 69a20af..c9b38cb 100644 --- a/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/SetPropertySerialiser.cpp @@ -20,10 +20,11 @@ #include "SetPropertySerialiser.h" -auto SetPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto SetPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { - std::string item_type; + Containers::String item_type; if(!reader.readUEString(item_type)) { return nullptr; } diff --git a/src/UESaveFile/Serialisers/SetPropertySerialiser.h b/src/UESaveFile/Serialisers/SetPropertySerialiser.h index 44f1a6a..8bfddee 100644 --- a/src/UESaveFile/Serialisers/SetPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/SetPropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/SetProperty.h" @@ -25,6 +27,8 @@ class SetPropertySerialiser : public UnrealPropertySerialiser { using ptr = Containers::Pointer; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/StringPropertySerialiser.cpp b/src/UESaveFile/Serialisers/StringPropertySerialiser.cpp index 047b25e..654b358 100644 --- a/src/UESaveFile/Serialisers/StringPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/StringPropertySerialiser.cpp @@ -19,13 +19,17 @@ #include "StringPropertySerialiser.h" -auto StringPropertySerialiser::types() -> Containers::ArrayView { - static const Containers::Array types{InPlaceInit, {"NameProperty", "StrProperty", "SoftObjectProperty", "ObjectProperty"}}; +auto StringPropertySerialiser::types() -> Containers::ArrayView { + using namespace Containers::Literals; + static const Containers::Array types{InPlaceInit, + {"NameProperty"_s, "StrProperty"_s, + "SoftObjectProperty"_s, "ObjectProperty"_s}}; return types; } -auto StringPropertySerialiser::deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto StringPropertySerialiser::deserialise(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(type); diff --git a/src/UESaveFile/Serialisers/StringPropertySerialiser.h b/src/UESaveFile/Serialisers/StringPropertySerialiser.h index a4a1924..1e3362c 100644 --- a/src/UESaveFile/Serialisers/StringPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/StringPropertySerialiser.h @@ -16,6 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "AbstractUnrealPropertySerialiser.h" #include "../Types/StringProperty.h" @@ -24,9 +27,11 @@ class StringPropertySerialiser : public AbstractUnrealPropertySerialiser { public: using ptr = Containers::Pointer; - auto types() -> Containers::ArrayView override; + auto types() -> Containers::ArrayView 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; }; diff --git a/src/UESaveFile/Serialisers/StructSerialiser.cpp b/src/UESaveFile/Serialisers/StructSerialiser.cpp index cecfb7a..906d10d 100644 --- a/src/UESaveFile/Serialisers/StructSerialiser.cpp +++ b/src/UESaveFile/Serialisers/StructSerialiser.cpp @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "../PropertySerialiser.h" @@ -23,15 +25,16 @@ #include "StructSerialiser.h" -auto StructSerialiser::types() -> Containers::ArrayView { - static const Containers::Array types{InPlaceInit, {"StructProperty"}}; +auto StructSerialiser::types() -> Containers::ArrayView { + using namespace Containers::Literals; + static const Containers::Array types{InPlaceInit, {"StructProperty"_s}}; 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 { - std::string item_type; + Containers::String item_type; if(!reader.readUEString(item_type)) { return nullptr; } @@ -76,10 +79,10 @@ auto StructSerialiser::deserialise(const std::string& name, const std::string& t 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 { - std::string item_type; + Containers::String item_type; if(!reader.readUEString(item_type)) { return nullptr; } @@ -110,7 +113,7 @@ auto StructSerialiser::deserialise(const std::string& name, const std::string& t return prop; } -auto StructSerialiser::serialise(Containers::ArrayView props, const std::string& item_type, +auto StructSerialiser::serialise(Containers::ArrayView props, Containers::StringView item_type, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool { bytes_written += writer.writeUEStringToArray(*(props.front()->name)); @@ -176,7 +179,7 @@ auto StructSerialiser::serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& by 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 { auto st_prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/StructSerialiser.h b/src/UESaveFile/Serialisers/StructSerialiser.h index 671290e..d9d5fbb 100644 --- a/src/UESaveFile/Serialisers/StructSerialiser.h +++ b/src/UESaveFile/Serialisers/StructSerialiser.h @@ -16,6 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "AbstractUnrealCollectionPropertySerialiser.h" #include "AbstractUnrealPropertySerialiser.h" #include "AbstractUnrealStructSerialiser.h" @@ -26,20 +29,20 @@ class StructSerialiser : public AbstractUnrealPropertySerialiser, public Abstrac public: using ptr = Containers::Pointer; - auto types() -> Containers::ArrayView override; + auto types() -> Containers::ArrayView override; - auto deserialise(const std::string& name, const std::string& type, UnsignedLong value_length, UnsignedInt count, - BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array 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, + UnsignedInt count, BinaryReader& reader, PropertySerialiser& serialiser) -> Containers::Array override; + auto deserialise(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialise(Containers::ArrayView props, const std::string& item_type, UnsignedLong& bytes_written, - BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto serialise(Containers::ArrayView props, Containers::StringView item_type, + UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; auto serialise(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; 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; auto writeStructValue(StructProperty* prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool; }; diff --git a/src/UESaveFile/Serialisers/TextPropertySerialiser.cpp b/src/UESaveFile/Serialisers/TextPropertySerialiser.cpp index 8e379f4..89d9af0 100644 --- a/src/UESaveFile/Serialisers/TextPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/TextPropertySerialiser.cpp @@ -14,13 +14,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "../BinaryReader.h" #include "../BinaryWriter.h" #include "TextPropertySerialiser.h" -auto TextPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto TextPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); @@ -49,7 +52,7 @@ auto TextPropertySerialiser::deserialiseProperty(const std::string& name, const auto interval = reader.position() - start_position; do { - std::string str; + Containers::String str; if(!reader.readUEString(str)) { return nullptr; diff --git a/src/UESaveFile/Serialisers/TextPropertySerialiser.h b/src/UESaveFile/Serialisers/TextPropertySerialiser.h index b408e83..0938936 100644 --- a/src/UESaveFile/Serialisers/TextPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/TextPropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/TextProperty.h" @@ -25,6 +27,8 @@ class TextPropertySerialiser : public UnrealPropertySerialiser { using ptr = Containers::Pointer; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/UnrealPropertySerialiser.h b/src/UESaveFile/Serialisers/UnrealPropertySerialiser.h index 1c963c9..9cf10da 100644 --- a/src/UESaveFile/Serialisers/UnrealPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/UnrealPropertySerialiser.h @@ -18,6 +18,10 @@ #include +#include +#include +#include + #include "AbstractUnrealPropertySerialiser.h" #include "../Types/StructProperty.h" @@ -28,31 +32,38 @@ class UnrealPropertySerialiser : public AbstractUnrealPropertySerialiser { public: using ptr = Containers::Pointer>; - auto types() -> Containers::ArrayView override { - static const Containers::Array types = []{ - Containers::Array array; + auto types() -> Containers::ArrayView override { + static const Containers::Array types = []{ + Containers::Array array; Containers::Pointer p(new T); if(std::is_base_of::value) { - array = Containers::Array{InPlaceInit, {dynamic_cast(p.get())->structType}}; + array = Containers::Array{InPlaceInit, {dynamic_cast(p.get())->structType}}; } else { - array = Containers::Array{InPlaceInit, {p->propertyType}}; + array = Containers::Array{InPlaceInit, {p->propertyType}}; } return array; }(); 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); } - 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); } 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; }; diff --git a/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp b/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp index 402f4d4..c133d8f 100644 --- a/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.cpp @@ -19,8 +19,9 @@ #include "Vector2DPropertySerialiser.h" -auto Vector2DPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto Vector2DPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.h b/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.h index 0351243..faa1682 100644 --- a/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/Vector2DPropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/Vector2DStructProperty.h" @@ -25,6 +27,8 @@ class Vector2DPropertySerialiser : public UnrealPropertySerialiser; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp b/src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp index ee11136..44255eb 100644 --- a/src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp +++ b/src/UESaveFile/Serialisers/VectorPropertySerialiser.cpp @@ -19,8 +19,9 @@ #include "VectorPropertySerialiser.h" -auto VectorPropertySerialiser::deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, - BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr +auto VectorPropertySerialiser::deserialiseProperty(Containers::StringView name, Containers::StringView type, + UnsignedLong value_length, BinaryReader& reader, + PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr { auto prop = Containers::pointer(); diff --git a/src/UESaveFile/Serialisers/VectorPropertySerialiser.h b/src/UESaveFile/Serialisers/VectorPropertySerialiser.h index a3c9e75..8a8cc7e 100644 --- a/src/UESaveFile/Serialisers/VectorPropertySerialiser.h +++ b/src/UESaveFile/Serialisers/VectorPropertySerialiser.h @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertySerialiser.h" #include "../Types/VectorStructProperty.h" @@ -25,6 +27,8 @@ class VectorPropertySerialiser : public UnrealPropertySerialiser; private: - auto deserialiseProperty(const std::string& name, const std::string& type, UnsignedLong value_length, BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; - auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, PropertySerialiser& serialiser) -> bool override; + auto deserialiseProperty(Containers::StringView name, Containers::StringView type, UnsignedLong value_length, + BinaryReader& reader, PropertySerialiser& serialiser) -> UnrealPropertyBase::ptr override; + auto serialiseProperty(UnrealPropertyBase::ptr& prop, UnsignedLong& bytes_written, BinaryWriter& writer, + PropertySerialiser& serialiser) -> bool override; }; diff --git a/src/UESaveFile/Types/ArrayProperty.h b/src/UESaveFile/Types/ArrayProperty.h index 5cda507..ab6bbec 100644 --- a/src/UESaveFile/Types/ArrayProperty.h +++ b/src/UESaveFile/Types/ArrayProperty.h @@ -17,6 +17,9 @@ // along with this program. If not, see . #include +#include +#include +#include #include "UnrealPropertyBase.h" @@ -24,7 +27,8 @@ struct ArrayProperty : public UnrealPropertyBase { using ptr = Containers::Pointer; ArrayProperty() { - propertyType = "ArrayProperty"; + using namespace Containers::Literals; + propertyType = "ArrayProperty"_s; } template @@ -37,6 +41,6 @@ struct ArrayProperty : public UnrealPropertyBase { return static_cast(items[index].get()); } - std::string itemType; + Containers::String itemType; Containers::Array items; }; diff --git a/src/UESaveFile/Types/BoolProperty.h b/src/UESaveFile/Types/BoolProperty.h index ad80c62..ccb6630 100644 --- a/src/UESaveFile/Types/BoolProperty.h +++ b/src/UESaveFile/Types/BoolProperty.h @@ -16,12 +16,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "UnrealProperty.h" +using namespace Corrade; + struct BoolProperty : public UnrealProperty { using ptr = Containers::Pointer; BoolProperty() { - propertyType = "BoolProperty"; + using namespace Containers::Literals; + propertyType = "BoolProperty"_s; } }; diff --git a/src/UESaveFile/Types/ByteProperty.h b/src/UESaveFile/Types/ByteProperty.h index 26d5398..fc1bb05 100644 --- a/src/UESaveFile/Types/ByteProperty.h +++ b/src/UESaveFile/Types/ByteProperty.h @@ -17,17 +17,23 @@ // along with this program. If not, see . #include +#include +#include +#include #include "UnrealProperty.h" +using namespace Corrade; + struct ByteProperty : public UnrealProperty> { using ptr = Containers::Pointer; ByteProperty() { - propertyType = "ByteProperty"; + using namespace Containers::Literals; + propertyType = "ByteProperty"_s; } // For some reason, M.A.S.S. Builder stores EnumProperties as ByteProperties. Ugh... - std::string enumType; - std::string enumValue; + Containers::String enumType; + Containers::String enumValue; }; diff --git a/src/UESaveFile/Types/ColourStructProperty.h b/src/UESaveFile/Types/ColourStructProperty.h index 56c898f..f9dd15f 100644 --- a/src/UESaveFile/Types/ColourStructProperty.h +++ b/src/UESaveFile/Types/ColourStructProperty.h @@ -16,12 +16,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "StructProperty.h" +using namespace Corrade; + struct ColourStructProperty : public StructProperty { using ptr = Containers::Pointer; ColourStructProperty() { - structType = "LinearColor"; + using namespace Containers::Literals; + structType = "LinearColor"_s; } Float r = 0.0f, g = 0.0f, b = 0.0f, a = 0.0f; }; diff --git a/src/UESaveFile/Types/DateTimeStructProperty.h b/src/UESaveFile/Types/DateTimeStructProperty.h index 4e3ecea..2a75b1e 100644 --- a/src/UESaveFile/Types/DateTimeStructProperty.h +++ b/src/UESaveFile/Types/DateTimeStructProperty.h @@ -16,13 +16,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + +#include + #include "StructProperty.h" +using namespace Corrade; +using namespace Magnum; + struct DateTimeStructProperty : public StructProperty { using ptr = Containers::Pointer; DateTimeStructProperty() { - structType = "DateTime"; + using namespace Containers::Literals; + structType = "DateTime"_s; } UnsignedLong timestamp = 0; diff --git a/src/UESaveFile/Types/EnumProperty.h b/src/UESaveFile/Types/EnumProperty.h index 9494856..b6c9730 100644 --- a/src/UESaveFile/Types/EnumProperty.h +++ b/src/UESaveFile/Types/EnumProperty.h @@ -16,14 +16,21 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include +#include + #include "UnrealProperty.h" -struct EnumProperty : public UnrealProperty { +using namespace Corrade; + +struct EnumProperty : public UnrealProperty { using ptr = Containers::Pointer; EnumProperty() { - propertyType = "EnumProperty"; + using namespace Containers::Literals; + propertyType = "EnumProperty"_s; } - std::string enumType; + Containers::String enumType; }; diff --git a/src/UESaveFile/Types/FloatProperty.h b/src/UESaveFile/Types/FloatProperty.h index bdc44b0..6f23ca9 100644 --- a/src/UESaveFile/Types/FloatProperty.h +++ b/src/UESaveFile/Types/FloatProperty.h @@ -16,12 +16,21 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + +#include + #include "UnrealProperty.h" +using namespace Corrade; +using namespace Magnum; + struct FloatProperty : public UnrealProperty { using ptr = Containers::Pointer; FloatProperty() { - propertyType = "FloatProperty"; + using namespace Containers::Literals; + propertyType = "FloatProperty"_s; } }; diff --git a/src/UESaveFile/Types/GenericStructProperty.h b/src/UESaveFile/Types/GenericStructProperty.h index a14c7d2..9c76828 100644 --- a/src/UESaveFile/Types/GenericStructProperty.h +++ b/src/UESaveFile/Types/GenericStructProperty.h @@ -16,18 +16,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include +#include #include +#include +#include #include "StructProperty.h" +using namespace Corrade; + struct GenericStructProperty : public StructProperty { using ptr = Containers::Pointer; template std::enable_if_t::value, T*> - at(const std::string& name) { + at(Containers::StringView name) { for(auto& item : properties) { if(item->name == name) { return static_cast(item.get()); @@ -38,7 +42,7 @@ struct GenericStructProperty : public StructProperty { template std::enable_if_t::value, typename T::ptr> - atMove(const std::string& name) { + atMove(Containers::StringView name) { for(auto& item : properties) { if(item && item->name == name) { return Containers::Pointer{static_cast(item.release())}; diff --git a/src/UESaveFile/Types/GuidStructProperty.h b/src/UESaveFile/Types/GuidStructProperty.h index cf5d1ca..34619a6 100644 --- a/src/UESaveFile/Types/GuidStructProperty.h +++ b/src/UESaveFile/Types/GuidStructProperty.h @@ -16,15 +16,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include #include +#include #include "StructProperty.h" +using namespace Corrade; + struct GuidStructProperty : public StructProperty { using ptr = Containers::Pointer; GuidStructProperty() { - structType = "Guid"; + using namespace Containers::Literals; + structType = "Guid"_s; } Containers::StaticArray<16, char> guid{ValueInit}; diff --git a/src/UESaveFile/Types/IntProperty.h b/src/UESaveFile/Types/IntProperty.h index 55774d1..8b231cf 100644 --- a/src/UESaveFile/Types/IntProperty.h +++ b/src/UESaveFile/Types/IntProperty.h @@ -16,12 +16,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "UnrealProperty.h" +using namespace Corrade; + struct IntProperty : public UnrealProperty { using ptr = Containers::Pointer; IntProperty() { - propertyType = "IntProperty"; + using namespace Containers::Literals; + propertyType = "IntProperty"_s; } }; diff --git a/src/UESaveFile/Types/MapProperty.h b/src/UESaveFile/Types/MapProperty.h index d52994f..62a26b3 100644 --- a/src/UESaveFile/Types/MapProperty.h +++ b/src/UESaveFile/Types/MapProperty.h @@ -16,17 +16,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include +#include + #include "UnrealPropertyBase.h" +using namespace Corrade; + struct MapProperty : public UnrealPropertyBase { using ptr = Containers::Pointer; MapProperty() { - propertyType = "MapProperty"; + using namespace Containers::Literals; + propertyType = "MapProperty"_s; } - std::string keyType; - std::string valueType; + Containers::String keyType; + Containers::String valueType; struct KeyValuePair { UnrealPropertyBase::ptr key; diff --git a/src/UESaveFile/Types/NoneProperty.h b/src/UESaveFile/Types/NoneProperty.h index 91e8ab9..4985642 100644 --- a/src/UESaveFile/Types/NoneProperty.h +++ b/src/UESaveFile/Types/NoneProperty.h @@ -16,13 +16,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + #include "UnrealPropertyBase.h" +using namespace Corrade; + struct NoneProperty : UnrealPropertyBase { using ptr = Containers::Pointer; NoneProperty() { - name.emplace("None"); - propertyType = "NoneProperty"; + using namespace Containers::Literals; + name.emplace("None"_s); + propertyType = "NoneProperty"_s; } }; diff --git a/src/UESaveFile/Types/ResourceItemValue.h b/src/UESaveFile/Types/ResourceItemValue.h index 4692296..e4b7c17 100644 --- a/src/UESaveFile/Types/ResourceItemValue.h +++ b/src/UESaveFile/Types/ResourceItemValue.h @@ -16,13 +16,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + +#include + #include "StructProperty.h" +using namespace Corrade; +using namespace Magnum; + struct ResourceItemValue : public StructProperty { using ptr = Containers::Pointer; 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'}; } diff --git a/src/UESaveFile/Types/RotatorStructProperty.h b/src/UESaveFile/Types/RotatorStructProperty.h index e1bdf21..eb001c8 100644 --- a/src/UESaveFile/Types/RotatorStructProperty.h +++ b/src/UESaveFile/Types/RotatorStructProperty.h @@ -16,13 +16,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + +#include + #include "StructProperty.h" +using namespace Corrade; +using namespace Magnum; + struct RotatorStructProperty : public StructProperty { using ptr = Containers::Pointer; RotatorStructProperty() { - structType = "Rotator"; + using namespace Containers::Literals; + structType = "Rotator"_s; } Float x = 0.0f, y = 0.0f, z = 0.0f; diff --git a/src/UESaveFile/Types/SetProperty.h b/src/UESaveFile/Types/SetProperty.h index 6c490ed..fa6389c 100644 --- a/src/UESaveFile/Types/SetProperty.h +++ b/src/UESaveFile/Types/SetProperty.h @@ -17,14 +17,20 @@ // along with this program. If not, see . #include +#include +#include +#include #include "UnrealPropertyBase.h" +using namespace Corrade; + struct SetProperty : public UnrealPropertyBase { using ptr = Containers::Pointer; SetProperty() { - propertyType = "SetProperty"; + using namespace Containers::Literals; + propertyType = "SetProperty"_s; } auto at(std::size_t index) -> UnrealPropertyBase* { @@ -35,6 +41,6 @@ struct SetProperty : public UnrealPropertyBase { return items[index].get(); } - std::string itemType; + Containers::String itemType; Containers::Array items; }; diff --git a/src/UESaveFile/Types/StringProperty.h b/src/UESaveFile/Types/StringProperty.h index 2d871b7..bc28a92 100644 --- a/src/UESaveFile/Types/StringProperty.h +++ b/src/UESaveFile/Types/StringProperty.h @@ -16,12 +16,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include +#include + #include "UnrealProperty.h" -struct StringProperty : public UnrealProperty { +using namespace Corrade; +using namespace Containers::Literals; + +struct StringProperty : public UnrealProperty { using ptr = Containers::Pointer; - explicit StringProperty(const std::string& type = "StrProperty") { + explicit StringProperty(Containers::StringView type = "StrProperty"_s) { propertyType = type; } }; diff --git a/src/UESaveFile/Types/StructProperty.h b/src/UESaveFile/Types/StructProperty.h index c38a048..a0ddb16 100644 --- a/src/UESaveFile/Types/StructProperty.h +++ b/src/UESaveFile/Types/StructProperty.h @@ -16,17 +16,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include #include +#include +#include #include "UnrealPropertyBase.h" +using namespace Corrade; + struct StructProperty : public UnrealPropertyBase { using ptr = Containers::Pointer; StructProperty() { - std::string propertyType = "StructProperty"; + using namespace Containers::Literals; + propertyType = "StructProperty"_s; } Containers::StaticArray<16, char> structGuid{ValueInit}; - std::string structType; + Containers::String structType; }; diff --git a/src/UESaveFile/Types/TextProperty.h b/src/UESaveFile/Types/TextProperty.h index bffaaad..409b393 100644 --- a/src/UESaveFile/Types/TextProperty.h +++ b/src/UESaveFile/Types/TextProperty.h @@ -16,16 +16,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include +#include +#include + #include "UnrealProperty.h" -struct TextProperty : public UnrealProperty { +using namespace Corrade; + +struct TextProperty : public UnrealProperty { using ptr = Containers::Pointer; TextProperty() { - propertyType = "TextProperty"; + using namespace Containers::Literals; + propertyType = "TextProperty"_s; } Containers::Array flags; char id = 0; - Containers::Array data; + Containers::Array data; }; diff --git a/src/UESaveFile/Types/UnrealProperty.h b/src/UESaveFile/Types/UnrealProperty.h index 2192028..adccf4c 100644 --- a/src/UESaveFile/Types/UnrealProperty.h +++ b/src/UESaveFile/Types/UnrealProperty.h @@ -16,8 +16,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "UnrealPropertyBase.h" +using namespace Corrade; + template struct UnrealProperty : public UnrealPropertyBase { using ptr = Containers::Pointer>; diff --git a/src/UESaveFile/Types/UnrealPropertyBase.h b/src/UESaveFile/Types/UnrealPropertyBase.h index d538428..47d8e52 100644 --- a/src/UESaveFile/Types/UnrealPropertyBase.h +++ b/src/UESaveFile/Types/UnrealPropertyBase.h @@ -16,10 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include +#include #include @@ -31,7 +30,7 @@ struct UnrealPropertyBase { virtual ~UnrealPropertyBase() = default; - Containers::Optional name = Containers::NullOpt; - std::string propertyType; + Containers::Optional name = Containers::NullOpt; + Containers::String propertyType; UnsignedLong valueLength = 0; }; diff --git a/src/UESaveFile/Types/Vector2DStructProperty.h b/src/UESaveFile/Types/Vector2DStructProperty.h index 9372881..057bfd9 100644 --- a/src/UESaveFile/Types/Vector2DStructProperty.h +++ b/src/UESaveFile/Types/Vector2DStructProperty.h @@ -16,13 +16,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + +#include + #include "StructProperty.h" +using namespace Corrade; +using namespace Magnum; + struct Vector2DStructProperty : public StructProperty { using ptr = Containers::Pointer; Vector2DStructProperty() { - structType = "Vector2D"; + using namespace Containers::Literals; + structType = "Vector2D"_s; } Float x = 0.0f, y = 0.0f; diff --git a/src/UESaveFile/Types/VectorStructProperty.h b/src/UESaveFile/Types/VectorStructProperty.h index 367435b..b753c11 100644 --- a/src/UESaveFile/Types/VectorStructProperty.h +++ b/src/UESaveFile/Types/VectorStructProperty.h @@ -16,13 +16,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include +#include + +#include + #include "StructProperty.h" +using namespace Corrade; +using namespace Magnum; + struct VectorStructProperty : public StructProperty { using ptr = Containers::Pointer; VectorStructProperty() { - structType = "Vector"; + using namespace Containers::Literals; + structType = "Vector"_s; } Float x = 0.0f, y = 0.0f, z = 0.0f; diff --git a/src/UESaveFile/UESaveFile.cpp b/src/UESaveFile/UESaveFile.cpp index 5835769..cbbeb16 100644 --- a/src/UESaveFile/UESaveFile.cpp +++ b/src/UESaveFile/UESaveFile.cpp @@ -23,7 +23,9 @@ #include "UESaveFile.h" -UESaveFile::UESaveFile(std::string filepath) +using namespace Containers::Literals; + +UESaveFile::UESaveFile(Containers::String filepath) { _filepath = std::move(filepath); @@ -34,7 +36,7 @@ auto UESaveFile::valid() const -> bool { return _valid; } -auto UESaveFile::lastError() const -> const std::string& { +auto UESaveFile::lastError() const -> Containers::StringView { return _lastError; } @@ -59,11 +61,14 @@ auto UESaveFile::props() -> Containers::ArrayView { return _properties; } +#include +#include + auto UESaveFile::saveToFile() -> bool { - BinaryWriter writer{_filepath + ".tmp"}; + BinaryWriter writer{_filepath + ".tmp"_s}; if(!writer.open()) { - _lastError = "Couldn't open the file for saving."; + _lastError = "Couldn't open the file for saving."_s; return false; } @@ -76,14 +81,14 @@ auto UESaveFile::saveToFile() -> bool { !writer.writeUnsignedInt(_engineVersion.build) || !writer.writeUEString(_engineVersion.buildId)) { - _lastError = "Couldn't write the header."; + _lastError = "Couldn't write the header."_s; return false; } if(!writer.writeUnsignedInt(_customFormatVersion) || !writer.writeUnsignedInt(_customFormatData.size())) { - _lastError = "Couldn't write the header."; + _lastError = "Couldn't write the header."_s; return false; } @@ -91,25 +96,25 @@ auto UESaveFile::saveToFile() -> bool { if(!writer.writeStaticArray(Containers::StaticArrayView<16, const char>{_customFormatData[i].id}) || !writer.writeUnsignedInt(_customFormatData[i].value)) { - _lastError = "Couldn't write the header."; + _lastError = "Couldn't write the header."_s; return false; } } if(!writer.writeUEString(_saveType)) { - _lastError = "Couldn't write the header."; + _lastError = "Couldn't write the header."_s; return false; } for(auto& prop : _properties) { UnsignedLong bytes_written = 0; if(!_propSerialiser.write(prop, bytes_written, writer)) { - _lastError = "Couldn't write the property " + *prop->name + " to the array."; + _lastError = "Couldn't write the property "_s + *prop->name + " to the array."_s; return false; } if(!writer.flushToFile()) { - _lastError = "Couldn't write the property " + *prop->name + " to the file."; + _lastError = "Couldn't write the property "_s + *prop->name + " to the file."_s; return false; } } @@ -118,7 +123,7 @@ auto UESaveFile::saveToFile() -> bool { writer.closeFile(); - if(!Utility::Directory::copy(_filepath, _filepath + ".bak")) { + if(!Utility::Directory::copy(_filepath, _filepath + ".bak"_s)) { return false; } @@ -126,8 +131,8 @@ auto UESaveFile::saveToFile() -> bool { return false; } - if(!Utility::Directory::move(_filepath + ".tmp", _filepath)) { - Utility::Directory::move(_filepath + ".bak", _filepath); + if(!Utility::Directory::move(_filepath + ".tmp"_s, _filepath)) { + Utility::Directory::move(_filepath + ".bak"_s, _filepath); return false; } @@ -146,17 +151,17 @@ void UESaveFile::loadData() { BinaryReader reader{_filepath}; if(!reader.open()) { - _lastError = _filepath + " couldn't be opened."; + _lastError = _filepath + " couldn't be opened."_s; return; } Containers::Array magic; if(!reader.readArray(magic, 4)) { - _lastError = "Couldn't read magic bytes in " + _filepath; + _lastError = "Couldn't read magic bytes in "_s + _filepath; return; } - std::string invalid = _filepath + " isn't a valid UE4 save."; + Containers::String invalid = _filepath + " isn't a valid UE4 save."_s; if(std::strncmp(magic.data(), _magicBytes.data(), 4) != 0) { _lastError = std::move(invalid); @@ -212,8 +217,8 @@ void UESaveFile::loadData() { arrayAppend(_properties, std::move(prop)); } - if(_properties.back()->name != "None" && _properties.back()->propertyType != "NoneProperty") { - _lastError = "Couldn't find a final NoneProperty."; + if(_properties.back()->name != "None"_s && _properties.back()->propertyType != "NoneProperty"_s) { + _lastError = "Couldn't find a final NoneProperty."_s; return; } diff --git a/src/UESaveFile/UESaveFile.h b/src/UESaveFile/UESaveFile.h index 856e12b..ed9652b 100644 --- a/src/UESaveFile/UESaveFile.h +++ b/src/UESaveFile/UESaveFile.h @@ -16,11 +16,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include - #include #include #include +#include +#include #include @@ -33,16 +33,16 @@ using namespace Magnum; class UESaveFile { public: - explicit UESaveFile(std::string filepath); + explicit UESaveFile(Containers::String filepath); auto valid() const -> bool; - auto lastError() const -> std::string const&; + auto lastError() const -> Containers::StringView; auto reloadData() -> bool; template std::enable_if_t::value, T*> - at(const std::string& name) { + at(Containers::StringView name) { for(auto& prop : _properties) { if(prop->name == name) { return static_cast(prop.get()); @@ -61,9 +61,9 @@ class UESaveFile { void loadData(); bool _valid{false}; - std::string _lastError; + Containers::String _lastError; - std::string _filepath; + Containers::String _filepath; bool _noReloadAfterSave = false; @@ -72,11 +72,11 @@ class UESaveFile { UnsignedInt _saveVersion = 0; UnsignedInt _packageVersion = 0; struct { - UnsignedShort major = 0; - UnsignedShort minor = 0; - UnsignedShort patch = 0; - UnsignedInt build = 0; - std::string buildId; + UnsignedShort major = 0; + UnsignedShort minor = 0; + UnsignedShort patch = 0; + UnsignedInt build = 0; + Containers::String buildId; } _engineVersion; UnsignedInt _customFormatVersion = 0; @@ -86,7 +86,7 @@ class UESaveFile { }; Containers::Array _customFormatData; - std::string _saveType; + Containers::String _saveType; Containers::Array _properties;