@@ -156,7 +156,12 @@ namespace game::resource::xml
|
||||
}
|
||||
}
|
||||
|
||||
int Dialogue::Pool::get() const { return this->at(math::random_max(this->size())); }
|
||||
int Dialogue::Pool::get() const
|
||||
{
|
||||
if (this->empty()) return -1;
|
||||
auto index = rand() % this->size();
|
||||
return this->at(index);
|
||||
}
|
||||
Dialogue::Entry* Dialogue::get(int id) { return &entries.at(id); }
|
||||
Dialogue::Entry* Dialogue::get(Dialogue::EntryReference& entry) { return &entries.at(entry.id); }
|
||||
Dialogue::Entry* Dialogue::get(const std::string& string) { return &entries.at(entryIDMap.at(string)); }
|
||||
|
||||
@@ -18,16 +18,17 @@ namespace game::resource::xml
|
||||
Save::Save(const std::filesystem::path& path)
|
||||
{
|
||||
XMLDocument document;
|
||||
auto pathString = path.string();
|
||||
|
||||
// Fail silently if there's no save.
|
||||
auto result = document.LoadFile(path.c_str());
|
||||
auto result = document.LoadFile(pathString.c_str());
|
||||
|
||||
if (result == XML_ERROR_FILE_NOT_FOUND || result == XML_ERROR_FILE_COULD_NOT_BE_OPENED) return;
|
||||
|
||||
if (result != XML_SUCCESS)
|
||||
{
|
||||
logger.error(
|
||||
std::format("Could not initialize character save file: {} ({})", path.string(), document.ErrorStr()));
|
||||
std::format("Could not initialize character save file: {} ({})", pathString, document.ErrorStr()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,7 +100,7 @@ namespace game::resource::xml
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(std::format("Initialized character save file: {}", path.string()));
|
||||
logger.info(std::format("Initialized character save file: {}", pathString));
|
||||
|
||||
isValid = true;
|
||||
}
|
||||
@@ -109,6 +110,7 @@ namespace game::resource::xml
|
||||
void Save::serialize(const std::filesystem::path& path)
|
||||
{
|
||||
XMLDocument document;
|
||||
auto pathString = path.string();
|
||||
|
||||
auto element = document.NewElement("Save");
|
||||
element->SetAttribute("IsPostgame", isPostgame ? "true" : "false");
|
||||
@@ -168,13 +170,13 @@ namespace game::resource::xml
|
||||
|
||||
document.InsertFirstChild(element);
|
||||
|
||||
if (document.SaveFile(path.c_str()) != XML_SUCCESS)
|
||||
if (document.SaveFile(pathString.c_str()) != XML_SUCCESS)
|
||||
{
|
||||
logger.error(std::format("Failed to save character save file: {} ({})", path.string(), document.ErrorStr()));
|
||||
logger.error(std::format("Failed to save character save file: {} ({})", pathString, document.ErrorStr()));
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(std::format("Saved character save file: {}", path.string()));
|
||||
logger.info(std::format("Saved character save file: {}", pathString));
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
web_filesystem::flush_async();
|
||||
|
||||
@@ -17,11 +17,12 @@ namespace game::resource::xml
|
||||
Settings::Settings(const std::filesystem::path& path)
|
||||
{
|
||||
XMLDocument document;
|
||||
auto pathString = path.string();
|
||||
|
||||
if (document.LoadFile(path.c_str()) != XML_SUCCESS)
|
||||
if (document.LoadFile(pathString.c_str()) != XML_SUCCESS)
|
||||
{
|
||||
logger.error(
|
||||
std::format("Could not initialize character save file: {} ({})", path.string(), document.ErrorStr()));
|
||||
std::format("Could not initialize character save file: {} ({})", pathString, document.ErrorStr()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ namespace game::resource::xml
|
||||
root->QueryIntAttribute("WindowH", &windowSize.y);
|
||||
}
|
||||
|
||||
logger.info(std::format("Initialized settings: {}", path.string()));
|
||||
logger.info(std::format("Initialized settings: {}", pathString));
|
||||
|
||||
isValid = true;
|
||||
}
|
||||
@@ -50,6 +51,7 @@ namespace game::resource::xml
|
||||
void Settings::serialize(const std::filesystem::path& path)
|
||||
{
|
||||
XMLDocument document;
|
||||
auto pathString = path.string();
|
||||
|
||||
auto element = document.NewElement("Settings");
|
||||
|
||||
@@ -65,13 +67,13 @@ namespace game::resource::xml
|
||||
|
||||
document.InsertFirstChild(element);
|
||||
|
||||
if (document.SaveFile(path.c_str()) != XML_SUCCESS)
|
||||
if (document.SaveFile(pathString.c_str()) != XML_SUCCESS)
|
||||
{
|
||||
logger.info(std::format("Failed to initialize settings: {} ({})", path.string(), document.ErrorStr()));
|
||||
logger.info(std::format("Failed to initialize settings: {} ({})", pathString, document.ErrorStr()));
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(std::format("Saved settings: {}", path.string()));
|
||||
logger.info(std::format("Saved settings: {}", pathString));
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
web_filesystem::flush_async();
|
||||
|
||||
Reference in New Issue
Block a user