2021-06-11 19:24:52 +02:00
|
|
|
// 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 <algorithm>
|
|
|
|
|
|
|
|
#include <Corrade/Containers/Array.h>
|
2021-09-23 19:01:42 +02:00
|
|
|
#include <Corrade/Containers/StaticArray.h>
|
2021-06-11 19:24:52 +02:00
|
|
|
#include <Corrade/Utility/Directory.h>
|
|
|
|
#include <Corrade/Utility/FormatStl.h>
|
|
|
|
#include <Corrade/Utility/String.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-09-24 21:51:06 +02:00
|
|
|
#include "ResourceIDs.h"
|
|
|
|
|
2021-06-11 19:24:52 +02:00
|
|
|
#include "Profile.h"
|
|
|
|
|
|
|
|
using namespace Corrade;
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
Profile::Profile(const std::string& path):
|
|
|
|
_profile(path)
|
|
|
|
{
|
2021-06-11 19:24:52 +02:00
|
|
|
_profileDirectory = Utility::Directory::path(path);
|
|
|
|
_filename = Utility::Directory::filename(path);
|
|
|
|
|
|
|
|
if(Utility::String::beginsWith(_filename, "Demo")) {
|
|
|
|
_type = ProfileType::Demo;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_type = ProfileType::FullGame;
|
|
|
|
}
|
|
|
|
|
|
|
|
_steamId = Utility::String::ltrim(Utility::String::rtrim(_filename, ".sav"), (_type == ProfileType::Demo ? "Demo" : "") + std::string{"Profile"});
|
|
|
|
|
2021-09-27 16:17:32 +02:00
|
|
|
refreshValues();
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
_valid = _profile.valid();
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::valid() const -> bool {
|
|
|
|
return _valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::lastError() const -> std::string const& {
|
|
|
|
return _lastError;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::filename() const -> std::string const& {
|
|
|
|
return _filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::type() const -> ProfileType {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::steamId() const -> std::string const& {
|
|
|
|
return _steamId;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
_name = _profile.at<StringProperty>("CompanyName")->value;
|
|
|
|
|
|
|
|
auto prop = _profile.at<IntProperty>("ActiveFrameSlot");
|
|
|
|
_activeFrameSlot = prop ? prop->value : 0;
|
|
|
|
|
|
|
|
prop = _profile.at<IntProperty>("Credit");
|
|
|
|
_credits = prop ? prop->value : 0;
|
|
|
|
|
|
|
|
prop = _profile.at<IntProperty>("StoryProgress");
|
|
|
|
_storyProgress = prop ? prop->value : 0;
|
|
|
|
|
|
|
|
prop = _profile.at<IntProperty>("LastMissionID");
|
|
|
|
_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);
|
|
|
|
|
|
|
|
_ednil = getResource("ResourceMaterial", Ednil);
|
|
|
|
_nuflalt = getResource("ResourceMaterial", Nuflalt);
|
|
|
|
_aurelene = getResource("ResourceMaterial", Aurelene);
|
|
|
|
_soldus = getResource("ResourceMaterial", Soldus);
|
|
|
|
_synthesisedN = getResource("ResourceMaterial", SynthesisedN);
|
|
|
|
|
|
|
|
_alcarbonite = getResource("ResourceMaterial", Alcarbonite);
|
|
|
|
_keriphene = getResource("ResourceMaterial", Keriphene);
|
|
|
|
_nitinolCM = getResource("ResourceMaterial", NitinolCM);
|
|
|
|
_quarkium = getResource("ResourceMaterial", Quarkium);
|
|
|
|
_alterene = getResource("ResourceMaterial", Alterene);
|
|
|
|
|
|
|
|
_mixedComposition = getResource("ResourceQuarkData", MixedComposition);
|
|
|
|
_voidResidue = getResource("ResourceQuarkData", VoidResidue);
|
|
|
|
_muscularConstruction = getResource("ResourceQuarkData", MuscularConstruction);
|
|
|
|
_mineralExoskeletology = getResource("ResourceQuarkData", MineralExoskeletology);
|
|
|
|
_carbonisedSkin = getResource("ResourceQuarkData", CarbonisedSkin);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::companyName() const -> std::string const& {
|
|
|
|
return _name;
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Profile::renameCompany(const std::string& new_name) -> bool {
|
2021-09-23 19:01:42 +02:00
|
|
|
auto name_prop = _profile.at<StringProperty>("CompanyName");
|
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()) {
|
|
|
|
_lastError = "Couldn't save the profile.";
|
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 {
|
|
|
|
auto credits_prop = _profile.at<IntProperty>("Credit");
|
2021-06-11 19:24:52 +02:00
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
if(!credits_prop) {
|
|
|
|
credits_prop = new IntProperty;
|
|
|
|
_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()) {
|
|
|
|
_lastError = "Couldn't save the profile.";
|
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 {
|
2021-09-23 19:01:42 +02:00
|
|
|
auto story_progress_prop = _profile.at<IntProperty>("StoryProgress");
|
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;
|
|
|
|
_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()) {
|
|
|
|
_lastError = "Couldn't save the profile.";
|
|
|
|
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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceMaterial", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceQuarkData", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceQuarkData", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceQuarkData", 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 {
|
2021-09-24 21:51:06 +02:00
|
|
|
return setResource("ResourceQuarkData", 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 {
|
|
|
|
return setResource("ResourceQuarkData", CarbonisedSkin, amount);
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:51:06 +02:00
|
|
|
auto Profile::getResource(const char* container, Int 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
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
auto Profile::setResource(const char* container, Int id, Int amount) -> bool {
|
|
|
|
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 false;
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:01:42 +02:00
|
|
|
static auto predicate = [&id](UnrealPropertyBase::ptr& prop){
|
|
|
|
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
|
|
|
|
|
|
|
return _profile.saveToFile();
|
2021-06-11 19:24:52 +02:00
|
|
|
}
|