mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Animations from config
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include "../../lib/RoadHandler.h"
|
#include "../../lib/RoadHandler.h"
|
||||||
#include "../../lib/TerrainHandler.h"
|
#include "../../lib/TerrainHandler.h"
|
||||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||||
|
#include "../../lib/mapObjects/MiscObjects.h"
|
||||||
#include "../../lib/mapping/CMap.h"
|
#include "../../lib/mapping/CMap.h"
|
||||||
|
|
||||||
struct NeighborTilesInfo
|
struct NeighborTilesInfo
|
||||||
@@ -394,15 +395,11 @@ std::shared_ptr<CAnimation> MapRendererObjects::getBaseAnimation(const CGObjectI
|
|||||||
|
|
||||||
bool generateMovementGroups = (info->id == Obj::TRANSPORT) || (info->id == Obj::HERO);
|
bool generateMovementGroups = (info->id == Obj::TRANSPORT) || (info->id == Obj::HERO);
|
||||||
|
|
||||||
//TODO: relocate to config file?
|
|
||||||
// Boat appearance files only contain single, unanimated image
|
// Boat appearance files only contain single, unanimated image
|
||||||
// proper boat animations are actually in different file
|
// proper boat animations are actually in different file
|
||||||
static const std::vector<std::string> boatAnimations = {
|
if (info->id == Obj::TRANSPORT)
|
||||||
"AB01_.def", "AB02_.def", "AB03_.def"
|
if(auto boat = dynamic_cast<const CGBoat*>(obj); boat && !boat->actualAnimation.empty())
|
||||||
};
|
return getAnimation(boat->actualAnimation, generateMovementGroups);
|
||||||
|
|
||||||
if (info->id == Obj::TRANSPORT && info->subid < boatAnimations.size())
|
|
||||||
return getAnimation(boatAnimations[info->subid], generateMovementGroups);
|
|
||||||
|
|
||||||
return getAnimation(info->animationFile, generateMovementGroups);
|
return getAnimation(info->animationFile, generateMovementGroups);
|
||||||
}
|
}
|
||||||
@@ -438,13 +435,6 @@ std::shared_ptr<CAnimation> MapRendererObjects::getFlagAnimation(const CGObjectI
|
|||||||
"AF00", "AF01", "AF02", "AF03", "AF04", "AF05", "AF06", "AF07"
|
"AF00", "AF01", "AF02", "AF03", "AF04", "AF05", "AF06", "AF07"
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: relocate to config file?
|
|
||||||
static const std::vector<std::vector<std::string>> boatFlags = {
|
|
||||||
{"ABF01L", "ABF01G", "ABF01R", "ABF01D", "ABF01B", "ABF01P", "ABF01W", "ABF01K"},
|
|
||||||
{"ABF02L", "ABF02G", "ABF02R", "ABF02D", "ABF02B", "ABF02P", "ABF02W", "ABF02K"},
|
|
||||||
{"ABF03L", "ABF03G", "ABF03R", "ABF03D", "ABF03B", "ABF03P", "ABF03W", "ABF03K"}
|
|
||||||
};
|
|
||||||
|
|
||||||
if(obj->ID == Obj::HERO)
|
if(obj->ID == Obj::HERO)
|
||||||
{
|
{
|
||||||
assert(dynamic_cast<const CGHeroInstance *>(obj) != nullptr);
|
assert(dynamic_cast<const CGHeroInstance *>(obj) != nullptr);
|
||||||
@@ -455,11 +445,8 @@ std::shared_ptr<CAnimation> MapRendererObjects::getFlagAnimation(const CGObjectI
|
|||||||
if(obj->ID == Obj::TRANSPORT)
|
if(obj->ID == Obj::TRANSPORT)
|
||||||
{
|
{
|
||||||
const auto * boat = dynamic_cast<const CGBoat *>(obj);
|
const auto * boat = dynamic_cast<const CGBoat *>(obj);
|
||||||
if(boat->hero && boat->subID < boatFlags.size())
|
if(boat && boat->hero && !boat->flagAnimations[boat->hero->tempOwner.getNum()].empty())
|
||||||
{
|
return getAnimation(boat->flagAnimations[boat->hero->tempOwner.getNum()], true);
|
||||||
assert(boat->hero->tempOwner.isValidPlayer());
|
|
||||||
return getAnimation(boatFlags[boat->subID][boat->hero->tempOwner.getNum()], true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -469,15 +456,10 @@ std::shared_ptr<CAnimation> MapRendererObjects::getOverlayAnimation(const CGObje
|
|||||||
{
|
{
|
||||||
if(obj->ID == Obj::TRANSPORT)
|
if(obj->ID == Obj::TRANSPORT)
|
||||||
{
|
{
|
||||||
//TODO: relocate to config file?
|
|
||||||
// Boats have additional animation with waves around boat
|
// Boats have additional animation with waves around boat
|
||||||
static const std::vector<std::string> boatAnimations = {
|
|
||||||
"ABM01_.def", "ABM02_.def", "ABM03_.def"
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto * boat = dynamic_cast<const CGBoat *>(obj);
|
const auto * boat = dynamic_cast<const CGBoat *>(obj);
|
||||||
if(boat->hero && obj->subID < boatAnimations.size())
|
if(boat && boat->hero && !boat->overlayAnimation.empty())
|
||||||
return getAnimation(boatAnimations[obj->subID], true);
|
return getAnimation(boat->overlayAnimation, true);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@@ -115,9 +115,32 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"types" : {
|
"types" : {
|
||||||
"evil" : { "index" : 0, "rmg" : { "mapLimit" : 64 } },
|
"evil" :
|
||||||
"good" : { "index" : 1, "rmg" : { "mapLimit" : 64 } },
|
{
|
||||||
"neutral" : { "index" : 2, "rmg" : { "mapLimit" : 64 } },
|
"index" : 0,
|
||||||
|
"rmg" : { "mapLimit" : 64 },
|
||||||
|
"layer" : "sail",
|
||||||
|
"actualAnimation" : "AB01_.def",
|
||||||
|
"overlayAnimation" : "ABM01_.def",
|
||||||
|
"flagAnimations" : ["ABF01L", "ABF01G", "ABF01R", "ABF01D", "ABF01B", "ABF01P", "ABF01W", "ABF01K"]
|
||||||
|
},
|
||||||
|
"good" :
|
||||||
|
{
|
||||||
|
"index" : 1,
|
||||||
|
"rmg" : { "mapLimit" : 64 },
|
||||||
|
"layer" : "sail",
|
||||||
|
"actualAnimation" : "AB02_.def",
|
||||||
|
"overlayAnimation" : "ABM02_.def",
|
||||||
|
"flagAnimations" : ["ABF02L", "ABF02G", "ABF02R", "ABF02D", "ABF02B", "ABF02P", "ABF02W", "ABF02K"]
|
||||||
|
},
|
||||||
|
"neutral" : {
|
||||||
|
"index" : 2,
|
||||||
|
"rmg" : { "mapLimit" : 64 },
|
||||||
|
"layer" : "sail",
|
||||||
|
"actualAnimation" : "AB03_.def",
|
||||||
|
"overlayAnimation" : "ABM03_.def",
|
||||||
|
"flagAnimations" : ["ABF03L", "ABF03G", "ABF03R", "ABF03D", "ABF03B", "ABF03P", "ABF03W", "ABF03K"]
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -114,4 +114,12 @@ namespace NMetaclass
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace NPathfindingLayer
|
||||||
|
{
|
||||||
|
const std::string names[EPathfindingLayer::NUM_LAYERS] =
|
||||||
|
{
|
||||||
|
"land", "sail", "water", "air"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include "JsonRandom.h"
|
#include "JsonRandom.h"
|
||||||
#include "../CModHandler.h"
|
#include "../CModHandler.h"
|
||||||
#include "../IGameCallback.h"
|
#include "../IGameCallback.h"
|
||||||
|
#include "../StringConstants.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@@ -259,24 +260,31 @@ std::vector<const CCreature *> CDwellingInstanceConstructor::getProducedCreature
|
|||||||
|
|
||||||
void BoatInstanceConstructor::initTypeData(const JsonNode & input)
|
void BoatInstanceConstructor::initTypeData(const JsonNode & input)
|
||||||
{
|
{
|
||||||
layer = EPathfindingLayer::EEPathfindingLayer::SAIL;
|
layer = EPathfindingLayer::SAIL;
|
||||||
if(input["layer"].String() == "land")
|
int pos = vstd::find_pos(NPathfindingLayer::names, input["layer"].String());
|
||||||
layer = EPathfindingLayer::EEPathfindingLayer::LAND;
|
if(pos != -1)
|
||||||
if(input["layer"].String() == "air")
|
layer = EPathfindingLayer(pos);
|
||||||
layer = EPathfindingLayer::EEPathfindingLayer::AIR;
|
actualAnimation = input["actualAnimation"].String();
|
||||||
if(input["layer"].String() == "water")
|
overlayAnimation = input["overlayAnimation"].String();
|
||||||
layer = EPathfindingLayer::EEPathfindingLayer::WATER;
|
for(int i = 0; i < flagAnimations.size() && i < input["flagAnimations"].Vector().size(); ++i)
|
||||||
if(input["layer"].String() == "sail")
|
flagAnimations[i] = input["flagAnimations"].Vector()[i].String();
|
||||||
layer = EPathfindingLayer::EEPathfindingLayer::SAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGObjectInstance * BoatInstanceConstructor::create(std::shared_ptr<const ObjectTemplate> tmpl) const
|
CGObjectInstance * BoatInstanceConstructor::create(std::shared_ptr<const ObjectTemplate> tmpl) const
|
||||||
{
|
{
|
||||||
CGBoat * boat = createTyped(tmpl);
|
CGBoat * boat = createTyped(tmpl);
|
||||||
boat->layer = layer;
|
boat->layer = layer;
|
||||||
|
boat->actualAnimation = actualAnimation;
|
||||||
|
boat->overlayAnimation = overlayAnimation;
|
||||||
|
boat->flagAnimations = flagAnimations;
|
||||||
return boat;
|
return boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BoatInstanceConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool CBankInstanceConstructor::hasNameTextID() const
|
bool CBankInstanceConstructor::hasNameTextID() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@@ -145,10 +145,14 @@ class BoatInstanceConstructor : public CDefaultObjectTypeHandler<CGBoat>
|
|||||||
protected:
|
protected:
|
||||||
void initTypeData(const JsonNode & config) override;
|
void initTypeData(const JsonNode & config) override;
|
||||||
|
|
||||||
EPathfindingLayer::EEPathfindingLayer layer;
|
EPathfindingLayer layer;
|
||||||
|
std::string actualAnimation; //for OH3 boats those have actual animations
|
||||||
|
std::string overlayAnimation; //waves animations
|
||||||
|
std::array<std::string, PlayerColor::PLAYER_LIMIT_I> flagAnimations;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
|
CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
|
||||||
|
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
|
@@ -422,6 +422,11 @@ public:
|
|||||||
|
|
||||||
EPathfindingLayer::EEPathfindingLayer layer;
|
EPathfindingLayer::EEPathfindingLayer layer;
|
||||||
|
|
||||||
|
//animation filenames. If empty - animations won't be used
|
||||||
|
std::string actualAnimation; //for OH3 boats those have actual animations
|
||||||
|
std::string overlayAnimation; //waves animations
|
||||||
|
std::array<std::string, PlayerColor::PLAYER_LIMIT_I> flagAnimations;
|
||||||
|
|
||||||
void initObj(CRandomGenerator & rand) override;
|
void initObj(CRandomGenerator & rand) override;
|
||||||
|
|
||||||
CGBoat()
|
CGBoat()
|
||||||
|
Reference in New Issue
Block a user