mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Fix subObject identification
This commit is contained in:
parent
b56b7017ba
commit
3f79d001c1
@ -884,3 +884,16 @@ void CModHandler::afterLoad()
|
||||
std::ofstream file(*CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json")), std::ofstream::trunc);
|
||||
file << modSettings;
|
||||
}
|
||||
|
||||
std::string CModHandler::normalizeIdentifier(const std::string & scope, const std::string & remoteScope, const std::string & identifier) const
|
||||
{
|
||||
auto p = splitString(identifier, ':');
|
||||
|
||||
if(p.first.empty())
|
||||
p.first = scope;
|
||||
|
||||
if(p.first == remoteScope)
|
||||
p.first.clear();
|
||||
|
||||
return p.first.empty() ? p.second : p.first +":"+p.second;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
/// Function callback will be called during ID resolution phase of loading
|
||||
void requestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback);
|
||||
///fullName = [remoteScope:]type.name
|
||||
void requestIdentifier(std::string scope, std::string fullName, const std::function<void(si32)> & callback);
|
||||
void requestIdentifier(std::string scope, std::string fullName, const std::function<void(si32)> & callback);
|
||||
void requestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback);
|
||||
void requestIdentifier(const JsonNode & name, const std::function<void(si32)> & callback);
|
||||
|
||||
@ -253,7 +253,7 @@ public:
|
||||
|
||||
int CREEP_SIZE; // neutral stacks won't grow beyond this number
|
||||
int WEEKLY_GROWTH; //percent
|
||||
int NEUTRAL_STACK_EXP;
|
||||
int NEUTRAL_STACK_EXP;
|
||||
int MAX_BUILDING_PER_TURN;
|
||||
bool DWELLINGS_ACCUMULATE_CREATURES;
|
||||
bool ALL_CREATURES_GET_DOUBLE_MONTHS;
|
||||
@ -282,6 +282,8 @@ public:
|
||||
|
||||
CModHandler();
|
||||
|
||||
std::string normalizeIdentifier(const std::string & scope, const std::string & remoteScope, const std::string & identifier) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & allMods & activeMods & settings & modules & identifiers;
|
||||
|
@ -154,11 +154,14 @@ void CObjectClassesHandler::loadObjectEntry(const std::string & identifier, cons
|
||||
logGlobal->errorStream() << "Handler with name " << obj->handlerName << " was not found!";
|
||||
return;
|
||||
}
|
||||
|
||||
std::string convertedId = VLC->modh->normalizeIdentifier(entry.meta, "core", identifier);
|
||||
|
||||
si32 id = selectNextID(entry["index"], obj->subObjects, 1000);
|
||||
|
||||
auto handler = handlerConstructors.at(obj->handlerName)();
|
||||
handler->setType(obj->id, id);
|
||||
handler->setTypeName(obj->identifier, identifier);
|
||||
handler->setTypeName(obj->identifier, convertedId);
|
||||
|
||||
if (customNames.count(obj->id) && customNames.at(obj->id).size() > id)
|
||||
handler->init(entry, customNames.at(obj->id).at(id));
|
||||
@ -175,10 +178,10 @@ void CObjectClassesHandler::loadObjectEntry(const std::string & identifier, cons
|
||||
legacyTemplates.erase(range.first, range.second);
|
||||
}
|
||||
|
||||
logGlobal->debugStream() << "Loaded object " << obj->identifier << "(" << obj->id << ")" << ":" << identifier << "(" << id << ")" ;
|
||||
logGlobal->debugStream() << "Loaded object " << obj->identifier << "(" << obj->id << ")" << ":" << convertedId << "(" << id << ")" ;
|
||||
assert(!obj->subObjects.count(id)); // DO NOT override
|
||||
obj->subObjects[id] = handler;
|
||||
obj->subIds[identifier] = id;//todo: scope
|
||||
obj->subIds[convertedId] = id;
|
||||
}
|
||||
|
||||
CObjectClassesHandler::ObjectContainter * CObjectClassesHandler::loadFromJson(const JsonNode & json, const std::string & name)
|
||||
|
@ -143,7 +143,7 @@ const std::string & CGObjectInstance::getStringId() const
|
||||
if(stringId == "")
|
||||
{
|
||||
boost::format fmt("%s_%d");
|
||||
fmt % "object" % id.getNum();
|
||||
fmt % typeName % id.getNum();
|
||||
stringId = fmt.str();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user