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")
|
||||
|
||||
Reference in New Issue
Block a user