mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
replace RESOURCE_NAMES where possible
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include "../AIGateway.h"
|
#include "../AIGateway.h"
|
||||||
#include "../../../lib/constants/StringConstants.h"
|
#include "../../../lib/constants/StringConstants.h"
|
||||||
#include "../../../lib/entities/artifact/CArtifact.h"
|
#include "../../../lib/entities/artifact/CArtifact.h"
|
||||||
|
#include "../../../lib/entities/ResourceTypeHandler.h"
|
||||||
|
|
||||||
namespace NKAI
|
namespace NKAI
|
||||||
{
|
{
|
||||||
@@ -43,13 +44,13 @@ std::string AbstractGoal::toString() const
|
|||||||
switch(goalType)
|
switch(goalType)
|
||||||
{
|
{
|
||||||
case COLLECT_RES:
|
case COLLECT_RES:
|
||||||
desc = "COLLECT RESOURCE " + GameConstants::RESOURCE_NAMES[resID] + " (" + std::to_string(value) + ")";
|
desc = "COLLECT RESOURCE " + LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey() + " (" + std::to_string(value) + ")";
|
||||||
break;
|
break;
|
||||||
case TRADE:
|
case TRADE:
|
||||||
{
|
{
|
||||||
auto obj = cb->getObjInstance(ObjectInstanceID(objid));
|
auto obj = cb->getObjInstance(ObjectInstanceID(objid));
|
||||||
if (obj)
|
if (obj)
|
||||||
desc = (boost::format("TRADE %d of %s at %s") % value % GameConstants::RESOURCE_NAMES[resID] % obj->getObjectName()).str();
|
desc = (boost::format("TRADE %d of %s at %s") % value % LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey() % obj->getObjectName()).str();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GATHER_TROOPS:
|
case GATHER_TROOPS:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "../BuildingManager.h"
|
#include "../BuildingManager.h"
|
||||||
#include "../../../lib/constants/StringConstants.h"
|
#include "../../../lib/constants/StringConstants.h"
|
||||||
#include "../../../lib/entities/artifact/CArtifact.h"
|
#include "../../../lib/entities/artifact/CArtifact.h"
|
||||||
|
#include "../../../lib/entities/ResourceTypeHandler.h"
|
||||||
|
|
||||||
using namespace Goals;
|
using namespace Goals;
|
||||||
|
|
||||||
@@ -56,13 +57,13 @@ std::string AbstractGoal::name() const //TODO: virtualize
|
|||||||
case BUILD_STRUCTURE:
|
case BUILD_STRUCTURE:
|
||||||
return "BUILD STRUCTURE";
|
return "BUILD STRUCTURE";
|
||||||
case COLLECT_RES:
|
case COLLECT_RES:
|
||||||
desc = "COLLECT RESOURCE " + GameConstants::RESOURCE_NAMES[resID] + " (" + std::to_string(value) + ")";
|
desc = "COLLECT RESOURCE " + LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey() + " (" + std::to_string(value) + ")";
|
||||||
break;
|
break;
|
||||||
case TRADE:
|
case TRADE:
|
||||||
{
|
{
|
||||||
auto obj = cb->getObjInstance(ObjectInstanceID(objid));
|
auto obj = cb->getObjInstance(ObjectInstanceID(objid));
|
||||||
if (obj)
|
if (obj)
|
||||||
desc = (boost::format("TRADE %d of %s at %s") % value % GameConstants::RESOURCE_NAMES[resID] % obj->getObjectName()).str();
|
desc = (boost::format("TRADE %d of %s at %s") % value % LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey() % obj->getObjectName()).str();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GATHER_TROOPS:
|
case GATHER_TROOPS:
|
||||||
|
|||||||
@@ -30,10 +30,12 @@
|
|||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../PlayerLocalState.h"
|
#include "../PlayerLocalState.h"
|
||||||
|
|
||||||
|
#include "../../lib/GameLibrary.h"
|
||||||
#include "../../lib/callback/CCallback.h"
|
#include "../../lib/callback/CCallback.h"
|
||||||
#include "../../lib/constants/StringConstants.h"
|
#include "../../lib/constants/StringConstants.h"
|
||||||
#include "../../lib/mapping/CMapHeader.h"
|
#include "../../lib/mapping/CMapHeader.h"
|
||||||
#include "../../lib/filesystem/ResourcePath.h"
|
#include "../../lib/filesystem/ResourcePath.h"
|
||||||
|
#include "../../lib/entities/ResourceTypeHandler.h"
|
||||||
|
|
||||||
AdventureMapWidget::AdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> shortcuts )
|
AdventureMapWidget::AdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> shortcuts )
|
||||||
: shortcuts(shortcuts)
|
: shortcuts(shortcuts)
|
||||||
@@ -286,7 +288,7 @@ std::shared_ptr<CIntObject> AdventureMapWidget::buildResourceDateBar(const JsonN
|
|||||||
|
|
||||||
for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY; i++)
|
for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY; i++)
|
||||||
{
|
{
|
||||||
const auto & node = input[GameConstants::RESOURCE_NAMES[i]];
|
const auto & node = input[LIBRARY->resourceTypeHandler->getById(i)->getJsonKey()];
|
||||||
|
|
||||||
if(node.isNull())
|
if(node.isNull())
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ ResourceSet::ResourceSet() = default;
|
|||||||
ResourceSet::ResourceSet(const JsonNode & node)
|
ResourceSet::ResourceSet(const JsonNode & node)
|
||||||
{
|
{
|
||||||
for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY; i++)
|
for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY; i++)
|
||||||
container[i] = static_cast<int>(node[GameConstants::RESOURCE_NAMES[i]].Float());
|
container[i] = static_cast<int>(node[LIBRARY->resourceTypeHandler->getById(i)->getJsonKey()].Float());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName)
|
void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName)
|
||||||
@@ -34,7 +34,7 @@ void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string
|
|||||||
|
|
||||||
//TODO: add proper support for mithril to map format
|
//TODO: add proper support for mithril to map format
|
||||||
for(int idx = 0; idx < GameConstants::RESOURCE_QUANTITY - 1; idx ++)
|
for(int idx = 0; idx < GameConstants::RESOURCE_QUANTITY - 1; idx ++)
|
||||||
handler.serializeInt(GameConstants::RESOURCE_NAMES[idx], this->operator[](idx), 0);
|
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), this->operator[](idx), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResourceSet::nonZero() const
|
bool ResourceSet::nonZero() const
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "entities/faction/CFaction.h"
|
#include "entities/faction/CFaction.h"
|
||||||
#include "entities/hero/CHero.h"
|
#include "entities/hero/CHero.h"
|
||||||
#include "entities/hero/CHeroClass.h"
|
#include "entities/hero/CHeroClass.h"
|
||||||
|
#include "entities/ResourceTypeHandler.h"
|
||||||
#include "mapObjectConstructors/AObjectTypeHandler.h"
|
#include "mapObjectConstructors/AObjectTypeHandler.h"
|
||||||
#include "constants/StringConstants.h"
|
#include "constants/StringConstants.h"
|
||||||
#include "texts/CGeneralTextHandler.h"
|
#include "texts/CGeneralTextHandler.h"
|
||||||
@@ -628,7 +629,7 @@ si32 GameResID::decode(const std::string & identifier)
|
|||||||
|
|
||||||
std::string GameResID::encode(const si32 index)
|
std::string GameResID::encode(const si32 index)
|
||||||
{
|
{
|
||||||
return GameConstants::RESOURCE_NAMES[index];
|
return LIBRARY->resourceTypeHandler->getById(index)->getJsonKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
si32 BuildingTypeUniqueID::decode(const std::string & identifier)
|
si32 BuildingTypeUniqueID::decode(const std::string & identifier)
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ void StatisticDataSetEntry::serializeJson(JsonSerializeFormat & handler)
|
|||||||
{
|
{
|
||||||
auto zonesData = handler.enterStruct("numMines");
|
auto zonesData = handler.enterStruct("numMines");
|
||||||
for(TResource idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
for(TResource idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
||||||
handler.serializeInt(GameConstants::RESOURCE_NAMES[idx], numMines[idx], 0);
|
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), numMines[idx], 0);
|
||||||
}
|
}
|
||||||
handler.serializeInt("score", score);
|
handler.serializeInt("score", score);
|
||||||
handler.serializeInt("maxHeroLevel", maxHeroLevel);
|
handler.serializeInt("maxHeroLevel", maxHeroLevel);
|
||||||
@@ -192,15 +192,15 @@ std::string StatisticDataSet::toCsv(std::string sep) const
|
|||||||
ss << "EventDefeatedStrongestHero" << sep;
|
ss << "EventDefeatedStrongestHero" << sep;
|
||||||
ss << "MovementPointsUsed";
|
ss << "MovementPointsUsed";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << GameConstants::RESOURCE_NAMES[resource];
|
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey();
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << GameConstants::RESOURCE_NAMES[resource] + "Mines";
|
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey() + "Mines";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << GameConstants::RESOURCE_NAMES[resource] + "SpentResourcesForArmy";
|
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey() + "SpentResourcesForArmy";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << GameConstants::RESOURCE_NAMES[resource] + "SpentResourcesForBuildings";
|
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey() + "SpentResourcesForBuildings";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << GameConstants::RESOURCE_NAMES[resource] + "TradeVolume";
|
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey() + "TradeVolume";
|
||||||
ss << "\r\n";
|
ss << "\r\n";
|
||||||
|
|
||||||
for(auto & entry : data)
|
for(auto & entry : data)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "../entities/artifact/CArtHandler.h"
|
#include "../entities/artifact/CArtHandler.h"
|
||||||
#include "../entities/hero/CHero.h"
|
#include "../entities/hero/CHero.h"
|
||||||
#include "../entities/hero/CHeroClass.h"
|
#include "../entities/hero/CHeroClass.h"
|
||||||
|
#include "../entities/ResourceTypeHandler.h"
|
||||||
#include "../gameState/CGameState.h"
|
#include "../gameState/CGameState.h"
|
||||||
#include "../mapObjects/army/CStackBasicDescriptor.h"
|
#include "../mapObjects/army/CStackBasicDescriptor.h"
|
||||||
#include "../mapObjects/IObjectInterface.h"
|
#include "../mapObjects/IObjectInterface.h"
|
||||||
@@ -300,7 +301,7 @@ JsonRandom::JsonRandom(IGameInfoCallback * cb, IGameRandomizer & gameRandomizer)
|
|||||||
|
|
||||||
for (size_t i=0; i<GameConstants::RESOURCE_QUANTITY; i++)
|
for (size_t i=0; i<GameConstants::RESOURCE_QUANTITY; i++)
|
||||||
{
|
{
|
||||||
ret[i] = loadValue(value[GameConstants::RESOURCE_NAMES[i]], variables);
|
ret[i] = loadValue(value[LIBRARY->resourceTypeHandler->getById(i)->getJsonKey()], variables);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ void CQuest::serializeJson(JsonSerializeFormat & handler, const std::string & fi
|
|||||||
|
|
||||||
for(size_t idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
for(size_t idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
||||||
{
|
{
|
||||||
handler.serializeInt(GameConstants::RESOURCE_NAMES[idx], mission.resources[idx], 0);
|
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), mission.resources[idx], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
|||||||
{
|
{
|
||||||
JsonNode node;
|
JsonNode node;
|
||||||
for(const auto & resID : abandonedMineResources)
|
for(const auto & resID : abandonedMineResources)
|
||||||
node.Vector().emplace_back(GameConstants::RESOURCE_NAMES[resID.getNum()]);
|
node.Vector().emplace_back(LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey());
|
||||||
|
|
||||||
handler.serializeRaw("possibleResources", node, std::nullopt);
|
handler.serializeRaw("possibleResources", node, std::nullopt);
|
||||||
}
|
}
|
||||||
@@ -252,7 +252,10 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
|||||||
|
|
||||||
for(const std::string & s : names)
|
for(const std::string & s : names)
|
||||||
{
|
{
|
||||||
int raw_res = vstd::find_pos(GameConstants::RESOURCE_NAMES, s);
|
std::vector<std::string> resNames;
|
||||||
|
for(auto & res : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
|
resNames.push_back(LIBRARY->resourceTypeHandler->getById(res)->getJsonKey());
|
||||||
|
int raw_res = vstd::find_pos(resNames, s);
|
||||||
if(raw_res < 0)
|
if(raw_res < 0)
|
||||||
logGlobal->error("Invalid resource name: %s", s);
|
logGlobal->error("Invalid resource name: %s", s);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -243,28 +243,29 @@ void ContentTypeHandler::afterLoadFinalization()
|
|||||||
|
|
||||||
void CContentHandler::init()
|
void CContentHandler::init()
|
||||||
{
|
{
|
||||||
handlers.insert(std::make_pair("heroClasses", ContentTypeHandler(LIBRARY->heroclassesh.get(), "heroClass")));
|
handlers.push_back(std::make_pair("resources", ContentTypeHandler(LIBRARY->resourceTypeHandler.get(), "resources"))); // needs to loaded first because needed by other handlers
|
||||||
handlers.insert(std::make_pair("artifacts", ContentTypeHandler(LIBRARY->arth.get(), "artifact")));
|
|
||||||
handlers.insert(std::make_pair("bonuses", ContentTypeHandler(LIBRARY->bth.get(), "bonus")));
|
handlers.push_back(std::make_pair("heroClasses", ContentTypeHandler(LIBRARY->heroclassesh.get(), "heroClass")));
|
||||||
handlers.insert(std::make_pair("creatures", ContentTypeHandler(LIBRARY->creh.get(), "creature")));
|
handlers.push_back(std::make_pair("artifacts", ContentTypeHandler(LIBRARY->arth.get(), "artifact")));
|
||||||
handlers.insert(std::make_pair("campaignRegions", ContentTypeHandler(LIBRARY->campaignRegions.get(), "campaignRegion")));
|
handlers.push_back(std::make_pair("bonuses", ContentTypeHandler(LIBRARY->bth.get(), "bonus")));
|
||||||
handlers.insert(std::make_pair("factions", ContentTypeHandler(LIBRARY->townh.get(), "faction")));
|
handlers.push_back(std::make_pair("creatures", ContentTypeHandler(LIBRARY->creh.get(), "creature")));
|
||||||
handlers.insert(std::make_pair("objects", ContentTypeHandler(LIBRARY->objtypeh.get(), "object")));
|
handlers.push_back(std::make_pair("campaignRegions", ContentTypeHandler(LIBRARY->campaignRegions.get(), "campaignRegion")));
|
||||||
handlers.insert(std::make_pair("heroes", ContentTypeHandler(LIBRARY->heroh.get(), "hero")));
|
handlers.push_back(std::make_pair("factions", ContentTypeHandler(LIBRARY->townh.get(), "faction")));
|
||||||
handlers.insert(std::make_pair("spells", ContentTypeHandler(LIBRARY->spellh.get(), "spell")));
|
handlers.push_back(std::make_pair("objects", ContentTypeHandler(LIBRARY->objtypeh.get(), "object")));
|
||||||
handlers.insert(std::make_pair("spellSchools", ContentTypeHandler(LIBRARY->spellSchoolHandler.get(), "spellSchool")));
|
handlers.push_back(std::make_pair("heroes", ContentTypeHandler(LIBRARY->heroh.get(), "hero")));
|
||||||
handlers.insert(std::make_pair("skills", ContentTypeHandler(LIBRARY->skillh.get(), "skill")));
|
handlers.push_back(std::make_pair("spells", ContentTypeHandler(LIBRARY->spellh.get(), "spell")));
|
||||||
handlers.insert(std::make_pair("templates", ContentTypeHandler(LIBRARY->tplh.get(), "template")));
|
handlers.push_back(std::make_pair("spellSchools", ContentTypeHandler(LIBRARY->spellSchoolHandler.get(), "spellSchool")));
|
||||||
|
handlers.push_back(std::make_pair("skills", ContentTypeHandler(LIBRARY->skillh.get(), "skill")));
|
||||||
|
handlers.push_back(std::make_pair("templates", ContentTypeHandler(LIBRARY->tplh.get(), "template")));
|
||||||
#if SCRIPTING_ENABLED
|
#if SCRIPTING_ENABLED
|
||||||
handlers.insert(std::make_pair("scripts", ContentTypeHandler(LIBRARY->scriptHandler.get(), "script")));
|
handlers.push_back(std::make_pair("scripts", ContentTypeHandler(LIBRARY->scriptHandler.get(), "script")));
|
||||||
#endif
|
#endif
|
||||||
handlers.insert(std::make_pair("battlefields", ContentTypeHandler(LIBRARY->battlefieldsHandler.get(), "battlefield")));
|
handlers.push_back(std::make_pair("battlefields", ContentTypeHandler(LIBRARY->battlefieldsHandler.get(), "battlefield")));
|
||||||
handlers.insert(std::make_pair("terrains", ContentTypeHandler(LIBRARY->terrainTypeHandler.get(), "terrain")));
|
handlers.push_back(std::make_pair("terrains", ContentTypeHandler(LIBRARY->terrainTypeHandler.get(), "terrain")));
|
||||||
handlers.insert(std::make_pair("resources", ContentTypeHandler(LIBRARY->resourceTypeHandler.get(), "resources")));
|
handlers.push_back(std::make_pair("rivers", ContentTypeHandler(LIBRARY->riverTypeHandler.get(), "river")));
|
||||||
handlers.insert(std::make_pair("rivers", ContentTypeHandler(LIBRARY->riverTypeHandler.get(), "river")));
|
handlers.push_back(std::make_pair("roads", ContentTypeHandler(LIBRARY->roadTypeHandler.get(), "road")));
|
||||||
handlers.insert(std::make_pair("roads", ContentTypeHandler(LIBRARY->roadTypeHandler.get(), "road")));
|
handlers.push_back(std::make_pair("obstacles", ContentTypeHandler(LIBRARY->obstacleHandler.get(), "obstacle")));
|
||||||
handlers.insert(std::make_pair("obstacles", ContentTypeHandler(LIBRARY->obstacleHandler.get(), "obstacle")));
|
handlers.push_back(std::make_pair("biomes", ContentTypeHandler(LIBRARY->biomeHandler.get(), "biome")));
|
||||||
handlers.insert(std::make_pair("biomes", ContentTypeHandler(LIBRARY->biomeHandler.get(), "biome")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CContentHandler::preloadData(const ModDescription & mod, bool validate)
|
bool CContentHandler::preloadData(const ModDescription & mod, bool validate)
|
||||||
@@ -309,7 +310,15 @@ void CContentHandler::afterLoadFinalization()
|
|||||||
|
|
||||||
const ContentTypeHandler & CContentHandler::operator[](const std::string & name) const
|
const ContentTypeHandler & CContentHandler::operator[](const std::string & name) const
|
||||||
{
|
{
|
||||||
return handlers.at(name);
|
auto it = std::find_if(handlers.begin(), handlers.end(), [&name](const auto& pair)
|
||||||
|
{
|
||||||
|
return pair.first == name;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it != handlers.end()) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
throw std::out_of_range("Handler not found for name: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
/// class used to load all game data into handlers. Used only during loading
|
/// class used to load all game data into handlers. Used only during loading
|
||||||
class DLL_LINKAGE CContentHandler
|
class DLL_LINKAGE CContentHandler
|
||||||
{
|
{
|
||||||
std::map<std::string, ContentTypeHandler> handlers;
|
std::vector<std::pair<std::string, ContentTypeHandler>> handlers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "../GameLibrary.h"
|
#include "../GameLibrary.h"
|
||||||
#include "../constants/StringConstants.h"
|
#include "../constants/StringConstants.h"
|
||||||
#include "../entities/faction/CTownHandler.h"
|
#include "../entities/faction/CTownHandler.h"
|
||||||
|
#include "../entities/ResourceTypeHandler.h"
|
||||||
#include "../modding/ModScope.h"
|
#include "../modding/ModScope.h"
|
||||||
#include "../serializer/JsonSerializeFormat.h"
|
#include "../serializer/JsonSerializeFormat.h"
|
||||||
|
|
||||||
@@ -536,7 +537,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
|||||||
|
|
||||||
for(TResource idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
for(TResource idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
||||||
{
|
{
|
||||||
handler.serializeInt(GameConstants::RESOURCE_NAMES[idx], mines[idx], 0);
|
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), mines[idx], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
#include "../../lib/entities/faction/CTownHandler.h"
|
#include "../../lib/entities/faction/CTownHandler.h"
|
||||||
#include "../../lib/constants/NumericConstants.h"
|
#include "../../lib/constants/NumericConstants.h"
|
||||||
#include "../../lib/constants/StringConstants.h"
|
#include "../../lib/constants/StringConstants.h"
|
||||||
|
#include "../../lib/GameLibrary.h"
|
||||||
|
#include "../../lib/entities/ResourceTypeHandler.h"
|
||||||
|
|
||||||
static const int FIRST_DAY_FOR_EVENT = 1;
|
static const int FIRST_DAY_FOR_EVENT = 1;
|
||||||
static const int LAST_DAY_FOR_EVENT = 999;
|
static const int LAST_DAY_FOR_EVENT = 999;
|
||||||
@@ -91,7 +93,7 @@ void TownEventDialog::initResources()
|
|||||||
item->setText(name);
|
item->setText(name);
|
||||||
ui->resourcesTable->setItem(i, 0, item);
|
ui->resourcesTable->setItem(i, 0, item);
|
||||||
|
|
||||||
int val = resourcesMap.value(QString::fromStdString(GameConstants::RESOURCE_NAMES[i])).toInt();
|
int val = resourcesMap.value(QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey())).toInt();
|
||||||
auto * edit = new QSpinBox(ui->resourcesTable);
|
auto * edit = new QSpinBox(ui->resourcesTable);
|
||||||
edit->setMaximum(i == GameResID::GOLD ? MAXIMUM_GOLD_CHANGE : MAXIMUM_RESOURCE_CHANGE);
|
edit->setMaximum(i == GameResID::GOLD ? MAXIMUM_GOLD_CHANGE : MAXIMUM_RESOURCE_CHANGE);
|
||||||
edit->setMinimum(i == GameResID::GOLD ? -MAXIMUM_GOLD_CHANGE : -MAXIMUM_RESOURCE_CHANGE);
|
edit->setMinimum(i == GameResID::GOLD ? -MAXIMUM_GOLD_CHANGE : -MAXIMUM_RESOURCE_CHANGE);
|
||||||
@@ -230,7 +232,7 @@ QVariantMap TownEventDialog::resourcesToVariant()
|
|||||||
auto res = params.value("resources").toMap();
|
auto res = params.value("resources").toMap();
|
||||||
for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
||||||
{
|
{
|
||||||
auto itemType = QString::fromStdString(GameConstants::RESOURCE_NAMES[i]);
|
auto itemType = QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey());
|
||||||
auto * itemQty = static_cast<QSpinBox *> (ui->resourcesTable->cellWidget(i, 1));
|
auto * itemQty = static_cast<QSpinBox *> (ui->resourcesTable->cellWidget(i, 1));
|
||||||
|
|
||||||
res[itemType] = QVariant::fromValue(itemQty->value());
|
res[itemType] = QVariant::fromValue(itemQty->value());
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
#include "../mapcontroller.h"
|
#include "../mapcontroller.h"
|
||||||
#include "../../lib/constants/NumericConstants.h"
|
#include "../../lib/constants/NumericConstants.h"
|
||||||
#include "../../lib/constants/StringConstants.h"
|
#include "../../lib/constants/StringConstants.h"
|
||||||
|
#include "../../lib/GameLibrary.h"
|
||||||
|
#include "../../lib/entities/ResourceTypeHandler.h"
|
||||||
|
|
||||||
QString toQString(const PlayerColor & player)
|
QString toQString(const PlayerColor & player)
|
||||||
{
|
{
|
||||||
@@ -42,7 +44,7 @@ QVariant toVariant(const TResources & resources)
|
|||||||
{
|
{
|
||||||
QVariantMap result;
|
QVariantMap result;
|
||||||
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
||||||
result[QString::fromStdString(GameConstants::RESOURCE_NAMES[i])] = QVariant::fromValue(resources[i]);
|
result[QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey())] = QVariant::fromValue(resources[i]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
#include "../mapeditorroles.h"
|
#include "../mapeditorroles.h"
|
||||||
#include "../../lib/constants/EntityIdentifiers.h"
|
#include "../../lib/constants/EntityIdentifiers.h"
|
||||||
#include "../../lib/constants/StringConstants.h"
|
#include "../../lib/constants/StringConstants.h"
|
||||||
|
#include "../../lib/GameLibrary.h"
|
||||||
|
#include "../../lib/entities/ResourceTypeHandler.h"
|
||||||
|
|
||||||
TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent) :
|
TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent) :
|
||||||
controller(c),
|
controller(c),
|
||||||
@@ -51,7 +53,7 @@ TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent)
|
|||||||
MetaString str;
|
MetaString str;
|
||||||
str.appendName(GameResID(i));
|
str.appendName(GameResID(i));
|
||||||
auto name = QString::fromStdString(str.toString());
|
auto name = QString::fromStdString(str.toString());
|
||||||
int val = params.value("resources").toMap().value(QString::fromStdString(GameConstants::RESOURCE_NAMES[i])).toInt();
|
int val = params.value("resources").toMap().value(QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey())).toInt();
|
||||||
ui->resources->setItem(i, 0, new QTableWidgetItem(name));
|
ui->resources->setItem(i, 0, new QTableWidgetItem(name));
|
||||||
auto nval = new QTableWidgetItem(QString::number(val));
|
auto nval = new QTableWidgetItem(QString::number(val));
|
||||||
nval->setFlags(nval->flags() | Qt::ItemIsEditable);
|
nval->setFlags(nval->flags() | Qt::ItemIsEditable);
|
||||||
@@ -96,7 +98,7 @@ void TimedEvent::on_TimedEvent_finished(int result)
|
|||||||
auto res = target->data(Qt::UserRole).toMap().value("resources").toMap();
|
auto res = target->data(Qt::UserRole).toMap().value("resources").toMap();
|
||||||
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
||||||
{
|
{
|
||||||
auto itemType = QString::fromStdString(GameConstants::RESOURCE_NAMES[i]);
|
auto itemType = QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey());
|
||||||
auto * itemQty = ui->resources->item(i, 1);
|
auto * itemQty = ui->resources->item(i, 1);
|
||||||
res[itemType] = QVariant::fromValue(itemQty->text().toInt());
|
res[itemType] = QVariant::fromValue(itemQty->text().toInt());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#include "../../../lib/constants/EntityIdentifiers.h"
|
#include "../../../lib/constants/EntityIdentifiers.h"
|
||||||
#include "../../../lib/constants/StringConstants.h"
|
#include "../../../lib/constants/StringConstants.h"
|
||||||
#include "../../../lib/rmg/CRmgTemplate.h"
|
#include "../../../lib/rmg/CRmgTemplate.h"
|
||||||
|
#include "../../../lib/GameLibrary.h"
|
||||||
|
#include "../../../lib/entities/ResourceTypeHandler.h"
|
||||||
|
|
||||||
QDomElement CardItem::getElementById(const QDomDocument& doc, const QString& id)
|
QDomElement CardItem::getElementById(const QDomDocument& doc, const QString& id)
|
||||||
{
|
{
|
||||||
@@ -149,11 +151,11 @@ int CardItem::getId()
|
|||||||
|
|
||||||
void CardItem::setResAmount(GameResID res, int val)
|
void CardItem::setResAmount(GameResID res, int val)
|
||||||
{
|
{
|
||||||
auto textElem = getElementById(doc, "text" + QString::fromStdString(GameConstants::RESOURCE_NAMES[res]));
|
auto textElem = getElementById(doc, "text" + QString::fromStdString(LIBRARY->resourceTypeHandler->getById(res)->getJsonKey()));
|
||||||
textElem.setAttribute("style", textElem.attribute("style").replace(QRegularExpression("fill:.*?;"), "fill:" + QColor(useBlackText ? Qt::black : Qt::white).name() + ";"));
|
textElem.setAttribute("style", textElem.attribute("style").replace(QRegularExpression("fill:.*?;"), "fill:" + QColor(useBlackText ? Qt::black : Qt::white).name() + ";"));
|
||||||
textElem.firstChild().setNodeValue(val ? QString::number(val) : "");
|
textElem.firstChild().setNodeValue(val ? QString::number(val) : "");
|
||||||
|
|
||||||
auto iconElem = getElementById(doc, "icon" + QString::fromStdString(GameConstants::RESOURCE_NAMES[res]));
|
auto iconElem = getElementById(doc, "icon" + QString::fromStdString(LIBRARY->resourceTypeHandler->getById(res)->getJsonKey()));
|
||||||
iconElem.setAttribute("opacity", val ? "1.0" : "0.1");
|
iconElem.setAttribute("opacity", val ? "1.0" : "0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ ResourceSet NewTurnProcessor::generatePlayerIncome(PlayerColor playerID, bool ne
|
|||||||
// Distribute weekly bonuses over 7 days, depending on the current day of the week
|
// Distribute weekly bonuses over 7 days, depending on the current day of the week
|
||||||
for (GameResID i : LIBRARY->resourceTypeHandler->getAllObjects())
|
for (GameResID i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
{
|
{
|
||||||
const std::string & name = GameConstants::RESOURCE_NAMES[i.getNum()];
|
const std::string & name = LIBRARY->resourceTypeHandler->getById(i)->getJsonKey();
|
||||||
int64_t weeklyBonus = difficultyConfig[name].Integer();
|
int64_t weeklyBonus = difficultyConfig[name].Integer();
|
||||||
int64_t dayOfWeek = gameHandler->gameState().getDate(Date::DAY_OF_WEEK);
|
int64_t dayOfWeek = gameHandler->gameState().getDate(Date::DAY_OF_WEEK);
|
||||||
int64_t dailyIncome = incomeHandicapped[i];
|
int64_t dailyIncome = incomeHandicapped[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user