From 15431bd3974e29947e1fccd23d22055805423197 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 17 Jan 2023 15:25:39 -0500 Subject: [PATCH 1/7] Add initial mapsjon type conversions --- tools/mapjson/mapjson.cpp | 279 ++++++++++++++++++++++++-------------- 1 file changed, 176 insertions(+), 103 deletions(-) diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index f78002e28c..526aa5f32a 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -60,13 +60,86 @@ void write_text_file(string filepath, string text) { out_file.close(); } +// Json values do not implicitly convert types. This will handle converting them +// if the user's JSON data is not the expected type (which may happen if e.g. it's +// written that way by a different version of Porymap). +string json_to_string(const Json &value) { + string output = ""; + switch (value.type()) { + case Json::Type::STRING: + output = value.string_value(); + break; + case Json::Type::NUMBER: + output = std::to_string(value.int_value()); + break; + case Json::Type::BOOL: + output = value.bool_value() ? "TRUE" : "FALSE"; + break; + default: + FATAL_ERROR("Value for %s is unexpected type; expected string.\n", /*field.c_str()*/ "JSON field"); + } + + if (output.empty()) + FATAL_ERROR("Value for %s cannot be empty.\n", /*field.c_str()*/ "JSON field"); + + return output; +} + +int json_to_int(const Json &value) { + switch (value.type()) { + case Json::Type::STRING: { + string s = value.string_value(); + if (s == "TRUE" || s == "true") return 1; + if (s == "FALSE" || s == "false") return 0; + int num; + try { + num = stoi(s); + } catch(std::invalid_argument& e){ + FATAL_ERROR("Unable to convert value %s for %s to int.\n", s.c_str(), /*field.c_str()*/ "JSON field"); + } + return num; + } + case Json::Type::NUMBER: + return value.int_value(); + case Json::Type::BOOL: + return value.bool_value() ? 0 : 1; + default: + FATAL_ERROR("Value for %s is unexpected type; expected int.\n", /*field.c_str()*/ "JSON field"); + } + return 0; +} + +bool json_to_bool(const Json &value) { + switch (value.type()) { + case Json::Type::STRING: { + string s = value.string_value(); + if (s == "TRUE" || s == "true") return true; + if (s == "FALSE" || s == "false") return false; + int num; + try { + num = stoi(s); + } catch(std::invalid_argument& e){ + FATAL_ERROR("Value %s for %s is unexpected type; expected bool\n", e.what(), /*field.c_str()*/ "JSON field"); + } + return num != 0; + } + case Json::Type::NUMBER: + return value.int_value() != 0; + case Json::Type::BOOL: + return value.bool_value(); + default: + FATAL_ERROR("Value for %s is unexpected type; expected bool.\n", /*field.c_str()*/ "JSON field"); + } + return false; +} + string generate_map_header_text(Json map_data, Json layouts_data, string version) { - string map_layout_id = map_data["layout"].string_value(); + string map_layout_id = json_to_string(map_data["layout"]); vector matched; for (auto &field : layouts_data["layouts"].array_items()) { - if (map_layout_id == field["id"].string_value()) + if (map_layout_id == json_to_string(field["id"])) matched.push_back(field); } @@ -78,46 +151,46 @@ string generate_map_header_text(Json map_data, Json layouts_data, string version ostringstream text; text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" - << map_data["name"].string_value() + << json_to_string(map_data["name"]) << "/map.json\n@\n\n"; - text << map_data["name"].string_value() << ":\n" - << "\t.4byte " << layout["name"].string_value() << "\n"; + text << json_to_string(map_data["name"]) << ":\n" + << "\t.4byte " << json_to_string(layout["name"]) << "\n"; if (map_data.object_items().find("shared_events_map") != map_data.object_items().end()) - text << "\t.4byte " << map_data["shared_events_map"].string_value() << "_MapEvents\n"; + text << "\t.4byte " << json_to_string(map_data["shared_events_map"]) << "_MapEvents\n"; else - text << "\t.4byte " << map_data["name"].string_value() << "_MapEvents\n"; + text << "\t.4byte " << json_to_string(map_data["name"]) << "_MapEvents\n"; if (map_data.object_items().find("shared_scripts_map") != map_data.object_items().end()) - text << "\t.4byte " << map_data["shared_scripts_map"].string_value() << "_MapScripts\n"; + text << "\t.4byte " << json_to_string(map_data["shared_scripts_map"]) << "_MapScripts\n"; else - text << "\t.4byte " << map_data["name"].string_value() << "_MapScripts\n"; + text << "\t.4byte " << json_to_string(map_data["name"]) << "_MapScripts\n"; if (map_data.object_items().find("connections") != map_data.object_items().end() && map_data["connections"].array_items().size() > 0) - text << "\t.4byte " << map_data["name"].string_value() << "_MapConnections\n"; + text << "\t.4byte " << json_to_string(map_data["name"]) << "_MapConnections\n"; else text << "\t.4byte 0x0\n"; - text << "\t.2byte " << map_data["music"].string_value() << "\n" - << "\t.2byte " << layout["id"].string_value() << "\n" - << "\t.byte " << map_data["region_map_section"].string_value() << "\n" - << "\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" + text << "\t.2byte " << json_to_string(map_data["music"]) << "\n" + << "\t.2byte " << json_to_string(layout["id"]) << "\n" + << "\t.byte " << json_to_string(map_data["region_map_section"]) << "\n" + << "\t.byte " << json_to_bool(map_data["requires_flash"]) << "\n" + << "\t.byte " << json_to_string(map_data["weather"]) << "\n" + << "\t.byte " << json_to_string(map_data["map_type"]) << "\n" << "\t.2byte 0\n"; if (version == "ruby") - text << "\t.byte " << map_data["show_map_name"].bool_value() << "\n"; + text << "\t.byte " << json_to_bool(map_data["show_map_name"]) << "\n"; else if (version == "emerald") text << "\tmap_header_flags " - << "allow_cycling=" << map_data["allow_cycling"].bool_value() << ", " - << "allow_escaping=" << map_data["allow_escaping"].bool_value() << ", " - << "allow_running=" << map_data["allow_running"].bool_value() << ", " - << "show_map_name=" << map_data["show_map_name"].bool_value() << "\n"; + << "allow_cycling=" << json_to_bool(map_data["allow_cycling"]) << ", " + << "allow_escaping=" << json_to_bool(map_data["allow_escaping"]) << ", " + << "allow_running=" << json_to_bool(map_data["allow_running"]) << ", " + << "show_map_name=" << json_to_bool(map_data["show_map_name"]) << "\n"; - text << "\t.byte " << map_data["battle_scene"].string_value() << "\n\n"; + text << "\t.byte " << json_to_string(map_data["battle_scene"]) << "\n\n"; return text.str(); } @@ -129,21 +202,21 @@ string generate_map_connections_text(Json map_data) { ostringstream text; text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" - << map_data["name"].string_value() + << json_to_string(map_data["name"]) << "/map.json\n@\n\n"; - text << map_data["name"].string_value() << "_MapConnectionsList:\n"; + text << json_to_string(map_data["name"]) << "_MapConnectionsList:\n"; for (auto &connection : map_data["connections"].array_items()) { text << "\tconnection " - << connection["direction"].string_value() << ", " - << connection["offset"].int_value() << ", " - << connection["map"].string_value() << "\n"; + << json_to_string(connection["direction"]) << ", " + << json_to_int(connection["offset"]) << ", " + << json_to_string(connection["map"]) << "\n"; } - text << "\n" << map_data["name"].string_value() << "_MapConnections:\n" + text << "\n" << json_to_string(map_data["name"]) << "_MapConnections:\n" << "\t.4byte " << map_data["connections"].array_items().size() << "\n" - << "\t.4byte " << map_data["name"].string_value() << "_MapConnectionsList\n\n"; + << "\t.4byte " << json_to_string(map_data["name"]) << "_MapConnectionsList\n\n"; return text.str(); } @@ -155,28 +228,28 @@ string generate_map_events_text(Json map_data) { ostringstream text; text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" - << map_data["name"].string_value() + << json_to_string(map_data["name"]) << "/map.json\n@\n\n"; string objects_label, warps_label, coords_label, bgs_label; if (map_data["object_events"].array_items().size() > 0) { - objects_label = map_data["name"].string_value() + "_ObjectEvents"; + objects_label = json_to_string(map_data["name"]) + "_ObjectEvents"; text << objects_label << ":\n"; 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, " - << obj_event["x"].int_value() << ", " - << obj_event["y"].int_value() << ", " - << obj_event["elevation"].int_value() << ", " - << obj_event["movement_type"].string_value() << ", " - << obj_event["movement_range_x"].int_value() << ", " - << obj_event["movement_range_y"].int_value() << ", " - << obj_event["trainer_type"].string_value() << ", " - << obj_event["trainer_sight_or_berry_tree_id"].string_value() << ", " - << obj_event["script"].string_value() << ", " - << obj_event["flag"].string_value() << "\n"; + << json_to_string(obj_event["graphics_id"]) << ", 0, " + << json_to_int(obj_event["x"]) << ", " + << json_to_int(obj_event["y"]) << ", " + << json_to_int(obj_event["elevation"]) << ", " + << json_to_string(obj_event["movement_type"]) << ", " + << json_to_int(obj_event["movement_range_x"]) << ", " + << json_to_int(obj_event["movement_range_y"]) << ", " + << json_to_string(obj_event["trainer_type"]) << ", " + << json_to_string(obj_event["trainer_sight_or_berry_tree_id"]) << ", " + << json_to_string(obj_event["script"]) << ", " + << json_to_string(obj_event["flag"]) << "\n"; } text << "\n"; } else { @@ -184,15 +257,15 @@ string generate_map_events_text(Json map_data) { } if (map_data["warp_events"].array_items().size() > 0) { - warps_label = map_data["name"].string_value() + "_MapWarps"; + warps_label = json_to_string(map_data["name"]) + "_MapWarps"; text << warps_label << ":\n"; for (auto &warp_event : map_data["warp_events"].array_items()) { text << "\twarp_def " - << warp_event["x"].int_value() << ", " - << warp_event["y"].int_value() << ", " - << warp_event["elevation"].int_value() << ", " - << warp_event["dest_warp_id"].string_value() << ", " - << warp_event["dest_map"].string_value() << "\n"; + << json_to_int(warp_event["x"]) << ", " + << json_to_int(warp_event["y"]) << ", " + << json_to_int(warp_event["elevation"]) << ", " + << json_to_string(warp_event["dest_warp_id"]) << ", " + << json_to_string(warp_event["dest_map"]) << "\n"; } text << "\n"; } else { @@ -200,24 +273,24 @@ string generate_map_events_text(Json map_data) { } if (map_data["coord_events"].array_items().size() > 0) { - coords_label = map_data["name"].string_value() + "_MapCoordEvents"; + coords_label = json_to_string(map_data["name"]) + "_MapCoordEvents"; text << coords_label << ":\n"; for (auto &coord_event : map_data["coord_events"].array_items()) { - if (coord_event["type"].string_value() == "trigger") { + if (json_to_string(coord_event["type"]) == "trigger") { text << "\tcoord_event " - << coord_event["x"].int_value() << ", " - << coord_event["y"].int_value() << ", " - << coord_event["elevation"].int_value() << ", " - << coord_event["var"].string_value() << ", " - << coord_event["var_value"].string_value() << ", " - << coord_event["script"].string_value() << "\n"; + << json_to_int(coord_event["x"]) << ", " + << json_to_int(coord_event["y"]) << ", " + << json_to_int(coord_event["elevation"]) << ", " + << json_to_string(coord_event["var"]) << ", " + << json_to_string(coord_event["var_value"]) << ", " + << json_to_string(coord_event["script"]) << "\n"; } else if (coord_event["type"] == "weather") { text << "\tcoord_weather_event " - << coord_event["x"].int_value() << ", " - << coord_event["y"].int_value() << ", " - << coord_event["elevation"].int_value() << ", " - << coord_event["weather"].string_value() << "\n"; + << json_to_int(coord_event["x"]) << ", " + << json_to_int(coord_event["y"]) << ", " + << json_to_int(coord_event["elevation"]) << ", " + << json_to_string(coord_event["weather"]) << "\n"; } } text << "\n"; @@ -226,31 +299,31 @@ string generate_map_events_text(Json map_data) { } if (map_data["bg_events"].array_items().size() > 0) { - bgs_label = map_data["name"].string_value() + "_MapBGEvents"; + bgs_label = json_to_string(map_data["name"]) + "_MapBGEvents"; text << bgs_label << ":\n"; for (auto &bg_event : map_data["bg_events"].array_items()) { if (bg_event["type"] == "sign") { text << "\tbg_sign_event " - << bg_event["x"].int_value() << ", " - << bg_event["y"].int_value() << ", " - << bg_event["elevation"].int_value() << ", " - << bg_event["player_facing_dir"].string_value() << ", " - << bg_event["script"].string_value() << "\n"; + << json_to_int(bg_event["x"]) << ", " + << json_to_int(bg_event["y"]) << ", " + << json_to_int(bg_event["elevation"]) << ", " + << json_to_string(bg_event["player_facing_dir"]) << ", " + << json_to_string(bg_event["script"]) << "\n"; } else if (bg_event["type"] == "hidden_item") { text << "\tbg_hidden_item_event " - << bg_event["x"].int_value() << ", " - << bg_event["y"].int_value() << ", " - << bg_event["elevation"].int_value() << ", " - << bg_event["item"].string_value() << ", " - << bg_event["flag"].string_value() << "\n"; + << json_to_int(bg_event["x"]) << ", " + << json_to_int(bg_event["y"]) << ", " + << json_to_int(bg_event["elevation"]) << ", " + << json_to_string(bg_event["item"]) << ", " + << json_to_string(bg_event["flag"]) << "\n"; } else if (bg_event["type"] == "secret_base") { text << "\tbg_secret_base_event " - << bg_event["x"].int_value() << ", " - << bg_event["y"].int_value() << ", " - << bg_event["elevation"].int_value() << ", " - << bg_event["secret_base_id"].string_value() << "\n"; + << json_to_int(bg_event["x"]) << ", " + << json_to_int(bg_event["y"]) << ", " + << json_to_int(bg_event["elevation"]) << ", " + << json_to_string(bg_event["secret_base_id"]) << "\n"; } } text << "\n"; @@ -258,7 +331,7 @@ string generate_map_events_text(Json map_data) { bgs_label = "0x0"; } - text << map_data["name"].string_value() << "_MapEvents::\n" + text << json_to_string(map_data["name"]) << "_MapEvents::\n" << "\tmap_events " << objects_label << ", " << warps_label << ", " << coords_label << ", " << bgs_label << "\n\n"; @@ -301,17 +374,17 @@ string generate_groups_text(Json groups_data) { text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/map_groups.json\n@\n\n"; for (auto &key : groups_data["group_order"].array_items()) { - string group = key.string_value(); + string group = json_to_string(key); text << group << "::\n"; auto maps = groups_data[group].array_items(); for (Json &map_name : maps) - text << "\t.4byte " << map_name.string_value() << "\n"; + text << "\t.4byte " << json_to_string(map_name) << "\n"; text << "\n"; } text << "\t.align 2\n" << "gMapGroups::\n"; for (auto &group : groups_data["group_order"].array_items()) - text << "\t.4byte " << group.string_value() << "\n"; + text << "\t.4byte " << json_to_string(group) << "\n"; text << "\n"; return text.str(); @@ -321,7 +394,7 @@ string generate_connections_text(Json groups_data) { vector map_names; for (auto &group : groups_data["group_order"].array_items()) - for (auto map_name : groups_data[group.string_value()].array_items()) + for (auto map_name : groups_data[json_to_string(group)].array_items()) map_names.push_back(map_name); vector connections_include_order = groups_data["connections_include_order"].array_items(); @@ -342,7 +415,7 @@ string generate_connections_text(Json groups_data) { text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/map_groups.json\n@\n\n"; for (Json map_name : map_names) - text << "\t.include \"data/maps/" << map_name.string_value() << "/connections.inc\"\n"; + text << "\t.include \"data/maps/" << json_to_string(map_name) << "/connections.inc\"\n"; return text.str(); } @@ -351,8 +424,8 @@ string generate_headers_text(Json groups_data) { vector map_names; for (auto &group : groups_data["group_order"].array_items()) - for (auto map_name : groups_data[group.string_value()].array_items()) - map_names.push_back(map_name.string_value()); + for (auto map_name : groups_data[json_to_string(group)].array_items()) + map_names.push_back(json_to_string(map_name)); ostringstream text; @@ -368,8 +441,8 @@ string generate_events_text(Json groups_data) { vector map_names; for (auto &group : groups_data["group_order"].array_items()) - for (auto map_name : groups_data[group.string_value()].array_items()) - map_names.push_back(map_name.string_value()); + for (auto map_name : groups_data[json_to_string(group)].array_items()) + map_names.push_back(json_to_string(map_name)); ostringstream text; @@ -395,22 +468,22 @@ string generate_map_constants_text(string groups_filepath, Json groups_data) { int group_num = 0; for (auto &group : groups_data["group_order"].array_items()) { - text << "// " << group.string_value() << "\n"; + text << "// " << json_to_string(group) << "\n"; vector map_ids; size_t max_length = 0; - for (auto &map_name : groups_data[group.string_value()].array_items()) { - string header_filepath = file_dir + map_name.string_value() + dir_separator + "map.json"; + for (auto &map_name : groups_data[json_to_string(group)].array_items()) { + string header_filepath = file_dir + json_to_string(map_name) + dir_separator + "map.json"; string err_str; Json map_data = Json::parse(read_text_file(header_filepath), err_str); map_ids.push_back(map_data["id"]); - if (map_data["id"].string_value().length() > max_length) - max_length = map_data["id"].string_value().length(); + if (json_to_string(map_data["id"]).length() > max_length) + max_length = json_to_string(map_data["id"]).length(); } int map_id_num = 0; for (Json map_id : map_ids) { - text << "#define " << map_id.string_value() << string((max_length - map_id.string_value().length() + 1), ' ') + text << "#define " << json_to_string(map_id) << string((max_length - json_to_string(map_id).length() + 1), ' ') << "(" << map_id_num++ << " | (" << group_num << " << 8))\n"; } text << "\n"; @@ -453,20 +526,20 @@ string generate_layout_headers_text(Json layouts_data) { text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/layouts/layouts.json\n@\n\n"; for (auto &layout : layouts_data["layouts"].array_items()) { - string border_label = layout["name"].string_value() + "_Border"; - string blockdata_label = layout["name"].string_value() + "_Blockdata"; + string border_label = json_to_string(layout["name"]) + "_Border"; + string blockdata_label = json_to_string(layout["name"]) + "_Blockdata"; text << border_label << "::\n" - << "\t.incbin \"" << layout["border_filepath"].string_value() << "\"\n\n" + << "\t.incbin \"" << json_to_string(layout["border_filepath"]) << "\"\n\n" << blockdata_label << "::\n" - << "\t.incbin \"" << layout["blockdata_filepath"].string_value() << "\"\n\n" + << "\t.incbin \"" << json_to_string(layout["blockdata_filepath"]) << "\"\n\n" << "\t.align 2\n" - << layout["name"].string_value() << "::\n" - << "\t.4byte " << layout["width"].int_value() << "\n" - << "\t.4byte " << layout["height"].int_value() << "\n" + << json_to_string(layout["name"]) << "::\n" + << "\t.4byte " << json_to_int(layout["width"]) << "\n" + << "\t.4byte " << json_to_int(layout["height"]) << "\n" << "\t.4byte " << border_label << "\n" << "\t.4byte " << blockdata_label << "\n" - << "\t.4byte " << layout["primary_tileset"].string_value() << "\n" - << "\t.4byte " << layout["secondary_tileset"].string_value() << "\n\n"; + << "\t.4byte " << json_to_string(layout["primary_tileset"]) << "\n" + << "\t.4byte " << json_to_string(layout["secondary_tileset"]) << "\n\n"; } return text.str(); @@ -478,10 +551,10 @@ string generate_layouts_table_text(Json layouts_data) { text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/layouts/layouts.json\n@\n\n"; text << "\t.align 2\n" - << layouts_data["layouts_table_label"].string_value() << "::\n"; + << json_to_string(layouts_data["layouts_table_label"]) << "::\n"; for (auto &layout : layouts_data["layouts"].array_items()) - text << "\t.4byte " << layout["name"].string_value() << "\n"; + text << "\t.4byte " << json_to_string(layout["name"]) << "\n"; return text.str(); } @@ -496,7 +569,7 @@ string generate_layouts_constants_text(Json layouts_data) { int i = 0; for (auto &layout : layouts_data["layouts"].array_items()) - text << "#define " << layout["id"].string_value() << " " << ++i << "\n"; + text << "#define " << json_to_string(layout["id"]) << " " << ++i << "\n"; text << "\n#endif // GUARD_CONSTANTS_LAYOUTS_H\n"; From b836d9ebfb7707f06c92ba2386af68afc2d8b6d8 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 17 Jan 2023 15:40:39 -0500 Subject: [PATCH 2/7] Stop some redundant JSON reads --- tools/mapjson/mapjson.cpp | 62 +++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index 526aa5f32a..139d395877 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -150,26 +150,26 @@ string generate_map_header_text(Json map_data, Json layouts_data, string version ostringstream text; - text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" - << json_to_string(map_data["name"]) - << "/map.json\n@\n\n"; + string mapName = json_to_string(map_data["name"]); - text << json_to_string(map_data["name"]) << ":\n" + text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" << mapName << "/map.json\n@\n\n"; + + text << mapName << ":\n" << "\t.4byte " << json_to_string(layout["name"]) << "\n"; if (map_data.object_items().find("shared_events_map") != map_data.object_items().end()) text << "\t.4byte " << json_to_string(map_data["shared_events_map"]) << "_MapEvents\n"; else - text << "\t.4byte " << json_to_string(map_data["name"]) << "_MapEvents\n"; + text << "\t.4byte " << mapName << "_MapEvents\n"; if (map_data.object_items().find("shared_scripts_map") != map_data.object_items().end()) text << "\t.4byte " << json_to_string(map_data["shared_scripts_map"]) << "_MapScripts\n"; else - text << "\t.4byte " << json_to_string(map_data["name"]) << "_MapScripts\n"; + text << "\t.4byte " << mapName << "_MapScripts\n"; if (map_data.object_items().find("connections") != map_data.object_items().end() && map_data["connections"].array_items().size() > 0) - text << "\t.4byte " << json_to_string(map_data["name"]) << "_MapConnections\n"; + text << "\t.4byte " << mapName << "_MapConnections\n"; else text << "\t.4byte 0x0\n"; @@ -201,11 +201,11 @@ string generate_map_connections_text(Json map_data) { ostringstream text; - text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" - << json_to_string(map_data["name"]) - << "/map.json\n@\n\n"; + string mapName = json_to_string(map_data["name"]); - text << json_to_string(map_data["name"]) << "_MapConnectionsList:\n"; + text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" << mapName << "/map.json\n@\n\n"; + + text << mapName << "_MapConnectionsList:\n"; for (auto &connection : map_data["connections"].array_items()) { text << "\tconnection " @@ -214,9 +214,9 @@ string generate_map_connections_text(Json map_data) { << json_to_string(connection["map"]) << "\n"; } - text << "\n" << json_to_string(map_data["name"]) << "_MapConnections:\n" + text << "\n" << mapName << "_MapConnections:\n" << "\t.4byte " << map_data["connections"].array_items().size() << "\n" - << "\t.4byte " << json_to_string(map_data["name"]) << "_MapConnectionsList\n\n"; + << "\t.4byte " << mapName << "_MapConnectionsList\n\n"; return text.str(); } @@ -227,14 +227,14 @@ string generate_map_events_text(Json map_data) { ostringstream text; - text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" - << json_to_string(map_data["name"]) - << "/map.json\n@\n\n"; + string mapName = json_to_string(map_data["name"]); + + text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" << mapName << "/map.json\n@\n\n"; string objects_label, warps_label, coords_label, bgs_label; if (map_data["object_events"].array_items().size() > 0) { - objects_label = json_to_string(map_data["name"]) + "_ObjectEvents"; + objects_label = mapName + "_ObjectEvents"; text << objects_label << ":\n"; for (unsigned int i = 0; i < map_data["object_events"].array_items().size(); i++) { auto obj_event = map_data["object_events"].array_items()[i]; @@ -257,7 +257,7 @@ string generate_map_events_text(Json map_data) { } if (map_data["warp_events"].array_items().size() > 0) { - warps_label = json_to_string(map_data["name"]) + "_MapWarps"; + warps_label = mapName + "_MapWarps"; text << warps_label << ":\n"; for (auto &warp_event : map_data["warp_events"].array_items()) { text << "\twarp_def " @@ -273,7 +273,7 @@ string generate_map_events_text(Json map_data) { } if (map_data["coord_events"].array_items().size() > 0) { - coords_label = json_to_string(map_data["name"]) + "_MapCoordEvents"; + coords_label = mapName + "_MapCoordEvents"; text << coords_label << ":\n"; for (auto &coord_event : map_data["coord_events"].array_items()) { if (json_to_string(coord_event["type"]) == "trigger") { @@ -299,7 +299,7 @@ string generate_map_events_text(Json map_data) { } if (map_data["bg_events"].array_items().size() > 0) { - bgs_label = json_to_string(map_data["name"]) + "_MapBGEvents"; + bgs_label = mapName + "_MapBGEvents"; text << bgs_label << ":\n"; for (auto &bg_event : map_data["bg_events"].array_items()) { if (bg_event["type"] == "sign") { @@ -331,7 +331,7 @@ string generate_map_events_text(Json map_data) { bgs_label = "0x0"; } - text << json_to_string(map_data["name"]) << "_MapEvents::\n" + text << mapName << "_MapEvents::\n" << "\tmap_events " << objects_label << ", " << warps_label << ", " << coords_label << ", " << bgs_label << "\n\n"; @@ -468,22 +468,25 @@ string generate_map_constants_text(string groups_filepath, Json groups_data) { int group_num = 0; for (auto &group : groups_data["group_order"].array_items()) { - text << "// " << json_to_string(group) << "\n"; + string groupName = json_to_string(group); + text << "// " << groupName << "\n"; vector map_ids; size_t max_length = 0; - for (auto &map_name : groups_data[json_to_string(group)].array_items()) { + for (auto &map_name : groups_data[groupName].array_items()) { string header_filepath = file_dir + json_to_string(map_name) + dir_separator + "map.json"; string err_str; Json map_data = Json::parse(read_text_file(header_filepath), err_str); map_ids.push_back(map_data["id"]); - if (json_to_string(map_data["id"]).length() > max_length) - max_length = json_to_string(map_data["id"]).length(); + string id = json_to_string(map_data["id"]); + if (id.length() > max_length) + max_length = id.length(); } int map_id_num = 0; for (Json map_id : map_ids) { - text << "#define " << json_to_string(map_id) << string((max_length - json_to_string(map_id).length() + 1), ' ') + string id = json_to_string(map_id); + text << "#define " << id << string((max_length - id.length() + 1), ' ') << "(" << map_id_num++ << " | (" << group_num << " << 8))\n"; } text << "\n"; @@ -526,14 +529,15 @@ string generate_layout_headers_text(Json layouts_data) { text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/layouts/layouts.json\n@\n\n"; for (auto &layout : layouts_data["layouts"].array_items()) { - string border_label = json_to_string(layout["name"]) + "_Border"; - string blockdata_label = json_to_string(layout["name"]) + "_Blockdata"; + string layoutName = json_to_string(layout["name"]); + string border_label = layoutName + "_Border"; + string blockdata_label = layoutName + "_Blockdata"; text << border_label << "::\n" << "\t.incbin \"" << json_to_string(layout["border_filepath"]) << "\"\n\n" << blockdata_label << "::\n" << "\t.incbin \"" << json_to_string(layout["blockdata_filepath"]) << "\"\n\n" << "\t.align 2\n" - << json_to_string(layout["name"]) << "::\n" + << layoutName << "::\n" << "\t.4byte " << json_to_int(layout["width"]) << "\n" << "\t.4byte " << json_to_int(layout["height"]) << "\n" << "\t.4byte " << border_label << "\n" From 1e3b0e8d760ea70788c3cc01399ce6c48f994ef0 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 17 Jan 2023 16:00:09 -0500 Subject: [PATCH 3/7] Treat all mapjson fields as strings --- tools/mapjson/mapjson.cpp | 117 +++++++++++--------------------------- 1 file changed, 33 insertions(+), 84 deletions(-) diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index 139d395877..29e1225b05 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -60,9 +60,6 @@ void write_text_file(string filepath, string text) { out_file.close(); } -// Json values do not implicitly convert types. This will handle converting them -// if the user's JSON data is not the expected type (which may happen if e.g. it's -// written that way by a different version of Porymap). string json_to_string(const Json &value) { string output = ""; switch (value.type()) { @@ -76,7 +73,7 @@ string json_to_string(const Json &value) { output = value.bool_value() ? "TRUE" : "FALSE"; break; default: - FATAL_ERROR("Value for %s is unexpected type; expected string.\n", /*field.c_str()*/ "JSON field"); + FATAL_ERROR("Value for %s is unexpected type; expected string, int, or bool.\n", /*field.c_str()*/ "JSON field"); } if (output.empty()) @@ -85,54 +82,6 @@ string json_to_string(const Json &value) { return output; } -int json_to_int(const Json &value) { - switch (value.type()) { - case Json::Type::STRING: { - string s = value.string_value(); - if (s == "TRUE" || s == "true") return 1; - if (s == "FALSE" || s == "false") return 0; - int num; - try { - num = stoi(s); - } catch(std::invalid_argument& e){ - FATAL_ERROR("Unable to convert value %s for %s to int.\n", s.c_str(), /*field.c_str()*/ "JSON field"); - } - return num; - } - case Json::Type::NUMBER: - return value.int_value(); - case Json::Type::BOOL: - return value.bool_value() ? 0 : 1; - default: - FATAL_ERROR("Value for %s is unexpected type; expected int.\n", /*field.c_str()*/ "JSON field"); - } - return 0; -} - -bool json_to_bool(const Json &value) { - switch (value.type()) { - case Json::Type::STRING: { - string s = value.string_value(); - if (s == "TRUE" || s == "true") return true; - if (s == "FALSE" || s == "false") return false; - int num; - try { - num = stoi(s); - } catch(std::invalid_argument& e){ - FATAL_ERROR("Value %s for %s is unexpected type; expected bool\n", e.what(), /*field.c_str()*/ "JSON field"); - } - return num != 0; - } - case Json::Type::NUMBER: - return value.int_value() != 0; - case Json::Type::BOOL: - return value.bool_value(); - default: - FATAL_ERROR("Value for %s is unexpected type; expected bool.\n", /*field.c_str()*/ "JSON field"); - } - return false; -} - string generate_map_header_text(Json map_data, Json layouts_data, string version) { string map_layout_id = json_to_string(map_data["layout"]); @@ -176,19 +125,19 @@ string generate_map_header_text(Json map_data, Json layouts_data, string version text << "\t.2byte " << json_to_string(map_data["music"]) << "\n" << "\t.2byte " << json_to_string(layout["id"]) << "\n" << "\t.byte " << json_to_string(map_data["region_map_section"]) << "\n" - << "\t.byte " << json_to_bool(map_data["requires_flash"]) << "\n" + << "\t.byte " << json_to_string(map_data["requires_flash"]) << "\n" << "\t.byte " << json_to_string(map_data["weather"]) << "\n" << "\t.byte " << json_to_string(map_data["map_type"]) << "\n" << "\t.2byte 0\n"; if (version == "ruby") - text << "\t.byte " << json_to_bool(map_data["show_map_name"]) << "\n"; + text << "\t.byte " << json_to_string(map_data["show_map_name"]) << "\n"; else if (version == "emerald") text << "\tmap_header_flags " - << "allow_cycling=" << json_to_bool(map_data["allow_cycling"]) << ", " - << "allow_escaping=" << json_to_bool(map_data["allow_escaping"]) << ", " - << "allow_running=" << json_to_bool(map_data["allow_running"]) << ", " - << "show_map_name=" << json_to_bool(map_data["show_map_name"]) << "\n"; + << "allow_cycling=" << json_to_string(map_data["allow_cycling"]) << ", " + << "allow_escaping=" << json_to_string(map_data["allow_escaping"]) << ", " + << "allow_running=" << json_to_string(map_data["allow_running"]) << ", " + << "show_map_name=" << json_to_string(map_data["show_map_name"]) << "\n"; text << "\t.byte " << json_to_string(map_data["battle_scene"]) << "\n\n"; @@ -210,7 +159,7 @@ string generate_map_connections_text(Json map_data) { for (auto &connection : map_data["connections"].array_items()) { text << "\tconnection " << json_to_string(connection["direction"]) << ", " - << json_to_int(connection["offset"]) << ", " + << json_to_string(connection["offset"]) << ", " << json_to_string(connection["map"]) << "\n"; } @@ -240,12 +189,12 @@ string generate_map_events_text(Json map_data) { auto obj_event = map_data["object_events"].array_items()[i]; text << "\tobject_event " << i + 1 << ", " << json_to_string(obj_event["graphics_id"]) << ", 0, " - << json_to_int(obj_event["x"]) << ", " - << json_to_int(obj_event["y"]) << ", " - << json_to_int(obj_event["elevation"]) << ", " + << json_to_string(obj_event["x"]) << ", " + << json_to_string(obj_event["y"]) << ", " + << json_to_string(obj_event["elevation"]) << ", " << json_to_string(obj_event["movement_type"]) << ", " - << json_to_int(obj_event["movement_range_x"]) << ", " - << json_to_int(obj_event["movement_range_y"]) << ", " + << json_to_string(obj_event["movement_range_x"]) << ", " + << json_to_string(obj_event["movement_range_y"]) << ", " << json_to_string(obj_event["trainer_type"]) << ", " << json_to_string(obj_event["trainer_sight_or_berry_tree_id"]) << ", " << json_to_string(obj_event["script"]) << ", " @@ -261,9 +210,9 @@ string generate_map_events_text(Json map_data) { text << warps_label << ":\n"; for (auto &warp_event : map_data["warp_events"].array_items()) { text << "\twarp_def " - << json_to_int(warp_event["x"]) << ", " - << json_to_int(warp_event["y"]) << ", " - << json_to_int(warp_event["elevation"]) << ", " + << json_to_string(warp_event["x"]) << ", " + << json_to_string(warp_event["y"]) << ", " + << json_to_string(warp_event["elevation"]) << ", " << json_to_string(warp_event["dest_warp_id"]) << ", " << json_to_string(warp_event["dest_map"]) << "\n"; } @@ -278,18 +227,18 @@ string generate_map_events_text(Json map_data) { for (auto &coord_event : map_data["coord_events"].array_items()) { if (json_to_string(coord_event["type"]) == "trigger") { text << "\tcoord_event " - << json_to_int(coord_event["x"]) << ", " - << json_to_int(coord_event["y"]) << ", " - << json_to_int(coord_event["elevation"]) << ", " + << json_to_string(coord_event["x"]) << ", " + << json_to_string(coord_event["y"]) << ", " + << json_to_string(coord_event["elevation"]) << ", " << json_to_string(coord_event["var"]) << ", " << json_to_string(coord_event["var_value"]) << ", " << json_to_string(coord_event["script"]) << "\n"; } else if (coord_event["type"] == "weather") { text << "\tcoord_weather_event " - << json_to_int(coord_event["x"]) << ", " - << json_to_int(coord_event["y"]) << ", " - << json_to_int(coord_event["elevation"]) << ", " + << json_to_string(coord_event["x"]) << ", " + << json_to_string(coord_event["y"]) << ", " + << json_to_string(coord_event["elevation"]) << ", " << json_to_string(coord_event["weather"]) << "\n"; } } @@ -304,25 +253,25 @@ string generate_map_events_text(Json map_data) { for (auto &bg_event : map_data["bg_events"].array_items()) { if (bg_event["type"] == "sign") { text << "\tbg_sign_event " - << json_to_int(bg_event["x"]) << ", " - << json_to_int(bg_event["y"]) << ", " - << json_to_int(bg_event["elevation"]) << ", " + << json_to_string(bg_event["x"]) << ", " + << json_to_string(bg_event["y"]) << ", " + << json_to_string(bg_event["elevation"]) << ", " << json_to_string(bg_event["player_facing_dir"]) << ", " << json_to_string(bg_event["script"]) << "\n"; } else if (bg_event["type"] == "hidden_item") { text << "\tbg_hidden_item_event " - << json_to_int(bg_event["x"]) << ", " - << json_to_int(bg_event["y"]) << ", " - << json_to_int(bg_event["elevation"]) << ", " + << json_to_string(bg_event["x"]) << ", " + << json_to_string(bg_event["y"]) << ", " + << json_to_string(bg_event["elevation"]) << ", " << json_to_string(bg_event["item"]) << ", " << json_to_string(bg_event["flag"]) << "\n"; } else if (bg_event["type"] == "secret_base") { text << "\tbg_secret_base_event " - << json_to_int(bg_event["x"]) << ", " - << json_to_int(bg_event["y"]) << ", " - << json_to_int(bg_event["elevation"]) << ", " + << json_to_string(bg_event["x"]) << ", " + << json_to_string(bg_event["y"]) << ", " + << json_to_string(bg_event["elevation"]) << ", " << json_to_string(bg_event["secret_base_id"]) << "\n"; } } @@ -538,8 +487,8 @@ string generate_layout_headers_text(Json layouts_data) { << "\t.incbin \"" << json_to_string(layout["blockdata_filepath"]) << "\"\n\n" << "\t.align 2\n" << layoutName << "::\n" - << "\t.4byte " << json_to_int(layout["width"]) << "\n" - << "\t.4byte " << json_to_int(layout["height"]) << "\n" + << "\t.4byte " << json_to_string(layout["width"]) << "\n" + << "\t.4byte " << json_to_string(layout["height"]) << "\n" << "\t.4byte " << border_label << "\n" << "\t.4byte " << blockdata_label << "\n" << "\t.4byte " << json_to_string(layout["primary_tileset"]) << "\n" From 713e1825bd8cf3cfacccfe48505ba46589cdb157 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 17 Jan 2023 16:11:15 -0500 Subject: [PATCH 4/7] Report JSON field names in errors --- tools/mapjson/mapjson.cpp | 166 ++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 80 deletions(-) diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index 29e1225b05..1a3058f3da 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -60,7 +60,9 @@ void write_text_file(string filepath, string text) { out_file.close(); } -string json_to_string(const Json &value) { + +string json_to_string(const Json &data, const string &field = "") { + const Json value = !field.empty() ? data[field] : data; string output = ""; switch (value.type()) { case Json::Type::STRING: @@ -72,23 +74,27 @@ string json_to_string(const Json &value) { case Json::Type::BOOL: output = value.bool_value() ? "TRUE" : "FALSE"; break; - default: - FATAL_ERROR("Value for %s is unexpected type; expected string, int, or bool.\n", /*field.c_str()*/ "JSON field"); + default:{ + string s = !field.empty() ? ("Value for '" + field + "'") : "JSON field"; + FATAL_ERROR("%s is unexpected type; expected string, number, or bool.\n", s.c_str()); + } } - if (output.empty()) - FATAL_ERROR("Value for %s cannot be empty.\n", /*field.c_str()*/ "JSON field"); + if (output.empty()){ + string s = !field.empty() ? ("Value for '" + field + "'") : "JSON field"; + FATAL_ERROR("%s cannot be empty.\n", s.c_str()); + } return output; } string generate_map_header_text(Json map_data, Json layouts_data, string version) { - string map_layout_id = json_to_string(map_data["layout"]); + string map_layout_id = json_to_string(map_data, "layout"); vector matched; for (auto &field : layouts_data["layouts"].array_items()) { - if (map_layout_id == json_to_string(field["id"])) + if (map_layout_id == json_to_string(field, "id")) matched.push_back(field); } @@ -99,20 +105,20 @@ string generate_map_header_text(Json map_data, Json layouts_data, string version ostringstream text; - string mapName = json_to_string(map_data["name"]); + string mapName = json_to_string(map_data, "name"); text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" << mapName << "/map.json\n@\n\n"; text << mapName << ":\n" - << "\t.4byte " << json_to_string(layout["name"]) << "\n"; + << "\t.4byte " << json_to_string(layout, "name") << "\n"; if (map_data.object_items().find("shared_events_map") != map_data.object_items().end()) - text << "\t.4byte " << json_to_string(map_data["shared_events_map"]) << "_MapEvents\n"; + text << "\t.4byte " << json_to_string(map_data, "shared_events_map") << "_MapEvents\n"; else text << "\t.4byte " << mapName << "_MapEvents\n"; if (map_data.object_items().find("shared_scripts_map") != map_data.object_items().end()) - text << "\t.4byte " << json_to_string(map_data["shared_scripts_map"]) << "_MapScripts\n"; + text << "\t.4byte " << json_to_string(map_data, "shared_scripts_map") << "_MapScripts\n"; else text << "\t.4byte " << mapName << "_MapScripts\n"; @@ -122,24 +128,24 @@ string generate_map_header_text(Json map_data, Json layouts_data, string version else text << "\t.4byte 0x0\n"; - text << "\t.2byte " << json_to_string(map_data["music"]) << "\n" - << "\t.2byte " << json_to_string(layout["id"]) << "\n" - << "\t.byte " << json_to_string(map_data["region_map_section"]) << "\n" - << "\t.byte " << json_to_string(map_data["requires_flash"]) << "\n" - << "\t.byte " << json_to_string(map_data["weather"]) << "\n" - << "\t.byte " << json_to_string(map_data["map_type"]) << "\n" + text << "\t.2byte " << json_to_string(map_data, "music") << "\n" + << "\t.2byte " << json_to_string(layout, "id") << "\n" + << "\t.byte " << json_to_string(map_data, "region_map_section") << "\n" + << "\t.byte " << json_to_string(map_data, "requires_flash") << "\n" + << "\t.byte " << json_to_string(map_data, "weather") << "\n" + << "\t.byte " << json_to_string(map_data, "map_type") << "\n" << "\t.2byte 0\n"; if (version == "ruby") - text << "\t.byte " << json_to_string(map_data["show_map_name"]) << "\n"; + text << "\t.byte " << json_to_string(map_data, "show_map_name") << "\n"; else if (version == "emerald") text << "\tmap_header_flags " - << "allow_cycling=" << json_to_string(map_data["allow_cycling"]) << ", " - << "allow_escaping=" << json_to_string(map_data["allow_escaping"]) << ", " - << "allow_running=" << json_to_string(map_data["allow_running"]) << ", " - << "show_map_name=" << json_to_string(map_data["show_map_name"]) << "\n"; + << "allow_cycling=" << json_to_string(map_data, "allow_cycling") << ", " + << "allow_escaping=" << json_to_string(map_data, "allow_escaping") << ", " + << "allow_running=" << json_to_string(map_data, "allow_running") << ", " + << "show_map_name=" << json_to_string(map_data, "show_map_name") << "\n"; - text << "\t.byte " << json_to_string(map_data["battle_scene"]) << "\n\n"; + text << "\t.byte " << json_to_string(map_data, "battle_scene") << "\n\n"; return text.str(); } @@ -150,7 +156,7 @@ string generate_map_connections_text(Json map_data) { ostringstream text; - string mapName = json_to_string(map_data["name"]); + string mapName = json_to_string(map_data, "name"); text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" << mapName << "/map.json\n@\n\n"; @@ -158,9 +164,9 @@ string generate_map_connections_text(Json map_data) { for (auto &connection : map_data["connections"].array_items()) { text << "\tconnection " - << json_to_string(connection["direction"]) << ", " - << json_to_string(connection["offset"]) << ", " - << json_to_string(connection["map"]) << "\n"; + << json_to_string(connection, "direction") << ", " + << json_to_string(connection, "offset") << ", " + << json_to_string(connection, "map") << "\n"; } text << "\n" << mapName << "_MapConnections:\n" @@ -176,7 +182,7 @@ string generate_map_events_text(Json map_data) { ostringstream text; - string mapName = json_to_string(map_data["name"]); + string mapName = json_to_string(map_data, "name"); text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/maps/" << mapName << "/map.json\n@\n\n"; @@ -188,17 +194,17 @@ string generate_map_events_text(Json map_data) { 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 << ", " - << json_to_string(obj_event["graphics_id"]) << ", 0, " - << json_to_string(obj_event["x"]) << ", " - << json_to_string(obj_event["y"]) << ", " - << json_to_string(obj_event["elevation"]) << ", " - << json_to_string(obj_event["movement_type"]) << ", " - << json_to_string(obj_event["movement_range_x"]) << ", " - << json_to_string(obj_event["movement_range_y"]) << ", " - << json_to_string(obj_event["trainer_type"]) << ", " - << json_to_string(obj_event["trainer_sight_or_berry_tree_id"]) << ", " - << json_to_string(obj_event["script"]) << ", " - << json_to_string(obj_event["flag"]) << "\n"; + << json_to_string(obj_event, "graphics_id") << ", 0, " + << json_to_string(obj_event, "x") << ", " + << json_to_string(obj_event, "y") << ", " + << json_to_string(obj_event, "elevation") << ", " + << json_to_string(obj_event, "movement_type") << ", " + << json_to_string(obj_event, "movement_range_x") << ", " + << json_to_string(obj_event, "movement_range_y") << ", " + << json_to_string(obj_event, "trainer_type") << ", " + << json_to_string(obj_event, "trainer_sight_or_berry_tree_id") << ", " + << json_to_string(obj_event, "script") << ", " + << json_to_string(obj_event, "flag") << "\n"; } text << "\n"; } else { @@ -210,11 +216,11 @@ string generate_map_events_text(Json map_data) { text << warps_label << ":\n"; for (auto &warp_event : map_data["warp_events"].array_items()) { text << "\twarp_def " - << json_to_string(warp_event["x"]) << ", " - << json_to_string(warp_event["y"]) << ", " - << json_to_string(warp_event["elevation"]) << ", " - << json_to_string(warp_event["dest_warp_id"]) << ", " - << json_to_string(warp_event["dest_map"]) << "\n"; + << json_to_string(warp_event, "x") << ", " + << json_to_string(warp_event, "y") << ", " + << json_to_string(warp_event, "elevation") << ", " + << json_to_string(warp_event, "dest_warp_id") << ", " + << json_to_string(warp_event, "dest_map") << "\n"; } text << "\n"; } else { @@ -225,21 +231,21 @@ string generate_map_events_text(Json map_data) { coords_label = mapName + "_MapCoordEvents"; text << coords_label << ":\n"; for (auto &coord_event : map_data["coord_events"].array_items()) { - if (json_to_string(coord_event["type"]) == "trigger") { + if (json_to_string(coord_event, "type") == "trigger") { text << "\tcoord_event " - << json_to_string(coord_event["x"]) << ", " - << json_to_string(coord_event["y"]) << ", " - << json_to_string(coord_event["elevation"]) << ", " - << json_to_string(coord_event["var"]) << ", " - << json_to_string(coord_event["var_value"]) << ", " - << json_to_string(coord_event["script"]) << "\n"; + << json_to_string(coord_event, "x") << ", " + << json_to_string(coord_event, "y") << ", " + << json_to_string(coord_event, "elevation") << ", " + << json_to_string(coord_event, "var") << ", " + << json_to_string(coord_event, "var_value") << ", " + << json_to_string(coord_event, "script") << "\n"; } else if (coord_event["type"] == "weather") { text << "\tcoord_weather_event " - << json_to_string(coord_event["x"]) << ", " - << json_to_string(coord_event["y"]) << ", " - << json_to_string(coord_event["elevation"]) << ", " - << json_to_string(coord_event["weather"]) << "\n"; + << json_to_string(coord_event, "x") << ", " + << json_to_string(coord_event, "y") << ", " + << json_to_string(coord_event, "elevation") << ", " + << json_to_string(coord_event, "weather") << "\n"; } } text << "\n"; @@ -253,26 +259,26 @@ string generate_map_events_text(Json map_data) { for (auto &bg_event : map_data["bg_events"].array_items()) { if (bg_event["type"] == "sign") { text << "\tbg_sign_event " - << json_to_string(bg_event["x"]) << ", " - << json_to_string(bg_event["y"]) << ", " - << json_to_string(bg_event["elevation"]) << ", " - << json_to_string(bg_event["player_facing_dir"]) << ", " - << json_to_string(bg_event["script"]) << "\n"; + << json_to_string(bg_event, "x") << ", " + << json_to_string(bg_event, "y") << ", " + << json_to_string(bg_event, "elevation") << ", " + << json_to_string(bg_event, "player_facing_dir") << ", " + << json_to_string(bg_event, "script") << "\n"; } else if (bg_event["type"] == "hidden_item") { text << "\tbg_hidden_item_event " - << json_to_string(bg_event["x"]) << ", " - << json_to_string(bg_event["y"]) << ", " - << json_to_string(bg_event["elevation"]) << ", " - << json_to_string(bg_event["item"]) << ", " - << json_to_string(bg_event["flag"]) << "\n"; + << json_to_string(bg_event, "x") << ", " + << json_to_string(bg_event, "y") << ", " + << json_to_string(bg_event, "elevation") << ", " + << json_to_string(bg_event, "item") << ", " + << json_to_string(bg_event, "flag") << "\n"; } else if (bg_event["type"] == "secret_base") { text << "\tbg_secret_base_event " - << json_to_string(bg_event["x"]) << ", " - << json_to_string(bg_event["y"]) << ", " - << json_to_string(bg_event["elevation"]) << ", " - << json_to_string(bg_event["secret_base_id"]) << "\n"; + << json_to_string(bg_event, "x") << ", " + << json_to_string(bg_event, "y") << ", " + << json_to_string(bg_event, "elevation") << ", " + << json_to_string(bg_event, "secret_base_id") << "\n"; } } text << "\n"; @@ -427,7 +433,7 @@ string generate_map_constants_text(string groups_filepath, Json groups_data) { string err_str; Json map_data = Json::parse(read_text_file(header_filepath), err_str); map_ids.push_back(map_data["id"]); - string id = json_to_string(map_data["id"]); + string id = json_to_string(map_data, "id"); if (id.length() > max_length) max_length = id.length(); } @@ -478,21 +484,21 @@ string generate_layout_headers_text(Json layouts_data) { text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/layouts/layouts.json\n@\n\n"; for (auto &layout : layouts_data["layouts"].array_items()) { - string layoutName = json_to_string(layout["name"]); + string layoutName = json_to_string(layout, "name"); string border_label = layoutName + "_Border"; string blockdata_label = layoutName + "_Blockdata"; text << border_label << "::\n" - << "\t.incbin \"" << json_to_string(layout["border_filepath"]) << "\"\n\n" + << "\t.incbin \"" << json_to_string(layout, "border_filepath") << "\"\n\n" << blockdata_label << "::\n" - << "\t.incbin \"" << json_to_string(layout["blockdata_filepath"]) << "\"\n\n" + << "\t.incbin \"" << json_to_string(layout, "blockdata_filepath") << "\"\n\n" << "\t.align 2\n" << layoutName << "::\n" - << "\t.4byte " << json_to_string(layout["width"]) << "\n" - << "\t.4byte " << json_to_string(layout["height"]) << "\n" + << "\t.4byte " << json_to_string(layout, "width") << "\n" + << "\t.4byte " << json_to_string(layout, "height") << "\n" << "\t.4byte " << border_label << "\n" << "\t.4byte " << blockdata_label << "\n" - << "\t.4byte " << json_to_string(layout["primary_tileset"]) << "\n" - << "\t.4byte " << json_to_string(layout["secondary_tileset"]) << "\n\n"; + << "\t.4byte " << json_to_string(layout, "primary_tileset") << "\n" + << "\t.4byte " << json_to_string(layout, "secondary_tileset") << "\n\n"; } return text.str(); @@ -504,10 +510,10 @@ string generate_layouts_table_text(Json layouts_data) { text << "@\n@ DO NOT MODIFY THIS FILE! It is auto-generated from data/layouts/layouts.json\n@\n\n"; text << "\t.align 2\n" - << json_to_string(layouts_data["layouts_table_label"]) << "::\n"; + << json_to_string(layouts_data, "layouts_table_label") << "::\n"; for (auto &layout : layouts_data["layouts"].array_items()) - text << "\t.4byte " << json_to_string(layout["name"]) << "\n"; + text << "\t.4byte " << json_to_string(layout, "name") << "\n"; return text.str(); } @@ -522,7 +528,7 @@ string generate_layouts_constants_text(Json layouts_data) { int i = 0; for (auto &layout : layouts_data["layouts"].array_items()) - text << "#define " << json_to_string(layout["id"]) << " " << ++i << "\n"; + text << "#define " << json_to_string(layout, "id") << " " << ++i << "\n"; text << "\n#endif // GUARD_CONSTANTS_LAYOUTS_H\n"; From 29c1af50cacc170622f0f345ccf261bfc6c6bf4a Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 20 Jan 2023 11:25:04 -0500 Subject: [PATCH 5/7] Fix Best Streak stat name --- data/specials.inc | 2 +- include/constants/game_stat.h | 108 +++++++++++++++++----------------- src/field_specials.c | 4 +- src/frontier_util.c | 2 +- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/data/specials.inc b/data/specials.inc index f14ff166f9..187e49ec77 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -258,7 +258,7 @@ gSpecials:: def_special CallSlateportTentFunction def_special ChoosePartyForBattleFrontier def_special ValidateEReaderTrainer - def_special GetBestBattleTowerStreak + def_special GetBattleTowerSinglesStreak def_special ReducePlayerPartyToSelectedMons def_special BedroomPC def_special PlayerPC diff --git a/include/constants/game_stat.h b/include/constants/game_stat.h index 2acdfd8a3e..053e4a8f9e 100644 --- a/include/constants/game_stat.h +++ b/include/constants/game_stat.h @@ -1,60 +1,60 @@ #ifndef GUARD_CONSTANTS_GAME_STAT_H #define GUARD_CONSTANTS_GAME_STAT_H -#define GAME_STAT_SAVED_GAME 0 -#define GAME_STAT_FIRST_HOF_PLAY_TIME 1 -#define GAME_STAT_STARTED_TRENDS 2 -#define GAME_STAT_PLANTED_BERRIES 3 -#define GAME_STAT_TRADED_BIKES 4 -#define GAME_STAT_STEPS 5 -#define GAME_STAT_GOT_INTERVIEWED 6 -#define GAME_STAT_TOTAL_BATTLES 7 -#define GAME_STAT_WILD_BATTLES 8 -#define GAME_STAT_TRAINER_BATTLES 9 -#define GAME_STAT_ENTERED_HOF 10 -#define GAME_STAT_POKEMON_CAPTURES 11 -#define GAME_STAT_FISHING_CAPTURES 12 -#define GAME_STAT_HATCHED_EGGS 13 -#define GAME_STAT_EVOLVED_POKEMON 14 -#define GAME_STAT_USED_POKECENTER 15 -#define GAME_STAT_RESTED_AT_HOME 16 -#define GAME_STAT_ENTERED_SAFARI_ZONE 17 -#define GAME_STAT_USED_CUT 18 -#define GAME_STAT_USED_ROCK_SMASH 19 -#define GAME_STAT_MOVED_SECRET_BASE 20 -#define GAME_STAT_POKEMON_TRADES 21 -#define GAME_STAT_UNKNOWN_22 22 -#define GAME_STAT_LINK_BATTLE_WINS 23 -#define GAME_STAT_LINK_BATTLE_LOSSES 24 -#define GAME_STAT_LINK_BATTLE_DRAWS 25 -#define GAME_STAT_USED_SPLASH 26 -#define GAME_STAT_USED_STRUGGLE 27 -#define GAME_STAT_SLOT_JACKPOTS 28 -#define GAME_STAT_CONSECUTIVE_ROULETTE_WINS 29 -#define GAME_STAT_ENTERED_BATTLE_TOWER 30 -#define GAME_STAT_UNKNOWN_31 31 -#define GAME_STAT_BATTLE_TOWER_BEST_STREAK 32 -#define GAME_STAT_POKEBLOCKS 33 -#define GAME_STAT_POKEBLOCKS_WITH_FRIENDS 34 -#define GAME_STAT_WON_LINK_CONTEST 35 -#define GAME_STAT_ENTERED_CONTEST 36 -#define GAME_STAT_WON_CONTEST 37 -#define GAME_STAT_SHOPPED 38 -#define GAME_STAT_USED_ITEMFINDER 39 -#define GAME_STAT_GOT_RAINED_ON 40 -#define GAME_STAT_CHECKED_POKEDEX 41 -#define GAME_STAT_RECEIVED_RIBBONS 42 -#define GAME_STAT_JUMPED_DOWN_LEDGES 43 -#define GAME_STAT_WATCHED_TV 44 -#define GAME_STAT_CHECKED_CLOCK 45 -#define GAME_STAT_WON_POKEMON_LOTTERY 46 -#define GAME_STAT_USED_DAYCARE 47 -#define GAME_STAT_RODE_CABLE_CAR 48 -#define GAME_STAT_ENTERED_HOT_SPRINGS 49 -#define GAME_STAT_NUM_UNION_ROOM_BATTLES 50 -#define GAME_STAT_PLAYED_BERRY_CRUSH 51 +#define GAME_STAT_SAVED_GAME 0 +#define GAME_STAT_FIRST_HOF_PLAY_TIME 1 +#define GAME_STAT_STARTED_TRENDS 2 +#define GAME_STAT_PLANTED_BERRIES 3 +#define GAME_STAT_TRADED_BIKES 4 +#define GAME_STAT_STEPS 5 +#define GAME_STAT_GOT_INTERVIEWED 6 +#define GAME_STAT_TOTAL_BATTLES 7 +#define GAME_STAT_WILD_BATTLES 8 +#define GAME_STAT_TRAINER_BATTLES 9 +#define GAME_STAT_ENTERED_HOF 10 +#define GAME_STAT_POKEMON_CAPTURES 11 +#define GAME_STAT_FISHING_CAPTURES 12 +#define GAME_STAT_HATCHED_EGGS 13 +#define GAME_STAT_EVOLVED_POKEMON 14 +#define GAME_STAT_USED_POKECENTER 15 +#define GAME_STAT_RESTED_AT_HOME 16 +#define GAME_STAT_ENTERED_SAFARI_ZONE 17 +#define GAME_STAT_USED_CUT 18 +#define GAME_STAT_USED_ROCK_SMASH 19 +#define GAME_STAT_MOVED_SECRET_BASE 20 +#define GAME_STAT_POKEMON_TRADES 21 +#define GAME_STAT_UNKNOWN_22 22 +#define GAME_STAT_LINK_BATTLE_WINS 23 +#define GAME_STAT_LINK_BATTLE_LOSSES 24 +#define GAME_STAT_LINK_BATTLE_DRAWS 25 +#define GAME_STAT_USED_SPLASH 26 +#define GAME_STAT_USED_STRUGGLE 27 +#define GAME_STAT_SLOT_JACKPOTS 28 +#define GAME_STAT_CONSECUTIVE_ROULETTE_WINS 29 +#define GAME_STAT_ENTERED_BATTLE_TOWER 30 +#define GAME_STAT_UNKNOWN_31 31 +#define GAME_STAT_BATTLE_TOWER_SINGLES_STREAK 32 +#define GAME_STAT_POKEBLOCKS 33 +#define GAME_STAT_POKEBLOCKS_WITH_FRIENDS 34 +#define GAME_STAT_WON_LINK_CONTEST 35 +#define GAME_STAT_ENTERED_CONTEST 36 +#define GAME_STAT_WON_CONTEST 37 +#define GAME_STAT_SHOPPED 38 +#define GAME_STAT_USED_ITEMFINDER 39 +#define GAME_STAT_GOT_RAINED_ON 40 +#define GAME_STAT_CHECKED_POKEDEX 41 +#define GAME_STAT_RECEIVED_RIBBONS 42 +#define GAME_STAT_JUMPED_DOWN_LEDGES 43 +#define GAME_STAT_WATCHED_TV 44 +#define GAME_STAT_CHECKED_CLOCK 45 +#define GAME_STAT_WON_POKEMON_LOTTERY 46 +#define GAME_STAT_USED_DAYCARE 47 +#define GAME_STAT_RODE_CABLE_CAR 48 +#define GAME_STAT_ENTERED_HOT_SPRINGS 49 +#define GAME_STAT_NUM_UNION_ROOM_BATTLES 50 +#define GAME_STAT_PLAYED_BERRY_CRUSH 51 -#define NUM_USED_GAME_STATS 52 -#define NUM_GAME_STATS 64 +#define NUM_USED_GAME_STATS 52 +#define NUM_GAME_STATS 64 #endif // GUARD_CONSTANTS_GAME_STAT_H diff --git a/src/field_specials.c b/src/field_specials.c index 097a16b45c..a2023196ba 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -1234,9 +1234,9 @@ void GetSecretBaseNearbyMapName(void) GetMapName(gStringVar1, VarGet(VAR_SECRET_BASE_MAP), 0); } -u16 GetBestBattleTowerStreak(void) +u16 GetBattleTowerSinglesStreak(void) { - return GetGameStat(GAME_STAT_BATTLE_TOWER_BEST_STREAK); + return GetGameStat(GAME_STAT_BATTLE_TOWER_SINGLES_STREAK); } void BufferEReaderTrainerName(void) diff --git a/src/frontier_util.c b/src/frontier_util.c index 686b69388a..4830f92117 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -2122,7 +2122,7 @@ static void IncrementWinStreak(void) gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode]++; if (battleMode == FRONTIER_MODE_SINGLES) { - SetGameStat(GAME_STAT_BATTLE_TOWER_BEST_STREAK, gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode]); + SetGameStat(GAME_STAT_BATTLE_TOWER_SINGLES_STREAK, gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode]); gSaveBlock2Ptr->frontier.towerSinglesStreak = gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode]; } } From 10230799d3bb61698bd8c98c39c5b5e65cc41d7a Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 23 Jan 2023 16:01:46 -0500 Subject: [PATCH 6/7] Simplify some max value macros --- src/battle_dome.c | 2 +- src/move_relearner.c | 2 +- src/pokemon_storage_system.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/battle_dome.c b/src/battle_dome.c index 2100b62117..f321999e15 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -4254,7 +4254,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) #undef tUsingAlternateSlot // allocatedArray below needs to be large enough to hold stat totals for each mon, or totals of each type of move points -#define ALLOC_ARRAY_SIZE (NUM_STATS * FRONTIER_PARTY_SIZE >= NUM_MOVE_POINT_TYPES ? (NUM_STATS * FRONTIER_PARTY_SIZE) : NUM_MOVE_POINT_TYPES) +#define ALLOC_ARRAY_SIZE max(NUM_STATS * FRONTIER_PARTY_SIZE, NUM_MOVE_POINT_TYPES) static void DisplayTrainerInfoOnCard(u8 flags, u8 trainerTourneyId) { diff --git a/src/move_relearner.c b/src/move_relearner.c index 9b4498a3a6..86ea06444e 100644 --- a/src/move_relearner.c +++ b/src/move_relearner.c @@ -150,7 +150,7 @@ #define JAM_HEART_EMPTY 2 #define JAM_HEART_FULL 3 -#define MAX_RELEARNER_MOVES (MAX_LEVEL_UP_MOVES > 25 ? MAX_LEVEL_UP_MOVES : 25) +#define MAX_RELEARNER_MOVES max(MAX_LEVEL_UP_MOVES, 25) static EWRAM_DATA struct { diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 730bbc7ed1..0e8d3633b5 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -256,7 +256,7 @@ enum { // The maximum number of Pokémon icons that can appear on-screen. // By default the limit is 40 (though in practice only 37 can be). -#define MAX_MON_ICONS (IN_BOX_COUNT + PARTY_SIZE + 1 >= 40 ? IN_BOX_COUNT + PARTY_SIZE + 1 : 40) +#define MAX_MON_ICONS max(IN_BOX_COUNT + PARTY_SIZE + 1, 40) // The maximum number of item icons that can appear on-screen while // moving held items. 1 in the cursor, and 2 more while switching From f4cb6d229f9c0130f763fa711c8a1f7ef59ac2c9 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 24 Jan 2023 17:02:17 -0500 Subject: [PATCH 7/7] Add some missing sizeof usage for SpriteSheets --- src/easy_chat.c | 6 +++--- src/egg_hatch.c | 4 ++-- src/item_menu_icons.c | 2 +- src/mirage_tower.c | 2 +- src/move_relearner.c | 41 +++++++++++++++++++++--------------- src/pokedex_cry_screen.c | 10 +++++---- src/pokemon_storage_system.c | 2 +- src/rotating_gate.c | 16 +++++++------- 8 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/easy_chat.c b/src/easy_chat.c index afbfebe54b..723800828e 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -867,17 +867,17 @@ static const u8 *const sEasyChatKeyboardAlphabet[NUM_ALPHABET_ROWS] = static const struct SpriteSheet sSpriteSheets[] = { { .data = sTriangleCursor_Gfx, - .size = 0x20, + .size = sizeof(sTriangleCursor_Gfx), .tag = GFXTAG_TRIANGLE_CURSOR }, { .data = sScrollIndicator_Gfx, - .size = 0x100, + .size = sizeof(sScrollIndicator_Gfx), .tag = GFXTAG_SCROLL_INDICATOR }, { .data = sStartSelectButtons_Gfx, - .size = 0x100, + .size = sizeof(sStartSelectButtons_Gfx), .tag = GFXTAG_START_SELECT_BUTTONS }, {0} diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 08c4d1feed..8c0bb5f79a 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -145,14 +145,14 @@ static const union AnimCmd *const sSpriteAnimTable_Egg[] = static const struct SpriteSheet sEggHatch_Sheet = { .data = sEggHatchTiles, - .size = 0x800, + .size = sizeof(sEggHatchTiles), .tag = GFXTAG_EGG, }; static const struct SpriteSheet sEggShards_Sheet = { .data = sEggShardTiles, - .size = 0x80, + .size = sizeof(sEggShardTiles), .tag = GFXTAG_EGG_SHARD, }; diff --git a/src/item_menu_icons.c b/src/item_menu_icons.c index e5d2d68ed3..7dbb912691 100644 --- a/src/item_menu_icons.c +++ b/src/item_menu_icons.c @@ -205,7 +205,7 @@ static const union AffineAnimCmd *const sRotatingBallAnimCmds_FullRotation[] = static const struct SpriteSheet sRotatingBallTable = { - sRotatingBall_Gfx, 0x80, TAG_ROTATING_BALL_GFX + sRotatingBall_Gfx, sizeof(sRotatingBall_Gfx), TAG_ROTATING_BALL_GFX }; static const struct SpritePalette sRotatingBallPaletteTable = diff --git a/src/mirage_tower.c b/src/mirage_tower.c index 37096619d3..01b87393ae 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -96,7 +96,7 @@ static const s16 sCeilingCrumblePositions[][3] = static const struct SpriteSheet sCeilingCrumbleSpriteSheets[] = { - {sMirageTowerCrumbles_Gfx, 0x80, TAG_CEILING_CRUMBLE}, + {sMirageTowerCrumbles_Gfx, sizeof(sMirageTowerCrumbles_Gfx), TAG_CEILING_CRUMBLE}, {} }; diff --git a/src/move_relearner.c b/src/move_relearner.c index 86ea06444e..05ec549e14 100644 --- a/src/move_relearner.c +++ b/src/move_relearner.c @@ -145,10 +145,17 @@ // The different versions of hearts are selected using animation // commands. -#define APPEAL_HEART_EMPTY 0 -#define APPEAL_HEART_FULL 1 -#define JAM_HEART_EMPTY 2 -#define JAM_HEART_FULL 3 +enum { + APPEAL_HEART_EMPTY, + APPEAL_HEART_FULL, + JAM_HEART_EMPTY, + JAM_HEART_FULL, +}; + +#define TAG_MODE_ARROWS 5325 +#define TAG_LIST_ARROWS 5425 +#define GFXTAG_UI 5525 +#define PALTAG_UI 5526 #define MAX_RELEARNER_MOVES max(MAX_LEVEL_UP_MOVES, 25) @@ -174,11 +181,11 @@ static EWRAM_DATA struct { bool8 showContestInfo; } sMoveRelearnerMenuSate = {0}; -static const u16 sMoveRelearnerPaletteData[] = INCBIN_U16("graphics/interface/ui_learn_move.gbapal"); +static const u16 sUI_Pal[] = INCBIN_U16("graphics/interface/ui_learn_move.gbapal"); // The arrow sprites in this spritesheet aren't used. The scroll-arrow system provides its own // arrow sprites. -static const u8 sMoveRelearnerSpriteSheetData[] = INCBIN_U8("graphics/interface/ui_learn_move.4bpp"); +static const u8 sUI_Tiles[] = INCBIN_U8("graphics/interface/ui_learn_move.4bpp"); static const struct OamData sHeartSpriteOamData = { @@ -233,15 +240,15 @@ static const struct OamData sUnusedOam2 = static const struct SpriteSheet sMoveRelearnerSpriteSheet = { - .data = sMoveRelearnerSpriteSheetData, - .size = 0x180, - .tag = 5525 + .data = sUI_Tiles, + .size = sizeof(sUI_Tiles), + .tag = GFXTAG_UI }; static const struct SpritePalette sMoveRelearnerPalette = { - .data = sMoveRelearnerPaletteData, - .tag = 5526 + .data = sUI_Pal, + .tag = PALTAG_UI }; static const struct ScrollArrowsTemplate sDisplayModeArrowsTemplate = @@ -254,8 +261,8 @@ static const struct ScrollArrowsTemplate sDisplayModeArrowsTemplate = .secondY = 16, .fullyUpThreshold = -1, .fullyDownThreshold = -1, - .tileTag = 5325, - .palTag = 5325, + .tileTag = TAG_MODE_ARROWS, + .palTag = TAG_MODE_ARROWS, .palNum = 0, }; @@ -269,8 +276,8 @@ static const struct ScrollArrowsTemplate sMoveListScrollArrowsTemplate = .secondY = 104, .fullyUpThreshold = 0, .fullyDownThreshold = 0, - .tileTag = 5425, - .palTag = 5425, + .tileTag = TAG_LIST_ARROWS, + .palTag = TAG_LIST_ARROWS, .palNum = 0, }; @@ -308,8 +315,8 @@ static const union AnimCmd *const sHeartSpriteAnimationCommands[] = static const struct SpriteTemplate sConstestMoveHeartSprite = { - .tileTag = 5525, - .paletteTag = 5526, + .tileTag = GFXTAG_UI, + .paletteTag = PALTAG_UI, .oam = &sHeartSpriteOamData, .anims = sHeartSpriteAnimationCommands, .images = NULL, diff --git a/src/pokedex_cry_screen.c b/src/pokedex_cry_screen.c index ed53ebf1ec..2c352c67a0 100644 --- a/src/pokedex_cry_screen.c +++ b/src/pokedex_cry_screen.c @@ -27,6 +27,8 @@ #define WAVEFORM_WINDOW_HEIGHT 56 +#define TAG_NEEDLE 0x2000 + struct PokedexCryMeterNeedle { s8 rotation; s8 targetRotation; @@ -202,8 +204,8 @@ static const struct OamData sOamData_CryMeterNeedle = static const struct SpriteTemplate sCryMeterNeedleSpriteTemplate = { - .tileTag = 0x2000, - .paletteTag = 0x2000, + .tileTag = TAG_NEEDLE, + .paletteTag = TAG_NEEDLE, .oam = &sOamData_CryMeterNeedle, .anims = sSpriteAnimTable_CryMeterNeedle, .images = NULL, @@ -213,13 +215,13 @@ static const struct SpriteTemplate sCryMeterNeedleSpriteTemplate = static const struct SpriteSheet sCryMeterNeedleSpriteSheets[] = { - {sCryMeterNeedle_Gfx, 0x800, 0x2000}, + {sCryMeterNeedle_Gfx, sizeof(sCryMeterNeedle_Gfx), TAG_NEEDLE}, {} }; static const struct SpritePalette sCryMeterNeedleSpritePalettes[] = { - {sCryMeterNeedle_Pal, 0x2000}, + {sCryMeterNeedle_Pal, TAG_NEEDLE}, {} }; diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 0e8d3633b5..c9855f9d5d 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -1240,7 +1240,7 @@ static const union AffineAnimCmd *const sAffineAnims_ReleaseMon[] = static const u16 sUnusedColor = RGB(26, 29, 8); -static const struct SpriteSheet sSpriteSheet_Arrow = {sArrow_Gfx, 0x80, GFXTAG_ARROW}; +static const struct SpriteSheet sSpriteSheet_Arrow = {sArrow_Gfx, sizeof(sArrow_Gfx), GFXTAG_ARROW}; static const struct OamData sOamData_BoxTitle = { diff --git a/src/rotating_gate.c b/src/rotating_gate.c index d1184dae01..f9e732eb74 100644 --- a/src/rotating_gate.c +++ b/src/rotating_gate.c @@ -264,14 +264,14 @@ static const struct OamData sOamData_RotatingGateRegular = static const struct SpriteSheet sRotatingGatesGraphicsTable[] = { - {sRotatingGateTiles_1, 0x200, ROTATING_GATE_TILE_TAG + GATE_SHAPE_L1}, - {sRotatingGateTiles_2, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_L2}, - {sRotatingGateTiles_3, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_L3}, - {sRotatingGateTiles_4, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_L4}, - {sRotatingGateTiles_5, 0x200, ROTATING_GATE_TILE_TAG + GATE_SHAPE_T1}, - {sRotatingGateTiles_6, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_T2}, - {sRotatingGateTiles_7, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_T3}, - {sRotatingGateTiles_8, 0x800, ROTATING_GATE_TILE_TAG + GATE_SHAPE_T4}, + {sRotatingGateTiles_1, sizeof(sRotatingGateTiles_1), ROTATING_GATE_TILE_TAG + GATE_SHAPE_L1}, + {sRotatingGateTiles_2, sizeof(sRotatingGateTiles_2), ROTATING_GATE_TILE_TAG + GATE_SHAPE_L2}, + {sRotatingGateTiles_3, sizeof(sRotatingGateTiles_3), ROTATING_GATE_TILE_TAG + GATE_SHAPE_L3}, + {sRotatingGateTiles_4, sizeof(sRotatingGateTiles_4), ROTATING_GATE_TILE_TAG + GATE_SHAPE_L4}, + {sRotatingGateTiles_5, sizeof(sRotatingGateTiles_5), ROTATING_GATE_TILE_TAG + GATE_SHAPE_T1}, + {sRotatingGateTiles_6, sizeof(sRotatingGateTiles_6), ROTATING_GATE_TILE_TAG + GATE_SHAPE_T2}, + {sRotatingGateTiles_7, sizeof(sRotatingGateTiles_7), ROTATING_GATE_TILE_TAG + GATE_SHAPE_T3}, + {sRotatingGateTiles_8, sizeof(sRotatingGateTiles_8), ROTATING_GATE_TILE_TAG + GATE_SHAPE_T4}, {NULL}, };