extends TextureRect var spritesheet_parser: SpritesheetParser = SpritesheetParser.new() var bpm = float(GlobalConfig.tempo_default) var anims = [ ] var active_anims = [] func _ready() -> void: texture = AtlasTexture.new() texture.atlas = SpritesheetParser.load_image(GlobalConfig.spritesheet_image) texture.region = Rect2(0, 0, 1, 1) spritesheet_parser.parse_spritesheet(GlobalConfig.spritesheet_data) self.item_rect_changed.connect(func(): self.get_parent().custom_minimum_size = self.size * self.scale self.position = Vector2.ZERO) var sprani = GlobalConfig.spritesheet_anims for animation in sprani: anims.append({ name = animation, key = "anim_" + sprani[animation].alias if sprani[animation].alias else null, tstamp = 0.0, active = sprani[animation].type == Config.SpritesheetAnimType.IDLE, keydown = sprani[animation].type == Config.SpritesheetAnimType.IDLE, type = sprani[animation].type }) func _process(delta: float) -> void: var time = Time.get_ticks_msec() var current_animation = active_anims.front() if current_animation == null: return if not spritesheet_parser.spritesheet.has(current_animation.name): return var animation = spritesheet_parser.spritesheet[current_animation.name] var beat_percentage = Tempo.beat_at_time(time - current_animation.tstamp, bpm) if beat_percentage >= 1 and current_animation.active: if current_animation.type == Config.SpritesheetAnimType.IDLE: current_animation.tstamp = time beat_percentage = 0 elif current_animation.type == Config.SpritesheetAnimType.DEFAULT and current_animation.keydown: beat_percentage = 1 var anim_current = floor(beat_percentage * animation.size()) var anim_current_props = spritesheet_parser.get_props_of_animation_frame(current_animation.name, anim_current) self.texture.region = anim_current_props.region self.texture.margin = anim_current_props.margin self.size = anim_current_props.margin.size