mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-12-26 03:34:15 +01:00
Merge pull request #1857 from GriffinRichards/sync-mapjson
Sync mapjson
This commit is contained in:
commit
f888021c8f
@ -19,11 +19,11 @@
|
||||
.4byte \script
|
||||
.endm
|
||||
|
||||
@ Defines an object event template for map data. Mirrors the struct layout of ObjectEventTemplate in include/global.fieldmap.h
|
||||
.macro object_event index:req, gfx:req, inConnection:req, x:req, y:req, elevation:req, movement_type:req, x_radius:req, y_radius:req, trainer_type:req, sight_radius_tree_etc:req, script:req, event_flag:req
|
||||
@ Defines an object event template for map data, to be used by a normal object. Mirrors the struct layout of ObjectEventTemplate in include/global.fieldmap.h
|
||||
.macro object_event index:req, gfx:req, x:req, y:req, elevation:req, movement_type:req, x_radius:req, y_radius:req, trainer_type:req, sight_radius_tree_etc:req, script:req, event_flag:req
|
||||
.byte \index
|
||||
.byte \gfx
|
||||
.byte \inConnection
|
||||
.byte OBJ_KIND_NORMAL
|
||||
.space 1 @ Padding
|
||||
.2byte \x, \y
|
||||
.byte \elevation
|
||||
@ -38,6 +38,22 @@
|
||||
inc _num_npcs
|
||||
.endm
|
||||
|
||||
@ Defines an object event template for map data, to be used by a clone object. Mirrors the struct layout of ObjectEventTemplate in include/global.fieldmap.h
|
||||
@ NOTE: The handling for this type of event does not exist in Emerald by default; it is exclusive to FRLG.
|
||||
.macro clone_event index:req, gfx:req, x:req, y:req, target_local_id:req, target_map_id:req
|
||||
.byte \index
|
||||
.byte \gfx
|
||||
.byte OBJ_KIND_CLONE
|
||||
.space 1 @ Padding
|
||||
.2byte \x, \y
|
||||
.byte \target_local_id
|
||||
.space 3 @ Padding
|
||||
.2byte \target_map_id & 0xFF @ map num
|
||||
.2byte \target_map_id >> 8 @ map group
|
||||
.space 8 @ Padding
|
||||
inc _num_npcs
|
||||
.endm
|
||||
|
||||
@ Defines a warp event for map data. Mirrors the struct layout of WarpEvent in include/global.fieldmap.h
|
||||
.macro warp_def x:req, y:req, elevation:req, warpId:req, map_id:req
|
||||
.2byte \x, \y
|
||||
@ -49,12 +65,12 @@
|
||||
.endm
|
||||
|
||||
@ Defines a coord event for map data. Mirrors the struct layout of CoordEvent in include/global.fieldmap.h
|
||||
.macro coord_event x:req, y:req, elevation:req, trigger:req, index:req, script:req
|
||||
.macro coord_event x:req, y:req, elevation:req, var:req, varValue:req, script:req
|
||||
.2byte \x, \y
|
||||
.byte \elevation
|
||||
.space 1 @ Padding
|
||||
.2byte \trigger
|
||||
.2byte \index
|
||||
.2byte \var
|
||||
.2byte \varValue
|
||||
.space 2 @ Padding
|
||||
.4byte \script
|
||||
inc _num_traps
|
||||
|
@ -288,6 +288,9 @@
|
||||
|
||||
#define FIRST_DECORATION_SPRITE_GFX OBJ_EVENT_GFX_PICHU_DOLL
|
||||
|
||||
#define OBJ_KIND_NORMAL 0
|
||||
#define OBJ_KIND_CLONE 255 // Exclusive to FRLG
|
||||
|
||||
// Special object event local ids
|
||||
#define OBJ_EVENT_ID_PLAYER 0xFF
|
||||
#define OBJ_EVENT_ID_CAMERA 0x7F
|
||||
|
@ -67,7 +67,7 @@ struct ObjectEventTemplate
|
||||
{
|
||||
/*0x00*/ u8 localId;
|
||||
/*0x01*/ u8 graphicsId;
|
||||
/*0x02*/ u8 inConnection; // Leftover from FRLG
|
||||
/*0x02*/ u8 kind; // Always OBJ_KIND_NORMAL in Emerald.
|
||||
/*0x03*/ //u8 padding1;
|
||||
/*0x04*/ s16 x;
|
||||
/*0x06*/ s16 y;
|
||||
|
@ -1498,7 +1498,7 @@ u8 SpawnSpecialObjectEventParameterized(u8 graphicsId, u8 movementBehavior, u8 l
|
||||
y -= MAP_OFFSET;
|
||||
objectEventTemplate.localId = localId;
|
||||
objectEventTemplate.graphicsId = graphicsId;
|
||||
objectEventTemplate.inConnection = 0;
|
||||
objectEventTemplate.kind = OBJ_KIND_NORMAL;
|
||||
objectEventTemplate.x = x;
|
||||
objectEventTemplate.y = y;
|
||||
objectEventTemplate.elevation = elevation;
|
||||
|
@ -29,6 +29,7 @@ using json11::Json;
|
||||
|
||||
#include "mapjson.h"
|
||||
|
||||
string version;
|
||||
|
||||
string read_text_file(string filepath) {
|
||||
ifstream in_file(filepath);
|
||||
@ -61,7 +62,7 @@ void write_text_file(string filepath, string text) {
|
||||
}
|
||||
|
||||
|
||||
string json_to_string(const Json &data, const string &field = "") {
|
||||
string json_to_string(const Json &data, const string &field = "", bool silent = false) {
|
||||
const Json value = !field.empty() ? data[field] : data;
|
||||
string output = "";
|
||||
switch (value.type()) {
|
||||
@ -75,12 +76,14 @@ string json_to_string(const Json &data, const string &field = "") {
|
||||
output = value.bool_value() ? "TRUE" : "FALSE";
|
||||
break;
|
||||
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 (!silent) {
|
||||
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()){
|
||||
if (!silent && output.empty()) {
|
||||
string s = !field.empty() ? ("Value for '" + field + "'") : "JSON field";
|
||||
FATAL_ERROR("%s cannot be empty.\n", s.c_str());
|
||||
}
|
||||
@ -88,14 +91,14 @@ string json_to_string(const Json &data, const string &field = "") {
|
||||
return output;
|
||||
}
|
||||
|
||||
string generate_map_header_text(Json map_data, Json layouts_data, string version) {
|
||||
string generate_map_header_text(Json map_data, Json layouts_data) {
|
||||
string map_layout_id = json_to_string(map_data, "layout");
|
||||
|
||||
vector<Json> matched;
|
||||
|
||||
for (auto &field : layouts_data["layouts"].array_items()) {
|
||||
if (map_layout_id == json_to_string(field, "id"))
|
||||
matched.push_back(field);
|
||||
for (auto &layout : layouts_data["layouts"].array_items()) {
|
||||
if (map_layout_id == json_to_string(layout, "id", true))
|
||||
matched.push_back(layout);
|
||||
}
|
||||
|
||||
if (matched.size() != 1)
|
||||
@ -123,28 +126,33 @@ string generate_map_header_text(Json map_data, Json layouts_data, string version
|
||||
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)
|
||||
&& map_data["connections"].array_items().size() > 0 && json_to_string(map_data, "connections_no_include", true) != "TRUE")
|
||||
text << "\t.4byte " << mapName << "_MapConnections\n";
|
||||
else
|
||||
text << "\t.4byte 0x0\n";
|
||||
text << "\t.4byte NULL\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";
|
||||
<< "\t.byte " << json_to_string(map_data, "map_type") << "\n";
|
||||
|
||||
if (version != "firered")
|
||||
text << "\t.2byte 0\n";
|
||||
|
||||
if (version == "ruby")
|
||||
text << "\t.byte " << json_to_string(map_data, "show_map_name") << "\n";
|
||||
else if (version == "emerald")
|
||||
else if (version == "emerald" || version == "firered")
|
||||
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";
|
||||
|
||||
if (version == "firered")
|
||||
text << "\t.byte " << json_to_string(map_data, "floor_number") << "\n";
|
||||
|
||||
text << "\t.byte " << json_to_string(map_data, "battle_scene") << "\n\n";
|
||||
|
||||
return text.str();
|
||||
@ -193,22 +201,36 @@ string generate_map_events_text(Json map_data) {
|
||||
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 << ", "
|
||||
<< 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";
|
||||
string type = json_to_string(obj_event, "type", true);
|
||||
|
||||
// If no type field is present, assume it's a regular object event.
|
||||
if (type == "" || type == "object") {
|
||||
text << "\tobject_event " << i + 1 << ", "
|
||||
<< json_to_string(obj_event, "graphics_id") << ", "
|
||||
<< 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";
|
||||
} else if (type == "clone") {
|
||||
text << "\tclone_event " << i + 1 << ", "
|
||||
<< json_to_string(obj_event, "graphics_id") << ", "
|
||||
<< json_to_string(obj_event, "x") << ", "
|
||||
<< json_to_string(obj_event, "y") << ", "
|
||||
<< json_to_string(obj_event, "target_local_id") << ", "
|
||||
<< json_to_string(obj_event, "target_map") << "\n";
|
||||
} else {
|
||||
FATAL_ERROR("Unknown object event type '%s'. Expected 'object' or 'clone'.\n", type.c_str());
|
||||
}
|
||||
}
|
||||
text << "\n";
|
||||
} else {
|
||||
objects_label = "0x0";
|
||||
objects_label = "NULL";
|
||||
}
|
||||
|
||||
if (map_data["warp_events"].array_items().size() > 0) {
|
||||
@ -224,14 +246,15 @@ string generate_map_events_text(Json map_data) {
|
||||
}
|
||||
text << "\n";
|
||||
} else {
|
||||
warps_label = "0x0";
|
||||
warps_label = "NULL";
|
||||
}
|
||||
|
||||
if (map_data["coord_events"].array_items().size() > 0) {
|
||||
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") {
|
||||
string type = json_to_string(coord_event, "type");
|
||||
if (type == "trigger") {
|
||||
text << "\tcoord_event "
|
||||
<< json_to_string(coord_event, "x") << ", "
|
||||
<< json_to_string(coord_event, "y") << ", "
|
||||
@ -240,24 +263,27 @@ string generate_map_events_text(Json map_data) {
|
||||
<< json_to_string(coord_event, "var_value") << ", "
|
||||
<< json_to_string(coord_event, "script") << "\n";
|
||||
}
|
||||
else if (coord_event["type"] == "weather") {
|
||||
else if (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";
|
||||
} else {
|
||||
FATAL_ERROR("Unknown coord event type '%s'. Expected 'trigger' or 'weather'.\n", type.c_str());
|
||||
}
|
||||
}
|
||||
text << "\n";
|
||||
} else {
|
||||
coords_label = "0x0";
|
||||
coords_label = "NULL";
|
||||
}
|
||||
|
||||
if (map_data["bg_events"].array_items().size() > 0) {
|
||||
bgs_label = mapName + "_MapBGEvents";
|
||||
text << bgs_label << ":\n";
|
||||
for (auto &bg_event : map_data["bg_events"].array_items()) {
|
||||
if (bg_event["type"] == "sign") {
|
||||
string type = json_to_string(bg_event, "type");
|
||||
if (type == "sign") {
|
||||
text << "\tbg_sign_event "
|
||||
<< json_to_string(bg_event, "x") << ", "
|
||||
<< json_to_string(bg_event, "y") << ", "
|
||||
@ -265,25 +291,33 @@ string generate_map_events_text(Json map_data) {
|
||||
<< json_to_string(bg_event, "player_facing_dir") << ", "
|
||||
<< json_to_string(bg_event, "script") << "\n";
|
||||
}
|
||||
else if (bg_event["type"] == "hidden_item") {
|
||||
else if (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, "flag");
|
||||
if (version == "firered") {
|
||||
text << ", "
|
||||
<< json_to_string(bg_event, "quantity") << ", "
|
||||
<< json_to_string(bg_event, "underfoot");
|
||||
}
|
||||
text << "\n";
|
||||
}
|
||||
else if (bg_event["type"] == "secret_base") {
|
||||
else if (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";
|
||||
} else {
|
||||
FATAL_ERROR("Unknown bg event type '%s'. Expected 'sign', 'hidden_item', or 'secret_base'.\n", type.c_str());
|
||||
}
|
||||
}
|
||||
text << "\n";
|
||||
} else {
|
||||
bgs_label = "0x0";
|
||||
bgs_label = "NULL";
|
||||
}
|
||||
|
||||
text << mapName << "_MapEvents::\n"
|
||||
@ -299,7 +333,7 @@ string get_directory_name(string filename) {
|
||||
return filename.substr(0, dir_pos + 1);
|
||||
}
|
||||
|
||||
void process_map(string map_filepath, string layouts_filepath, string version) {
|
||||
void process_map(string map_filepath, string layouts_filepath) {
|
||||
string mapdata_err, layouts_err;
|
||||
|
||||
string mapdata_json_text = read_text_file(map_filepath);
|
||||
@ -313,7 +347,7 @@ void process_map(string map_filepath, string layouts_filepath, string version) {
|
||||
if (layouts_data == Json())
|
||||
FATAL_ERROR("%s\n", layouts_err.c_str());
|
||||
|
||||
string header_text = generate_map_header_text(map_data, layouts_data, version);
|
||||
string header_text = generate_map_header_text(map_data, layouts_data);
|
||||
string events_text = generate_map_events_text(map_data);
|
||||
string connections_text = generate_map_connections_text(map_data);
|
||||
|
||||
@ -484,6 +518,7 @@ 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()) {
|
||||
if (layout == Json::object()) continue;
|
||||
string layoutName = json_to_string(layout, "name");
|
||||
string border_label = layoutName + "_Border";
|
||||
string blockdata_label = layoutName + "_Blockdata";
|
||||
@ -498,7 +533,13 @@ string generate_layout_headers_text(Json layouts_data) {
|
||||
<< "\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, "secondary_tileset") << "\n";
|
||||
if (version == "firered") {
|
||||
text << "\t.byte " << json_to_string(layout, "border_width") << "\n"
|
||||
<< "\t.byte " << json_to_string(layout, "border_height") << "\n"
|
||||
<< "\t.2byte 0\n";
|
||||
}
|
||||
text << "\n";
|
||||
}
|
||||
|
||||
return text.str();
|
||||
@ -512,8 +553,11 @@ string generate_layouts_table_text(Json layouts_data) {
|
||||
text << "\t.align 2\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";
|
||||
for (auto &layout : layouts_data["layouts"].array_items()) {
|
||||
string layout_name = json_to_string(layout, "name", true);
|
||||
if (layout_name.empty()) layout_name = "NULL";
|
||||
text << "\t.4byte " << layout_name << "\n";
|
||||
}
|
||||
|
||||
return text.str();
|
||||
}
|
||||
@ -526,9 +570,12 @@ string generate_layouts_constants_text(Json layouts_data) {
|
||||
|
||||
text << "//\n// DO NOT MODIFY THIS FILE! It is auto-generated from data/layouts/layouts.json\n//\n\n";
|
||||
|
||||
int i = 0;
|
||||
for (auto &layout : layouts_data["layouts"].array_items())
|
||||
text << "#define " << json_to_string(layout, "id") << " " << ++i << "\n";
|
||||
int i = 1;
|
||||
for (auto &layout : layouts_data["layouts"].array_items()) {
|
||||
if (layout != Json::object())
|
||||
text << "#define " << json_to_string(layout, "id") << " " << i << "\n";
|
||||
i++;
|
||||
}
|
||||
|
||||
text << "\n#endif // GUARD_CONSTANTS_LAYOUTS_H\n";
|
||||
|
||||
@ -559,9 +606,9 @@ int main(int argc, char *argv[]) {
|
||||
FATAL_ERROR("USAGE: mapjson <mode> <game-version> [options]\n");
|
||||
|
||||
char *version_arg = argv[2];
|
||||
string version(version_arg);
|
||||
if (version != "emerald" && version != "ruby")
|
||||
FATAL_ERROR("ERROR: <game-version> must be 'emerald' or 'ruby'.\n");
|
||||
version = string(version_arg);
|
||||
if (version != "emerald" && version != "ruby" && version != "firered")
|
||||
FATAL_ERROR("ERROR: <game-version> must be 'emerald', 'firered', or 'ruby'.\n");
|
||||
|
||||
char *mode_arg = argv[1];
|
||||
string mode(mode_arg);
|
||||
@ -575,7 +622,7 @@ int main(int argc, char *argv[]) {
|
||||
string filepath(argv[3]);
|
||||
string layouts_filepath(argv[4]);
|
||||
|
||||
process_map(filepath, layouts_filepath, version);
|
||||
process_map(filepath, layouts_filepath);
|
||||
}
|
||||
else if (mode == "groups") {
|
||||
if (argc != 4)
|
||||
|
Loading…
Reference in New Issue
Block a user