1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Names for object supertypes are passed through translator

This commit is contained in:
Ivan Savenko
2022-12-30 19:18:31 +02:00
parent 25ef065dbe
commit c5f72ccdc7
3 changed files with 40 additions and 12 deletions

View File

@@ -160,6 +160,7 @@ class DLL_LINKAGE CGeneralTextHandler
/// Attempts to detect encoding & language of H3 files
void detectInstallParameters() const;
public:
/// Loads translation from provided json
/// Any entries loaded by this will have priority over texts registered normally
void loadTranslationOverrides(JsonNode const & file);

View File

@@ -177,7 +177,7 @@ void CObjectClassesHandler::loadObjectEntry(const std::string & identifier, cons
auto handler = handlerConstructors.at(obj->handlerName)();
handler->setType(obj->id, id);
handler->setTypeName(obj->identifier, convertedId);
handler->setTypeName(obj->getIdentifier(), convertedId);
if (customNames.count(obj->id) && customNames.at(obj->id).size() > id)
handler->init(entry, customNames.at(obj->id).at(id));
@@ -194,7 +194,7 @@ void CObjectClassesHandler::loadObjectEntry(const std::string & identifier, cons
legacyTemplates.erase(range.first, range.second);
}
logGlobal->debug("Loaded object %s(%d)::%s(%d)", obj->identifier, obj->id, convertedId, id);
logGlobal->debug("Loaded object %s(%d)::%s(%d)", obj->getIdentifier(), obj->id, convertedId, id);
//some mods redefine content handlers in the decoration.json in such way:
//"core:sign" : { "types" : { "forgeSign" : { ...
@@ -219,22 +219,37 @@ void CObjectClassesHandler::loadObjectEntry(const std::string & identifier, cons
else if(isExistingKey) //It's supposed that fan mods handlers are not overridden by default handlers
{
logGlobal->trace("Handler '%s' has not been overridden with handler '%s' in object %s(%d)::%s(%d)",
obj->subObjects[id]->subTypeName, obj->handlerName, obj->identifier, obj->id, convertedId, id);
obj->subObjects[id]->subTypeName, obj->handlerName, obj->getIdentifier(), obj->id, convertedId, id);
}
else
{
logGlobal->warn("Handler '%s' for object %s(%d)::%s(%d) has not been activated as RMG breaker",
obj->handlerName, obj->identifier, obj->id, convertedId, id);
obj->handlerName, obj->getIdentifier(), obj->id, convertedId, id);
}
}
std::string CObjectClassesHandler::ObjectContainter::getIdentifier() const
{
return modScope + ":" + identifier;
}
std::string CObjectClassesHandler::ObjectContainter::getNameTextID() const
{
return TextIdentifier ("object", modScope, identifier, "name").get();
}
std::string CObjectClassesHandler::ObjectContainter::getNameTranslated() const
{
return VLC->generaltexth->translate(getNameTextID());
}
CObjectClassesHandler::ObjectContainter * CObjectClassesHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name)
{
auto obj = new ObjectContainter();
auto obj = new ObjectContainter(scope, name);
static const si32 fixedObjectsBound = 256; //Legacy value for backward compatibility
obj->identifier = name;
obj->name = json["name"].String();
VLC->generaltexth->registerString( obj->getNameTextID(), json["name"].String());
obj->handlerName = json["handler"].String();
obj->base = json["base"];
obj->id = selectNextID(json["index"], objects, fixedObjectsBound);
@@ -387,7 +402,7 @@ void CObjectClassesHandler::afterLoadFinalization()
std::string CObjectClassesHandler::getObjectName(si32 type) const
{
if (objects.count(type))
return objects.at(type)->name;
return objects.at(type)->getNameTranslated();
logGlobal->error("Access to non existing object of type %d", type);
return "";
}

View File

@@ -234,11 +234,19 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
{
/// Small internal structure that contains information on specific group of objects
/// (creating separate entity is overcomplicating at least at this point)
struct ObjectContainter
class DLL_LINKAGE ObjectContainter
{
si32 id;
std::string identifier;
std::string name; // human-readable name
std::string modScope;
public:
ObjectContainter() = default;
ObjectContainter(const std::string & modScope, const std::string & identifier):
identifier(identifier),
modScope(modScope)
{}
si32 id;
std::string handlerName; // ID of handler that controls this object, should be determined using handlerConstructor map
JsonNode base;
@@ -249,13 +257,17 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
boost::optional<si32> groupDefaultAiValue;
std::string getIdentifier() const;
std::string getNameTextID() const; // {scope, "objects", name, "name"}
std::string getNameTranslated() const;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & name;
h & handlerName;
h & base;
h & subObjects;
h & identifier;
h & modScope;
h & subIds;
h & sounds;
h & groupDefaultAiValue;