Skip to content

Commit

Permalink
Generate region_map_sections from JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Nov 7, 2024
1 parent bb50006 commit 29d5913
Show file tree
Hide file tree
Showing 9 changed files with 530 additions and 443 deletions.
1 change: 1 addition & 0 deletions include/constants/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Will be moved to build/ eventually
map_groups.h
layouts.h
region_map_sections.h
214 changes: 0 additions & 214 deletions include/constants/region_map_sections.h

This file was deleted.

4 changes: 4 additions & 0 deletions json_data_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ $(DATA_SRC_SUBDIR)/region_map/region_map_entry_strings.h: $(DATA_SRC_SUBDIR)/reg

$(C_BUILDDIR)/region_map.o: c_dep += $(DATA_SRC_SUBDIR)/region_map/region_map_entry_strings.h

AUTO_GEN_TARGETS += include/constants/region_map_sections.h
include/constants/region_map_sections.h: $(DATA_SRC_SUBDIR)/region_map/region_map_sections.json $(DATA_SRC_SUBDIR)/region_map/region_map_sections.constants.json.txt
$(JSONPROC) $^ $@

AUTO_GEN_TARGETS += $(DATA_SRC_SUBDIR)/items.h
$(DATA_SRC_SUBDIR)/items.h: $(DATA_SRC_SUBDIR)/items.json $(DATA_SRC_SUBDIR)/items.json.txt
$(JSONPROC) $^ $@
Expand Down
24 changes: 24 additions & 0 deletions src/data/region_map/region_map_sections.constants.json.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{ doNotModifyHeader }}
#ifndef GUARD_CONSTANTS_REGION_MAP_SECTIONS_H
#define GUARD_CONSTANTS_REGION_MAP_SECTIONS_H

enum {
## for map_section in map_sections
{{ map_section.id }},
## endfor
MAPSEC_NONE,
MAPSEC_COUNT
};

// Values before KANTO_MAPSEC_START are assumed to have no data.
#define KANTO_MAPSEC_START MAPSEC_PALLET_TOWN

// Values starting from SEVII_MAPSEC_START are assumed to have data in sSeviiMapsecs.
#define SEVII_MAPSEC_START MAPSEC_ONE_ISLAND

// Special location IDs that use the same value space as MAPSECs.
#define METLOC_SPECIAL_EGG 0xFD
#define METLOC_IN_GAME_TRADE 0xFE
#define METLOC_FATEFUL_ENCOUNTER 0xFF

#endif // GUARD_CONSTANTS_REGION_MAP_SECTIONS_H
14 changes: 10 additions & 4 deletions src/data/region_map/region_map_sections.entries.json.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
#define GUARD_DATA_REGION_MAP_REGION_MAP_ENTRIES_H

## for map_section in map_sections
{% if isEmptyString(getVar(map_section.name)) and not existsIn(map_section, "name_clone") %}{{ setVar(map_section.name, map_section.map_section) }}{% endif %}
{% if existsIn(map_section, "name") and isEmptyString(getVar(map_section.name)) and not existsIn(map_section, "name_clone") %}{{ setVar(map_section.name, map_section.id) }}{% endif %}
## endfor

static const u8 *const sMapNames[] = {
## for map_section in map_sections
[{{ map_section.map_section }} - MAPSECS_KANTO] = sMapsecName_{{ cleanString(map_section.name) }}{% if existsIn(map_section, "name_clone") %}_Clone{% endif %},
{% if existsIn(map_section, "name") %}
[{{ map_section.id }} - KANTO_MAPSEC_START] = sMapsecName_{{ cleanString(map_section.name) }}{% if existsIn(map_section, "name_clone") %}_Clone{% endif %},
{% endif %}
## endfor
};

static const u16 sMapSectionTopLeftCorners[MAPSEC_COUNT][2] = {
## for map_section in map_sections
[{{ map_section.map_section }} - MAPSECS_KANTO] = { {{ map_section.x }}, {{ map_section.y }} },
{% if existsIn(map_section, "x") and existsIn(map_section, "y") %}
[{{ map_section.id }} - KANTO_MAPSEC_START] = { {{ map_section.x }}, {{ map_section.y }} },
{% endif %}
## endfor
};

static const u16 sMapSectionDimensions[MAPSEC_COUNT][2] = {
## for map_section in map_sections
[{{ map_section.map_section }} - MAPSECS_KANTO] = { {{ map_section.width }}, {{ map_section.height }} },
{% if existsIn(map_section, "width") and existsIn(map_section, "height") %}
[{{ map_section.id }} - KANTO_MAPSEC_START] = { {{ map_section.width }}, {{ map_section.height }} },
{% endif %}
## endfor
};

Expand Down
Loading

0 comments on commit 29d5913

Please sign in to comment.