mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
Events serialization
This commit is contained in:
parent
52cbb613ae
commit
6e3817f18c
@ -56,9 +56,37 @@ bool CMapEvent::earlierThanOrEqual(const CMapEvent & other) const
|
|||||||
return firstOccurence <= other.firstOccurence;
|
return firstOccurence <= other.firstOccurence;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCastleEvent::CCastleEvent() : town(nullptr)
|
void CMapEvent::serializeJson(JsonSerializeFormat & handler)
|
||||||
{
|
{
|
||||||
|
handler.serializeString("name", name);
|
||||||
|
handler.serializeString("message", message);
|
||||||
|
handler.serializeInt("players", players);
|
||||||
|
handler.serializeInt("humanAffected", humanAffected);
|
||||||
|
handler.serializeInt("computerAffected", computerAffected);
|
||||||
|
handler.serializeInt("firstOccurence", firstOccurence);
|
||||||
|
handler.serializeInt("nextOccurence", nextOccurence);
|
||||||
|
resources.serializeJson(handler, "resources");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCastleEvent::serializeJson(JsonSerializeFormat & handler)
|
||||||
|
{
|
||||||
|
CMapEvent::serializeJson(handler);
|
||||||
|
{
|
||||||
|
std::vector<BuildingID> temp(buildings.begin(), buildings.end());
|
||||||
|
auto a = handler.enterArray("buildings");
|
||||||
|
a.syncSize(temp);
|
||||||
|
for(int i = 0; i < temp.size(); ++i)
|
||||||
|
{
|
||||||
|
a.serializeInt(i, temp[i]);
|
||||||
|
buildings.insert(temp[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto a = handler.enterArray("creatures");
|
||||||
|
a.syncSize(creatures);
|
||||||
|
for(int i = 0; i < creatures.size(); ++i)
|
||||||
|
a.serializeInt(i, creatures[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TerrainTile::TerrainTile():
|
TerrainTile::TerrainTile():
|
||||||
|
@ -19,6 +19,7 @@ class RiverType;
|
|||||||
class RoadType;
|
class RoadType;
|
||||||
class CGObjectInstance;
|
class CGObjectInstance;
|
||||||
class CGTownInstance;
|
class CGTownInstance;
|
||||||
|
class JsonSerializeFormat;
|
||||||
|
|
||||||
/// The map event is an event which e.g. gives or takes resources of a specific
|
/// The map event is an event which e.g. gives or takes resources of a specific
|
||||||
/// amount to/from players and can appear regularly or once a time.
|
/// amount to/from players and can appear regularly or once a time.
|
||||||
@ -26,6 +27,7 @@ class DLL_LINKAGE CMapEvent
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CMapEvent();
|
CMapEvent();
|
||||||
|
virtual ~CMapEvent() = default;
|
||||||
|
|
||||||
bool earlierThan(const CMapEvent & other) const;
|
bool earlierThan(const CMapEvent & other) const;
|
||||||
bool earlierThanOrEqual(const CMapEvent & other) const;
|
bool earlierThanOrEqual(const CMapEvent & other) const;
|
||||||
@ -51,17 +53,18 @@ public:
|
|||||||
h & firstOccurence;
|
h & firstOccurence;
|
||||||
h & nextOccurence;
|
h & nextOccurence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void serializeJson(JsonSerializeFormat & handler);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The castle event builds/adds buildings/creatures for a specific town.
|
/// The castle event builds/adds buildings/creatures for a specific town.
|
||||||
class DLL_LINKAGE CCastleEvent: public CMapEvent
|
class DLL_LINKAGE CCastleEvent: public CMapEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCastleEvent();
|
CCastleEvent() = default;
|
||||||
|
|
||||||
std::set<BuildingID> buildings;
|
std::set<BuildingID> buildings;
|
||||||
std::vector<si32> creatures;
|
std::vector<si32> creatures;
|
||||||
CGTownInstance * town;
|
|
||||||
|
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
@ -70,6 +73,8 @@ public:
|
|||||||
h & buildings;
|
h & buildings;
|
||||||
h & creatures;
|
h & creatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serializeJson(JsonSerializeFormat & handler) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The terrain tile describes the terrain type and the visual representation of the terrain.
|
/// The terrain tile describes the terrain type and the visual representation of the terrain.
|
||||||
|
@ -2097,7 +2097,6 @@ CGObjectInstance * CMapLoaderH3M::readTown(const int3 & position, std::shared_pt
|
|||||||
for(int eventID = 0; eventID < eventsCount; ++eventID)
|
for(int eventID = 0; eventID < eventsCount; ++eventID)
|
||||||
{
|
{
|
||||||
CCastleEvent event;
|
CCastleEvent event;
|
||||||
event.town = object;
|
|
||||||
event.name = readBasicString();
|
event.name = readBasicString();
|
||||||
event.message = readLocalizedString(TextIdentifier("town", position.x, position.y, position.z, "event", eventID, "description"));
|
event.message = readLocalizedString(TextIdentifier("town", position.x, position.y, position.z, "event", eventID, "description"));
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ namespace TerrainDetail
|
|||||||
|
|
||||||
///CMapFormatJson
|
///CMapFormatJson
|
||||||
const int CMapFormatJson::VERSION_MAJOR = 1;
|
const int CMapFormatJson::VERSION_MAJOR = 1;
|
||||||
const int CMapFormatJson::VERSION_MINOR = 1;
|
const int CMapFormatJson::VERSION_MINOR = 2;
|
||||||
|
|
||||||
const std::string CMapFormatJson::HEADER_FILE_NAME = "header.json";
|
const std::string CMapFormatJson::HEADER_FILE_NAME = "header.json";
|
||||||
const std::string CMapFormatJson::OBJECTS_FILE_NAME = "objects.json";
|
const std::string CMapFormatJson::OBJECTS_FILE_NAME = "objects.json";
|
||||||
@ -775,6 +775,14 @@ void CMapFormatJson::serializeRumors(JsonSerializeFormat & handler)
|
|||||||
rumors.serializeStruct(map->rumors);
|
rumors.serializeStruct(map->rumors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMapFormatJson::serializeTimedEvents(JsonSerializeFormat & handler)
|
||||||
|
{
|
||||||
|
auto events = handler.enterArray("events");
|
||||||
|
std::vector<CMapEvent> temp(map->events.begin(), map->events.end());
|
||||||
|
events.serializeStruct(temp);
|
||||||
|
map->events.assign(temp.begin(), temp.end());
|
||||||
|
}
|
||||||
|
|
||||||
void CMapFormatJson::serializePredefinedHeroes(JsonSerializeFormat & handler)
|
void CMapFormatJson::serializePredefinedHeroes(JsonSerializeFormat & handler)
|
||||||
{
|
{
|
||||||
//todo:serializePredefinedHeroes
|
//todo:serializePredefinedHeroes
|
||||||
@ -817,6 +825,8 @@ void CMapFormatJson::serializeOptions(JsonSerializeFormat & handler)
|
|||||||
{
|
{
|
||||||
serializeRumors(handler);
|
serializeRumors(handler);
|
||||||
|
|
||||||
|
serializeTimedEvents(handler);
|
||||||
|
|
||||||
serializePredefinedHeroes(handler);
|
serializePredefinedHeroes(handler);
|
||||||
|
|
||||||
handler.serializeLIC("allowedAbilities", &CSkillHandler::decodeSkill, &CSkillHandler::encodeSkill, VLC->skillh->getDefaultAllowed(), map->allowedAbilities);
|
handler.serializeLIC("allowedAbilities", &CSkillHandler::decodeSkill, &CSkillHandler::encodeSkill, VLC->skillh->getDefaultAllowed(), map->allowedAbilities);
|
||||||
|
@ -110,6 +110,8 @@ protected:
|
|||||||
|
|
||||||
void serializeRumors(JsonSerializeFormat & handler);
|
void serializeRumors(JsonSerializeFormat & handler);
|
||||||
|
|
||||||
|
void serializeTimedEvents(JsonSerializeFormat & handler);
|
||||||
|
|
||||||
///common part of map attributes saving/loading
|
///common part of map attributes saving/loading
|
||||||
void serializeOptions(JsonSerializeFormat & handler);
|
void serializeOptions(JsonSerializeFormat & handler);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user