1 #ifndef CORE_FILES_GAMESAVE_HPP
2 #define CORE_FILES_GAMESAVE_HPP
4 #include <BLIB/Events.hpp>
5 #include <BLIB/Serialization/JSON.hpp>
6 #include <BLIB/Tilemap/Position.hpp>
33 std::unordered_map<std::string, std::unordered_set<std::string>>*
talkedto;
63 std::unordered_map<std::string, bl::script::Value>*
entries;
87 static void listSaves(std::vector<GameSave>& result);
96 static bool saveGame(
const std::string& name);
104 static bool loadFromFile(
const std::string& sourceFile);
154 std::unordered_map<std::string, std::unordered_set<std::string>> talkedto;
155 std::unordered_set<std::string> convFlags;
156 std::string playerName;
160 std::vector<pplmn::OwnedPeoplemon> peoplemon;
161 std::string whiteoutMap;
162 unsigned int whiteoutSpawn;
163 unsigned int repelSteps;
165 std::unordered_set<std::string> visitedTowns;
166 std::string currentMap;
168 bl::tmap::Position playerPos;
169 bl::tmap::Position prevPlayerPos;
170 std::unordered_map<std::string, bl::script::Value> entries;
172 std::unordered_set<std::string> defeatedTrainers;
173 std::unordered_map<pplmn::Id, std::uint32_t> seenPeoplemon;
174 std::unordered_map<pplmn::Id, std::string> firstSightingLocations;
177 std::optional<Data> localData;
178 std::string sourceFile;
189 struct SerializableObject<
core::file::GameSave::InteractDataPointers>
190 :
public SerializableObjectBase {
192 using M = std::unordered_map<std::string, std::unordered_set<std::string>>;
193 using F = std::unordered_set<std::string>;
199 : SerializableObjectBase(
"GameSaveInteraction")
200 , talkedTo(
"talked", *this, &
I::talkedto, SerializableFieldBase::Required{})
201 , flags(
"flags", *this, &
I::convFlags, SerializableFieldBase::Required{}) {}
205 struct SerializableObject<
core::file::GameSave::WorldDataPointers> : SerializableObjectBase {
207 using Pos = bl::tmap::Position;
210 SerializableField<2, World, std::string*>
prevMap;
215 : SerializableObjectBase(
"GameSaveWorld")
216 , currentMap(
"current", *this, &
World::currentMap, SerializableFieldBase::Required{})
217 , prevMap(
"previous", *this, &
World::prevMap, SerializableFieldBase::Required{})
218 , playerPos(
"position", *this, &
World::playerPos, SerializableFieldBase::Required{})
219 , prevPlayerPos(
"prevPos", *this, &
World::prevPlayerPos, SerializableFieldBase::Required{}) {}
223 struct SerializableObject<
core::file::GameSave::PlayerDataPointers>
224 :
public SerializableObjectBase {
227 SerializableField<1, Player, std::string*>
name;
228 SerializableField<2, Player, core::player::Gender*>
gender;
229 SerializableField<3, Player, core::player::Bag*>
bag;
230 SerializableField<4, Player, std::vector<core::pplmn::OwnedPeoplemon>*>
peoplemon;
231 SerializableField<5, Player, long*>
money;
235 SerializableField<9,
Player,
236 std::array<std::vector<core::pplmn::StoredPeoplemon>,
239 SerializableField<10, Player, std::unordered_set<std::string>*>
visitedTowns;
240 SerializableField<11, Player, std::unordered_map<core::pplmn::Id, std::uint32_t>*>
seenCounts;
241 SerializableField<12, Player, std::unordered_map<core::pplmn::Id, std::string>*>
seenSpots;
244 : SerializableObjectBase(
"GameSavePlayer")
245 , name(
"name", *this, &
Player::playerName, SerializableFieldBase::Required{})
246 , gender(
"gender", *this, &
Player::sex, SerializableFieldBase::Required{})
247 , bag(
"bag", *this, &
Player::inventory, SerializableFieldBase::Required{})
248 , peoplemon(
"peoplemon", *this, &
Player::peoplemon, SerializableFieldBase::Required{})
249 , money(
"money", *this, &
Player::monei, SerializableFieldBase::Required{})
250 , whiteoutMap(
"whiteoutMap", *this, &
Player::whiteoutMap, SerializableFieldBase::Required{})
251 , whiteoutSpawn(
"whiteoutSpawn", *this, &
Player::whiteoutSpawn,
252 SerializableFieldBase::Required{})
253 , repelSteps(
"repelSteps", *this, &
Player::repelSteps, SerializableFieldBase::Required{})
254 , storage(
"storage", *this, &
Player::storage, SerializableFieldBase::Optional{})
255 , visitedTowns(
"visitedTowns", *this, &
Player::visitedTowns, SerializableFieldBase::Optional{})
256 , seenCounts(
"seenPeoplemon", *this, &
Player::seenPeoplemon, SerializableFieldBase::Optional{})
257 , seenSpots(
"seenSpots", *this, &
Player::firstSightingLocations,
258 SerializableFieldBase::Optional{}) {}
262 struct SerializableObject<
core::file::GameSave::ScriptDataPointers>
263 :
public SerializableObjectBase {
265 using M = std::unordered_map<std::string, bl::script::Value>;
270 : SerializableObjectBase(
"GameSaveScript")
271 , entries(
"saveEntries", *this, &
S::entries, SerializableFieldBase::Required{}) {}
275 struct SerializableObject<
core::file::GameSave::ClockPointers> :
public SerializableObjectBase {
279 SerializableField<1, C, T*>
time;
282 : SerializableObjectBase(
"GameSaveTime")
283 , time(
"time", *this, &
C::time, SerializableFieldBase::Required{}) {}
287 struct SerializableObject<
core::file::GameSave::TrainerPointers> :
public SerializableObjectBase {
289 using D = std::unordered_set<std::string>;
294 : SerializableObjectBase(
"GameSaveTrainer")
295 , defeated(
"defeated", *this, &
T::defeated, SerializableFieldBase::Required{}) {}
299 struct SerializableObject<
core::file::GameSave> :
public SerializableObjectBase {
301 SerializableField<1, GS, unsigned long long>
saveTime;
302 SerializableField<2, GS, GS::PlayerDataPointers>
player;
304 SerializableField<4, GS, GS::WorldDataPointers>
world;
305 SerializableField<5, GS, GS::ScriptDataPointers>
script;
306 SerializableField<6, GS, GS::ClockPointers>
clock;
309 : SerializableObjectBase(
"GameSave")
310 , saveTime(
"saveTime", *this, &
GS::saveTime, SerializableFieldBase::Required{})
311 , player(
"player", *this, &
GS::player, SerializableFieldBase::Required{})
312 , interaction(
"interaction", *this, &
GS::interaction, SerializableFieldBase::Required{})
313 , world(
"world", *this, &
GS::world, SerializableFieldBase::Required{})
314 , script(
"script", *this, &
GS::scripts, SerializableFieldBase::Required{})
315 , clock(
"clock", *this, &
GS::clock, SerializableFieldBase::Required{}) {}
Gender
Possible genders for the player.
Core classes and functionality for both the editor and game.
Represents a game save and provides functionality to load and save.
bool operator<(const GameSave &rhs) const
For sorting.
struct core::file::GameSave::ScriptDataPointers scripts
struct core::file::GameSave::TrainerPointers trainers
struct core::file::GameSave::WorldDataPointers world
static bool loadFromFile(const std::string &sourceFile)
Loads the game from the given save file.
struct core::file::GameSave::PlayerDataPointers player
GameSave()
Initializes all pointers to the local members.
struct core::file::GameSave::InteractDataPointers interaction
unsigned long long saveTime
Local timestamp that the save was modified on.
bool load()
Loads the save represented by this object and fires an event::GameSaveLoaded event to allow systems t...
static bool saveGame(const std::string &name)
Saves the game. Fires an event::GameSaveInitializing event for systems to add their data to the save ...
static std::string filename(const std::string &saveName)
Returns the filename for the given save name.
void useLocalData()
Instantiates the save data in this object and sets all the pointers to it. Useful for loading a save ...
static void listSaves(std::vector< GameSave > &result)
Lists all saves in the save directory.
bool remove() const
Deletes the game save.
std::string saveName
Same as the player name but always valid.
void editorSave()
Saves the data back to the file it was loaded from.
struct core::file::GameSave::ClockPointers clock
Stores pointers to the actual data to save/load from.
std::unordered_set< std::string > * convFlags
std::unordered_map< std::string, std::unordered_set< std::string > > * talkedto
Stores pointers to the actual data to save/load from.
std::unordered_map< pplmn::Id, std::string > * firstSightingLocations
std::array< std::vector< pplmn::StoredPeoplemon >, player::StorageSystem::BoxCount > * storage
std::string * whiteoutMap
unsigned int * whiteoutSpawn
unsigned int * repelSteps
std::unordered_set< std::string > * visitedTowns
std::vector< pplmn::OwnedPeoplemon > * peoplemon
std::unordered_map< pplmn::Id, std::uint32_t > * seenPeoplemon
Stores pointers to the actual data to save/load from.
bl::tmap::Position * prevPlayerPos
bl::tmap::Position * playerPos
Stores pointers to the actual data to save/load from.
std::unordered_map< std::string, bl::script::Value > * entries
system::Clock::Time * time
Stores defeated trainer information.
std::unordered_set< std::string > * defeated
SerializableField< 2, I, F * > flags
SerializableField< 1, I, M * > talkedTo
std::unordered_set< std::string > F
std::unordered_map< std::string, std::unordered_set< std::string > > M
SerializableField< 2, World, std::string * > prevMap
SerializableField< 4, World, Pos * > prevPlayerPos
SerializableField< 3, World, Pos * > playerPos
SerializableField< 1, World, std::string * > currentMap
SerializableField< 12, Player, std::unordered_map< core::pplmn::Id, std::string > * > seenSpots
SerializableField< 2, Player, core::player::Gender * > gender
SerializableField< 4, Player, std::vector< core::pplmn::OwnedPeoplemon > * > peoplemon
SerializableField< 8, Player, unsigned int * > repelSteps
SerializableField< 7, Player, unsigned int * > whiteoutSpawn
SerializableField< 1, Player, std::string * > name
SerializableField< 6, Player, std::string * > whiteoutMap
SerializableField< 5, Player, long * > money
SerializableField< 11, Player, std::unordered_map< core::pplmn::Id, std::uint32_t > * > seenCounts
SerializableField< 10, Player, std::unordered_set< std::string > * > visitedTowns
SerializableField< 3, Player, core::player::Bag * > bag
SerializableField< 9, Player, std::array< std::vector< core::pplmn::StoredPeoplemon >, core::player::StorageSystem::BoxCount > * > storage
std::unordered_map< std::string, bl::script::Value > M
SerializableField< 1, S, M * > entries
SerializableField< 1, C, T * > time
SerializableField< 1, T, D * > defeated
std::unordered_set< std::string > D
SerializableField< 3, GS, GS::InteractDataPointers > interaction
SerializableField< 5, GS, GS::ScriptDataPointers > script
SerializableField< 1, GS, unsigned long long > saveTime
SerializableField< 2, GS, GS::PlayerDataPointers > player
SerializableField< 6, GS, GS::ClockPointers > clock
SerializableField< 4, GS, GS::WorldDataPointers > world
Basic inventory class for managing player items.
static constexpr int BoxCount
Simple struct representing a point in time.