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)); } } }
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); }
ControllerPtr Manager::create_controller(const Pathname& filename) { ControllerPtr controller(new Controller(desc)); ReaderObject reader_object = Reader::parse(filename); if (reader_object.get_name() != "pingus-controller") { raise_exception(std::runtime_error, "Controller: invalid config file '" << filename.str() << "'"); } else { ReaderMapping reader = reader_object.get_mapping(); ReaderMapping controls_mapping; if (!reader.read_mapping("controls", controls_mapping)) { log_warn("%1%: 'controls' section missing", filename); } else { for (const auto& key : controls_mapping.get_keys()) { ReaderCollection collection; if (!controls_mapping.read_collection(key.c_str(), collection)) { log_error("%1%: mapping must contain object at %2%", filename, key); } else { if (StringUtil::has_suffix(key, "pointer")) { int id = desc.get_definition(key).id; ControllerPointer* ctrl_pointer = controller->get_pointer(id); for(const auto& object : collection.get_objects()) { auto pointer = create_pointer(object, ctrl_pointer); if (pointer) { ctrl_pointer->add_pointer(std::move(pointer)); } else { log_error("Manager: pointer: Couldn't create pointer %1%", object.get_name()); } } } else if (StringUtil::has_suffix(key, "scroller")) { int id = desc.get_definition(key).id; ControllerScroller* ctrl_scroller = controller->get_scroller(id); for(const auto& object : collection.get_objects()) { auto scroller = create_scroller(object, ctrl_scroller); if (scroller) { ctrl_scroller->add_scroller(std::move(scroller)); } else { log_error("Manager: scroller: Couldn't create scroller %1%", object.get_name()); } } } else if (StringUtil::has_suffix(key, "button")) { int id = desc.get_definition(key).id; ControllerButton* ctrl_button = controller->get_button(id); for(const auto& object : collection.get_objects()) { auto button = create_button(object, ctrl_button); if (button) { ctrl_button->add_button(std::move(button)); } else { log_error("Manager: button: Couldn't create button %1%", object.get_name()); } } } else if (StringUtil::has_suffix(key, "axis")) { int id = desc.get_definition(key).id; ControllerAxis* ctrl_axis = controller->get_axis(id); for(const auto& object : collection.get_objects()) { auto axis = create_axis(object, ctrl_axis); if (axis) { ctrl_axis->add_axis(std::move(axis)); } else { log_error("Manager: axis: Couldn't create axis %1%", object.get_name()); } } } else if (StringUtil::has_suffix(key, "keyboard")) { int id = desc.get_definition(key).id; ControllerKeyboard* ctrl_keyboard = controller->get_keyboard(id); for(const auto& object : collection.get_objects()) { std::unique_ptr<Keyboard> keyboard = create_keyboard(object, ctrl_keyboard); if (keyboard) { ctrl_keyboard->add_keyboard(std::move(keyboard)); } else { log_error("Manager: keyboard: Couldn't create keyboard %1%", object.get_name()); } } } else { raise_exception(std::runtime_error, "Manager: Unkown Element in Controller Config: " << key); } } } } } controllers.push_back(controller); return controller; }
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); } } } }