mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
First part of implementation of some type-specific handlers.
TODO: - merge dwellings.json into object configs - proper implementation of overrides for towns - fully connect new API to RMG/H3M
This commit is contained in:
@@ -81,13 +81,16 @@ class AObjectTypeHandler
|
||||
protected:
|
||||
|
||||
virtual bool objectFilter(const CGObjectInstance *, const ObjectTemplate &) const;
|
||||
|
||||
/// initialization for classes that inherit this one
|
||||
virtual void initTypeData(const JsonNode & input);
|
||||
public:
|
||||
virtual ~AObjectTypeHandler(){}
|
||||
|
||||
void setType(si32 type, si32 subtype);
|
||||
|
||||
/// loads generic data from Json structure
|
||||
virtual void init(const JsonNode & input);
|
||||
/// loads generic data from Json structure and passes it towards type-specific constructors
|
||||
void init(const JsonNode & input);
|
||||
|
||||
void addTemplate(ObjectTemplate templ);
|
||||
void addTemplate(JsonNode config);
|
||||
@@ -102,11 +105,16 @@ public:
|
||||
|
||||
const RandomMapInfo & getRMGInfo();
|
||||
|
||||
virtual bool isStaticObject();
|
||||
|
||||
virtual void afterLoadFinalization();
|
||||
|
||||
/// Creates object and set up core properties (like ID/subID). Object is NOT initialized
|
||||
/// to allow creating objects before game start (e.g. map loading)
|
||||
virtual CGObjectInstance * create(ObjectTemplate tmpl) const = 0;
|
||||
|
||||
/// Configures object properties. Should be re-entrable, resetting state of the object if necessarily
|
||||
/// This should set remaining properties, including randomized or depending on map
|
||||
virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const = 0;
|
||||
|
||||
/// Returns object configuration, if available. Othervice returns NULL
|
||||
@@ -118,29 +126,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/// Class that is used for objects that do not have dedicated handler
|
||||
template<class ObjectType>
|
||||
class CDefaultObjectTypeHandler : public AObjectTypeHandler
|
||||
{
|
||||
CGObjectInstance * create(ObjectTemplate tmpl) const
|
||||
{
|
||||
auto obj = new ObjectType();
|
||||
obj->ID = tmpl.id;
|
||||
obj->subID = tmpl.subid;
|
||||
obj->appearance = tmpl;
|
||||
return obj;
|
||||
}
|
||||
|
||||
virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
|
||||
{
|
||||
}
|
||||
|
||||
virtual const IObjectInfo * getObjectInfo(ObjectTemplate tmpl) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<AObjectTypeHandler> TObjectTypeHandler;
|
||||
|
||||
class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
|
||||
|
||||
Reference in New Issue
Block a user