mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-13 01:20:34 +02:00
Map object use format mod:object (or mod:object.subobject)
This commit is contained in:
@ -156,7 +156,7 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData(size_t dataSize)
|
|||||||
|
|
||||||
void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj)
|
void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj)
|
||||||
{
|
{
|
||||||
auto object = loadSubObjectFromJson(scope, VLC->modh->normalizeIdentifier(scope, CModHandler::scopeBuiltin(), identifier), entry, obj, obj->objects.size());
|
auto object = loadSubObjectFromJson(scope, identifier, entry, obj, obj->objects.size());
|
||||||
|
|
||||||
assert(object);
|
assert(object);
|
||||||
obj->objects.push_back(object);
|
obj->objects.push_back(object);
|
||||||
@ -166,8 +166,7 @@ void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::
|
|||||||
|
|
||||||
void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index)
|
void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index)
|
||||||
{
|
{
|
||||||
//TODO: load name for subobjects
|
auto object = loadSubObjectFromJson(scope, identifier, entry, obj, index);
|
||||||
auto object = loadSubObjectFromJson(scope, VLC->modh->normalizeIdentifier(scope, CModHandler::scopeBuiltin(), identifier), entry, obj, index);
|
|
||||||
|
|
||||||
assert(object);
|
assert(object);
|
||||||
assert(obj->objects[index] == nullptr); // ensure that this id was not loaded before
|
assert(obj->objects[index] == nullptr); // ensure that this id was not loaded before
|
||||||
@ -178,6 +177,9 @@ void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::
|
|||||||
|
|
||||||
TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index)
|
TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index)
|
||||||
{
|
{
|
||||||
|
assert(identifier.find(':') == std::string::npos);
|
||||||
|
assert(!scope.empty());
|
||||||
|
|
||||||
if(!handlerConstructors.count(obj->handlerName))
|
if(!handlerConstructors.count(obj->handlerName))
|
||||||
{
|
{
|
||||||
logGlobal->error("Handler with name %s was not found!", obj->handlerName);
|
logGlobal->error("Handler with name %s was not found!", obj->handlerName);
|
||||||
@ -186,12 +188,12 @@ TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::strin
|
|||||||
|
|
||||||
auto createdObject = handlerConstructors.at(obj->handlerName)();
|
auto createdObject = handlerConstructors.at(obj->handlerName)();
|
||||||
|
|
||||||
if (identifier.find(':') == std::string::npos)
|
createdObject->modScope = scope;
|
||||||
createdObject->setTypeName(obj->getJsonKey(), scope + ":" + identifier);
|
createdObject->typeName = obj->identifier;;
|
||||||
else
|
createdObject->subTypeName = identifier;
|
||||||
createdObject->setTypeName(obj->getJsonKey(), identifier);
|
|
||||||
|
|
||||||
createdObject->setType(obj->id, index);
|
createdObject->type = obj->id;
|
||||||
|
createdObject->subtype = index;
|
||||||
createdObject->init(entry);
|
createdObject->init(entry);
|
||||||
|
|
||||||
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, index));
|
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, index));
|
||||||
@ -208,7 +210,7 @@ TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::strin
|
|||||||
|
|
||||||
std::string ObjectClass::getJsonKey() const
|
std::string ObjectClass::getJsonKey() const
|
||||||
{
|
{
|
||||||
return identifier;
|
return modScope + ':' + identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ObjectClass::getNameTextID() const
|
std::string ObjectClass::getNameTextID() const
|
||||||
@ -223,8 +225,10 @@ std::string ObjectClass::getNameTranslated() const
|
|||||||
|
|
||||||
ObjectClass * CObjectClassesHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index)
|
ObjectClass * CObjectClassesHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index)
|
||||||
{
|
{
|
||||||
auto obj = new ObjectClass(scope, name);
|
auto obj = new ObjectClass();
|
||||||
|
|
||||||
|
obj->modScope = scope;
|
||||||
|
obj->identifier = name;
|
||||||
obj->handlerName = json["handler"].String();
|
obj->handlerName = json["handler"].String();
|
||||||
obj->base = json["base"];
|
obj->base = json["base"];
|
||||||
obj->id = index;
|
obj->id = index;
|
||||||
@ -252,14 +256,14 @@ ObjectClass * CObjectClassesHandler::loadFromJson(const std::string & scope, con
|
|||||||
|
|
||||||
void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||||
{
|
{
|
||||||
auto object = loadFromJson(scope, data, VLC->modh->normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name), objects.size());
|
auto object = loadFromJson(scope, data, name, objects.size());
|
||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
VLC->modh->identifiers.registerObject(scope, "object", name, object->id);
|
VLC->modh->identifiers.registerObject(scope, "object", name, object->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||||
{
|
{
|
||||||
auto object = loadFromJson(scope, data, VLC->modh->normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name), index);
|
auto object = loadFromJson(scope, data, name, index);
|
||||||
assert(objects[(si32)index] == nullptr); // ensure that this id was not loaded before
|
assert(objects[(si32)index] == nullptr); // ensure that this id was not loaded before
|
||||||
objects[(si32)index] = object;
|
objects[(si32)index] = object;
|
||||||
VLC->modh->identifiers.registerObject(scope, "object", name, object->id);
|
VLC->modh->identifiers.registerObject(scope, "object", name, object->id);
|
||||||
@ -437,21 +441,19 @@ AObjectTypeHandler::~AObjectTypeHandler()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void AObjectTypeHandler::setType(si32 type, si32 subtype)
|
|
||||||
{
|
|
||||||
this->type = type;
|
|
||||||
this->subtype = subtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AObjectTypeHandler::setTypeName(std::string type, std::string subtype)
|
|
||||||
{
|
|
||||||
this->typeName = type;
|
|
||||||
this->subTypeName = subtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string AObjectTypeHandler::getJsonKey() const
|
std::string AObjectTypeHandler::getJsonKey() const
|
||||||
{
|
{
|
||||||
return subTypeName;
|
return modScope + ':' + subTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
si32 AObjectTypeHandler::getIndex() const
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
si32 AObjectTypeHandler::getSubIndex() const
|
||||||
|
{
|
||||||
|
return subtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AObjectTypeHandler::getTypeName() const
|
std::string AObjectTypeHandler::getTypeName() const
|
||||||
|
@ -152,23 +152,26 @@ class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable
|
|||||||
boost::optional<si32> aiValue;
|
boost::optional<si32> aiValue;
|
||||||
boost::optional<std::string> battlefield;
|
boost::optional<std::string> battlefield;
|
||||||
|
|
||||||
|
std::string modScope;
|
||||||
|
std::string typeName;
|
||||||
|
std::string subTypeName;
|
||||||
|
|
||||||
|
si32 type;
|
||||||
|
si32 subtype;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void preInitObject(CGObjectInstance * obj) const;
|
void preInitObject(CGObjectInstance * obj) const;
|
||||||
virtual bool objectFilter(const CGObjectInstance *, std::shared_ptr<const ObjectTemplate>) const;
|
virtual bool objectFilter(const CGObjectInstance *, std::shared_ptr<const ObjectTemplate>) const;
|
||||||
|
|
||||||
/// initialization for classes that inherit this one
|
/// initialization for classes that inherit this one
|
||||||
virtual void initTypeData(const JsonNode & input);
|
virtual void initTypeData(const JsonNode & input);
|
||||||
std::string typeName;
|
|
||||||
std::string subTypeName;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
si32 type;
|
|
||||||
si32 subtype;
|
|
||||||
AObjectTypeHandler();
|
AObjectTypeHandler();
|
||||||
virtual ~AObjectTypeHandler();
|
virtual ~AObjectTypeHandler();
|
||||||
|
|
||||||
void setType(si32 type, si32 subtype);
|
si32 getIndex() const;
|
||||||
void setTypeName(std::string type, std::string subtype);
|
si32 getSubIndex() const;
|
||||||
|
|
||||||
std::string getTypeName() const;
|
std::string getTypeName() const;
|
||||||
std::string getSubTypeName() const;
|
std::string getSubTypeName() const;
|
||||||
@ -229,6 +232,7 @@ public:
|
|||||||
h & subtype;
|
h & subtype;
|
||||||
h & templates;
|
h & templates;
|
||||||
h & rmgInfo;
|
h & rmgInfo;
|
||||||
|
h & modScope;
|
||||||
h & typeName;
|
h & typeName;
|
||||||
h & subTypeName;
|
h & subTypeName;
|
||||||
h & sounds;
|
h & sounds;
|
||||||
@ -242,18 +246,9 @@ typedef std::shared_ptr<AObjectTypeHandler> TObjectTypeHandler;
|
|||||||
/// Class responsible for creation of adventure map objects of specific type
|
/// Class responsible for creation of adventure map objects of specific type
|
||||||
class DLL_LINKAGE ObjectClass
|
class DLL_LINKAGE ObjectClass
|
||||||
{
|
{
|
||||||
std::string identifier;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectClass() = default;
|
std::string modScope;
|
||||||
ObjectClass(const std::string & modScope, const std::string & identifier)
|
std::string identifier;
|
||||||
{
|
|
||||||
if (identifier.find(':') == std::string::npos)
|
|
||||||
this->identifier = modScope + ":" + identifier;
|
|
||||||
else
|
|
||||||
this->identifier = identifier;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
si32 id;
|
si32 id;
|
||||||
std::string handlerName; // ID of handler that controls this object, should be determined using handlerConstructor map
|
std::string handlerName; // ID of handler that controls this object, should be determined using handlerConstructor map
|
||||||
@ -261,6 +256,8 @@ public:
|
|||||||
JsonNode base;
|
JsonNode base;
|
||||||
std::vector<TObjectTypeHandler> objects;
|
std::vector<TObjectTypeHandler> objects;
|
||||||
|
|
||||||
|
ObjectClass() = default;
|
||||||
|
|
||||||
std::string getJsonKey() const;
|
std::string getJsonKey() const;
|
||||||
std::string getNameTextID() const;
|
std::string getNameTextID() const;
|
||||||
std::string getNameTranslated() const;
|
std::string getNameTranslated() const;
|
||||||
@ -271,6 +268,7 @@ public:
|
|||||||
h & base;
|
h & base;
|
||||||
h & objects;
|
h & objects;
|
||||||
h & identifier;
|
h & identifier;
|
||||||
|
h & modScope;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1159,8 +1159,8 @@ void CMapLoaderJson::MapObjectLoader::construct()
|
|||||||
|
|
||||||
auto appearance = new ObjectTemplate;
|
auto appearance = new ObjectTemplate;
|
||||||
|
|
||||||
appearance->id = Obj(handler->type);
|
appearance->id = Obj(handler->getIndex());
|
||||||
appearance->subid = handler->subtype;
|
appearance->subid = handler->getSubIndex();
|
||||||
appearance->readJson(configuration["template"], false);
|
appearance->readJson(configuration["template"], false);
|
||||||
|
|
||||||
// Will be destroyed soon and replaced with shared template
|
// Will be destroyed soon and replaced with shared template
|
||||||
|
Reference in New Issue
Block a user