mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
use JsonKey or NameTranslated instead of ambiguos Name
This commit is contained in:
parent
009705e794
commit
f51b3bca57
@ -340,7 +340,7 @@ void CMusicHandler::loadTerrainMusicThemes()
|
||||
{
|
||||
for (const auto & terrain : CGI->terrainTypeHandler->objects)
|
||||
{
|
||||
addEntryToSet("terrain_" + terrain->getName(), "Music/" + terrain->musicFilename);
|
||||
addEntryToSet("terrain_" + terrain->getJsonKey(), "Music/" + terrain->musicFilename);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
|
||||
{
|
||||
updateAmbientSounds();
|
||||
//We may need to change music - select new track, music handler will change it if needed
|
||||
CCS->musich->playMusicFromSet("terrain", LOCPLINT->cb->getTile(hero->visitablePos())->terType->getName(), true, false);
|
||||
CCS->musich->playMusicFromSet("terrain", LOCPLINT->cb->getTile(hero->visitablePos())->terType->getJsonKey(), true, false);
|
||||
|
||||
if(details.result == TryMoveHero::TELEPORTATION)
|
||||
{
|
||||
|
@ -137,7 +137,7 @@ BattleInterface::~BattleInterface()
|
||||
{
|
||||
//FIXME: this should be moved to adventureInt which should restore correct track based on selection/active player
|
||||
const auto * terrain = LOCPLINT->cb->getTile(adventureInt->selection->visitablePos())->terType;
|
||||
CCS->musich->playMusicFromSet("terrain", terrain->getName(), true, false);
|
||||
CCS->musich->playMusicFromSet("terrain", terrain->getJsonKey(), true, false);
|
||||
}
|
||||
|
||||
// may happen if user decided to close game while in battle
|
||||
|
@ -110,10 +110,10 @@ RandomMapTab::RandomMapTab():
|
||||
|
||||
for(auto road : VLC->roadTypeHandler->objects)
|
||||
{
|
||||
std::string cbRoadType = "selectRoad_" + road->getName();
|
||||
std::string cbRoadType = "selectRoad_" + road->getJsonKey();
|
||||
addCallback(cbRoadType, [&, road](bool on)
|
||||
{
|
||||
mapGenOptions->setRoadEnabled(road->getName(), on);
|
||||
mapGenOptions->setRoadEnabled(road->getJsonKey(), on);
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
}
|
||||
@ -285,9 +285,9 @@ void RandomMapTab::setMapGenOptions(std::shared_ptr<CMapGenOptions> opts)
|
||||
}
|
||||
for(auto r : VLC->roadTypeHandler->objects)
|
||||
{
|
||||
if(auto w = widget<CToggleButton>(r->getName()))
|
||||
if(auto w = widget<CToggleButton>(r->getJsonKey()))
|
||||
{
|
||||
w->setSelected(opts->isRoadEnabled(r->getName()));
|
||||
w->setSelected(opts->isRoadEnabled(r->getJsonKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,15 +177,15 @@ void CMapHandler::initTerrainGraphics()
|
||||
std::map<std::string, std::string> roadFiles;
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->objects)
|
||||
{
|
||||
terrainFiles[terrain->getName()] = terrain->tilesFilename;
|
||||
terrainFiles[terrain->getJsonKey()] = terrain->tilesFilename;
|
||||
}
|
||||
for(const auto & river : VLC->riverTypeHandler->objects)
|
||||
{
|
||||
riverFiles[river->tilesFilename] = river->tilesFilename;
|
||||
riverFiles[river->getJsonKey()] = river->tilesFilename;
|
||||
}
|
||||
for(const auto & road : VLC->roadTypeHandler->objects)
|
||||
{
|
||||
roadFiles[road->tilesFilename] = road->tilesFilename;
|
||||
roadFiles[road->getJsonKey()] = road->tilesFilename;
|
||||
}
|
||||
|
||||
loadFlipped(terrainAnimations, terrainImages, terrainFiles);
|
||||
@ -606,7 +606,7 @@ void CMapHandler::CMapBlitter::drawTileTerrain(SDL_Surface * targetSurf, const T
|
||||
ui8 rotation = tinfo.extTileFlags % 4;
|
||||
|
||||
//TODO: use ui8 instead of string key
|
||||
auto terrainName = tinfo.terType->getName();
|
||||
auto terrainName = tinfo.terType->getJsonKey();
|
||||
|
||||
if(parent->terrainImages[terrainName].size()<=tinfo.terView)
|
||||
return;
|
||||
@ -791,7 +791,7 @@ void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainT
|
||||
ui8 rotation = (tinfoUpper->extTileFlags >> 4) % 4;
|
||||
Rect source(0, tileSize / 2, tileSize, tileSize / 2);
|
||||
Rect dest(realPos.x, realPos.y, tileSize, tileSize / 2);
|
||||
drawElement(EMapCacheType::ROADS, parent->roadImages[tinfoUpper->roadType->tilesFilename][tinfoUpper->roadDir][rotation],
|
||||
drawElement(EMapCacheType::ROADS, parent->roadImages[tinfoUpper->roadType->getJsonKey()][tinfoUpper->roadDir][rotation],
|
||||
&source, targetSurf, &dest);
|
||||
}
|
||||
|
||||
@ -800,7 +800,7 @@ void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainT
|
||||
ui8 rotation = (tinfo.extTileFlags >> 4) % 4;
|
||||
Rect source(0, 0, tileSize, halfTileSizeCeil);
|
||||
Rect dest(realPos.x, realPos.y + tileSize / 2, tileSize, tileSize / 2);
|
||||
drawElement(EMapCacheType::ROADS, parent->roadImages[tinfo.roadType->tilesFilename][tinfo.roadDir][rotation],
|
||||
drawElement(EMapCacheType::ROADS, parent->roadImages[tinfo.roadType->getJsonKey()][tinfo.roadDir][rotation],
|
||||
&source, targetSurf, &dest);
|
||||
}
|
||||
}
|
||||
@ -809,7 +809,7 @@ void CMapHandler::CMapBlitter::drawRiver(SDL_Surface * targetSurf, const Terrain
|
||||
{
|
||||
Rect destRect(realTileRect);
|
||||
ui8 rotation = (tinfo.extTileFlags >> 2) % 4;
|
||||
drawElement(EMapCacheType::RIVERS, parent->riverImages[tinfo.riverType->tilesFilename][tinfo.riverDir][rotation], nullptr, targetSurf, &destRect);
|
||||
drawElement(EMapCacheType::RIVERS, parent->riverImages[tinfo.riverType->getJsonKey()][tinfo.riverDir][rotation], nullptr, targetSurf, &destRect);
|
||||
}
|
||||
|
||||
void CMapHandler::CMapBlitter::drawFow(SDL_Surface * targetSurf) const
|
||||
|
@ -1414,7 +1414,7 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView)
|
||||
auto pos = sel->visitablePos();
|
||||
auto tile = LOCPLINT->cb->getTile(pos);
|
||||
if(tile)
|
||||
CCS->musich->playMusicFromSet("terrain", tile->terType->getName(), true, false);
|
||||
CCS->musich->playMusicFromSet("terrain", tile->terType->getJsonKey(), true, false);
|
||||
}
|
||||
if(centerView)
|
||||
centerOn(sel);
|
||||
|
@ -2136,7 +2136,7 @@ int CreatureTerrainLimiter::limit(const BonusLimitationContext &context) const
|
||||
std::string CreatureTerrainLimiter::toString() const
|
||||
{
|
||||
boost::format fmt("CreatureTerrainLimiter(terrainType=%s)");
|
||||
auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->getName();
|
||||
auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->getJsonKey();
|
||||
fmt % (terrainType == ETerrainId::NATIVE_TERRAIN ? "native" : terrainName);
|
||||
return fmt.str();
|
||||
}
|
||||
@ -2146,7 +2146,7 @@ JsonNode CreatureTerrainLimiter::toJsonNode() const
|
||||
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
|
||||
|
||||
root["type"].String() = "CREATURE_TERRAIN_LIMITER";
|
||||
auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->getName();
|
||||
auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->getJsonKey();
|
||||
root["parameters"].Vector().push_back(JsonUtils::stringNode(terrainName));
|
||||
|
||||
return root;
|
||||
|
@ -27,10 +27,10 @@ class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
|
||||
TerrainId id;
|
||||
ui8 passabilityType;
|
||||
|
||||
const std::string & getName() const override { return identifier;}
|
||||
public:
|
||||
int32_t getIndex() const override { return id.getNum(); }
|
||||
int32_t getIconIndex() const override { return 0; }
|
||||
const std::string & getName() const override { return identifier;}
|
||||
const std::string & getJsonKey() const override { return identifier;}
|
||||
void registerIcons(const IconRegistar & cb) const override {}
|
||||
TerrainId getId() const override { return id;}
|
||||
@ -104,10 +104,10 @@ class DLL_LINKAGE RiverType : public EntityT<RiverId>
|
||||
std::string identifier;
|
||||
RiverId id;
|
||||
|
||||
const std::string & getName() const override { return identifier;}
|
||||
public:
|
||||
int32_t getIndex() const override { return id.getNum(); }
|
||||
int32_t getIconIndex() const override { return 0; }
|
||||
const std::string & getName() const override { return identifier;}
|
||||
const std::string & getJsonKey() const override { return identifier;}
|
||||
void registerIcons(const IconRegistar & cb) const override {}
|
||||
RiverId getId() const override { return id;}
|
||||
@ -136,10 +136,10 @@ class DLL_LINKAGE RoadType : public EntityT<RoadId>
|
||||
std::string identifier;
|
||||
RoadId id;
|
||||
|
||||
const std::string & getName() const override { return identifier;}
|
||||
public:
|
||||
int32_t getIndex() const override { return id.getNum(); }
|
||||
int32_t getIconIndex() const override { return 0; }
|
||||
const std::string & getName() const override { return identifier;}
|
||||
const std::string & getJsonKey() const override { return identifier;}
|
||||
void registerIcons(const IconRegistar & cb) const override {}
|
||||
RoadId getId() const override { return id;}
|
||||
|
@ -213,7 +213,7 @@ void CGObjectInstance::setType(si32 ID, si32 subID)
|
||||
}
|
||||
else
|
||||
{
|
||||
logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", ID, subID, visitablePos().toString(), tile.terType->getName());
|
||||
logGlobal->warn("Object %d:%d at %s has no templates suitable for terrain %s", ID, subID, visitablePos().toString(), tile.terType->getNameTranslated());
|
||||
appearance = handler->getTemplates()[0]; // get at least some appearance since alternative is crash
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
|
||||
for(auto type : allowedTerrains)
|
||||
{
|
||||
JsonNode value(JsonNode::JsonType::DATA_STRING);
|
||||
value.String() = VLC->terrainTypeHandler->getById(type)->getName();
|
||||
value.String() = VLC->terrainTypeHandler->getById(type)->getJsonKey();
|
||||
data.push_back(value);
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
|
||||
static std::string encode(const si32 index)
|
||||
{
|
||||
return VLC->terrainTypeHandler->getByIndex(index)->getName();
|
||||
return VLC->terrainTypeHandler->getByIndex(index)->getJsonKey();
|
||||
}
|
||||
};
|
||||
|
||||
@ -365,7 +365,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
||||
for(auto & ttype : terrainTypes)
|
||||
{
|
||||
JsonNode n;
|
||||
n.String() = VLC->terrainTypeHandler->getById(ttype)->getName();
|
||||
n.String() = VLC->terrainTypeHandler->getById(ttype)->getJsonKey();
|
||||
node.Vector().push_back(n);
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ void Object::Instance::setTemplate(TerrainId terrain)
|
||||
auto templates = VLC->objtypeh->getHandlerFor(dObject.ID, dObject.subID)->getTemplates(terrain);
|
||||
if (templates.empty())
|
||||
{
|
||||
auto terrainName = VLC->terrainTypeHandler->getById(terrain)->getName();
|
||||
auto terrainName = VLC->terrainTypeHandler->getById(terrain)->getNameTranslated();
|
||||
throw rmgException(boost::to_string(boost::format("Did not find graphics for object (%d,%d) at %s") % dObject.ID % dObject.subID % terrainName));
|
||||
}
|
||||
dObject.appearance = templates.front();
|
||||
|
@ -545,12 +545,12 @@ void MainWindow::loadObjectsTree()
|
||||
//adding terrains
|
||||
for(auto & terrain : VLC->terrainTypeHandler->objects)
|
||||
{
|
||||
QPushButton *b = new QPushButton(QString::fromStdString(terrain->getName()));
|
||||
QPushButton *b = new QPushButton(QString::fromStdString(terrain->getNameTranslated()));
|
||||
ui->terrainLayout->addWidget(b);
|
||||
connect(b, &QPushButton::clicked, this, [this, terrain]{ terrainButtonClicked(terrain->getId()); });
|
||||
|
||||
//filter
|
||||
ui->terrainFilterCombo->addItem(QString::fromStdString(terrain->getName()));
|
||||
ui->terrainFilterCombo->addItem(QString::fromStdString(terrain->getNameTranslated()));
|
||||
}
|
||||
//add spacer to keep terrain button on the top
|
||||
ui->terrainLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||
@ -919,7 +919,7 @@ void MainWindow::on_terrainFilterCombo_currentTextChanged(const QString &arg1)
|
||||
if (!arg1.isEmpty())
|
||||
{
|
||||
for (auto const & terrain : VLC->terrainTypeHandler->objects)
|
||||
if (terrain->getName() == arg1.toStdString())
|
||||
if (terrain->getJsonKey() == arg1.toStdString())
|
||||
objectBrowser->terrain = terrain->getId();
|
||||
}
|
||||
objectBrowser->invalidate();
|
||||
|
@ -80,15 +80,15 @@ void MapHandler::initTerrainGraphics()
|
||||
std::map<std::string, std::string> riverFiles;
|
||||
for(const auto & terrain : VLC->terrainTypeHandler->objects)
|
||||
{
|
||||
terrainFiles[terrain->getName()] = terrain->tilesFilename;
|
||||
terrainFiles[terrain->getJsonKey()] = terrain->tilesFilename;
|
||||
}
|
||||
for(const auto & river : VLC->riverTypeHandler->objects)
|
||||
{
|
||||
riverFiles[river->tilesFilename] = river->tilesFilename;
|
||||
riverFiles[river->getJsonKey()] = river->tilesFilename;
|
||||
}
|
||||
for(const auto & road : VLC->roadTypeHandler->objects)
|
||||
{
|
||||
roadFiles[road->tilesFilename] = road->tilesFilename;
|
||||
roadFiles[road->getJsonKey()] = road->tilesFilename;
|
||||
}
|
||||
|
||||
loadFlipped(terrainAnimations, terrainImages, terrainFiles);
|
||||
@ -101,7 +101,7 @@ void MapHandler::drawTerrainTile(QPainter & painter, int x, int y, int z)
|
||||
auto & tinfo = map->getTile(int3(x, y, z));
|
||||
ui8 rotation = tinfo.extTileFlags % 4;
|
||||
|
||||
auto terrainName = tinfo.terType->getName();
|
||||
auto terrainName = tinfo.terType->getJsonKey();
|
||||
|
||||
if(terrainImages.at(terrainName).size() <= tinfo.terView)
|
||||
return;
|
||||
@ -117,7 +117,7 @@ void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
|
||||
|
||||
if(tinfoUpper && tinfoUpper->roadType->getId() != Road::NO_ROAD)
|
||||
{
|
||||
auto roadName = tinfoUpper->roadType->tilesFilename;
|
||||
auto roadName = tinfoUpper->roadType->getJsonKey();
|
||||
QRect source(0, tileSize / 2, tileSize, tileSize / 2);
|
||||
ui8 rotation = (tinfoUpper->extTileFlags >> 4) % 4;
|
||||
bool hflip = (rotation == 1 || rotation == 3), vflip = (rotation == 2 || rotation == 3);
|
||||
@ -129,7 +129,7 @@ void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
|
||||
|
||||
if(tinfo.roadType->getId() != Road::NO_ROAD) //print road from this tile
|
||||
{
|
||||
auto roadName = tinfo.roadType->tilesFilename;
|
||||
auto roadName = tinfo.roadType->getJsonKey();;
|
||||
QRect source(0, 0, tileSize, tileSize / 2);
|
||||
ui8 rotation = (tinfo.extTileFlags >> 4) % 4;
|
||||
bool hflip = (rotation == 1 || rotation == 3), vflip = (rotation == 2 || rotation == 3);
|
||||
@ -148,7 +148,7 @@ void MapHandler::drawRiver(QPainter & painter, int x, int y, int z)
|
||||
return;
|
||||
|
||||
//TODO: use ui8 instead of string key
|
||||
auto riverName = tinfo.riverType->tilesFilename;
|
||||
auto riverName = tinfo.riverType->getJsonKey();
|
||||
|
||||
if(riverImages.at(riverName).size() <= tinfo.riverDir)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user