Add weapons
This commit is contained in:
@@ -101,7 +101,7 @@ def group_by_class(tiles):
|
||||
|
||||
|
||||
class EnumWriter:
|
||||
def __init__(self, writer: ExtractFileWriter, prefix, tiles):
|
||||
def __init__(self, writer: ExtractFileWriter, tiles, prefix, anim_prefix=None):
|
||||
self.writer = writer
|
||||
self.prefix = prefix
|
||||
self.all_tiles = tiles
|
||||
@@ -111,10 +111,43 @@ class EnumWriter:
|
||||
self.enums.append(self.to_enum("count"))
|
||||
self.enums.append(self.to_enum("none"))
|
||||
self.enum_type = f"{prefix.capitalize()}Type"
|
||||
if anim_prefix:
|
||||
self.anim_prefix = anim_prefix
|
||||
self.anim_type = f"{anim_prefix.capitalize()}Type"
|
||||
self.anim_map = defaultdict(lambda: defaultdict(list))
|
||||
self.animations = []
|
||||
self.all_tiles = tiles
|
||||
|
||||
animations = []
|
||||
|
||||
for tile in self.all_tiles:
|
||||
if 'animation' not in tile:
|
||||
continue
|
||||
if 'properties' not in tile:
|
||||
continue
|
||||
if 'type' not in tile:
|
||||
continue
|
||||
|
||||
enum = self.to_enum(tile['type'])
|
||||
props = tile['properties']
|
||||
anim_type = [prop['value'] for prop in props if prop['name'] == 'animation'][0]
|
||||
anim_type = self.to_anim_enum(anim_type)
|
||||
animations.append(anim_type)
|
||||
|
||||
self.anim_map[enum][anim_type] = tile['animation']
|
||||
|
||||
animations.append(self.to_anim_enum("count"))
|
||||
animations.append(self.to_anim_enum("none"))
|
||||
anim_seen = set()
|
||||
anim_add = anim_seen.add
|
||||
self.animations = [x for x in animations if not (x in anim_seen or anim_add(x))]
|
||||
|
||||
def to_enum(self, name):
|
||||
return f"{self.prefix.upper()}_{name.upper()}"
|
||||
|
||||
def to_anim_enum(self, name):
|
||||
return f"{self.anim_prefix.upper()}_{name.upper()}"
|
||||
|
||||
def output_enum(self):
|
||||
self.writer.enum_list(self.enum_type, self.enums)
|
||||
|
||||
@@ -291,44 +324,6 @@ class EnumWriter:
|
||||
writer.block_end()
|
||||
writer.empty_line()
|
||||
|
||||
|
||||
class AnimationWriter(EnumWriter):
|
||||
def __init__(self, writer: ExtractFileWriter, class_prefix, anim_prefix, tiles):
|
||||
super().__init__(writer, class_prefix, tiles)
|
||||
self.writer = writer
|
||||
self.anim_prefix = anim_prefix
|
||||
self.anim_type = f"{anim_prefix.capitalize()}Type"
|
||||
self.anim_map = defaultdict(lambda: defaultdict(list))
|
||||
self.animations = []
|
||||
self.all_tiles = tiles
|
||||
|
||||
animations = []
|
||||
|
||||
for tile in self.all_tiles:
|
||||
if 'animation' not in tile:
|
||||
continue
|
||||
if 'properties' not in tile:
|
||||
continue
|
||||
if 'type' not in tile:
|
||||
continue
|
||||
|
||||
enum = self.to_enum(tile['type'])
|
||||
props = tile['properties']
|
||||
anim_type = [prop['value'] for prop in props if prop['name'] == 'animation'][0]
|
||||
anim_type = self.to_anim_enum(anim_type)
|
||||
animations.append(anim_type)
|
||||
|
||||
self.anim_map[enum][anim_type] = tile['animation']
|
||||
|
||||
animations.append(self.to_anim_enum("count"))
|
||||
animations.append(self.to_anim_enum("none"))
|
||||
anim_seen = set()
|
||||
anim_add = anim_seen.add
|
||||
self.animations = [x for x in animations if not (x in anim_seen or anim_add(x))]
|
||||
|
||||
def to_anim_enum(self, name):
|
||||
return f"{self.anim_prefix.upper()}_{name.upper()}"
|
||||
|
||||
def output_anim_enum(self):
|
||||
writer = self.writer
|
||||
writer.enum_list(self.anim_type, self.animations)
|
||||
@@ -415,7 +410,8 @@ class AnimationWriter(EnumWriter):
|
||||
frames = [str(x['tileid']) for x in anim]
|
||||
durations = [x['duration'] * 0.001 for x in anim]
|
||||
|
||||
anim_frames = [f"{{{frame}, {format(duration, '0.4f')}f}}" for frame, duration in zip(frames, durations)]
|
||||
anim_frames = [f"{{{frame}, {format(duration, '0.4f')}f}}" for frame, duration in
|
||||
zip(frames, durations)]
|
||||
ret = f"((AnimationFrame []) {{{', '.join(anim_frames)}}}) [frameIdx]"
|
||||
writer.output(f"case {anim_type}: return {ret};\n")
|
||||
writer.output("default: break;\n")
|
||||
|
||||
@@ -39,6 +39,7 @@ remove_properties(content, "../assets/game.tsj")
|
||||
terrain_tiles = extract_by_property(tiles, "terrain")
|
||||
building_tiles = extract_by_property(tiles, "building")
|
||||
entity_tiles = extract_by_property(tiles, "entity")
|
||||
item_tiles = extract_by_property(tiles, "item")
|
||||
|
||||
writer.header_guard_start()
|
||||
script_name = os.path.basename(__file__)
|
||||
@@ -50,9 +51,9 @@ writer.empty_line()
|
||||
writer.output_anim_sequence_struct()
|
||||
writer.output_anim_frame_struct()
|
||||
|
||||
terrain_writer = EnumWriter(writer, "terrain", terrain_tiles)
|
||||
building_writer = EnumWriter(writer, "building", building_tiles)
|
||||
entity_writer = EnumWriter(writer, "entity", entity_tiles)
|
||||
terrain_writer = EnumWriter(writer, terrain_tiles, "terrain")
|
||||
building_writer = EnumWriter(writer, building_tiles, "building")
|
||||
entity_writer = EnumWriter(writer, entity_tiles, "entity")
|
||||
|
||||
terrain_writer.output_enum()
|
||||
terrain_writer.output_tile_has_anim("terrainHasAnimation")
|
||||
@@ -68,7 +69,7 @@ building_writer.output_enum_to_str("getBuildingStr")
|
||||
building_writer.output_enum_tile_size("getBuildingSize")
|
||||
writer.empty_line()
|
||||
|
||||
anim_writer = AnimationWriter(writer, "entity", "anim", entity_tiles)
|
||||
anim_writer = EnumWriter(writer, entity_tiles, "entity", "anim")
|
||||
|
||||
anim_writer.output_enum()
|
||||
anim_writer.output_anim_enum()
|
||||
@@ -78,7 +79,15 @@ anim_writer.output_has_anim("entityHasAnimation")
|
||||
anim_writer.output_anim_sequence("entityGetAnimationSequence")
|
||||
anim_writer.output_anim_frame("entityGetAnimationFrame")
|
||||
|
||||
print(item_tiles)
|
||||
item_writer = EnumWriter(writer, item_tiles, "item", "item_anim")
|
||||
item_writer.output_enum()
|
||||
#item_writer.output_anim_enum()
|
||||
item_writer.output_enum_to_tile("getItemTile")
|
||||
#item_writer.output_has_handle("itemHasHandle")
|
||||
#item_writer.output_handle("itemGetHandle")
|
||||
|
||||
|
||||
writer.header_guard_stop()
|
||||
|
||||
|
||||
writer.to_file("../game/game_tileset.h")
|
||||
|
||||
Reference in New Issue
Block a user