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

Fix resource creation

This commit is contained in:
Ivan Savenko 2023-09-04 16:16:00 +03:00
parent 9cfcf5ea19
commit 6a260a60cf
10 changed files with 13 additions and 12 deletions

View File

@ -61,7 +61,7 @@ void SettingsStorage::init()
// Probably new install. Create config file to save settings to // Probably new install. Create config file to save settings to
if (!CResourceHandler::get("local")->existsResource(confName)) if (!CResourceHandler::get("local")->existsResource(confName))
CResourceHandler::get("local")->createResource(confName); CResourceHandler::get("local")->createResource("config/settings.json");
JsonUtils::maximize(config, "vcmi:settings"); JsonUtils::maximize(config, "vcmi:settings");
JsonUtils::validate(config, "vcmi:settings", "settings"); JsonUtils::validate(config, "vcmi:settings", "settings");

View File

@ -128,9 +128,9 @@ std::unordered_set<ResourcePath> CFilesystemList::getFilteredFiles(std::function
return ret; return ret;
} }
bool CFilesystemList::createResource(const ResourcePath & filename, bool update) bool CFilesystemList::createResource(const std::string & filename, bool update)
{ {
logGlobal->trace("Creating %s", filename.getOriginalName()); logGlobal->trace("Creating %s", filename);
for (auto & loader : boost::adaptors::reverse(loaders)) for (auto & loader : boost::adaptors::reverse(loaders))
{ {
if (writeableLoaders.count(loader.get()) != 0 // writeable, 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; std::set<boost::filesystem::path> getResourceNames(const ResourcePath & resourceName) const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) 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; std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override;
bool createResource(const ResourcePath & filename, bool update = false) override; bool createResource(const std::string & filename, bool update = false) override;
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourcePath & resourceName) const override; std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourcePath & resourceName) const override;
/** /**

View File

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

View File

@ -37,7 +37,7 @@ public:
std::unique_ptr<CInputStream> load(const ResourcePath & resourceName) const override; std::unique_ptr<CInputStream> load(const ResourcePath & resourceName) const override;
bool existsResource(const ResourcePath & resourceName) const override; bool existsResource(const ResourcePath & resourceName) const override;
std::string getMountPoint() const override; std::string getMountPoint() const override;
bool createResource(const ResourcePath & filename, bool update = false) override; bool createResource(const std::string & filename, bool update = false) override;
std::optional<boost::filesystem::path> getResourceName(const ResourcePath & resourceName) const override; std::optional<boost::filesystem::path> getResourceName(const ResourcePath & resourceName) const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) 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; 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 * @return true if new file was created, false on error or if file already exists
*/ */
virtual bool createResource(const ResourcePath & filename, bool update = false) virtual bool createResource(const std::string & filename, bool update = false)
{ {
return false; return false;
} }

View File

@ -984,7 +984,7 @@ void CMapLoaderH3M::readObjectTemplates()
auto tmpl = reader->readObjectTemplate(); auto tmpl = reader->readObjectTemplate();
templates.push_back(tmpl); templates.push_back(tmpl);
if (!CResourceHandler::get()->existsResource(tmpl->animationFile)) if (!CResourceHandler::get()->existsResource(tmpl->animationFile.addPrefix("SPRITES/")))
logMod->warn("Template animation %s of type (%d %d) is missing!", tmpl->animationFile.getOriginalName(), tmpl->id, tmpl->subid ); logMod->warn("Template animation %s of type (%d %d) is missing!", tmpl->animationFile.getOriginalName(), tmpl->id, tmpl->subid );
} }
} }

View File

@ -56,7 +56,7 @@ void MapIdentifiersH3M::loadMapping(const JsonNode & mapping)
std::string h3mName = boost::to_lower_copy(entryTemplate.second.String()); std::string h3mName = boost::to_lower_copy(entryTemplate.second.String());
std::string vcmiName = boost::to_lower_copy(entryTemplate.first); std::string vcmiName = boost::to_lower_copy(entryTemplate.first);
if (!CResourceHandler::get()->existsResource(AnimationPath::builtin("SPRITES/" + vcmiName))) if (!CResourceHandler::get()->existsResource(AnimationPath::builtinTODO("SPRITES/" + vcmiName)))
logMod->warn("Template animation file %s was not found!", vcmiName); logMod->warn("Template animation file %s was not found!", vcmiName);
mappingObjectTemplate[h3mName] = vcmiName; mappingObjectTemplate[h3mName] = vcmiName;

View File

@ -35,7 +35,7 @@ static JsonNode loadModSettings(const JsonPath & path)
return JsonNode(path); return JsonNode(path);
} }
// Probably new install. Create initial configuration // Probably new install. Create initial configuration
CResourceHandler::get("local")->createResource(path); CResourceHandler::get("local")->createResource(path.getOriginalName() + ".json");
return JsonNode(); return JsonNode();
} }

View File

@ -1718,7 +1718,7 @@ void CGameHandler::save(const std::string & filename)
const auto stem = FileInfo::GetPathStem(filename); const auto stem = FileInfo::GetPathStem(filename);
const auto savefname = stem.to_string() + ".vsgm1"; const auto savefname = stem.to_string() + ".vsgm1";
ResourcePath savePath(stem.to_string(), EResType::SAVEGAME); ResourcePath savePath(stem.to_string(), EResType::SAVEGAME);
CResourceHandler::get("local")->createResource(savePath); CResourceHandler::get("local")->createResource(savefname);
try try
{ {