Add enum prefix and function name option
This commit is contained in:
@@ -27,6 +27,12 @@ enum_type = os.path.basename(path).split(".")[0].capitalize()
|
||||
enum_name = enum_type.upper()
|
||||
if sys.argv[2]:
|
||||
enum_type = sys.argv[2]
|
||||
fun_name = enum_type
|
||||
if sys.argv[3]:
|
||||
fun_name = sys.argv[3]
|
||||
enum_prefix = enum_name
|
||||
if sys.argv[4]:
|
||||
enum_prefix = sys.argv[4]
|
||||
|
||||
indent_level = 0
|
||||
indent_offset = 4
|
||||
@@ -37,11 +43,11 @@ def indent():
|
||||
|
||||
|
||||
def enum_string(name):
|
||||
return f"{enum_name}_{name.upper()}"
|
||||
return f"{enum_prefix}_{name.upper()}"
|
||||
|
||||
|
||||
# ============================
|
||||
header_guard = f"{enum_type.capitalize()}_H"
|
||||
header_guard = f"{enum_type.upper()}_H"
|
||||
print(f"#ifndef {header_guard}")
|
||||
print(f"#define {header_guard}")
|
||||
script_name = os.path.basename(__file__)
|
||||
@@ -71,7 +77,7 @@ print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static {enum_type} getTileBuilding(BzTile tile) {{")
|
||||
print(f"{indent()}static {enum_type} getTile{fun_name}(BzTile tile) {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()}switch (tile) {{")
|
||||
for enum, ids in types.items():
|
||||
@@ -99,7 +105,7 @@ print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static BzTile getBuildingTile({enum_type} type) {{")
|
||||
print(f"{indent()}static BzTile get{fun_name}Tile({enum_type} type) {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()}switch (type) {{")
|
||||
indent_level += indent_offset
|
||||
@@ -118,7 +124,7 @@ print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static {enum_type} getBuildingFromStr(const char *str) {{")
|
||||
print(f"{indent()}static {enum_type} get{fun_name}FromStr(const char *str) {{")
|
||||
indent_level += indent_offset
|
||||
|
||||
# trie would be much better
|
||||
@@ -131,7 +137,7 @@ print(f"{indent()}}}")
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static const char *getBuildingStr({enum_type} type) {{")
|
||||
print(f"{indent()}static const char *get{fun_name}Str({enum_type} type) {{")
|
||||
indent_level += indent_offset
|
||||
|
||||
print(f"{indent()}switch (type) {{")
|
||||
@@ -151,7 +157,7 @@ print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static void getBuildingSize({enum_type} type, BzTile *outWidth, BzTile *outHeight) {{")
|
||||
print(f"{indent()}static void get{fun_name}Size({enum_type} type, BzTile *outWidth, BzTile *outHeight) {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()} switch (type) {{")
|
||||
indent_level += indent_offset
|
||||
|
||||
Reference in New Issue
Block a user