void EditorLevel::save_level(Writer& fw) { // Sort the level before saving, so that object order doesn't change // after a save/load cycle (load sort() too) sort(); // Write header fw.begin_object("pingus-level"); fw.write_int("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); // 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.end_mapping(); // actions fw.write_size("levelsize", impl->size); fw.end_mapping(); // head // Write the objects fw.begin_collection("objects"); for (auto it = impl->objects.begin(); it != impl->objects.end(); ++it) { (*it)->write_properties(fw); } fw.end_collection(); // objects fw.end_object(); // pingus-level }