1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Use ResourcePath for referencing texts and json's

This commit is contained in:
Ivan Savenko 2023-09-02 00:26:14 +03:00
parent 823ffa7a07
commit 6f0108e462
51 changed files with 124 additions and 130 deletions

View File

@ -75,7 +75,7 @@ void CSoundHandler::onVolumeChange(const JsonNode &volumeNode)
CSoundHandler::CSoundHandler():
listener(settings.listen["general"]["sound"]),
ambientConfig(JsonNode(ResourcePath("config/ambientSounds.json")))
ambientConfig(JsonPath::builtin("config/ambientSounds.json"))
{
listener(std::bind(&CSoundHandler::onVolumeChange, this, _1));

View File

@ -56,7 +56,7 @@ AdventureMapWidget::AdventureMapWidget( std::shared_ptr<AdventureMapShortcuts> s
for (const auto & entry : shortcuts->getShortcuts())
addShortcut(entry.shortcut, entry.callback);
const JsonNode config(ResourcePath("config/widgets/adventureMap.json"));
const JsonNode config(JsonPath::builtin("config/widgets/adventureMap.json"));
for(const auto & entry : config["options"]["imagesPlayerColored"].Vector())
{

View File

@ -47,7 +47,7 @@ TurnTimerWidget::TurnTimerWidget():
recActions &= ~DEACTIVATE;
const JsonNode config(ResourcePath("config/widgets/turnTimer.json"));
const JsonNode config(JsonPath::builtin("config/widgets/turnTimer.json"));
build(config);

View File

@ -132,7 +132,7 @@ void BattleEffectsController::collectRenderableObjects(BattleRenderer & renderer
void BattleEffectsController::loadColorMuxers()
{
const JsonNode config(ResourcePath("config/battleEffects.json"));
const JsonNode config(JsonPath::builtin("config/battleEffects.json"));
for(auto & muxer : config["colorMuxers"].Struct())
{

View File

@ -51,7 +51,7 @@ BattleWindow::BattleWindow(BattleInterface & owner):
REGISTER_BUILDER("battleConsole", &BattleWindow::buildBattleConsole);
const JsonNode config(ResourcePath("config/widgets/BattleWindow2.json"));
const JsonNode config(JsonPath::builtin("config/widgets/BattleWindow2.json"));
addShortcut(EShortcut::GLOBAL_OPTIONS, std::bind(&BattleWindow::bOptionsf, this));
addShortcut(EShortcut::BATTLE_SURRENDER, std::bind(&BattleWindow::bSurrenderf, this));

View File

@ -110,7 +110,7 @@ void InterfaceObjectConfigurable::build(const JsonNode &config)
{
if (!config["library"].isNull())
{
const JsonNode library(ResourcePath(config["library"].String()));
const JsonNode library(JsonPath::fromJson(config["library"]));
loadCustomBuilders(library);
}

View File

@ -137,7 +137,7 @@ OptionsTab::OptionsTab() : humanPlayers(0)
}
});
const JsonNode config(ResourcePath("config/widgets/optionsTab.json"));
const JsonNode config(JsonPath::builtin("config/widgets/optionsTab.json"));
build(config);
//set timers combo box callbacks

View File

@ -118,7 +118,7 @@ RandomMapTab::RandomMapTab():
});
}
const JsonNode config(ResourcePath("config/widgets/randomMapTab.json"));
const JsonNode config(JsonPath::builtin("config/widgets/randomMapTab.json"));
build(config);
//set combo box callbacks
@ -388,7 +388,7 @@ std::vector<int> RandomMapTab::getPossibleMapSizes()
TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab):
InterfaceObjectConfigurable()
{
const JsonNode config(ResourcePath("config/widgets/randomMapTeamsWidget.json"));
const JsonNode config(JsonPath::builtin("config/widgets/randomMapTeamsWidget.json"));
variables = config["variables"];
int humanPlayers = randomMapTab.obtainMapGenOptions().getPlayerCount();

View File

@ -262,7 +262,8 @@ CMenuEntry::CMenuEntry(CMenuScreen * parent, const JsonNode & config)
}
CMainMenuConfig::CMainMenuConfig()
: campaignSets(JsonNode(ResourcePath("config/campaignSets.json"))), config(JsonNode(ResourcePath("config/mainmenu.json")))
: campaignSets(JsonPath::builtin("config/campaignSets.json"))
, config(JsonPath::builtin("config/mainmenu.json"))
{
}

View File

@ -105,7 +105,7 @@ void Graphics::initializeBattleGraphics()
if(!CResourceHandler::get(mod)->existsResource(ResourcePath("config/battles_graphics.json")))
continue;
const JsonNode config(mod, ResourcePath("config/battles_graphics.json"));
const JsonNode config(mod, JsonPath::builtin("config/battles_graphics.json"));
//initialization of AC->def name mapping
if(!config["ac_mapping"].isNull())
@ -204,7 +204,7 @@ void Graphics::blueToPlayersAdv(SDL_Surface * sur, PlayerColor player)
void Graphics::loadFonts()
{
const JsonNode config(ResourcePath("config/fonts.json"));
const JsonNode config(JsonPath::builtin("config/fonts.json"));
const JsonVector & bmpConf = config["bitmap"].Vector();
const JsonNode & ttfConf = config["trueType"];
@ -228,7 +228,7 @@ void Graphics::loadFonts()
void Graphics::loadErmuToPicture()
{
//loading ERMU to picture
const JsonNode config(ResourcePath("config/ERMU_to_picture.json"));
const JsonNode config(JsonPath::builtin("config/ERMU_to_picture.json"));
int etp_idx = 0;
for(const JsonNode &etp : config["ERMU_to_picture"].Vector()) {
int idx = 0;

View File

@ -44,7 +44,7 @@ AdventureOptionsTab::AdventureOptionsTab()
addConditional("desktop", true);
#endif
const JsonNode config(ResourcePath("config/widgets/settings/adventureOptionsTab.json"));
const JsonNode config(JsonPath::builtin("config/widgets/settings/adventureOptionsTab.json"));
addCallback("playerHeroSpeedChanged", [this](int value)
{
auto targetLabel = widget<CLabel>("heroSpeedValueLabel");

View File

@ -23,7 +23,7 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
setRedrawParent(true);
const JsonNode config(ResourcePath("config/widgets/settings/battleOptionsTab.json"));
const JsonNode config(JsonPath::builtin("config/widgets/settings/battleOptionsTab.json"));
addCallback("viewGridChanged", [this, owner](bool value)
{
viewGridChangedCallback(value, owner);

View File

@ -105,7 +105,7 @@ GeneralOptionsTab::GeneralOptionsTab()
addConditional("desktop", true);
#endif
const JsonNode config(ResourcePath("config/widgets/settings/generalOptionsTab.json"));
const JsonNode config(JsonPath::builtin("config/widgets/settings/generalOptionsTab.json"));
addCallback("spellbookAnimationChanged", [](bool value)
{
setBoolSetting("video", "spellbookAnimation", value);

View File

@ -26,7 +26,7 @@ OtherOptionsTab::OtherOptionsTab() : InterfaceObjectConfigurable()
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
const JsonNode config(ResourcePath("config/widgets/settings/otherOptionsTab.json"));
const JsonNode config(JsonPath::builtin("config/widgets/settings/otherOptionsTab.json"));
addCallback("availableCreaturesAsDwellingLabelChanged", [](bool value)
{
return setBoolSetting("gameTweaks", "availableCreaturesAsDwellingLabel", value);

View File

@ -35,7 +35,7 @@ SettingsMainWindow::SettingsMainWindow(BattleInterface * parentBattleUi) : Inter
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
const JsonNode config(ResourcePath("config/widgets/settings/settingsMainContainer.json"));
const JsonNode config(JsonPath::builtin("config/widgets/settings/settingsMainContainer.json"));
addCallback("activateSettingsTab", [this](int tabId) { openTab(tabId); });
addCallback("loadGame", [this](int) { loadGameButtonCallback(); });
addCallback("saveGame", [this](int) { saveGameButtonCallback(); });

View File

@ -84,7 +84,7 @@ void CModManager::loadMods()
for(auto modname : installedMods)
{
ResourcePath resID(CModInfo::getModFile(modname));
auto resID = CModInfo::getModFile(modname);
if(CResourceHandler::get()->existsResource(resID))
{
boost::filesystem::path name = *CResourceHandler::get()->getResourceName(resID);

View File

@ -332,8 +332,8 @@ std::vector<JsonNode> CArtHandler::loadLegacyData()
static std::map<char, std::string> classes =
{{'S',"SPECIAL"}, {'T',"TREASURE"},{'N',"MINOR"},{'J',"MAJOR"},{'R',"RELIC"},};
CLegacyConfigParser parser("DATA/ARTRAITS.TXT");
CLegacyConfigParser events("DATA/ARTEVENT.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/ARTRAITS.TXT"));
CLegacyConfigParser events(TextPath::builtin("DATA/ARTEVENT.TXT"));
parser.endLine(); // header
parser.endLine();

View File

@ -196,7 +196,7 @@ ImagePath CBonusTypeHandler::bonusToGraphics(const std::shared_ptr<Bonus> & bonu
void CBonusTypeHandler::load()
{
const JsonNode gameConf(ResourcePath("config/gameConfig.json"));
const JsonNode gameConf(JsonPath::builtin("config/gameConfig.json"));
const JsonNode config(JsonUtils::assembleFromFiles(gameConf["bonuses"].convertTo<std::vector<std::string>>()));
load(config);
}

View File

@ -55,12 +55,12 @@ SettingsStorage::SettingsStorage():
void SettingsStorage::init()
{
std::string confName = "config/settings.json";
JsonPath confName = JsonPath::builtin("config/settings.json");
JsonUtils::assembleFromFiles(confName).swap(config);
JsonUtils::assembleFromFiles(confName.getOriginalName()).swap(config);
// Probably new install. Create config file to save settings to
if (!CResourceHandler::get("local")->existsResource(ResourcePath(confName)))
if (!CResourceHandler::get("local")->existsResource(confName))
CResourceHandler::get("local")->createResource(confName);
JsonUtils::maximize(config, "vcmi:settings");

View File

@ -415,7 +415,7 @@ const CCreature * CCreatureHandler::getCreature(const std::string & scope, const
void CCreatureHandler::loadCommanders()
{
ResourcePath configResource("config/commanders.json");
auto configResource = JsonPath::builtin("config/commanders.json");
std::string modSource = VLC->modh->findResourceOrigin(configResource);
JsonNode data(configResource);
@ -507,7 +507,7 @@ std::vector<JsonNode> CCreatureHandler::loadLegacyData()
std::vector<JsonNode> h3Data;
h3Data.reserve(dataSize);
CLegacyConfigParser parser("DATA/CRTRAITS.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/CRTRAITS.TXT"));
parser.endLine(); // header
@ -698,7 +698,7 @@ void CCreatureHandler::loadCrExpMod()
}
}
CLegacyConfigParser expBonParser("DATA/CREXPMOD.TXT");
CLegacyConfigParser expBonParser(TextPath::builtin("DATA/CREXPMOD.TXT"));
expBonParser.endLine(); //header
@ -745,7 +745,7 @@ void CCreatureHandler::loadCrExpBon(CBonusSystemNode & globalEffects)
globalEffects.addNewBonus(b);
};
CLegacyConfigParser parser("DATA/CREXPBON.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/CREXPBON.TXT"));
Bonus b; //prototype with some default properties
b.source = BonusSource::STACK_EXPERIENCE;
@ -804,7 +804,7 @@ void CCreatureHandler::loadCrExpBon(CBonusSystemNode & globalEffects)
void CCreatureHandler::loadAnimationInfo(std::vector<JsonNode> &h3Data) const
{
CLegacyConfigParser parser("DATA/CRANIM.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/CRANIM.TXT"));
parser.endLine(); // header
parser.endLine();

View File

@ -119,9 +119,8 @@ protected:
}
};
CLegacyConfigParser::CLegacyConfigParser(std::string URI)
CLegacyConfigParser::CLegacyConfigParser(const TextPath & resource)
{
ResourcePath resource(URI, EResType::TEXT);
auto input = CResourceHandler::get()->load(resource);
std::string modName = VLC->modh->findResourceOrigin(resource);
std::string language = VLC->modh->getModLanguage(modName);
@ -250,7 +249,7 @@ bool CLegacyConfigParser::endLine()
void CGeneralTextHandler::readToVector(const std::string & sourceID, const std::string & sourceName)
{
CLegacyConfigParser parser(sourceName);
CLegacyConfigParser parser(TextPath::builtin(sourceName));
size_t index = 0;
do
{
@ -434,7 +433,7 @@ CGeneralTextHandler::CGeneralTextHandler():
readToVector("vcmi.quickExchange", QE_MOD_COMMANDS);
{
CLegacyConfigParser parser("DATA/RANDTVRN.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/RANDTVRN.TXT"));
parser.endLine();
size_t index = 0;
do
@ -449,7 +448,7 @@ CGeneralTextHandler::CGeneralTextHandler():
while (parser.endLine());
}
{
CLegacyConfigParser parser("DATA/GENRLTXT.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/GENRLTXT.TXT"));
parser.endLine();
size_t index = 0;
do
@ -460,7 +459,7 @@ CGeneralTextHandler::CGeneralTextHandler():
while (parser.endLine());
}
{
CLegacyConfigParser parser("DATA/HELP.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/HELP.TXT"));
size_t index = 0;
do
{
@ -473,7 +472,7 @@ CGeneralTextHandler::CGeneralTextHandler():
while (parser.endLine());
}
{
CLegacyConfigParser parser("DATA/PLCOLORS.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/PLCOLORS.TXT"));
size_t index = 0;
do
{
@ -487,7 +486,7 @@ CGeneralTextHandler::CGeneralTextHandler():
while (parser.endLine());
}
{
CLegacyConfigParser parser("DATA/SEERHUT.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/SEERHUT.TXT"));
//skip header
parser.endLine();
@ -531,7 +530,7 @@ CGeneralTextHandler::CGeneralTextHandler():
}
}
{
CLegacyConfigParser parser("DATA/CAMPTEXT.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/CAMPTEXT.TXT"));
//skip header
parser.endLine();

View File

@ -9,6 +9,8 @@
*/
#pragma once
#include "filesystem/ResourcePath.h"
VCMI_LIB_NAMESPACE_BEGIN
class CInputStream;
@ -56,7 +58,7 @@ public:
/// end current line
bool endLine();
explicit CLegacyConfigParser(std::string URI);
explicit CLegacyConfigParser(const TextPath & URI);
};
class CGeneralTextHandler;

View File

@ -320,7 +320,7 @@ std::vector<JsonNode> CHeroClassHandler::loadLegacyData()
std::vector<JsonNode> h3Data;
h3Data.reserve(dataSize);
CLegacyConfigParser parser("DATA/HCTRAITS.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/HCTRAITS.TXT"));
parser.endLine(); // header
parser.endLine();
@ -681,9 +681,9 @@ std::vector<JsonNode> CHeroHandler::loadLegacyData()
std::vector<JsonNode> h3Data;
h3Data.reserve(dataSize);
CLegacyConfigParser specParser("DATA/HEROSPEC.TXT");
CLegacyConfigParser bioParser("DATA/HEROBIOS.TXT");
CLegacyConfigParser parser("DATA/HOTRAITS.TXT");
CLegacyConfigParser specParser(TextPath::builtin("DATA/HEROSPEC.TXT"));
CLegacyConfigParser bioParser(TextPath::builtin("DATA/HEROBIOS.TXT"));
CLegacyConfigParser parser(TextPath::builtin("DATA/HOTRAITS.TXT"));
parser.endLine(); //ignore header
parser.endLine();

View File

@ -146,7 +146,7 @@ void CSkill::serializeJson(JsonSerializeFormat & handler)
///CSkillHandler
std::vector<JsonNode> CSkillHandler::loadLegacyData()
{
CLegacyConfigParser parser("DATA/SSTRAITS.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/SSTRAITS.TXT"));
//skip header
parser.endLine();

View File

@ -330,7 +330,7 @@ std::vector<JsonNode> CTownHandler::loadLegacyData()
return dest[town]["town"]["buildings"][EBuildingType::names[building]];
};
CLegacyConfigParser parser("DATA/BUILDING.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/BUILDING.TXT"));
parser.endLine(); // header
parser.endLine();
@ -382,7 +382,7 @@ std::vector<JsonNode> CTownHandler::loadLegacyData()
}
}
{
CLegacyConfigParser parser("DATA/BLDGNEUT.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/BLDGNEUT.TXT"));
for(int building=0; building<15; building++)
{
@ -420,7 +420,7 @@ std::vector<JsonNode> CTownHandler::loadLegacyData()
}
}
{
CLegacyConfigParser parser("DATA/BLDGSPEC.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/BLDGSPEC.TXT"));
for(int town=0; town<dataSize; town++)
{
@ -440,7 +440,7 @@ std::vector<JsonNode> CTownHandler::loadLegacyData()
}
}
{
CLegacyConfigParser parser("DATA/DWELLING.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/DWELLING.TXT"));
for(int town=0; town<dataSize; town++)
{
@ -453,8 +453,8 @@ std::vector<JsonNode> CTownHandler::loadLegacyData()
}
}
{
CLegacyConfigParser typeParser("DATA/TOWNTYPE.TXT");
CLegacyConfigParser nameParser("DATA/TOWNNAME.TXT");
CLegacyConfigParser typeParser(TextPath::builtin("DATA/TOWNTYPE.TXT"));
CLegacyConfigParser nameParser(TextPath::builtin("DATA/TOWNNAME.TXT"));
size_t townID=0;
do
{
@ -1148,9 +1148,7 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
void CTownHandler::loadRandomFaction()
{
static const ResourcePath randomFactionPath("config/factions/random.json");
JsonNode randomFactionJson(randomFactionPath);
JsonNode randomFactionJson(JsonPath::builtin("config/factions/random.json"));
randomFactionJson.setMeta(ModScope::scopeBuiltin(), true);
loadBuildings(randomTown, randomFactionJson["random"]["town"]["buildings"]);
}

View File

@ -80,7 +80,7 @@ JsonNode::JsonNode(const char *data, size_t datasize):
*this = parser.parse("<unknown>");
}
JsonNode::JsonNode(ResourcePath && fileURI):
JsonNode::JsonNode(const JsonPath & fileURI):
type(JsonType::DATA_NULL)
{
auto file = CResourceHandler::get()->load(fileURI)->readAll();
@ -89,16 +89,7 @@ JsonNode::JsonNode(ResourcePath && fileURI):
*this = parser.parse(fileURI.getName());
}
JsonNode::JsonNode(const ResourcePath & fileURI):
type(JsonType::DATA_NULL)
{
auto file = CResourceHandler::get()->load(fileURI)->readAll();
JsonParser parser(reinterpret_cast<char*>(file.first.get()), file.second);
*this = parser.parse(fileURI.getName());
}
JsonNode::JsonNode(const std::string & idx, const ResourcePath & fileURI):
JsonNode::JsonNode(const std::string & idx, const JsonPath & fileURI):
type(JsonType::DATA_NULL)
{
auto file = CResourceHandler::get(idx)->load(fileURI)->readAll();
@ -107,7 +98,7 @@ type(JsonType::DATA_NULL)
*this = parser.parse(fileURI.getName());
}
JsonNode::JsonNode(ResourcePath && fileURI, bool &isValidSyntax):
JsonNode::JsonNode(const JsonPath & fileURI, bool &isValidSyntax):
type(JsonType::DATA_NULL)
{
auto file = CResourceHandler::get()->load(fileURI)->readAll();
@ -1253,11 +1244,11 @@ const JsonNode & getSchemaByName(const std::string & name)
if (vstd::contains(loadedSchemas, name))
return loadedSchemas[name];
std::string filename = "config/schemas/" + name;
auto filename = JsonPath::builtin("config/schemas/" + name);
if (CResourceHandler::get()->existsResource(ResourcePath(filename)))
if (CResourceHandler::get()->existsResource(filename))
{
loadedSchemas[name] = JsonNode(ResourcePath(filename));
loadedSchemas[name] = JsonNode(filename);
return loadedSchemas[name];
}
@ -1444,10 +1435,10 @@ JsonNode JsonUtils::assembleFromFiles(const std::vector<std::string> & files, bo
isValid = true;
JsonNode result;
for(const std::string & file : files)
for(const auto & file : files)
{
bool isValidFile = false;
JsonNode section(ResourcePath(file, EResType::TEXT), isValidFile);
JsonNode section(JsonPath::builtinTODO(file), isValidFile);
merge(result, section);
isValid |= isValidFile;
}
@ -1457,7 +1448,7 @@ JsonNode JsonUtils::assembleFromFiles(const std::vector<std::string> & files, bo
JsonNode JsonUtils::assembleFromFiles(const std::string & filename)
{
JsonNode result;
ResourcePath resID(filename, EResType::TEXT);
JsonPath resID(filename);
for(auto & loader : CResourceHandler::get()->getResourcesWithName(resID))
{

View File

@ -9,6 +9,7 @@
*/
#pragma once
#include "GameConstants.h"
#include "filesystem/ResourcePath.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -18,7 +19,6 @@ using JsonVector = std::vector<JsonNode>;
struct Bonus;
class CSelector;
class ResourcePath;
class CAddInfo;
class ILimiter;
@ -61,10 +61,9 @@ public:
//Create tree from Json-formatted input
explicit JsonNode(const char * data, size_t datasize);
//Create tree from JSON file
explicit JsonNode(ResourcePath && fileURI);
explicit JsonNode(const ResourcePath & fileURI);
explicit JsonNode(const std::string& idx, const ResourcePath & fileURI);
explicit JsonNode(ResourcePath && fileURI, bool & isValidSyntax);
explicit JsonNode(const JsonPath & fileURI);
explicit JsonNode(const std::string & modName, const JsonPath & fileURI);
explicit JsonNode(const JsonPath & fileURI, bool & isValidSyntax);
//Copy c-tor
JsonNode(const JsonNode &copy);

View File

@ -127,7 +127,7 @@ std::vector<JsonNode> TerrainTypeHandler::loadLegacyData()
objects.resize(dataSize);
CLegacyConfigParser terrainParser("DATA/TERRNAME.TXT");
CLegacyConfigParser terrainParser(TextPath::builtin("DATA/TERRNAME.TXT"));
std::vector<JsonNode> result;
do

View File

@ -348,7 +348,7 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, TerrainId terrain, const
std::vector<std::vector<int>> creBankFormations[2];
std::vector<int> commanderField;
std::vector<int> commanderBank;
const JsonNode config(ResourcePath("config/battleStartpos.json"));
const JsonNode config(JsonPath::builtin("config/battleStartpos.json"));
const JsonVector &positions = config["battle_positions"].Vector();
CGH::readBattlePositions(positions[0]["levels"], looseFormations[0]);

View File

@ -592,7 +592,7 @@ std::vector< std::vector<ui8> > CampaignHandler::getFile(std::unique_ptr<CInputS
std::string CampaignHandler::prologVideoName(ui8 index)
{
JsonNode config(ResourcePath(std::string("CONFIG/campaignMedia"), EResType::TEXT));
JsonNode config(JsonPath::builtin("CONFIG/campaignMedia"));
auto vids = config["videos"].Vector();
if(index < vids.size())
return vids[index].String();
@ -607,7 +607,7 @@ std::string CampaignHandler::prologMusicName(ui8 index)
std::string CampaignHandler::prologVoiceName(ui8 index)
{
JsonNode config(ResourcePath(std::string("CONFIG/campaignMedia"), EResType::TEXT));
JsonNode config(JsonPath::builtin("CONFIG/campaignMedia"));
auto audio = config["voice"].Vector();
if(index < audio.size())
return audio[index].String();

View File

@ -58,7 +58,7 @@ CampaignRegions CampaignRegions::getLegacy(int campId)
static std::vector<CampaignRegions> campDescriptions;
if(campDescriptions.empty()) //read once
{
const JsonNode config(ResourcePath("config/campaign_regions.json"));
const JsonNode config(JsonPath::builtin("config/campaign_regions.json"));
for(const JsonNode & campaign : config["campaign_regions"].Vector())
campDescriptions.push_back(CampaignRegions::fromJson(campaign));
}

View File

@ -128,9 +128,9 @@ std::unordered_set<ResourcePath> CFilesystemList::getFilteredFiles(std::function
return ret;
}
bool CFilesystemList::createResource(std::string filename, bool update)
bool CFilesystemList::createResource(const ResourcePath & filename, bool update)
{
logGlobal->trace("Creating %s", filename);
logGlobal->trace("Creating %s", filename.getOriginalName());
for (auto & loader : boost::adaptors::reverse(loaders))
{
if (writeableLoaders.count(loader.get()) != 0 // writeable,

View File

@ -75,7 +75,7 @@ public:
std::set<boost::filesystem::path> getResourceNames(const ResourcePath & resourceName) const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override;
std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override;
bool createResource(std::string filename, bool update = false) override;
bool createResource(const ResourcePath & filename, bool update = false) override;
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourcePath & resourceName) const override;
/**

View File

@ -68,9 +68,9 @@ std::unordered_set<ResourcePath> CFilesystemLoader::getFilteredFiles(std::functi
return foundID;
}
bool CFilesystemLoader::createResource(std::string filename, bool update)
bool CFilesystemLoader::createResource(const ResourcePath & resID, bool update)
{
ResourcePath resID(filename);
std::string filename = resID.getOriginalName();
if (fileList.find(resID) != fileList.end())
return true;

View File

@ -37,7 +37,7 @@ public:
std::unique_ptr<CInputStream> load(const ResourcePath & resourceName) const override;
bool existsResource(const ResourcePath & resourceName) const override;
std::string getMountPoint() const override;
bool createResource(std::string filename, bool update = false) override;
bool createResource(const ResourcePath & filename, bool update = false) override;
std::optional<boost::filesystem::path> getResourceName(const ResourcePath & resourceName) const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override;
std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override;

View File

@ -90,7 +90,7 @@ public:
*
* @return true if new file was created, false on error or if file already exists
*/
virtual bool createResource(std::string filename, bool update = false)
virtual bool createResource(const ResourcePath & filename, bool update = false)
{
return false;
}

View File

@ -19,7 +19,8 @@ class JsonSerializeFormat;
*
* Supported file extensions:
*
* Text: .txt .json
* Text: .txt
* Json: .json
* Animation: .def
* Mask: .msk .msg
* Campaign: .h3c
@ -36,6 +37,7 @@ class JsonSerializeFormat;
enum class EResType
{
TEXT,
JSON,
ANIMATION,
MASK,
CAMPAIGN,
@ -167,6 +169,8 @@ public:
using AnimationPath = ResourcePathTempl<EResType::ANIMATION>;
using ImagePath = ResourcePathTempl<EResType::IMAGE>;
using TextPath = ResourcePathTempl<EResType::TEXT>;
using JsonPath = ResourcePathTempl<EResType::JSON>;
namespace EResTypeHelper
{

View File

@ -804,7 +804,7 @@ void CGameState::removeHeroPlaceholders()
void CGameState::initStartingResources()
{
logGlobal->debug("\tSetting up resources");
const JsonNode config(ResourcePath("config/startres.json"));
const JsonNode config(JsonPath::builtin("config/startres.json"));
const JsonVector &vector = config["difficulty"].Vector();
const JsonNode &level = vector[scenarioOps->difficulty];

View File

@ -112,7 +112,7 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
{
size_t dataSize = VLC->settings()->getInteger(EGameSettings::TEXTS_OBJECT);
CLegacyConfigParser parser("Data/Objects.txt");
CLegacyConfigParser parser(TextPath::builtin("Data/Objects.txt"));
auto totalNumber = static_cast<size_t>(parser.readNumber()); // first line contains number of objects to read and nothing else
parser.endLine();
@ -132,7 +132,7 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
std::vector<JsonNode> ret(dataSize);// create storage for 256 objects
assert(dataSize == 256);
CLegacyConfigParser namesParser("Data/ObjNames.txt");
CLegacyConfigParser namesParser(TextPath::builtin("Data/ObjNames.txt"));
for (size_t i=0; i<256; i++)
{
ret[i]["name"].String() = namesParser.readString();
@ -142,7 +142,7 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
JsonNode cregen1;
JsonNode cregen4;
CLegacyConfigParser cregen1Parser("data/crgen1");
CLegacyConfigParser cregen1Parser(TextPath::builtin("data/crgen1"));
do
{
JsonNode subObject;
@ -151,7 +151,7 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
}
while(cregen1Parser.endLine());
CLegacyConfigParser cregen4Parser("data/crgen4");
CLegacyConfigParser cregen4Parser(TextPath::builtin("data/crgen4"));
do
{
JsonNode subObject;

View File

@ -19,7 +19,7 @@ VCMI_LIB_NAMESPACE_BEGIN
CObjectHandler::CObjectHandler()
{
logGlobal->trace("\t\tReading resources prices ");
const JsonNode config2(ResourcePath("config/resources.json"));
const JsonNode config2(JsonPath::builtin("config/resources.json"));
for(const JsonNode &price : config2["resources_prices"].Vector())
{
resVals.push_back(static_cast<ui32>(price.Float()));

View File

@ -154,9 +154,9 @@ std::unique_ptr<IMapLoader> CMapService::getMapLoader(std::unique_ptr<CInputStre
}
}
static JsonNode loadPatches(std::string path)
static JsonNode loadPatches(const std::string & path)
{
JsonNode node = JsonUtils::assembleFromFiles(std::move(path));
JsonNode node = JsonUtils::assembleFromFiles(path);
for (auto & entry : node.Struct())
JsonUtils::validate(entry.second, "vcmi:mapHeader", "patch for " + entry.first);

View File

@ -174,7 +174,7 @@ void TerrainViewPattern::WeightedRule::setNative()
CTerrainViewPatternConfig::CTerrainViewPatternConfig()
{
const JsonNode config(ResourcePath("config/terrainViewPatterns.json"));
const JsonNode config(JsonPath::builtin("config/terrainViewPatterns.json"));
static const std::string patternTypes[] = { "terrainView", "terrainType" };
for (int i = 0; i < std::size(patternTypes); ++i)
{

View File

@ -28,11 +28,11 @@
VCMI_LIB_NAMESPACE_BEGIN
static JsonNode loadModSettings(const std::string & path)
static JsonNode loadModSettings(const JsonPath & path)
{
if (CResourceHandler::get("local")->existsResource(ResourcePath(path)))
{
return JsonNode(ResourcePath(path, EResType::TEXT));
return JsonNode(path);
}
// Probably new install. Create initial configuration
CResourceHandler::get("local")->createResource(path);
@ -200,9 +200,9 @@ void CModHandler::loadOneMod(std::string modName, const std::string & parent, co
return;
}
if(CResourceHandler::get("initial")->existsResource(ResourcePath(CModInfo::getModFile(modFullName))))
if(CResourceHandler::get("initial")->existsResource(CModInfo::getModFile(modFullName)))
{
CModInfo mod(modFullName, modSettings[modName], JsonNode(ResourcePath(CModInfo::getModFile(modFullName))));
CModInfo mod(modFullName, modSettings[modName], JsonNode(CModInfo::getModFile(modFullName)));
if (!parent.empty()) // this is submod, add parent to dependencies
mod.dependencies.insert(parent);
@ -224,11 +224,11 @@ void CModHandler::loadMods(bool onlyEssential)
}
else
{
modConfig = loadModSettings("config/modSettings.json");
modConfig = loadModSettings(JsonPath::builtin("config/modSettings.json"));
loadMods("", "", modConfig["activeMods"], true);
}
coreMod = std::make_unique<CModInfo>(ModScope::scopeBuiltin(), modConfig[ModScope::scopeBuiltin()], JsonNode(ResourcePath("config/gameConfig.json")));
coreMod = std::make_unique<CModInfo>(ModScope::scopeBuiltin(), modConfig[ModScope::scopeBuiltin()], JsonNode(JsonPath::builtin("config/gameConfig.json")));
coreMod->name = "Original game files";
}
@ -283,7 +283,7 @@ static ui32 calculateModChecksum(const std::string & modName, ISimpleResourceLoa
// FIXME: remove workaround for core mod
if (modName != ModScope::scopeBuiltin())
{
ResourcePath modConfFile(CModInfo::getModFile(modName), EResType::TEXT);
auto modConfFile = CModInfo::getModFile(modName);
ui32 configChecksum = CResourceHandler::get("initial")->load(modConfFile)->calculateCRC32();
modChecksum.process_bytes(reinterpret_cast<const void *>(&configChecksum), sizeof(configChecksum));
}

View File

@ -75,9 +75,9 @@ std::string CModInfo::getModDir(const std::string & name)
return "MODS/" + boost::algorithm::replace_all_copy(name, ".", "/MODS/");
}
std::string CModInfo::getModFile(const std::string & name)
JsonPath CModInfo::getModFile(const std::string & name)
{
return getModDir(name) + "/mod.json";
return JsonPath::builtinTODO(getModDir(name) + "/mod.json");
}
void CModInfo::updateChecksum(ui32 newChecksum)
@ -152,7 +152,7 @@ bool CModInfo::checkModGameplayAffecting() const
"obstacles"
};
ResourcePath modFileResource(CModInfo::getModFile(identifier));
JsonPath modFileResource(CModInfo::getModFile(identifier));
if(CResourceHandler::get("initial")->existsResource(modFileResource))
{

View File

@ -69,7 +69,7 @@ public:
void setEnabled(bool on);
static std::string getModDir(const std::string & name);
static std::string getModFile(const std::string & name);
static JsonPath getModFile(const std::string & name);
/// return true if this mod can affect gameplay, e.g. adds or modifies any game objects
bool checkModGameplayAffecting() const;

View File

@ -51,8 +51,7 @@ int CMapGenerator::getRandomSeed() const
void CMapGenerator::loadConfig()
{
static const ResourcePath path("config/randomMap.json");
JsonNode randomMapJson(path);
JsonNode randomMapJson(JsonPath::builtin("config/randomMap.json"));
config.shipyardGuard = randomMapJson["waterZone"]["shipyard"]["value"].Integer();
for(auto & treasure : randomMapJson["waterZone"]["treasure"].Vector())

View File

@ -561,7 +561,7 @@ std::vector<JsonNode> CSpellHandler::loadLegacyData()
using namespace SpellConfig;
std::vector<JsonNode> legacyData;
CLegacyConfigParser parser("DATA/SPTRAITS.TXT");
CLegacyConfigParser parser(TextPath::builtin("DATA/SPTRAITS.TXT"));
auto readSchool = [&](JsonMap & schools, const std::string & name)
{

View File

@ -1717,12 +1717,13 @@ void CGameHandler::save(const std::string & filename)
logGlobal->info("Saving to %s", filename);
const auto stem = FileInfo::GetPathStem(filename);
const auto savefname = stem.to_string() + ".vsgm1";
CResourceHandler::get("local")->createResource(savefname);
ResourcePath savePath(stem.to_string(), EResType::SAVEGAME);
CResourceHandler::get("local")->createResource(savePath);
try
{
{
CSaveFile save(*CResourceHandler::get("local")->getResourceName(ResourcePath(stem.to_string(), EResType::SAVEGAME)));
CSaveFile save(*CResourceHandler::get("local")->getResourceName(savePath));
saveCommonState(save);
logGlobal->info("Saving server state");
save << *this;

View File

@ -120,7 +120,7 @@ TEST(MapManager, DrawTerrain_View)
// Validate edit manager
auto editManager = map->getEditManager();
CRandomGenerator gen;
const JsonNode viewNode(ResourcePath("test/terrainViewMappings", EResType::TEXT));
const JsonNode viewNode(JsonPath::builtin("test/terrainViewMappings"));
const auto & mappingsNode = viewNode["mappings"].Vector();
for (const auto & node : mappingsNode)
{

View File

@ -153,14 +153,14 @@ TEST(MapFormat, Objects)
{
static const std::string MAP_DATA_PATH = "test/ObjectPropertyTest/";
const JsonNode initialHeader(ResourcePath(MAP_DATA_PATH + CMapFormatJson::HEADER_FILE_NAME));
const JsonNode expectedHeader(ResourcePath(MAP_DATA_PATH + CMapFormatJson::HEADER_FILE_NAME));//same as initial for now
const JsonNode initialHeader(JsonPath::builtin(MAP_DATA_PATH + CMapFormatJson::HEADER_FILE_NAME));
const JsonNode expectedHeader(JsonPath::builtin(MAP_DATA_PATH + CMapFormatJson::HEADER_FILE_NAME));//same as initial for now
const JsonNode initialObjects(ResourcePath(MAP_DATA_PATH + CMapFormatJson::OBJECTS_FILE_NAME));
const JsonNode expectedObjects(ResourcePath(MAP_DATA_PATH + "objects.ex.json"));
const JsonNode initialObjects(JsonPath::builtin(MAP_DATA_PATH + CMapFormatJson::OBJECTS_FILE_NAME));
const JsonNode expectedObjects(JsonPath::builtin(MAP_DATA_PATH + "objects.ex.json"));
const JsonNode expectedSurface(ResourcePath(MAP_DATA_PATH + "surface_terrain.json"));
const JsonNode expectedUnderground(ResourcePath(MAP_DATA_PATH + "underground_terrain.json"));
const JsonNode expectedSurface(JsonPath::builtin(MAP_DATA_PATH + "surface_terrain.json"));
const JsonNode expectedUnderground(JsonPath::builtin(MAP_DATA_PATH + "underground_terrain.json"));
std::unique_ptr<CMap> originalMap = loadOriginal(initialHeader, initialObjects, expectedSurface, expectedUnderground);
@ -192,11 +192,11 @@ TEST(MapFormat, Terrain)
{
static const std::string MAP_DATA_PATH = "test/TerrainTest/";
const JsonNode expectedHeader(ResourcePath(MAP_DATA_PATH + CMapFormatJson::HEADER_FILE_NAME));
const JsonNode expectedObjects(ResourcePath(MAP_DATA_PATH + CMapFormatJson::OBJECTS_FILE_NAME));
const JsonNode expectedHeader(JsonPath::builtin(MAP_DATA_PATH + CMapFormatJson::HEADER_FILE_NAME));
const JsonNode expectedObjects(JsonPath::builtin(MAP_DATA_PATH + CMapFormatJson::OBJECTS_FILE_NAME));
const JsonNode expectedSurface(ResourcePath(MAP_DATA_PATH + "surface_terrain.json"));
const JsonNode expectedUnderground(ResourcePath(MAP_DATA_PATH + "underground_terrain.json"));
const JsonNode expectedSurface(JsonPath::builtin(MAP_DATA_PATH + "surface_terrain.json"));
const JsonNode expectedUnderground(JsonPath::builtin(MAP_DATA_PATH + "underground_terrain.json"));
std::unique_ptr<CMap> originalMap = loadOriginal(expectedHeader, expectedObjects, expectedSurface, expectedUnderground);

View File

@ -23,15 +23,15 @@ MapServiceMock::MapServiceMock(const std::string & path, MapListener * mapListen
CZipSaver saver(io, "_");
const JsonNode header(ResourcePath(path+CMapFormatJson::HEADER_FILE_NAME));
const JsonNode objects(ResourcePath(path+CMapFormatJson::OBJECTS_FILE_NAME));
const JsonNode surface(ResourcePath(path+"surface_terrain.json"));
const JsonNode header(JsonPath::builtin(path+CMapFormatJson::HEADER_FILE_NAME));
const JsonNode objects(JsonPath::builtin(path+CMapFormatJson::OBJECTS_FILE_NAME));
const JsonNode surface(JsonPath::builtin(path+"surface_terrain.json"));
addToArchive(saver, header, CMapFormatJson::HEADER_FILE_NAME);
addToArchive(saver, objects, CMapFormatJson::OBJECTS_FILE_NAME);
addToArchive(saver, surface, "surface_terrain.json");
ResourcePath undergroundPath(path+"underground_terrain.json");
auto undergroundPath = JsonPath::builtin(path+"underground_terrain.json");
if(CResourceHandler::get()->existsResource(undergroundPath))
{