diff --git a/data/maps/.gitignore b/data/maps/.gitignore index c07d4e03a6..59405b1767 100755 --- a/data/maps/.gitignore +++ b/data/maps/.gitignore @@ -1,4 +1,4 @@ -connections.in +connections.inc events.inc groups.inc headers.inc diff --git a/include/constants/layouts.h b/include/constants/layouts.h index 45b37ff8bf..d12db9b33f 100755 --- a/include/constants/layouts.h +++ b/include/constants/layouts.h @@ -443,4 +443,4 @@ #define LAYOUT_SOOTOPOLIS_CITY_MYSTERY_EVENTS_HOUSE_B1F 440 #define LAYOUT_UNKNOWN_MAP_08481DBC 441 -#endif // GUARD_CONSTANTS_LAYOUTS_H +#endif // GUARD_CONSTANTS_LAYOUTS_H diff --git a/include/constants/map_groups.h b/include/constants/map_groups.h index 003b8c6ce6..dc2ac2f32e 100755 --- a/include/constants/map_groups.h +++ b/include/constants/map_groups.h @@ -589,4 +589,4 @@ #define MAP_GROUPS_COUNT 34 -#endif // GUARD_CONSTANTS_MAP_GROUPS_H +#endif // GUARD_CONSTANTS_MAP_GROUPS_H diff --git a/map_data_rules.mk b/map_data_rules.mk index 6d133eb504..5a7d9dd842 100755 --- a/map_data_rules.mk +++ b/map_data_rules.mk @@ -14,18 +14,18 @@ $(DATA_ASM_BUILDDIR)/map_events.o: $(DATA_ASM_SUBDIR)/map_events.s $(MAPS_DIR)/e $(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@ $(MAPS_DIR)/%/header.inc: $(MAPS_DIR)/%/map.json - $(MAPJSON) map $< $(LAYOUTS_DIR)/layouts.json + $(MAPJSON) map emerald $< $(LAYOUTS_DIR)/layouts.json $(MAPS_DIR)/%/events.inc: $(MAPS_DIR)/%/header.inc ; $(MAPS_DIR)/%/connections.inc: $(MAPS_DIR)/%/events.inc ; $(MAPS_DIR)/groups.inc: $(MAPS_DIR)/map_groups.json - $(MAPJSON) groups $< + $(MAPJSON) groups emerald $< $(MAPS_DIR)/connections.inc: $(MAPS_DIR)/groups.inc ; $(MAPS_DIR)/events.inc: $(MAPS_DIR)/connections.inc ; $(MAPS_DIR)/headers.inc: $(MAPS_DIR)/events.inc ; include/constants/map_groups.h: $(MAPS_DIR)/headers.inc ; $(LAYOUTS_DIR)/layouts.inc: $(LAYOUTS_DIR)/layouts.json - $(MAPJSON) layouts $< + $(MAPJSON) layouts emerald $< $(LAYOUTS_DIR)/layouts_table.inc: $(LAYOUTS_DIR)/layouts.inc ; include/constants/layouts.h: $(LAYOUTS_DIR)/layouts_table.inc ; diff --git a/tools/mapjson/.gitignore b/tools/mapjson/.gitignore new file mode 100755 index 0000000000..a5d5684797 --- /dev/null +++ b/tools/mapjson/.gitignore @@ -0,0 +1 @@ +mapjson diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index e1e86b5c5f..2dd6e5b315 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -50,7 +50,7 @@ string read_text_file(string filepath) { } void write_text_file(string filepath, string text) { - ofstream out_file(filepath); + ofstream out_file(filepath, std::ofstream::binary); if (!out_file.is_open()) FATAL_ERROR("Cannot open file %s for writing.\n", filepath.c_str()); @@ -60,7 +60,7 @@ void write_text_file(string filepath, string text) { out_file.close(); } -string generate_map_header_text(Json map_data, Json layouts_data) { +string generate_map_header_text(Json map_data, Json layouts_data, string version) { string map_layout_id = map_data["layout"].string_value(); vector matched; @@ -102,13 +102,18 @@ string generate_map_header_text(Json map_data, Json layouts_data) { << "\t.byte " << map_data["requires_flash"].bool_value() << "\n" << "\t.byte " << map_data["weather"].string_value() << "\n" << "\t.byte " << map_data["map_type"].string_value() << "\n" - << "\t.2byte 0\n\t" - << "map_header_flags " - << "allow_bike=" << map_data["allow_bike"].bool_value() << ", " - << "allow_escape_rope=" << map_data["allow_escape_rope"].bool_value() << ", " - << "allow_run=" << map_data["allow_running"].bool_value() << ", " - << "show_map_name=" << map_data["show_map_name"].bool_value() << "\n" - << "\t.byte " << map_data["battle_scene"].string_value() << "\n\n"; + << "\t.2byte 0\n"; + + if (version == "ruby") + text << "\t.byte " << map_data["show_map_name"].bool_value() << "\n"; + else if (version == "emerald") + text << "\tmap_header_flags " + << "allow_bike=" << map_data["allow_bike"].bool_value() << ", " + << "allow_escape_rope=" << map_data["allow_escape_rope"].bool_value() << ", " + << "allow_run=" << map_data["allow_running"].bool_value() << ", " + << "show_map_name=" << map_data["show_map_name"].bool_value() << "\n"; + + text << "\t.byte " << map_data["battle_scene"].string_value() << "\n\n"; return text.str(); } @@ -146,7 +151,7 @@ string generate_map_events_text(Json map_data) { if (map_data["object_events"].array_items().size() > 0) { objects_label = map_data["name"].string_value() + "_EventObjects"; text << objects_label << ":\n"; - for (int i = 0; i < map_data["object_events"].array_items().size(); i++) { + for (unsigned int i = 0; i < map_data["object_events"].array_items().size(); i++) { auto obj_event = map_data["object_events"].array_items()[i]; text << "\tobject_event " << i + 1 << ", " << obj_event["graphics_id"].string_value() << ", 0, " @@ -254,7 +259,7 @@ string get_directory_name(string filename) { return filename.substr(0, dir_pos + 1); } -void process_map(string map_filepath, string layouts_filepath) { +void process_map(string map_filepath, string layouts_filepath, string version) { string mapdata_err, layouts_err; string mapdata_json_text = read_text_file(map_filepath); @@ -268,7 +273,7 @@ void process_map(string map_filepath, string layouts_filepath) { if (layouts_data == Json()) FATAL_ERROR("%s\n", layouts_err.c_str()); - string header_text = generate_map_header_text(map_data, layouts_data); + string header_text = generate_map_header_text(map_data, layouts_data, version); string events_text = generate_map_events_text(map_data); string connections_text = generate_map_connections_text(map_data); @@ -490,8 +495,13 @@ void process_layouts(string layouts_filepath) { } int main(int argc, char *argv[]) { - if (argc < 2) - FATAL_ERROR("USAGE: mapjson [options]\n"); + if (argc < 3) + FATAL_ERROR("USAGE: mapjson [options]\n"); + + char *version_arg = argv[2]; + string version(version_arg); + if (version != "emerald" && version != "ruby") + FATAL_ERROR("ERROR: must be 'emerald' or 'ruby'.\n"); char *mode_arg = argv[1]; string mode(mode_arg); @@ -499,27 +509,27 @@ int main(int argc, char *argv[]) { FATAL_ERROR("ERROR: must be 'layouts', 'map', or 'groups'.\n"); if (mode == "map") { - if (argc != 4) - FATAL_ERROR("USAGE: mapjson map \n"); + if (argc != 5) + FATAL_ERROR("USAGE: mapjson map \n"); - string filepath(argv[2]); - string layouts_filepath(argv[3]); + string filepath(argv[3]); + string layouts_filepath(argv[4]); - process_map(filepath, layouts_filepath); + process_map(filepath, layouts_filepath, version); } else if (mode == "groups") { - if (argc != 3) - FATAL_ERROR("USAGE: mapjson groups \n"); + if (argc != 4) + FATAL_ERROR("USAGE: mapjson groups \n"); - string filepath(argv[2]); + string filepath(argv[3]); process_groups(filepath); } else if (mode == "layouts") { - if (argc != 3) - FATAL_ERROR("USAGE: mapjson layouts \n"); + if (argc != 4) + FATAL_ERROR("USAGE: mapjson layouts \n"); - string filepath(argv[2]); + string filepath(argv[3]); process_layouts(filepath); }