Handle default values for flags in the generator
MODIFY
generator/generate.py
generator/generate.py
@@ -92,6 +92,16 @@ def pod_default(field):
def flag_size(flag):
return (len(flag) + 7) // 8
+def flag_set(field, bit):
+ bit -= 1
+ try:
+ res = bool(int(field.default) & (1 << bit))
+ except ValueError:
+ # Default was not an int
+ res = False
+
+ return str(res).lower()
+
def filter_structs_without_codes(structs):
for struct in structs:
if all(f.code for f in sfields[struct.name]):
@@ -334,6 +344,7 @@ def main(argv):
env.filters["struct_has_code"] = filter_structs_without_codes
env.filters["field_is_used"] = filter_unused_fields
env.filters["flag_size"] = flag_size
+ env.filters["flag_set"] = flag_set
env.tests['needs_ctor'] = needs_ctor
globals = dict(

MODIFY
generator/templates/rpg_header.tmpl
generator/templates/rpg_header.tmpl
@@ -49,7 +49,7 @@ namespace RPG {
{%- if field.type.endswith("_Flags") %}
struct Flags {
{%- for flag in flags[struct_name] %}
- bool {{ flag.field }};
+ bool {{ flag.field }} = {{ field|flag_set(loop.index) }};
{%- endfor %}
} {{ field.name }};
{%- else %}

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

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

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

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

Handle default values for flags in the generator