WorldmapStory::WorldmapStory(const ReaderMapping& reader) : title(), music(), pages() { reader.read_string("title", title); title = _(title); reader.read_string("music", music); ReaderCollection all_pages; reader.read_collection("pages", all_pages); // Temporary objects ResDescriptor desc; std::string text; std::string page_name; // Read each page into the pages vector std::vector<ReaderObject> childs = all_pages.get_objects(); for(auto i = childs.begin(); i != childs.end(); ++i) { page_name = i->get_name(); ReaderMapping mapping = i->get_mapping(); mapping.read_desc("surface", desc); mapping.read_string("text", text); // Translate the text and break it up. text = StringFormat::break_line(_(text), 570, Fonts::chalk_normal); pages.push_back(StoryPage(desc, text, page_name)); } std::reverse(pages.begin(), pages.end()); if (pages.empty()) raise_exception(std::runtime_error, "WorldmapStory: Worldmap does not include a valid story"); }
void PingusWorldmap::parse_file(const ReaderObject& reader_object) { if (reader_object.get_name() != "pingus-worldmap") { raise_exception(std::runtime_error, "Worldmap:" << impl->filename << ": not a Worldmap file"); } else { ReaderMapping reader = reader_object.get_mapping(); if (!reader.read_mapping("graph", impl->path_graph)) { raise_exception(std::runtime_error, "Worldmap: " << impl->filename << " is missed 'graph' section"); } impl->objects = reader.read_collection("objects").get_objects(); parse_properties(reader.read_mapping("head")); std::string intro_story; std::string end_story; if (reader.read_string("intro-story", intro_story)) { impl->intro_story = FileReader::parse(Pathname(intro_story, Pathname::DATA_PATH)); } if (reader.read_string("end-story", end_story)) { impl->end_story = FileReader::parse(Pathname(end_story, Pathname::DATA_PATH)); } } }
PingusDemo::PingusDemo(const Pathname& pathname) : m_levelname(), m_checksum(), m_events() { std::vector<ReaderObject> lines = FileReader::parse_many(pathname); if (lines.empty()) { raise_exception(std::runtime_error, "'" << pathname.str() << "', demo file is empty"); } else { if (lines.front().get_name() == "level") { ReaderMapping reader = lines.front().get_mapping(); if (!reader.read_string("name", m_levelname)) { raise_exception(std::runtime_error, "(level (name ...)) entry missing in demo file '" << pathname.str() << "'"); } reader.read_string("checksum", m_checksum); } for(auto i = lines.begin() + 1; i != lines.end(); ++i) { if (i->get_name() != "checksum") // workaround for old incorrectly recorded demo files { m_events.push_back(ServerEvent(*i)); } } } }
StoryDot::StoryDot(const ReaderMapping& reader) : Dot(reader.read_mapping("dot")), m_story_dot_highlight("core/worldmap/story_dot_highlight"), m_story_dot("core/worldmap/story_dot"), m_name(), m_story(), m_credits(false) { reader.read_string("name", m_name); reader.read_string("story", m_story); reader.read_bool("credits", m_credits); }
ServerEvent::ServerEvent(const ReaderObject& reader_object) : type(PINGU_ACTION_EVENT), time_stamp(0), pingu_id(0), pos(), pingu_action(ActionName::WALKER) { ReaderMapping reader = reader_object.get_mapping(); if (reader_object.get_name() == "armageddon") { type = ARMAGEDDON_EVENT; reader.read_int("time", time_stamp); } else if (reader_object.get_name() == "end") { type = END_EVENT; reader.read_int("time", time_stamp); } else if (reader_object.get_name() == "finish") { type = FINISH_EVENT; reader.read_int("time", time_stamp); } else if (reader_object.get_name() == "pingu-action") { std::string raw_x; std::string raw_y; type = PINGU_ACTION_EVENT; reader.read_int ("time", time_stamp); int pingu_id_tmp; reader.read_int ("id", pingu_id_tmp); pingu_id = static_cast<unsigned int>(pingu_id_tmp); if (reader.read_string("raw-x", raw_x)) pos.x = Math::string2float(raw_x); if (reader.read_string("raw-y", raw_y)) pos.y = Math::string2float(raw_y); reader.read_enum("action", pingu_action, &ActionName::from_string); } else { raise_exception(std::runtime_error, "ServerEvent: Parse error: Unknown event: " << reader_object.get_name()); } }
int main(int argc, char** argv) { for(int i = 1; i < argc; ++i) { Pathname filename(argv[i], Pathname::SYSTEM_PATH); if (filename.has_extension(".pingus")) { PingusLevel plf(filename); emit_msgid(plf.get_levelname()); emit_msgid(plf.get_description()); } else if (filename.has_extension(".worldmap")) { // worldmaps don't contain translatable strings at the moment } else if (filename.has_extension(".story")) { ReaderObject reader_object = FileReader::parse(filename); ReaderMapping reader = reader_object.get_mapping(); std::string tmp; if (reader.read_string("title", tmp)) { emit_msgid(tmp); } ReaderCollection all_pages = reader.read_collection("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)) { emit_msgid(tmp); } } } else { raise_exception(std::runtime_error, "unknown file type: " << filename); } } return 0; }
Teleporter::Teleporter(const ReaderMapping& reader) : pos(), sprite("worldobjs/teleporter"), target_id(), target() { reader.read_vector("position", pos); reader.read_string("target-id", target_id); }
Savegame::Savegame(const ReaderMapping& reader) : filename(), status(), needed_time(), saved_pingus() { reader.read_string("filename", filename); reader.read_enum("status", status, string_to_status); reader.read_int("time", needed_time); reader.read_int("saved-pingus", saved_pingus); }
bool ReaderMapping::read_desc(const char* key, ResDescriptor& value) const { ReaderMapping reader; if (read_mapping(key, reader)) { reader.read_string("image", value.res_name); reader.read_enum("modifier", value.modifier, &ResourceModifier::from_string); return true; } else { return false; } }
void PingusWorldmap::parse_properties(const ReaderMapping& reader) { reader.read_string("music", impl->music); reader.read_string("author", impl->author); reader.read_string("name", impl->name); reader.read_string("short-name", impl->short_name); reader.read_string("email", impl->email); reader.read_int("width", impl->width); reader.read_int("height", impl->height); reader.read_string("default-node", impl->default_node); reader.read_string("final-node", impl->final_node); }
void PingusLevel::load(const std::string& resname, const Pathname& pathname) { impl->checksum = System::checksum(pathname); impl->resname = resname; ReaderObject reader_object = FileReader::parse(pathname); if (reader_object.get_name() != "pingus-level") { raise_exception(std::runtime_error, "Error: " << pathname.str() << ": not a 'pingus-level' file"); } else { ReaderMapping reader = reader_object.get_mapping(); int version; if (reader.read_int("version", version)) log_info("Levelfile Version: %1%", version); else log_info("Unknown Levelfile Version: %1%", version); ReaderMapping head; if (!reader.read_mapping("head", head)) { raise_exception(std::runtime_error, "Error: (head) section not found in '" << pathname.str() << "'"); } else { log_info("Reading head"); head.read_string("levelname", impl->levelname); head.read_string("description", impl->description); head.read_size ("levelsize", impl->size); head.read_string("music", impl->music); head.read_int ("time", impl->time); head.read_int ("number-of-pingus", impl->number_of_pingus); head.read_int ("number-to-save", impl->number_to_save); head.read_colorf("ambient-light", impl->ambient_light); head.read_string("author", impl->author); log_info("Size: %1%x%2%", impl->size.width, impl->size.height); ReaderMapping actions; if (head.read_mapping("actions", actions)) { std::vector<std::string> lst = actions.get_keys(); for(std::vector<std::string>::iterator i = lst.begin(); i != lst.end(); ++i) { int count = 0; log_info("Actions: %1%", i->c_str()); if (actions.read_int(i->c_str(), count)) impl->actions[*i] = count; } } else { raise_exception(std::runtime_error, "Error: (pingus-level head actions) not found in '" << pathname.str() << "'"); } } ReaderCollection collection; if (reader.read_collection("objects", collection)) { std::vector<ReaderObject> object_lst = collection.get_objects(); for(auto i = object_lst.begin(); i != object_lst.end(); ++i) { impl->objects.push_back(*i); } } } }