MassBuilderSaveTool/src/Mass/Mass.h

264 lines
7.7 KiB
C
Raw Normal View History

#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021 Guillaume Jacquemin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string>
2021-09-27 17:52:47 +02:00
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StaticArray.h>
2021-06-20 14:06:36 +02:00
#include <Magnum/Magnum.h>
2021-09-27 17:52:47 +02:00
#include <Magnum/Math/Color.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/Math/Vector3.h>
#include "../UESaveFile/UESaveFile.h"
2021-06-20 14:06:36 +02:00
using namespace Corrade;
2021-06-20 14:06:36 +02:00
using namespace Magnum;
struct ArrayProperty;
struct Joints {
Float neck = 0.0f;
Float body = 0.0f;
Float shoulders = 0.0f;
Float hips = 0.0f;
Float upperArms = 0.0f;
Float lowerArms = 0.0f;
Float upperLegs = 0.0f;
Float lowerLegs = 0.0f;
};
2021-09-27 17:52:47 +02:00
struct CustomStyle {
std::string name;
Color4 colour{0.0f};
Float metallic = 0.5f;
Float gloss = 0.5f;
bool glow = false;
2021-09-27 17:52:47 +02:00
Int patternId = 0;
2021-09-29 11:07:10 +02:00
Float opacity = 0.5f;
Vector2 offset{0.5f};
2021-09-27 17:52:47 +02:00
Float rotation = 0.0f;
Float scale = 0.5f;
2021-09-27 17:52:47 +02:00
};
struct Decal {
Int id = -1;
Color4 colour{0.0f};
Vector3 position{0.0f};
Vector3 uAxis{0.0f};
Vector3 vAxis{0.0f};
Vector2 offset{0.5f};
Float scale = 0.5f;
Float rotation = 0.0f;
bool flip = false;
bool wrap = false;
};
struct Accessory {
Int attachIndex = -1;
Int id = -1;
Containers::StaticArray<2, Int> styles{ValueInit};
Vector3 relativePosition{0.0f};
Vector3 relativePositionOffset{0.0f};
Vector3 relativeRotation{0.0f};
Vector3 relativeRotationOffset{0.0f};
Vector3 localScale{1.0f};
};
struct ArmourPart {
2021-09-27 17:52:47 +02:00
std::string slot;
Int id = 0;
Containers::StaticArray<4, Int> styles{ValueInit};
2021-10-12 16:35:49 +02:00
UnsignedInt demoDecals = 8;
2021-09-27 17:52:47 +02:00
Containers::StaticArray<8, Decal> decals{ValueInit};
Containers::StaticArray<8, Accessory> accessories{ValueInit};
};
struct WeaponPart {
Int id = 0;
Containers::StaticArray<4, Int> styles{ValueInit};
UnsignedInt demoDecals = 8;
2021-09-27 17:52:47 +02:00
Containers::StaticArray<8, Decal> decals{ValueInit};
Containers::StaticArray<8, Accessory> accessories{ValueInit};
};
struct Weapon {
std::string name;
std::string type;
Containers::Array<WeaponPart> parts;
Containers::StaticArray<16, CustomStyle> customStyles{ValueInit};
bool attached = false;
std::string damageType;
bool dualWield = false;
std::string effectColourMode;
Color4 effectColour{0.0f};
};
class Mass {
public:
enum class State : UnsignedByte {
Empty, Invalid, Valid
};
explicit Mass(const std::string& path);
Mass(const Mass&) = delete;
Mass& operator=(const Mass&) = delete;
Mass(Mass&&) = default;
Mass& operator=(Mass&&) = default;
static auto lastError() -> std::string const&;
2021-09-27 17:52:47 +02:00
static auto getNameFromFile(const std::string& path) -> Containers::Optional<std::string>;
void refreshValues();
auto filename() -> std::string const&;
2021-09-27 17:52:47 +02:00
auto name() -> Containers::Optional<std::string> const&;
auto setName(std::string new_name) -> bool;
auto state() -> State;
auto demo() const -> bool;
2021-09-27 17:52:47 +02:00
auto dirty() const -> bool;
void setDirty(bool dirty = true);
auto jointSliders() -> Joints&;
void getJointSliders();
auto writeJointSliders() -> bool;
auto frameStyles() -> Containers::ArrayView<Int>;
void getFrameStyles();
auto writeFrameStyles() -> bool;
auto eyeFlareColour() -> Color4&;
void getEyeFlareColour();
auto writeEyeFlareColour() -> bool;
2021-09-27 17:52:47 +02:00
auto frameCustomStyles() -> Containers::ArrayView<CustomStyle>;
void getFrameCustomStyles();
auto writeFrameCustomStyle(UnsignedLong index) -> bool;
auto armourParts() -> Containers::ArrayView<ArmourPart>;
void getArmourParts();
auto writeArmourPart(UnsignedLong index) -> bool;
auto armourCustomStyles() -> Containers::ArrayView<CustomStyle>;
void getArmourCustomStyles();
auto writeArmourCustomStyle(UnsignedLong index) -> bool;
auto meleeWeapons() -> Containers::ArrayView<Weapon>;
void getMeleeWeapons();
auto writeMeleeWeapons() -> bool;
auto shields() -> Containers::ArrayView<Weapon>;
void getShields();
auto writeShields() -> bool;
auto bulletShooters() -> Containers::ArrayView<Weapon>;
void getBulletShooters();
auto writeBulletShooters() -> bool;
auto energyShooters() -> Containers::ArrayView<Weapon>;
void getEnergyShooters();
auto writeEnergyShooters() -> bool;
auto bulletLaunchers() -> Containers::ArrayView<Weapon>;
void getBulletLaunchers();
auto writeBulletLaunchers() -> bool;
auto energyLaunchers() -> Containers::ArrayView<Weapon>;
void getEnergyLaunchers();
auto writeEnergyLaunchers() -> bool;
auto globalStyles() -> Containers::ArrayView<CustomStyle>;
void getGlobalStyles();
auto writeGlobalStyle(UnsignedLong index) -> bool;
auto updateSteamId(const std::string& steam_id) -> bool;
private:
2021-10-17 15:28:54 +02:00
void getCustomStyles(Containers::ArrayView<CustomStyle> styles, ArrayProperty* style_array);
auto setCustomStyle(const CustomStyle& style, UnsignedLong index, ArrayProperty* style_array) -> bool;
void getDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array);
void getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array);
void getWeaponType(const char* prop_name, Containers::ArrayView<Weapon> weapon_array);
auto writeWeaponType(const char* prop_name, Containers::ArrayView<Weapon> weapon_array) -> bool;
2021-09-27 17:52:47 +02:00
Containers::Optional<UESaveFile> _mass;
static std::string _lastError;
std::string _folder;
std::string _filename;
State _state = State::Empty;
bool _demo = false;
2021-09-27 17:52:47 +02:00
bool _dirty = false;
Containers::Optional<std::string> _name = Containers::NullOpt;
struct {
Joints joints{};
Containers::StaticArray<4, Int> styles{ValueInit};
Color4 eyeFlare{0.0f};
2021-10-02 14:51:39 +02:00
Containers::StaticArray<16, CustomStyle> customStyles;
2021-09-27 17:52:47 +02:00
} _frame;
struct {
Containers::StaticArray<38, ArmourPart> parts;
2021-09-27 17:52:47 +02:00
2021-10-02 14:51:39 +02:00
Containers::StaticArray<16, CustomStyle> customStyles;
2021-09-27 17:52:47 +02:00
} _armour;
struct {
2021-10-16 11:36:31 +02:00
Containers::StaticArray<8, Weapon> melee;
2021-09-27 17:52:47 +02:00
Containers::StaticArray<1, Weapon> shields;
Containers::StaticArray<4, Weapon> bulletShooters;
Containers::StaticArray<4, Weapon> energyShooters;
Containers::StaticArray<4, Weapon> bulletLaunchers;
Containers::StaticArray<4, Weapon> energyLaunchers;
} _weapons;
Containers::StaticArray<16, CustomStyle> _globalStyles;
struct {
Int engineId;
Containers::StaticArray<7, Int> gearIds;
Int osId;
Containers::StaticArray<7, Int> moduleIds;
Int archId;
Containers::StaticArray<7, Int> techIds;
} _tuning;
2021-09-27 17:52:47 +02:00
std::string _steamId;
};