1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Merge pull request #2291 from IvanSavenko/terrain_animations_config

Moved hardcoded terrain palette-cycling animations to config
This commit is contained in:
Ivan Savenko 2023-07-07 14:28:39 +03:00 committed by GitHub
commit fa4a0004b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 147 additions and 66 deletions

View File

@ -145,16 +145,8 @@ void MapRendererTerrain::renderTile(IMapRendererContext & context, Canvas & targ
const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex); const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex);
if(mapTile.terType->getId() == ETerrainId::LAVA) for( auto const & element : mapTile.terType->paletteAnimation)
{ image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length));
image->shiftPalette(246, 9, context.terrainImageIndex(9));
}
if(mapTile.terType->getId() == ETerrainId::WATER)
{
image->shiftPalette(229, 12, context.terrainImageIndex(12));
image->shiftPalette(242, 14, context.terrainImageIndex(14));
}
target.draw(image, Point(0, 0)); target.draw(image, Point(0, 0));
} }
@ -163,7 +155,7 @@ uint8_t MapRendererTerrain::checksum(IMapRendererContext & context, const int3 &
{ {
const TerrainTile & mapTile = context.getMapTile(coordinates); const TerrainTile & mapTile = context.getMapTile(coordinates);
if(mapTile.terType->getId() == ETerrainId::LAVA || mapTile.terType->getId() == ETerrainId::WATER) if(!mapTile.terType->paletteAnimation.empty())
return context.terrainImageIndex(250); return context.terrainImageIndex(250);
return 0xff - 1; return 0xff - 1;
} }
@ -188,23 +180,8 @@ void MapRendererRiver::renderTile(IMapRendererContext & context, Canvas & target
const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex); const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex);
if(mapTile.riverType->getId() == River::WATER_RIVER) for( auto const & element : mapTile.riverType->paletteAnimation)
{ image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length));
image->shiftPalette(183, 12, context.terrainImageIndex(12));
image->shiftPalette(195, 6, context.terrainImageIndex(6));
}
if(mapTile.riverType->getId() == River::MUD_RIVER)
{
image->shiftPalette(228, 12, context.terrainImageIndex(12));
image->shiftPalette(183, 6, context.terrainImageIndex(6));
image->shiftPalette(240, 6, context.terrainImageIndex(6));
}
if(mapTile.riverType->getId() == River::LAVA_RIVER)
{
image->shiftPalette(240, 9, context.terrainImageIndex(9));
}
target.draw(image, Point(0, 0)); target.draw(image, Point(0, 0));
} }
@ -213,9 +190,7 @@ uint8_t MapRendererRiver::checksum(IMapRendererContext & context, const int3 & c
{ {
const TerrainTile & mapTile = context.getMapTile(coordinates); const TerrainTile & mapTile = context.getMapTile(coordinates);
if(mapTile.riverType->getId() == River::WATER_RIVER || if(!mapTile.riverType->paletteAnimation.empty())
mapTile.riverType->getId() == River::MUD_RIVER ||
mapTile.riverType->getId() == River::LAVA_RIVER)
return context.terrainImageIndex(250); return context.terrainImageIndex(250);
return 0xff-1; return 0xff-1;
} }

View File

@ -5,7 +5,11 @@
"text" : "Water river", "text" : "Water river",
"shortIdentifier": "rw", //must be 2 characters "shortIdentifier": "rw", //must be 2 characters
"tilesFilename": "clrrvr", "tilesFilename": "clrrvr",
"delta": "clrdelt" "delta": "clrdelt",
"paletteAnimation" : [
{ "start" : 183, "length" : 12 },
{ "start" : 195, "length" : 6 }
]
}, },
"iceRiver": "iceRiver":
{ {
@ -21,7 +25,12 @@
"text" : "Mud river", "text" : "Mud river",
"shortIdentifier": "rm", "shortIdentifier": "rm",
"tilesFilename": "mudrvr", "tilesFilename": "mudrvr",
"delta": "muddelt" "delta": "muddelt",
"paletteAnimation" : [
{ "start" : 228, "length" : 12 },
{ "start" : 183, "length" : 6 },
{ "start" : 240, "length" : 6 }
]
}, },
"lavaRiver": "lavaRiver":
{ {
@ -29,6 +38,9 @@
"text" : "Lava river", "text" : "Lava river",
"shortIdentifier": "rl", "shortIdentifier": "rl",
"tilesFilename": "lavrvr", "tilesFilename": "lavrvr",
"delta": "lavdelt" "delta": "lavdelt",
"paletteAnimation" : [
{ "start" : 240, "length" : 9 }
]
} }
} }

View File

@ -27,6 +27,23 @@
"type" : "string", "type" : "string",
"description" : "Name of file with river delta graphics" "description" : "Name of file with river delta graphics"
}, },
"paletteAnimation" : {
"type" : "array",
"description" : "If defined, terrain will be animated using palette color cycling effect",
"items" :
{
"type" : "object",
"additionalProperties" : false,
"properties" : {
"start" : {
"type" : "number"
},
"length" : {
"type" : "number"
}
}
}
},
"index" : "index" :
{ {
"type" : "number", "type" : "number",

View File

@ -47,6 +47,23 @@
"type" : "string", "type" : "string",
"description" : "River type which should be used for that terrain" "description" : "River type which should be used for that terrain"
}, },
"paletteAnimation" : {
"type" : "array",
"description" : "If defined, terrain will be animated using palette color cycling effect",
"items" :
{
"type" : "object",
"additionalProperties" : false,
"properties" : {
"start" : {
"type" : "number"
},
"length" : {
"type" : "number"
}
}
}
},
"battleFields" : "battleFields" :
{ {
"type" : "array", "type" : "array",

View File

@ -122,7 +122,10 @@
"battleFields" : ["lava"], "battleFields" : ["lava"],
"rockTerrain" : "rock", "rockTerrain" : "rock",
"horseSound" : "horse07", "horseSound" : "horse07",
"horseSoundPenalty" : "horse27" "horseSoundPenalty" : "horse27",
"paletteAnimation" : [
{ "start" : 246, "length" : 9 }
]
}, },
"water" : "water" :
{ {
@ -139,6 +142,10 @@
"terrainViewPatterns" : "water", "terrainViewPatterns" : "water",
"horseSound" : "horse08", "horseSound" : "horse08",
"horseSoundPenalty" : "horse08", "horseSoundPenalty" : "horse08",
"paletteAnimation" : [
{ "start" : 229, "length" : 12 },
{ "start" : 242, "length" : 12 }
],
"sounds": { "sounds": {
"ambient": ["LOOPOCEA"] "ambient": ["LOOPOCEA"]
} }

View File

@ -40,6 +40,15 @@ RiverType * RiverTypeHandler::loadFromJson(
info->shortIdentifier = json["shortIdentifier"].String(); info->shortIdentifier = json["shortIdentifier"].String();
info->deltaName = json["delta"].String(); info->deltaName = json["delta"].String();
for(const auto & t : json["paletteAnimation"].Vector())
{
RiverPaletteAnimation element{
static_cast<int>(t["start"].Integer()),
static_cast<int>(t["length"].Integer())
};
info->paletteAnimation.push_back(element);
}
VLC->generaltexth->registerString(scope, info->getNameTextID(), json["text"].String()); VLC->generaltexth->registerString(scope, info->getNameTextID(), json["text"].String());
return info; return info;

View File

@ -17,6 +17,20 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
struct DLL_LINKAGE RiverPaletteAnimation
{
/// index of first color to cycle
int32_t start;
/// total numbers of colors to cycle
int32_t length;
template <typename Handler> void serialize(Handler& h, const int version)
{
h & start;
h & length;
}
};
class DLL_LINKAGE RiverType : public EntityT<RiverId> class DLL_LINKAGE RiverType : public EntityT<RiverId>
{ {
friend class RiverTypeHandler; friend class RiverTypeHandler;
@ -39,6 +53,8 @@ public:
std::string shortIdentifier; std::string shortIdentifier;
std::string deltaName; std::string deltaName;
std::vector<RiverPaletteAnimation> paletteAnimation;
RiverType(); RiverType();
template <typename Handler> void serialize(Handler& h, const int version) template <typename Handler> void serialize(Handler& h, const int version)
@ -48,6 +64,7 @@ public:
h & modScope; h & modScope;
h & deltaName; h & deltaName;
h & id; h & id;
h & paletteAnimation;
} }
}; };

View File

@ -73,6 +73,15 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
}); });
} }
for(const auto & t : json["paletteAnimation"].Vector())
{
TerrainPaletteAnimation element{
static_cast<int>(t["start"].Integer()),
static_cast<int>(t["length"].Integer())
};
info->paletteAnimation.push_back(element);
}
info->shortIdentifier = json["shortIdentifier"].String(); info->shortIdentifier = json["shortIdentifier"].String();
assert(info->shortIdentifier.length() == 2); assert(info->shortIdentifier.length() == 2);

View File

@ -18,6 +18,21 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
struct DLL_LINKAGE TerrainPaletteAnimation
{
/// index of first color to cycle
int32_t start;
/// total numbers of colors to cycle
int32_t length;
template <typename Handler> void serialize(Handler& h, const int version)
{
h & start;
h & length;
}
};
class DLL_LINKAGE TerrainType : public EntityT<TerrainId> class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
{ {
friend class TerrainTypeHandler; friend class TerrainTypeHandler;
@ -57,6 +72,8 @@ public:
std::string horseSound; std::string horseSound;
std::string horseSoundPenalty; std::string horseSoundPenalty;
std::vector<TerrainPaletteAnimation> paletteAnimation;
TerrainId rockTerrain; TerrainId rockTerrain;
RiverId river; RiverId river;
int moveCost; int moveCost;
@ -87,6 +104,7 @@ public:
h & terrainViewPatterns; h & terrainViewPatterns;
h & rockTerrain; h & rockTerrain;
h & river; h & river;
h & paletteAnimation;
h & id; h & id;
h & moveCost; h & moveCost;

View File

@ -14,8 +14,8 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
const ui32 SERIALIZATION_VERSION = 823; const ui32 SERIALIZATION_VERSION = 824;
const ui32 MINIMAL_SERIALIZATION_VERSION = 823; const ui32 MINIMAL_SERIALIZATION_VERSION = 824;
const std::string SAVEGAME_MAGIC = "VCMISVG"; const std::string SAVEGAME_MAGIC = "VCMISVG";
class CHero; class CHero;