Skip to content

Commit

Permalink
Switch file reading over to priocpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Oct 9, 2020
1 parent b6c88d7 commit 7cf1a1f
Show file tree
Hide file tree
Showing 85 changed files with 750 additions and 603 deletions.
4 changes: 2 additions & 2 deletions data/worldmaps/tutorial.worldmap
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;
2 changes: 1 addition & 1 deletion external/priocpp
Submodule priocpp updated from 675282 to 869a03
2 changes: 1 addition & 1 deletion extra/pingus-level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int main(int argc, char** argv)
<< static_cast<int>(plf.get_ambient_light().b) << " "
<< static_cast<int>(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
Expand Down
4 changes: 2 additions & 2 deletions extra/pingus-level2png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions extra/pingus-po-extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReaderCollection>("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);
}
Expand Down
36 changes: 17 additions & 19 deletions src/editor/editor_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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<float>(get_size().width())/2.0f,
static_cast<float>(get_size().height())/2.0f);
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/editor/editor_level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
#include <memory>
#include <vector>

#include <prio/fwd.hpp>

#include "math/size.hpp"
#include "editor/level_obj.hpp"

class Pathname;
class Writer;

namespace Editor {

Expand Down
50 changes: 25 additions & 25 deletions src/editor/generic_level_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions src/editor/group_level_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GroupLevelObj::from_prefab(const std::string& name)
std::shared_ptr<GroupLevelObj> group = std::make_shared<GroupLevelObj>();

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)
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/editor/group_level_obj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <list>

class ReaderMapping;
#include "util/reader.hpp"

namespace Editor {

Expand Down Expand Up @@ -59,7 +59,7 @@ class GroupLevelObj : public LevelObj

std::list<LevelObjPtr>& get_objects() { return m_objects; }

void set_overrides(const ReaderMapping& reader);
void set_overrides(ReaderMapping const& reader);

public:
/** Retrieve the object's position */
Expand Down
Loading

0 comments on commit 7cf1a1f

Please sign in to comment.