12#include <boost/property_tree/xml_parser.hpp>
16using boost::property_tree::ptree;
20 return object.fromXML(filePath, fileName);
25 return object.toXML(filePath, fileName);
47 if (backupReturnCode != FileError::NONE &&
48 backupReturnCode != FileError::FILE_NOT_FOUND &&
49 backupReturnCode != FileError::FILE_EMPTY)
60 read_xml(loadPath.
string().c_str(),
62 boost::property_tree::xml_parser::trim_whitespace);
66 catch (
const boost::property_tree::xml_parser_error& error )
86 const FileError backupReturnCode =
copyFile(path, file, path, (file +
".bak"),
true);
87 if (backupReturnCode != FileError::NONE &&
88 backupReturnCode != FileError::FILE_NOT_FOUND &&
89 backupReturnCode != FileError::FILE_EMPTY)
101 write_xml(savePath.
string().c_str(),
104 boost::property_tree::xml_writer_make_settings<boost::property_tree::iptree::key_type>(
'\t', 1));
108 catch(
const boost::property_tree::xml_parser_error& error)
126 modifiersOut.resize(0);
127 actionsUpOut.resize(0);
128 actionsDownOut.resize(0);
132 const std::string modifiers = attributes.get<std::string>(
"modifier",
"");
133 if (!modifiers.empty()) {
134 Util::Split<vector<std::string>, std::string>(modifiers.c_str(),
',', modifiersOut);
135 for (
const auto& it : modifiersOut) {
145 const std::string actionsUp = attributes.get<std::string>(
"actionUp",
"");
146 if (!actionsUp.empty()) {
147 Util::Split<vector<std::string>, std::string>(actionsUp.c_str(),
',', actionsUpOut);
148 for (
const auto& it : actionsUpOut) {
153 entryOut.releaseIDs().insert(
id);
159 const std::string actionsDown = attributes.get<std::string>(
"actionDown",
"");
160 if (!actionsDown.empty()) {
161 Util::Split<vector<std::string>, std::string>(actionsDown.c_str(),
',', actionsDownOut);
162 for (
const auto& it : actionsDownOut) {
167 entryOut.pressIDs().insert(
id);
177 read_xml(file.
string().c_str(), pt);
179 for(
const auto & [tag, data] : pt.get_child(
"actions", g_emptyPtree))
181 const ptree & attributes = data.get_child(
"<xmlattr>", g_emptyPtree);
182 scene->input()->actionList().getInputAction(attributes.get<
U16>(
"id", 0)).displayName(attributes.get<
string>(
"name",
"").c_str());
186 for (
const auto & [tag, data] : pt.get_child(
"keys", g_emptyPtree))
188 if (tag ==
"<xmlcomment>") {
192 const ptree & attributes = data.get_child(
"<xmlattr>", g_emptyPtree);
196 scene->input()->addKeyMapping(key,
entry);
199 for (
const auto & [tag, data] : pt.get_child(
"mouseButtons", g_emptyPtree))
201 if (tag.compare(
"<xmlcomment>") == 0)
206 const ptree & attributes = data.get_child(
"<xmlattr>", g_emptyPtree);
211 scene->input()->addMouseMapping(btn,
entry);
214 const std::string label(
"joystickButtons.joystick");
218 for (
const auto & [tag, value] : pt.get_child(label + std::to_string(i + 1), g_emptyPtree))
220 if ( tag.compare(
"<xmlcomment>" ) == 0 )
225 const ptree & attributes = value.get_child(
"<xmlattr>", g_emptyPtree);
247 read_xml(file.
string().c_str(), pt);
249 for (
const auto & [tag, data] : pt.get_child(
"backgroundThemes", g_emptyPtree))
251 const ptree & attributes = data.get_child(
"<xmlattr>", g_emptyPtree);
253 attributes.get<
string>(
"name",
"").c_str(),
254 Paths::g_assetsLocation / attributes.get<
string>(
"src",
"") );
260 static boost::property_tree::xml_writer_settings<std::string> settings(
' ', 4);
262 write_xml(path.
string().c_str(), tree, std::locale(), settings);
269 read_xml(path.
string().c_str(), tree);
271 catch (
const boost::property_tree::xml_parser_error& e)
static constexpr Input::KeyCode s_modifierMappings[to_base(Modifier::COUNT)]
static constexpr const char * s_modifierNames[to_base(Modifier::COUNT)]
void addMusic(MusicType type, const std::string_view name, const ResourcePath &srcFile)
constexpr bool IS_SHIPPING_BUILD
bool loadFromXML(IXMLSerializable &object, const ResourcePath &filePath, const char *fileName)
bool saveToXML(const IXMLSerializable &object, const ResourcePath &filePath, const char *fileName)
void loadDefaultKeyBindings(const ResourcePath &file, const Scene *scene)
Child Functions.
void loadMusicPlaylist(const ResourcePath &scenePath, const Str< 64 > &fileName, Scene *scene, const Configuration &config)
static void PopulatePressRelease(const ptree &attributes, PressReleaseActions::Entry &entryOut)
void writeXML(const ResourcePath &path, const boost::property_tree::ptree &tree)
void readXML(const ResourcePath &path, boost::property_tree::ptree &tree)
eastl::vector< Type > vector
FileError copyFile(const ResourcePath &sourcePath, const std::string_view sourceName, const ResourcePath &targetPath, const std::string_view targetName, const bool overwrite)
bool fileIsEmpty(const ResourcePath &filePathAndName)
bool fileExists(const ResourcePath &filePathAndName)
Project const SceneEntry & entry
FileNameAndPath splitPathToNameAndLocation(const ResourcePath &input)
bool createFile(const ResourcePath &filePathAndName, const bool overwriteExisting)
constexpr auto to_base(const Type value) -> Type
static NO_INLINE void errorfn(const char *format, T &&... args)
static NO_INLINE void printfn(const char *format, T &&... args)
StringReturnType< N > string() const noexcept
bool write(const ResourcePath &filePath, const char *fileName) const
boost::property_tree::iptree XmlTree
std::string _rootNodePath
bool read(const ResourcePath &filePath, const char *fileName, const std::string &rootNode)