Test case for dialog XMLs in-engine

This commit is contained in:
2023-01-06 01:20:38 -07:00
committed by Celtic Minstrel
parent 6471604fd9
commit ac5cbe3a60
3 changed files with 45 additions and 9 deletions

View File

@@ -16,15 +16,7 @@ extern std::ostream& std_fmterr(std::ostream& out);
class DialogLoader : public ResMgr::cLoader<DialogDefn> {
/// Load a dialog definition from an XML file.
DialogDefn* operator() (const fs::path& fpath) const override {
TiXmlBase::SetCondenseWhiteSpace(false);
ticpp::Document xml(fpath.string().c_str());
try {
xml.LoadFile();
} catch(ticpp::Exception& e) {
std::cerr << "Error reading XML file: " << e.what();
throw ResMgr::xError(ResMgr::ERR_LOAD, "Failed to load dialog: " + fpath.string());
}
return new DialogDefn{fpath.stem().string(), std::move(xml)};
return load_dialog_defn(fpath);
}
ResourceList expand(const std::string& name) const override {
@@ -36,6 +28,18 @@ class DialogLoader : public ResMgr::cLoader<DialogDefn> {
}
};
DialogDefn* load_dialog_defn(const fs::path& fpath) {
TiXmlBase::SetCondenseWhiteSpace(false);
ticpp::Document xml(fpath.string().c_str());
try {
xml.LoadFile();
} catch(ticpp::Exception& e) {
std::cerr << "Error reading XML file: " << e.what();
throw ResMgr::xError(ResMgr::ERR_LOAD, "Failed to load dialog: " + fpath.string());
}
return new DialogDefn{fpath.stem().string(), std::move(xml)};
}
// TODO: What's a good max dialogs count?
static DialogLoader loader;
ResMgr::cPool<DialogDefn> ResMgr::dialogs(loader, 80);

View File

@@ -19,6 +19,8 @@ struct DialogDefn {
/// The XML definition of the dialog.
ticpp::Document defn;
};
/// Load a dialog definition from an XML file.
DialogDefn* load_dialog_defn(const fs::path& fpath);
using DialogRsrc = ResMgr::cPointer<DialogDefn>;