Place buildings
This commit is contained in:
@@ -23,10 +23,10 @@ for tile in tiles:
|
||||
type = tile["type"]
|
||||
types[type].append(id)
|
||||
|
||||
enum_identifier = os.path.basename(path).split(".")[0].capitalize()
|
||||
enum_name = enum_identifier.upper()
|
||||
enum_type = os.path.basename(path).split(".")[0].capitalize()
|
||||
enum_name = enum_type.upper()
|
||||
if sys.argv[2]:
|
||||
enum_identifier = sys.argv[2]
|
||||
enum_type = sys.argv[2]
|
||||
|
||||
indent_level = 0
|
||||
indent_offset = 4
|
||||
@@ -53,21 +53,21 @@ print()
|
||||
enum_none = enum_string("none")
|
||||
enum_count = enum_string("count")
|
||||
|
||||
print(f"{indent()}typedef enum {enum_identifier} {{")
|
||||
print(f"{indent()}typedef enum {enum_type} {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()}{enum_none},")
|
||||
for enum in types:
|
||||
print(f"{indent()}{enum_string(enum)},")
|
||||
print(f"{indent()}{enum_count}")
|
||||
indent_level -= indent_offset
|
||||
print(f"{indent()}}} {enum_identifier};")
|
||||
print(f"{indent()}}} {enum_type};")
|
||||
|
||||
print()
|
||||
print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static {enum_identifier} getTileBuilding(BzTile tile) {{")
|
||||
print(f"{indent()}static {enum_type} getTileBuilding(BzTile tile) {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()}switch (tile) {{")
|
||||
for enum, ids in types.items():
|
||||
@@ -95,7 +95,26 @@ print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static {enum_identifier} getBuildingFromStr(const char *str) {{")
|
||||
print(f"{indent()}static BzTile getBuildingTile({enum_type} type) {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()}switch (type) {{")
|
||||
indent_level += indent_offset
|
||||
for type, ids in types.items():
|
||||
min_id = min(ids)
|
||||
print(f"{indent()}case {enum_string(type)}: return {min_id};")
|
||||
|
||||
print(f"{indent()}default: return -1;")
|
||||
indent_level -= indent_offset
|
||||
print(f"{indent()}}}")
|
||||
|
||||
indent_level -= indent_offset
|
||||
|
||||
print(f"{indent()}}}")
|
||||
print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static {enum_type} getBuildingFromStr(const char *str) {{")
|
||||
indent_level += indent_offset
|
||||
|
||||
# trie would be much better
|
||||
@@ -108,7 +127,27 @@ print(f"{indent()}}}")
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static void getBuildingSize({enum_identifier} type, BzTile *outWidth, BzTile *outHeight) {{")
|
||||
print(f"{indent()}static const char *getBuildingStr({enum_type} type) {{")
|
||||
indent_level += indent_offset
|
||||
|
||||
print(f"{indent()}switch (type) {{")
|
||||
indent_level += indent_offset
|
||||
|
||||
print(f"{indent()}case {enum_string('none')}: return \"none\";")
|
||||
for type in types:
|
||||
print(f"{indent()}case {enum_string(type)}: return \"{type}\";")
|
||||
print(f"{indent()}default: return NULL;")
|
||||
indent_level -= indent_offset
|
||||
print(f"{indent()}}}")
|
||||
|
||||
indent_level -= indent_offset
|
||||
print(f"{indent()}}}")
|
||||
print()
|
||||
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static void getBuildingSize({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