BUGFIX: Don't generate tags for unsupported enums
enum tags only works for enums which start from 0
and increase monotonically by 1. Until we have a better
solution, don't generate tags for enums where it would break.
MODIFY
generator/generate.py
generator/generate.py
@@ -309,6 +309,14 @@ def needs_ctor(struct_name):
return struct_name in setup and any('Init()' in method
for method, hdrs in setup[struct_name])
+def is_monotonic_from_0(enum):
+ expected = 0
+ for (val, idx) in enum:
+ if int(idx) != expected:
+ return False
+ expected += 1
+ return True
+
def generate():
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
@@ -400,6 +408,7 @@ def main(argv):
env.filters["flag_size"] = flag_size
env.filters["flag_set"] = flag_set
env.tests['needs_ctor'] = needs_ctor
+ env.tests['monotonic_from_0'] = is_monotonic_from_0
globals = dict(
structs=structs,

MODIFY
generator/templates/rpg_enums.tmpl
generator/templates/rpg_enums.tmpl
@@ -11,9 +11,13 @@ namespace RPG {
{%- for ftype, structlist in structs.items() %}
{%- for struct in structlist %}
- {%- for enum_name in enums[struct.name] %}
-constexpr decltype({{ struct.name }}::k{{ enum_name }}Tags) {{ struct.name }}::k{{ enum_name }}Tags;
+ {%- if struct.name in enums %}
+ {%- for name, enum in enums[struct.name].items() %}
+ {%- if enum is monotonic_from_0 %}
+constexpr decltype({{ struct.name }}::k{{ name }}Tags) {{ struct.name }}::k{{ name }}Tags;
+ {%- endif %}
{%- endfor %}
+ {%- endif %}
{%- endfor %}
{%- endfor %}

MODIFY
generator/templates/rpg_header.tmpl
generator/templates/rpg_header.tmpl
@@ -42,11 +42,13 @@ namespace RPG {
{%- endfor %}
};
{%- endif %}
+ {%- if enum is monotonic_from_0 %}
static constexpr auto k{{ name }}Tags = makeEnumTags<{{name}}{%- if name == "Code" %}::Index{%- endif %}>(
{%- for field in enum %}
"{{ field.0 }}"{%- if not loop.last %},{% endif %}
{%- endfor %}
);
+ {%- endif %}
{%- endfor %}
{% endif %}
{%- if struct_name is needs_ctor %}

MODIFY
src/generated/rpg_battleranimation.h
src/generated/rpg_battleranimation.h
Binary files a/src/generated/rpg_battleranimation.h and b/src/generated/rpg_battleranimation.h differ

MODIFY
src/generated/rpg_commonevent.h
src/generated/rpg_commonevent.h
Binary files a/src/generated/rpg_commonevent.h and b/src/generated/rpg_commonevent.h differ

MODIFY
src/generated/rpg_enums.cpp
src/generated/rpg_enums.cpp
Binary files a/src/generated/rpg_enums.cpp and b/src/generated/rpg_enums.cpp differ

MODIFY
src/generated/rpg_eventcommand.h
src/generated/rpg_eventcommand.h
Binary files a/src/generated/rpg_eventcommand.h and b/src/generated/rpg_eventcommand.h differ

MODIFY
src/generated/rpg_eventpage.h
src/generated/rpg_eventpage.h
Binary files a/src/generated/rpg_eventpage.h and b/src/generated/rpg_eventpage.h differ

BUGFIX: Don't generate tags for unsupported enums

enum tags only works for enums which start from 0
and increase monotonically by 1. Until we have a better
solution, don't generate tags for enums where it would break.