diff options
author | Shauren <shauren.trinity@gmail.com> | 2020-01-03 21:55:45 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-10-04 00:19:38 +0200 |
commit | 76be303351ae398b7f9e69e4c472cb5b05fce45e (patch) | |
tree | b7139aa70f1e9492fe8b94224fee28bbbe1ec34c /src/server/game/Instances/InstanceScriptData.h | |
parent | 9b924522d0549dd67b10e2cbdfc20297dd21e182 (diff) |
Core/Scripts: Save instance data in JSON format
Diffstat (limited to 'src/server/game/Instances/InstanceScriptData.h')
-rw-r--r-- | src/server/game/Instances/InstanceScriptData.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/server/game/Instances/InstanceScriptData.h b/src/server/game/Instances/InstanceScriptData.h new file mode 100644 index 00000000000..c489123d625 --- /dev/null +++ b/src/server/game/Instances/InstanceScriptData.h @@ -0,0 +1,86 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * 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 2 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef InstanceScriptData_h__ +#define InstanceScriptData_h__ + +#include "Errors.h" // rapidjson depends on WPAssert +#include <rapidjson/document.h> +#include <string> + +class InstanceScript; +struct UpdateBossStateSaveDataEvent; +struct UpdateAdditionalSaveDataEvent; + +class InstanceScriptDataReader +{ +public: + enum class Result + { + Ok, + MalformedJson, + RootIsNotAnObject, + MissingHeader, + UnexpectedHeader, + MissingBossStates, + BossStatesIsNotAnObject, + UnknownBoss, + BossStateIsNotAnObject, + MissingBossState, + BossStateValueIsNotANumber, + AdditionalDataIsNotAnObject, + AdditionalDataUnexpectedValueType + }; + + InstanceScriptDataReader(InstanceScript& instance) : _instance(instance) { } + + Result Load(char const* data); + +private: + Result ParseHeader(); + Result ParseBossStates(); + Result ParseAdditionalData(); + + // logging helpers + uint32 GetInstanceId() const; + uint32 GetMapId() const; + char const* GetMapName() const; + uint32 GetDifficultyId() const; + char const* GetDifficultyName() const; + + InstanceScript& _instance; + rapidjson::Document _doc; +}; + +class InstanceScriptDataWriter +{ +public: + InstanceScriptDataWriter(InstanceScript& instance) : _instance(instance) { } + + std::string GetString(); + void FillData(bool withValues = true); + void FillDataFrom(std::string const& data); + + void SetBossState(UpdateBossStateSaveDataEvent const& data); + void SetAdditionalData(UpdateAdditionalSaveDataEvent const& data); + +private: + InstanceScript& _instance; + rapidjson::Document _doc; +}; + +#endif // InstanceScriptData_h__ |