From 7cf1a1fdf3cbb78a3660b4d94026b52f8751c5a9 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Fri, 9 Oct 2020 22:25:13 +0200 Subject: [PATCH] Switch file reading over to priocpp --- data/worldmaps/tutorial.worldmap | 4 +- external/priocpp | 2 +- extra/pingus-level.cpp | 2 +- extra/pingus-level2png.cpp | 4 +- extra/pingus-po-extract.cpp | 10 +- src/editor/editor_level.cpp | 36 ++--- src/editor/editor_level.hpp | 3 +- src/editor/generic_level_obj.cpp | 50 +++--- src/editor/group_level_obj.cpp | 22 +-- src/editor/group_level_obj.hpp | 4 +- src/editor/level_obj_factory.cpp | 64 ++++---- src/editor/level_obj_factory.hpp | 4 +- src/engine/display/font_description.cpp | 26 +-- src/engine/display/font_description.hpp | 6 +- src/engine/display/sprite_description.cpp | 22 +-- src/engine/input/core_driver.cpp | 20 +-- src/engine/input/manager.cpp | 10 +- src/engine/input/sdl_driver.cpp | 12 +- src/math/vector2f.hpp | 16 ++ src/pingus/levelset.cpp | 22 +-- src/pingus/options.cpp | 71 +++++---- src/pingus/options.hpp | 7 +- src/pingus/pingus_demo.cpp | 8 +- src/pingus/pingus_level.cpp | 44 +++--- src/pingus/pingus_level.hpp | 2 +- src/pingus/pingus_level_impl.hpp | 10 +- src/pingus/pingus_main.cpp | 3 +- src/pingus/prefab_file.cpp | 43 ++--- src/pingus/prefab_file.hpp | 20 +-- src/pingus/resource_manager.hpp | 1 - src/pingus/savegame.cpp | 16 +- src/pingus/savegame.hpp | 6 +- src/pingus/savegame_manager.cpp | 6 +- src/pingus/screens/pingus_menu.cpp | 4 +- src/pingus/screens/story_screen.cpp | 2 +- src/pingus/screens/story_screen.hpp | 2 +- src/pingus/server.cpp | 4 +- src/pingus/server_event.cpp | 16 +- src/pingus/server_event.hpp | 6 +- src/pingus/stat_manager.cpp | 10 +- src/pingus/world.cpp | 14 +- src/pingus/worldmap/dot.cpp | 5 +- src/pingus/worldmap/drawable.hpp | 2 +- src/pingus/worldmap/level_dot.cpp | 4 +- src/pingus/worldmap/path_graph.cpp | 15 +- src/pingus/worldmap/pingus_worldmap.cpp | 51 +++--- src/pingus/worldmap/pingus_worldmap.hpp | 8 +- src/pingus/worldmap/sprite_drawable.cpp | 7 +- src/pingus/worldmap/story_dot.cpp | 12 +- src/pingus/worldmap/story_dot.hpp | 6 +- src/pingus/worldmap/worldmap.cpp | 22 ++- src/pingus/worldmap/worldmap_story.cpp | 10 +- src/pingus/worldmap/worldmap_story.hpp | 6 +- src/pingus/worldobj.cpp | 2 +- src/pingus/worldobj.hpp | 3 +- src/pingus/worldobj_factory.cpp | 13 +- src/pingus/worldobj_renderer.cpp | 37 +++-- src/pingus/worldobj_renderer.hpp | 4 +- src/pingus/worldobjs/conveyor_belt.cpp | 9 +- src/pingus/worldobjs/entrance.cpp | 9 +- src/pingus/worldobjs/exit.cpp | 7 +- src/pingus/worldobjs/fake_exit.cpp | 3 +- src/pingus/worldobjs/groundpiece.cpp | 7 +- src/pingus/worldobjs/guillotine.cpp | 3 +- src/pingus/worldobjs/hammer.cpp | 3 +- src/pingus/worldobjs/hotspot.cpp | 7 +- src/pingus/worldobjs/ice_block.cpp | 7 +- src/pingus/worldobjs/laser_exit.cpp | 3 +- src/pingus/worldobjs/liquid.cpp | 7 +- src/pingus/worldobjs/smasher.cpp | 3 +- src/pingus/worldobjs/snow_generator.cpp | 2 +- .../worldobjs/solid_color_background.cpp | 4 +- src/pingus/worldobjs/spike.cpp | 3 +- src/pingus/worldobjs/starfield_background.cpp | 6 +- src/pingus/worldobjs/surface_background.cpp | 23 +-- src/pingus/worldobjs/switch_door_door.cpp | 5 +- src/pingus/worldobjs/switch_door_switch.cpp | 5 +- src/pingus/worldobjs/teleporter.cpp | 5 +- src/pingus/worldobjs/teleporter_target.cpp | 3 +- src/reader/overrride_reader.cpp | 12 +- src/util/reader.cpp | 148 ++++++++++++++++++ src/util/reader.hpp | 28 +++- src/util/writer.cpp | 57 +++++++ src/util/writer.hpp | 23 ++- tests/reader_test.cpp | 120 -------------- 85 files changed, 750 insertions(+), 603 deletions(-) create mode 100644 src/util/reader.cpp create mode 100644 src/util/writer.cpp delete mode 100644 tests/reader_test.cpp diff --git a/data/worldmaps/tutorial.worldmap b/data/worldmaps/tutorial.worldmap index e1a8e1d32..a01774846 100644 --- a/data/worldmaps/tutorial.worldmap +++ b/data/worldmaps/tutorial.worldmap @@ -287,12 +287,12 @@ (image "worldmaps/tutorial/layer1") (modifer )) (position 586 608 -50) - (auto-uncover 1)) + (auto-uncover #t)) (surface (name "mountain_2") (surface (image "worldmaps/tutorial/layer2") (modifer )) (position 1166 642 100) - (auto-uncover 0)))) + (auto-uncover #f)))) ;; EOF ;; diff --git a/external/priocpp b/external/priocpp index 675282e8d..869a03196 160000 --- a/external/priocpp +++ b/external/priocpp @@ -1 +1 @@ -Subproject commit 675282e8daff0ab63b58b60ad50ed7582195fc56 +Subproject commit 869a0319699464628545bf4f48989eefa2fa7018 diff --git a/extra/pingus-level.cpp b/extra/pingus-level.cpp index 3b320a2b2..f406f7f13 100644 --- a/extra/pingus-level.cpp +++ b/extra/pingus-level.cpp @@ -110,7 +110,7 @@ int main(int argc, char** argv) << static_cast(plf.get_ambient_light().b) << " " << static_cast(plf.get_ambient_light().a) << std::endl; - std::cout << "objects : " << plf.get_objects().size() << std::endl; + std::cout << "objects : " << plf.get_objects().get_objects().size() << std::endl; std::cout << std::endl; } else diff --git a/extra/pingus-level2png.cpp b/extra/pingus-level2png.cpp index 56067118b..a106d8d35 100644 --- a/extra/pingus-level2png.cpp +++ b/extra/pingus-level2png.cpp @@ -100,8 +100,8 @@ int main(int argc, char** argv) std::ostringstream out; Writer writer(out); writer.begin_mapping("pingus-sprite"); - writer.write_string("image", System::cut_file_extension(System::basename(files[0].get_raw_path())) + ".png"); - writer.write_vector2i("offset", offset); + writer.write("image", System::cut_file_extension(System::basename(files[0].get_raw_path())) + ".png"); + writer.write("offset", offset); writer.end_mapping(); out << std::endl; log_info("writing: %1%", outfile); diff --git a/extra/pingus-po-extract.cpp b/extra/pingus-po-extract.cpp index 4221b4121..a90e3315c 100644 --- a/extra/pingus-po-extract.cpp +++ b/extra/pingus-po-extract.cpp @@ -32,21 +32,21 @@ int po_extract_main(int argc, char** argv) } else if (filename.has_extension(".story")) { - ReaderObject reader_object = Reader::parse(filename); - ReaderMapping reader = reader_object.get_mapping(); + auto doc = ReaderDocument::from_file(filename.get_sys_path(), true); + ReaderMapping reader = doc.get_mapping(); std::string tmp; - if (reader.read_string("title", tmp)) + if (reader.read("title", tmp)) { emit_msgid(tmp); } - ReaderCollection all_pages = reader.read_collection("pages"); + ReaderCollection all_pages = reader.get("pages"); const auto& childs = all_pages.get_objects(); for(auto it = childs.begin(); it != childs.end(); ++it) { ReaderMapping r = it->get_mapping(); - if (r.read_string("text", tmp)) + if (r.read("text", tmp)) { emit_msgid(tmp); } diff --git a/src/editor/editor_level.cpp b/src/editor/editor_level.cpp index b59bd0e5f..3240c6ec8 100644 --- a/src/editor/editor_level.cpp +++ b/src/editor/editor_level.cpp @@ -122,12 +122,10 @@ EditorLevel::from_level_file(const Pathname& pathname) } // Get the objects - auto objs = plf.get_objects(); - for (auto i = objs.begin(); i != objs.end(); i++) - { - LevelObjPtr obj = LevelObjFactory::create(*i); - if (obj) - { + ReaderCollection const& objects = plf.get_objects(); + for (auto const& reader_object : objects.get_objects()) { + LevelObjPtr obj = LevelObjFactory::create(reader_object); + if (obj) { level->add_object(obj); } } @@ -154,7 +152,7 @@ EditorLevel::from_prefab_file(const Pathname& pathname) // FIXME: overrides are getting ignored // Get the objects - auto objs = prefab.get_objects(); + auto const& objs = prefab.get_objects().get_objects(); for (auto i = objs.begin(); i != objs.end(); i++) { LevelObjPtr obj = LevelObjFactory::create(*i); @@ -208,7 +206,7 @@ EditorLevel::save_prefab(const std::string& filename) // Write header fw.begin_object("pingus-prefab"); - fw.write_int("version", 3); + fw.write("version", 3); Vector2f level_center(static_cast(get_size().width())/2.0f, static_cast(get_size().height())/2.0f); @@ -251,27 +249,27 @@ EditorLevel::save_level(Writer& fw) // Write header fw.begin_object("pingus-level"); - fw.write_int("version", 3); + fw.write("version", 3); fw.begin_mapping("head"); - fw.write_string("license", "GPLv3+"); - fw.write_string("levelname", impl->levelname); - fw.write_string("description", impl->description); - fw.write_string("author", impl->author); - fw.write_int("number-of-pingus", impl->number_of_pingus); - fw.write_int("number-to-save", impl->number_to_save); - fw.write_int("time", impl->time); - fw.write_string("music", impl->music); + fw.write("license", "GPLv3+"); + fw.write("levelname", impl->levelname); + fw.write("description", impl->description); + fw.write("author", impl->author); + fw.write("number-of-pingus", impl->number_of_pingus); + fw.write("number-to-save", impl->number_to_save); + fw.write("time", impl->time); + fw.write("music", impl->music); // Write the list of actions to the file fw.begin_mapping("actions"); for (auto i = impl->actions.begin(); i != impl->actions.end(); i++) { if (i->second > 0) - fw.write_int(i->first.c_str(), i->second); + fw.write(i->first.c_str(), i->second); } fw.end_mapping(); // actions - fw.write_size("levelsize", impl->size); + fw.write("levelsize", impl->size); fw.end_mapping(); // head // Write the objects diff --git a/src/editor/editor_level.hpp b/src/editor/editor_level.hpp index 496366379..198a94459 100644 --- a/src/editor/editor_level.hpp +++ b/src/editor/editor_level.hpp @@ -23,11 +23,12 @@ #include #include +#include + #include "math/size.hpp" #include "editor/level_obj.hpp" class Pathname; -class Writer; namespace Editor { diff --git a/src/editor/generic_level_obj.cpp b/src/editor/generic_level_obj.cpp index 815095b2d..0aa6a4826 100644 --- a/src/editor/generic_level_obj.cpp +++ b/src/editor/generic_level_obj.cpp @@ -287,71 +287,71 @@ GenericLevelObj::write_properties(Writer &fw) const unsigned attribs_ = get_attributes(section_name); if (attribs_ & HAS_TYPE) - fw.write_string("type", object_type); + fw.write("type", object_type); if (attribs_ & HAS_GPTYPE) - fw.write_string("type", ground_type); + fw.write("type", ground_type); if (attribs_ & HAS_SPRITE) { fw.begin_mapping("surface"); - fw.write_string("image", desc.res_name); - fw.write_string("modifier", ResourceModifier::to_string(desc.modifier)); + fw.write("image", desc.res_name); + fw.write("modifier", ResourceModifier::to_string(desc.modifier)); fw.end_mapping(); // surface } - fw.write_vector("position", pos, z_index()); + fw.write("position", OutVector2fZ{pos, m_z_index}); if (attribs_ & HAS_SPEED) - fw.write_int("speed", speed); + fw.write("speed", speed); if (attribs_ & HAS_PARALLAX) - fw.write_float("parallax", parallax); + fw.write("parallax", parallax); if (attribs_ & HAS_REPEAT) - fw.write_int("repeat", repeat); + fw.write("repeat", repeat); if (attribs_ & HAS_OWNER) - fw.write_int("owner-id", owner_id); + fw.write("owner-id", owner_id); if (attribs_ & HAS_DIRECTION) - fw.write_string("direction", direction); + fw.write("direction", direction); if (attribs_ & HAS_RELEASE_RATE) - fw.write_int("release-rate", release_rate); + fw.write("release-rate", release_rate); if (attribs_ & HAS_COLOR) - fw.write_colori("colori", color); + fw.write("colori", color); if (attribs_ & HAS_STRETCH) { - fw.write_bool("stretch-x", stretch_x); - fw.write_bool("stretch-y", stretch_y); - fw.write_bool("keep-aspect", keep_aspect); + fw.write("stretch-x", stretch_x); + fw.write("stretch-y", stretch_y); + fw.write("keep-aspect", keep_aspect); } if (attribs_ & HAS_SCROLL) { - fw.write_float("scroll-x", scroll_x); - fw.write_float("scroll-y", scroll_y); + fw.write("scroll-x", scroll_x); + fw.write("scroll-y", scroll_y); } if (attribs_ & HAS_PARA) { - fw.write_float("para-x", para_x); - fw.write_float("para-y", para_y); + fw.write("para-x", para_x); + fw.write("para-y", para_y); } if (attribs_ & HAS_STARFIELD) { - fw.write_int("small-stars", small_stars); - fw.write_int("middle-stars", middle_stars); - fw.write_int("large-stars", large_stars); + fw.write("small-stars", small_stars); + fw.write("middle-stars", middle_stars); + fw.write("large-stars", large_stars); } if (attribs_ & HAS_ID) { - fw.write_string("id", id); + fw.write("id", id); } if (attribs_ & HAS_TARGET_ID) { - fw.write_string("target-id", target_id); + fw.write("target-id", target_id); } if (attribs_ & HAS_HEIGHT) - fw.write_int("height", height); + fw.write("height", height); // Writes any extra properties that may be necessary (virtual function) write_extra_properties(fw); diff --git a/src/editor/group_level_obj.cpp b/src/editor/group_level_obj.cpp index ca6753f35..0f32610af 100644 --- a/src/editor/group_level_obj.cpp +++ b/src/editor/group_level_obj.cpp @@ -34,7 +34,7 @@ GroupLevelObj::from_prefab(const std::string& name) std::shared_ptr group = std::make_shared(); group->m_name = name; - for(auto const& obj_desc : prefab.get_objects()) + for(auto const& obj_desc : prefab.get_objects().get_objects()) { LevelObjPtr obj = LevelObjFactory::create(obj_desc); if (obj) @@ -93,25 +93,25 @@ GroupLevelObj::add_child(const LevelObjPtr& obj) void GroupLevelObj::set_overrides(const ReaderMapping& reader) { - if (reader.read_int("repeat", m_repeat)) + if (reader.read("repeat", m_repeat)) { set_repeat(m_repeat); m_overrides |= HAS_REPEAT; } - if (reader.read_int("owner-id", m_owner_id)) + if (reader.read("owner-id", m_owner_id)) { set_owner(m_owner_id); m_overrides |= HAS_OWNER; } - if (reader.read_int("release-rate", m_release_rate)) + if (reader.read("release-rate", m_release_rate)) { set_release_rate(m_release_rate); m_overrides |= HAS_RELEASE_RATE; } - if (reader.read_string("direction", m_direction)) + if (reader.read("direction", m_direction)) { set_direction(m_direction); m_overrides |= HAS_DIRECTION; @@ -135,13 +135,13 @@ GroupLevelObj::write_properties(Writer& writer) else { writer.begin_object("prefab"); - writer.write_string("name", m_name); - writer.write_vector("position", m_pos, z_index()); + writer.write("name", m_name); + writer.write("position", OutVector2fZ{m_pos, z_index()}); writer.begin_mapping("overrides"); - if (m_overrides & HAS_REPEAT) writer.write_int("repeat", m_repeat); - if (m_overrides & HAS_RELEASE_RATE) writer.write_int("release-rate", m_release_rate); - if (m_overrides & HAS_DIRECTION) writer.write_string("direction", m_direction); - if (m_overrides & HAS_OWNER) writer.write_int("owner-id", m_owner_id); + if (m_overrides & HAS_REPEAT) writer.write("repeat", m_repeat); + if (m_overrides & HAS_RELEASE_RATE) writer.write("release-rate", m_release_rate); + if (m_overrides & HAS_DIRECTION) writer.write("direction", m_direction); + if (m_overrides & HAS_OWNER) writer.write("owner-id", m_owner_id); writer.end_mapping(); writer.end_object(); } diff --git a/src/editor/group_level_obj.hpp b/src/editor/group_level_obj.hpp index 9d475a2da..ad6dcd252 100644 --- a/src/editor/group_level_obj.hpp +++ b/src/editor/group_level_obj.hpp @@ -21,7 +21,7 @@ #include -class ReaderMapping; +#include "util/reader.hpp" namespace Editor { @@ -59,7 +59,7 @@ class GroupLevelObj : public LevelObj std::list& get_objects() { return m_objects; } - void set_overrides(const ReaderMapping& reader); + void set_overrides(ReaderMapping const& reader); public: /** Retrieve the object's position */ diff --git a/src/editor/level_obj_factory.cpp b/src/editor/level_obj_factory.cpp index 50e19a599..564d770d8 100644 --- a/src/editor/level_obj_factory.cpp +++ b/src/editor/level_obj_factory.cpp @@ -31,7 +31,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) ReaderMapping reader = reader_object.get_mapping(); ReaderCollection collection; - reader.read_collection("objects", collection); + reader.read("objects", collection); std::vector objects = collection.get_objects(); for(auto it = objects.begin(); it != objects.end(); ++it) { @@ -48,11 +48,12 @@ LevelObjFactory::create(const ReaderObject& reader_object) ReaderMapping reader = reader_object.get_mapping(); std::string name; - reader.read_string("name", name); + reader.read("name", name); Vector2f p; float z_index = 0.0f; - reader.read_vector("position", p, z_index); + InVector2fZ in_vec{p, z_index}; + reader.read("position", in_vec); std::shared_ptr group = GroupLevelObj::from_prefab(name); if (!group) @@ -62,7 +63,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) else { ReaderMapping overrides; - if (reader.read_mapping("overrides", overrides)) + if (reader.read("overrides", overrides)) group->set_overrides(overrides); group->set_orig_pos(p); @@ -90,7 +91,8 @@ LevelObjFactory::create(const ReaderObject& reader_object) attribs = obj->get_attribs(); // All objects have a position - get that. - if (!reader.read_vector("position", p, z_index)) + InVector2fZ in_vec{p, z_index}; + if (!reader.read("position", in_vec)) { // Workaround for lack of position for background if (reader_object.get_name() == "surface-background") { p = Vector2f(0.f, 0.f); @@ -105,7 +107,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) // Get optional attributes based on the attribs value if (attribs & HAS_SPRITE) { - if (reader.read_desc("surface", desc)) + if (reader.read("surface", desc)) { obj->set_res_desc(desc); } @@ -113,7 +115,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_TYPE) { - if (reader.read_string("type", tmp_str)) + if (reader.read("type", tmp_str)) { obj->set_type(tmp_str); } @@ -121,7 +123,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_GPTYPE) { - if (reader.read_string("type", tmp_str)) + if (reader.read("type", tmp_str)) { obj->set_ground_type(tmp_str); } @@ -129,7 +131,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_SPEED) { - if (reader.read_int("speed", tmp_int)) + if (reader.read("speed", tmp_int)) { obj->set_speed(tmp_int); } @@ -137,8 +139,8 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_REPEAT) { - if (reader.read_int("repeat", tmp_int) || - reader.read_int("width", tmp_int)) + if (reader.read("repeat", tmp_int) || + reader.read("width", tmp_int)) { obj->set_repeat(tmp_int); } @@ -146,7 +148,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_PARALLAX) { - if (reader.read_float("parallax", tmp_float)) + if (reader.read("parallax", tmp_float)) { obj->set_parallax(tmp_float); } @@ -154,7 +156,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_OWNER) { - if (reader.read_int("owner-id", tmp_int)) + if (reader.read("owner-id", tmp_int)) { obj->set_owner(tmp_int); } @@ -162,7 +164,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_DIRECTION) { - if (reader.read_string("direction", tmp_str)) + if (reader.read("direction", tmp_str)) { obj->set_direction(tmp_str); } @@ -172,22 +174,22 @@ LevelObjFactory::create(const ReaderObject& reader_object) { Color tmp_color; Colorf tmp_colorf; - if (reader.read_colori("colori", tmp_color)) { + if (reader.read("colori", tmp_color)) { obj->set_color(tmp_color); - } else if (reader.read_colori("colori", tmp_color)) { - reader.read_colorf("color", tmp_colorf);; + } else if (reader.read("colori", tmp_color)) { + reader.read("color", tmp_colorf); obj->set_color(tmp_colorf.to_color()); } } if (attribs & HAS_SCROLL) { - if (reader.read_float("scroll-x", tmp_float)) + if (reader.read("scroll-x", tmp_float)) { obj->set_scroll_x(tmp_float); } - if (reader.read_float("scroll-y", tmp_float)) + if (reader.read("scroll-y", tmp_float)) { obj->set_scroll_y(tmp_float); } @@ -195,17 +197,17 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_STRETCH) { - if (reader.read_bool("stretch-x", tmp_bool)) + if (reader.read("stretch-x", tmp_bool)) { obj->set_stretch_x(tmp_bool); } - if (reader.read_bool("stretch-y", tmp_bool)) + if (reader.read("stretch-y", tmp_bool)) { obj->set_stretch_y(tmp_bool); } - if (reader.read_bool("keep-aspect", tmp_bool)) + if (reader.read("keep-aspect", tmp_bool)) { obj->set_keep_aspect(tmp_bool); } @@ -213,12 +215,12 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_PARA) { - if (reader.read_float("para-x", tmp_float)) + if (reader.read("para-x", tmp_float)) { obj->set_para_x(tmp_float); } - if (reader.read_float("para-y", tmp_float)) + if (reader.read("para-y", tmp_float)) { obj->set_para_y(tmp_float); } @@ -226,7 +228,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_RELEASE_RATE) { - if (reader.read_int("release-rate", tmp_int)) + if (reader.read("release-rate", tmp_int)) { obj->set_release_rate(tmp_int); } @@ -234,7 +236,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_ID) { - if (reader.read_string("id", tmp_str)) + if (reader.read("id", tmp_str)) { obj->set_id(tmp_str); } @@ -242,7 +244,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_TARGET_ID) { - if (reader.read_string("target-id", tmp_str)) + if (reader.read("target-id", tmp_str)) { obj->set_target_id(tmp_str); } @@ -250,17 +252,17 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_STARFIELD) { - if (reader.read_int("small-stars", tmp_int)) + if (reader.read("small-stars", tmp_int)) { obj->set_small_stars(tmp_int); } - if (reader.read_int("middle-stars", tmp_int)) + if (reader.read("middle-stars", tmp_int)) { obj->set_middle_stars(tmp_int); } - if (reader.read_int("large-stars", tmp_int)) + if (reader.read("large-stars", tmp_int)) { obj->set_large_stars(tmp_int); } @@ -268,7 +270,7 @@ LevelObjFactory::create(const ReaderObject& reader_object) if (attribs & HAS_HEIGHT) { - if (reader.read_int("height", tmp_int)) + if (reader.read("height", tmp_int)) { obj->set_height(tmp_int); } diff --git a/src/editor/level_obj_factory.hpp b/src/editor/level_obj_factory.hpp index 9cd385fbc..4954bbbdf 100644 --- a/src/editor/level_obj_factory.hpp +++ b/src/editor/level_obj_factory.hpp @@ -19,7 +19,7 @@ #include "editor/level_obj_ptr.hpp" -class ReaderObject; +#include namespace Editor { @@ -27,7 +27,7 @@ class LevelObjFactory { private: public: - static LevelObjPtr create(const ReaderObject& reader_object); + static LevelObjPtr create(const prio::ReaderObject& reader_object); private: LevelObjFactory(const LevelObjFactory&); diff --git a/src/engine/display/font_description.cpp b/src/engine/display/font_description.cpp index 6d9c32577..981851e93 100644 --- a/src/engine/display/font_description.cpp +++ b/src/engine/display/font_description.cpp @@ -40,11 +40,11 @@ GlyphDescription::GlyphDescription(const ReaderMapping& reader) : rect() { int lazy = 0; // FIXME: implement read_uint32 - reader.read_int("unicode", lazy); + reader.read("unicode", lazy); unicode = static_cast(lazy); - reader.read_vector2i("offset", offset); - reader.read_int("advance", advance); - reader.read_rect("rect", rect); + reader.read("offset", offset); + reader.read("advance", advance); + reader.read("rect", rect); } FontDescription::FontDescription(const Pathname& pathname_) : @@ -57,22 +57,22 @@ FontDescription::FontDescription(const Pathname& pathname_) : char_spacing = 1.0f; vertical_spacing = 1.0f; - ReaderObject reader_object = Reader::parse(pathname); + auto doc = ReaderDocument::from_file(pathname.get_sys_path(), true); - if (reader_object.get_name() != "pingus-font") + if (doc.get_root().get_name() != "pingus-font") { raise_exception(std::runtime_error, pathname << ": not a pingus-font file"); } else { - ReaderMapping reader = reader_object.get_mapping(); + ReaderMapping reader = doc.get_root().get_mapping(); - reader.read_float("char-spacing", char_spacing); - reader.read_float("vertical-spacing", vertical_spacing); - reader.read_int("size", size); + reader.read("char-spacing", char_spacing); + reader.read("vertical-spacing", vertical_spacing); + reader.read("size", size); ReaderCollection images_reader; - if (reader.read_collection("images", images_reader)) + if (reader.read("images", images_reader)) { auto images_lst = images_reader.get_objects(); @@ -81,10 +81,10 @@ FontDescription::FontDescription(const Pathname& pathname_) : ReaderMapping mapping = i->get_mapping(); GlyphImageDescription image_desc; - mapping.read_path("filename", image_desc.pathname); + mapping.read("filename", image_desc.pathname); ReaderCollection glyph_collection; - if (mapping.read_collection("glyphs", glyph_collection)) + if (mapping.read("glyphs", glyph_collection)) { std::vector glyph_reader = glyph_collection.get_objects(); for(auto j = glyph_reader.begin(); j != glyph_reader.end(); ++j) diff --git a/src/engine/display/font_description.hpp b/src/engine/display/font_description.hpp index e5564c281..d3b1186c1 100644 --- a/src/engine/display/font_description.hpp +++ b/src/engine/display/font_description.hpp @@ -19,11 +19,11 @@ #include +#include + #include "math/rect.hpp" #include "util/pathname.hpp" -class ReaderMapping; - class GlyphDescription { public: @@ -34,7 +34,7 @@ class GlyphDescription Rect rect; GlyphDescription(); - GlyphDescription(const ReaderMapping& reader); + GlyphDescription(const prio::ReaderMapping& reader); }; class GlyphImageDescription diff --git a/src/engine/display/sprite_description.cpp b/src/engine/display/sprite_description.cpp index 469023bc1..e30b7c3b6 100644 --- a/src/engine/display/sprite_description.cpp +++ b/src/engine/display/sprite_description.cpp @@ -21,26 +21,26 @@ SpriteDescriptionPtr SpriteDescription::from_file(const Pathname& path) { - ReaderObject reader_object = Reader::parse(path); - ReaderMapping reader = reader_object.get_mapping(); + auto doc = ReaderDocument::from_file(path.get_sys_path(), true); + ReaderMapping reader = doc.get_root().get_mapping(); SpriteDescriptionPtr desc(new SpriteDescription); - reader.read_int("speed", desc->speed); - reader.read_bool("loop", desc->loop); - reader.read_vector2i("offset", desc->offset); + reader.read("speed", desc->speed); + reader.read("loop", desc->loop); + reader.read("offset", desc->offset); - reader.read_enum("origin", desc->origin, string2origin); + reader.read("origin", desc->origin, string2origin); - if (!reader.read_path("image", desc->filename)) + if (!reader.read("image", desc->filename)) { - log_error("'image' missing for {}", reader_object.get_name()); + log_error("'image' missing for {}", doc.get_root().get_name()); } desc->filename = Pathname(desc->filename.get_raw_path(), Pathname::DATA_PATH); // FIXME: Hack - reader.read_size("array", desc->array); - reader.read_vector2i("position", desc->frame_pos); - reader.read_size("size", desc->frame_size); + reader.read("array", desc->array); + reader.read("position", desc->frame_pos); + reader.read("size", desc->frame_size); return desc; } diff --git a/src/engine/input/core_driver.cpp b/src/engine/input/core_driver.cpp index 040c6331f..a72d19bb5 100644 --- a/src/engine/input/core_driver.cpp +++ b/src/engine/input/core_driver.cpp @@ -233,14 +233,14 @@ CoreDriver::create_scroller(const ReaderObject& reader_object, Control* parent) auto axis = std::make_unique(parent); ReaderObject x_reader; - if (!reader.read_object("x-axis", x_reader)) + if (!reader.read("x-axis", x_reader)) { log_error("CoreDriver: Couldn't find x-axis"); return {}; } ReaderObject y_reader; - if (!reader.read_object("y-axis", y_reader)) + if (!reader.read("y-axis", y_reader)) { log_error("CoreDriver: Couldn't find y-axis"); return {}; @@ -251,7 +251,7 @@ CoreDriver::create_scroller(const ReaderObject& reader_object, Control* parent) std::unique_ptr