mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Merge pull request #2291 from IvanSavenko/terrain_animations_config
Moved hardcoded terrain palette-cycling animations to config
This commit is contained in:
		| @@ -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; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,34 +1,46 @@ | |||||||
| { | { | ||||||
|     "waterRiver": | 	"waterRiver": | ||||||
|     { | 	{ | ||||||
|         "index": 1, | 		"index": 1, | ||||||
|         "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" : [ | ||||||
|     "iceRiver": | 			{ "start" : 183, "length" : 12 }, | ||||||
|     { | 			{ "start" : 195, "length" : 6 } | ||||||
|         "index": 2, | 		] | ||||||
|         "text" : "Ice river", | 	}, | ||||||
|         "shortIdentifier": "ri", | 	"iceRiver": | ||||||
|         "tilesFilename": "icyrvr", | 	{ | ||||||
|         "delta": "icedelt" | 		"index": 2, | ||||||
|     }, | 		"text" : "Ice river", | ||||||
|     "mudRiver": | 		"shortIdentifier": "ri", | ||||||
|     { | 		"tilesFilename": "icyrvr", | ||||||
|         "index": 3, | 		"delta": "icedelt" | ||||||
|         "text" : "Mud river", | 	}, | ||||||
|         "shortIdentifier": "rm", | 	"mudRiver": | ||||||
|         "tilesFilename": "mudrvr", | 	{ | ||||||
|         "delta": "muddelt" | 		"index": 3, | ||||||
|     }, | 		"text" : "Mud river", | ||||||
|     "lavaRiver": | 		"shortIdentifier": "rm", | ||||||
|     { | 		"tilesFilename": "mudrvr", | ||||||
|         "index": 4, | 		"delta": "muddelt", | ||||||
|         "text" : "Lava river", | 		"paletteAnimation" : [ | ||||||
|         "shortIdentifier": "rl", | 			{ "start" : 228, "length" : 12 }, | ||||||
|         "tilesFilename": "lavrvr", | 			{ "start" : 183, "length" : 6 }, | ||||||
|         "delta": "lavdelt" | 			{ "start" : 240, "length" : 6 } | ||||||
|     } | 		] | ||||||
|  | 	}, | ||||||
|  | 	"lavaRiver": | ||||||
|  | 	{ | ||||||
|  | 		"index": 4, | ||||||
|  | 		"text" : "Lava river", | ||||||
|  | 		"shortIdentifier": "rl", | ||||||
|  | 		"tilesFilename": "lavrvr", | ||||||
|  | 		"delta": "lavdelt", | ||||||
|  | 		"paletteAnimation" : [ | ||||||
|  | 			{ "start" : 240, "length" : 9 } | ||||||
|  | 		] | ||||||
|  | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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", | ||||||
|   | |||||||
| @@ -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", | ||||||
|   | |||||||
| @@ -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"] | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
| @@ -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; | ||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user