2021-06-11 19:24:52 +02:00
|
|
|
// MassBuilderSaveTool
|
2022-01-30 11:36:56 +01:00
|
|
|
// Copyright (C) 2021-2022 Guillaume Jacquemin
|
2021-06-11 19:24:52 +02:00
|
|
|
//
|
|
|
|
// 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 <algorithm>
|
|
|
|
|
2022-03-09 11:04:19 +01:00
|
|
|
#include <Corrade/Containers/Pair.h>
|
|
|
|
#include <Corrade/Utility/Path.h>
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2022-11-21 18:58:01 +01:00
|
|
|
#include "PropertyNames.h"
|
2021-09-23 19:01:42 +02:00
|
|
|
#include "../UESaveFile/Types/ArrayProperty.h"
|
|
|
|
#include "../UESaveFile/Types/ResourceItemValue.h"
|
|
|
|
#include "../UESaveFile/Types/IntProperty.h"
|
|
|
|
#include "../UESaveFile/Types/StringProperty.h"
|
|
|
|
|
2021-06-11 19:24:52 +02:00
|
|
|
#include "Profile.h"
|
|
|
|
|
|
|
|
using namespace Corrade;
|
2022-03-04 21:18:55 +01:00
|
|
|
using namespace Containers::Literals;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
Profile::Profile(Containers::StringView path):
|
2021-09-23 19:01:42 +02:00
|
|
|
_profile(path)
|
|
|
|
{
|
2022-03-06 14:42:24 +01:00
|
|
|
if(!_profile.valid()) {
|
|
|
|
_lastError = _profile.lastError();
|
2022-11-21 18:58:57 +01:00
|
|
|
_valid = false;
|
2022-03-06 14:42:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-09 11:04:19 +01:00
|
|
|
_filename = Utility::Path::split(path).second();
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2022-03-06 14:42:24 +01:00
|
|
|
if(_filename.hasPrefix("Demo"_s)) {
|
2021-06-11 19:24:52 +02:00
|
|
|
_type = ProfileType::Demo;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_type = ProfileType::FullGame;
|
|
|
|
}
|
|
|
|
|
2022-11-21 18:58:01 +01:00
|
|
|
auto account_prop = _profile.at<StringProperty>(PROFILE_ACCOUNT);
|
2022-02-24 14:00:47 +01:00
|
|
|
if(!account_prop) {
|
2022-03-04 21:18:55 +01:00
|
|
|
_lastError = "Couldn't find an account ID in "_s + _filename;
|
2022-02-24 14:00:47 +01:00
|
|
|
_valid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_account = account_prop->value;
|
2022-01-20 19:42:27 +01:00
|
|
|
|
2022-03-06 14:42:24 +01:00
|
|
|
if(_account.hasPrefix("PMCSlot"_s)) {
|
2022-01-20 19:42:27 +01:00
|
|
|
_version = ProfileVersion::Normal;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_version = ProfileVersion::Legacy;
|
|
|
|
}
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-27 16:17:32 +02:00
|
|
|
refreshValues();
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::valid() const -> bool {
|
|
|
|
return _valid;
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
auto Profile::lastError() const -> Containers::StringView {
|
2021-06-11 19:24:52 +02:00
|
|
|
return _lastError;
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
auto Profile::filename() const -> Containers::StringView {
|
2021-06-11 19:24:52 +02:00
|
|
|
return _filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::type() const -> ProfileType {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
2022-03-09 13:25:26 +01:00
|
|
|
auto Profile::isDemo() const -> bool {
|
|
|
|
return _type == ProfileType::Demo;
|
|
|
|
}
|
|
|
|
|
2022-01-20 19:42:27 +01:00
|
|
|
auto Profile::version() const -> ProfileVersion {
|
|
|
|
return _version;
|
|
|
|
}
|
|
|
|
|
2022-03-09 13:25:26 +01:00
|
|
|
auto Profile::isLegacy() const -> bool {
|
|
|
|
return _version == ProfileVersion::Legacy;
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
auto Profile::account() const -> Containers::StringView {
|
2022-01-20 19:42:27 +01:00
|
|
|
return _account;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Profile::refreshValues() {
|
2021-09-24 21:51:06 +02:00
|
|
|
if(!_profile.reloadData()) {
|
|
|
|
_lastError = _profile.lastError();
|
2021-09-27 16:17:32 +02:00
|
|
|
_valid = false;
|
2021-09-24 21:51:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-02 19:54:32 +02:00
|
|
|
if(_profile.saveType() != "/Game/Core/Save/bpSaveGameProfile.bpSaveGameProfile_C"_s) {
|
|
|
|
Utility::Error{} << _filename << "is not a valid profile save.";
|
|
|
|
}
|
|
|
|
|
2022-11-21 18:58:01 +01:00
|
|
|
auto name_prop = _profile.at<StringProperty>(PROFILE_NAME);
|
2022-02-24 14:00:47 +01:00
|
|
|
if(!name_prop) {
|
2022-03-04 21:18:55 +01:00
|
|
|
_lastError = "No company name in "_s + _filename;
|
2022-02-24 14:00:47 +01:00
|
|
|
_valid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_name = name_prop->value;
|
2021-09-24 21:51:06 +02:00
|
|
|
|
2022-11-21 18:58:01 +01:00
|
|
|
auto prop = _profile.at<IntProperty>(PROFILE_ACTIVE_FRAME_SLOT);
|
2021-09-24 21:51:06 +02:00
|
|
|
_activeFrameSlot = prop ? prop->value : 0;
|
|
|
|
|
2022-11-21 18:58:01 +01:00
|
|
|
prop = _profile.at<IntProperty>(PROFILE_CREDITS);
|
2021-09-24 21:51:06 +02:00
|
|
|
_credits = prop ? prop->value : 0;
|
|
|
|
|
2022-11-21 18:58:01 +01:00
|
|
|
prop = _profile.at<IntProperty>(PROFILE_STORY_PROGRESS);
|
2021-09-24 21:51:06 +02:00
|
|
|
_storyProgress = prop ? prop->value : 0;
|
|
|
|
|
2022-11-21 18:58:01 +01:00
|
|
|
prop = _profile.at<IntProperty>(PROFILE_LAST_MISSION_ID);
|
2021-09-24 21:51:06 +02:00
|
|
|
_lastMissionId = prop ? prop->value : 0;
|
|
|
|
|
2022-11-21 18:58:01 +01:00
|
|
|
_verseSteel = getResource(PROFILE_MATERIAL, VerseSteel);
|
|
|
|
_undinium = getResource(PROFILE_MATERIAL, Undinium);
|
|
|
|
_necriumAlloy = getResource(PROFILE_MATERIAL, NecriumAlloy);
|
|
|
|
_lunarite = getResource(PROFILE_MATERIAL, Lunarite);
|
|
|
|
_asterite = getResource(PROFILE_MATERIAL, Asterite);
|
|
|
|
|
|
|
|
_ednil = getResource(PROFILE_MATERIAL, Ednil);
|
|
|
|
_nuflalt = getResource(PROFILE_MATERIAL, Nuflalt);
|
|
|
|
_aurelene = getResource(PROFILE_MATERIAL, Aurelene);
|
|
|
|
_soldus = getResource(PROFILE_MATERIAL, Soldus);
|
|
|
|
_synthesisedN = getResource(PROFILE_MATERIAL, SynthesisedN);
|
|
|
|
|
|
|
|
_alcarbonite = getResource(PROFILE_MATERIAL, Alcarbonite);
|
|
|
|
_keriphene = getResource(PROFILE_MATERIAL, Keriphene);
|
|
|
|
_nitinolCM = getResource(PROFILE_MATERIAL, NitinolCM);
|
|
|
|
_quarkium = getResource(PROFILE_MATERIAL, Quarkium);
|
|
|
|
_alterene = getResource(PROFILE_MATERIAL, Alterene);
|
|
|
|
|
|
|
|
_mixedComposition = getResource(PROFILE_QUARK_DATA, MixedComposition);
|
|
|
|
_voidResidue = getResource(PROFILE_QUARK_DATA, VoidResidue);
|
|
|
|
_muscularConstruction = getResource(PROFILE_QUARK_DATA, MuscularConstruction);
|
|
|
|
_mineralExoskeletology = getResource(PROFILE_QUARK_DATA, MineralExoskeletology);
|
|
|
|
_carbonisedSkin = getResource(PROFILE_QUARK_DATA, CarbonisedSkin);
|
2022-02-24 14:00:47 +01:00
|
|
|
|
|
|
|
_valid = true;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
auto Profile::companyName() const -> Containers::StringView {
|
2021-09-24 21:51:06 +02:00
|
|
|
return _name;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
auto Profile::renameCompany(Containers::StringView new_name) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
auto name_prop = _profile.at<StringProperty>(PROFILE_NAME);
|
2022-02-24 14:00:47 +01:00
|
|
|
if(!name_prop) {
|
2022-03-04 21:18:55 +01:00
|
|
|
_lastError = "No company name in "_s + _filename;
|
2022-02-24 14:00:47 +01:00
|
|
|
_valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
name_prop->value = new_name;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!_profile.saveToFile()) {
|
2022-02-24 14:00:47 +01:00
|
|
|
_lastError = _profile.lastError();
|
2021-06-11 19:24:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
return true;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::activeFrameSlot() const -> Int {
|
|
|
|
return _activeFrameSlot;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::credits() const -> Int {
|
|
|
|
return _credits;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::setCredits(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
auto credits_prop = _profile.at<IntProperty>(PROFILE_CREDITS);
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!credits_prop) {
|
|
|
|
credits_prop = new IntProperty;
|
2022-03-04 21:18:55 +01:00
|
|
|
credits_prop->name.emplace("Credit"_s);
|
2021-09-23 19:01:42 +02:00
|
|
|
_profile.appendProperty(IntProperty::ptr{credits_prop});
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
credits_prop->value = amount;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!_profile.saveToFile()) {
|
2022-02-24 14:00:47 +01:00
|
|
|
_lastError = _profile.lastError();
|
2021-06-11 19:24:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
return true;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::storyProgress() const -> Int {
|
|
|
|
return _storyProgress;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setStoryProgress(Int progress) -> bool {
|
2022-03-04 21:18:55 +01:00
|
|
|
auto story_progress_prop = _profile.at<IntProperty>("StoryProgress"_s);
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!story_progress_prop) {
|
|
|
|
story_progress_prop = new IntProperty;
|
2022-03-04 21:18:55 +01:00
|
|
|
story_progress_prop->name.emplace("StoryProgress"_s);
|
2021-09-23 19:01:42 +02:00
|
|
|
_profile.appendProperty(IntProperty::ptr{story_progress_prop});
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
story_progress_prop->value = progress;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!_profile.saveToFile()) {
|
2022-02-24 14:00:47 +01:00
|
|
|
_lastError = _profile.lastError();
|
2021-09-23 19:01:42 +02:00
|
|
|
return false;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
return true;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::lastMissionId() const -> Int {
|
|
|
|
return _lastMissionId;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::verseSteel() const -> Int {
|
|
|
|
return _verseSteel;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setVerseSteel(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, VerseSteel, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::undinium() const -> Int {
|
|
|
|
return _undinium;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setUndinium(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Undinium, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::necriumAlloy() const -> Int {
|
|
|
|
return _necriumAlloy;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setNecriumAlloy(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, NecriumAlloy, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::lunarite() const -> Int {
|
|
|
|
return _lunarite;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setLunarite(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Lunarite, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::asterite() const -> Int {
|
|
|
|
return _asterite;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setAsterite(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Asterite, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::ednil() const -> Int {
|
|
|
|
return _ednil;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setEdnil(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Ednil, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::nuflalt() const -> Int {
|
|
|
|
return _nuflalt;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setNuflalt(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Nuflalt, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::aurelene() const -> Int {
|
|
|
|
return _aurelene;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setAurelene(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Aurelene, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::soldus() const -> Int {
|
|
|
|
return _soldus;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setSoldus(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Soldus, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::synthesisedN() const -> Int {
|
|
|
|
return _synthesisedN;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::setSynthesisedN(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, SynthesisedN, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::alcarbonite() const -> Int {
|
|
|
|
return _alcarbonite;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setAlcarbonite(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Alcarbonite, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::keriphene() const -> Int {
|
|
|
|
return _keriphene;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setKeriphene(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Keriphene, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::nitinolCM() const -> Int {
|
|
|
|
return _nitinolCM;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setNitinolCM(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, NitinolCM, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::quarkium() const -> Int {
|
|
|
|
return _quarkium;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setQuarkium(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Quarkium, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::alterene() const -> Int {
|
|
|
|
return _alterene;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setAlterene(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_MATERIAL, Alterene, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::mixedComposition() const -> Int {
|
|
|
|
return _mixedComposition;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setMixedComposition(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_QUARK_DATA, MixedComposition, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::voidResidue() const -> Int {
|
|
|
|
return _voidResidue;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setVoidResidue(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_QUARK_DATA, VoidResidue, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::muscularConstruction() const -> Int {
|
|
|
|
return _muscularConstruction;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 14:07:43 +02:00
|
|
|
auto Profile::setMuscularConstruction(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_QUARK_DATA, MuscularConstruction, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::mineralExoskeletology() const -> Int {
|
|
|
|
return _mineralExoskeletology;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::setMineralExoskeletology(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_QUARK_DATA, MineralExoskeletology, amount);
|
2021-09-23 19:01:42 +02:00
|
|
|
}
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::carbonisedSkin() const -> Int {
|
|
|
|
return _carbonisedSkin;
|
2021-09-23 19:01:42 +02:00
|
|
|
}
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::setCarbonisedSkin(Int amount) -> bool {
|
2022-11-21 18:58:01 +01:00
|
|
|
return setResource(PROFILE_QUARK_DATA, CarbonisedSkin, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
auto Profile::getResource(Containers::StringView container, MaterialID id) -> Int {
|
2021-09-23 19:01:42 +02:00
|
|
|
auto mats_prop = _profile.at<ArrayProperty>(container);
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
if(!mats_prop) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-04 18:17:51 +02:00
|
|
|
auto predicate = [&id](UnrealPropertyBase::ptr& prop){
|
2021-09-23 19:01:42 +02:00
|
|
|
auto res_prop = static_cast<ResourceItemValue*>(prop.get());
|
|
|
|
return res_prop->id == id;
|
|
|
|
};
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto it = std::find_if(mats_prop->items.begin(), mats_prop->items.end(), predicate);
|
|
|
|
return it != mats_prop->items.end() ? static_cast<ResourceItemValue*>(it->get())->quantity : 0;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
auto Profile::setResource(Containers::StringView container, MaterialID id, Int amount) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
auto mats_prop = _profile.at<ArrayProperty>(container);
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
if(!mats_prop) {
|
2022-03-04 21:18:55 +01:00
|
|
|
_lastError = "Couldn't find "_s + container + " in "_s + _filename;
|
2022-02-24 14:00:47 +01:00
|
|
|
_valid = false;
|
2021-09-24 21:51:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-24 14:00:47 +01:00
|
|
|
auto predicate = [&id](UnrealPropertyBase::ptr& prop){
|
2021-09-23 19:01:42 +02:00
|
|
|
auto res_prop = static_cast<ResourceItemValue*>(prop.get());
|
|
|
|
return res_prop->id == id;
|
|
|
|
};
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto it = std::find_if(mats_prop->items.begin(), mats_prop->items.end(), predicate);
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
ResourceItemValue* res_prop;
|
|
|
|
if(it == mats_prop->items.end()) {
|
|
|
|
res_prop = new ResourceItemValue;
|
|
|
|
res_prop->id = id;
|
|
|
|
ResourceItemValue::ptr prop{res_prop};
|
|
|
|
arrayAppend(mats_prop->items, std::move(prop));
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-09-23 19:01:42 +02:00
|
|
|
res_prop = static_cast<ResourceItemValue*>(it->get());
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
res_prop->quantity = amount;
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!_profile.saveToFile()) {
|
|
|
|
_lastError = _profile.lastError();
|
2021-06-11 19:24:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-23 19:01:42 +02:00
|
|
|
|
2022-02-24 14:00:47 +01:00
|
|
|
return true;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|