SpriteDescriptionPtr SpriteDescription::from_file(const Pathname& path) { ReaderObject reader_object = FileReader::parse(path); ReaderMapping reader = reader_object.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_enum("origin", desc->origin, string2origin); if (!reader.read_path("image", desc->filename)) { log_error("'image' missing for %1%", reader_object.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); return desc; }
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); } } } }