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)); } } }
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"); }
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; }
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); } } } }