diff --git a/test/battle_sprites.gd b/test/battle_sprites.gd index d6b9560..82b3ea0 100644 --- a/test/battle_sprites.gd +++ b/test/battle_sprites.gd @@ -1,17 +1,28 @@ extends Control -var PC = load('res://PC.tscn') -var PCs = [] -func _ready() -> void: +var PC := preload('res://PC.gd') +var PC_scene := preload('res://PC.tscn') +var PCs := [] +var num_animations: int = len(PC.Battle_Anim) + +func initialize() -> void: + # Clean up any existing + for scn in PCs: + remove_child(scn) + PCs = [] + + # Make new sprites var strips = len(SpriteLoader.strip_textures) # * 4 / 5 #var strip_divide = strips * 2 / 5 var strip_divide = strips * 1 / 5 + var anim_id = $btn_anim_choice.get_selected_id() for i in strips: - PCs.append(PC.instance()) + PCs.append(PC_scene.instance()) #PCs[-1].set_position(Vector2((i%strip_divide)*16, (i/strip_divide)*24*11)) PCs[-1].set_position(Vector2((i%strip_divide)*17, (i/strip_divide)*32)) PCs[-1].material.set_shader_param('palette', SpriteLoader.character_battle_sprite_palette_textures[i]) PCs[-1].texture = SpriteLoader.strip_textures[i] + PCs[-1].animation = anim_id add_child(PCs[-1]) # PCs.append(PC.instance()) @@ -20,6 +31,22 @@ func _ready() -> void: # PCs[-1].texture = SpriteLoader.weapon_textures['Fist'] # add_child(PCs[-1]) +func _ready() -> void: + initialize() + RomLoader.connect('rom_loaded', self, 'initialize') # Attempt to reload sprites if a new ROM is hot loaded + func _on_OptionButton_item_selected(ID): for pc in PCs: pc.animation = ID + +func _on_btn_next_pressed(): + var id = $btn_anim_choice.get_selected_id() + if id < num_animations-1: + $btn_anim_choice.select(id+1) + _on_OptionButton_item_selected(id+1) + +func _on_btn_prev_pressed(): + var id = $btn_anim_choice.get_selected_id() + if id > 0: + $btn_anim_choice.select(id-1) + _on_OptionButton_item_selected(id-1) diff --git a/test/battle_sprites.tscn b/test/battle_sprites.tscn index 781ce34..b0fa76c 100644 --- a/test/battle_sprites.tscn +++ b/test/battle_sprites.tscn @@ -1,13 +1,29 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://test/battle_sprites.gd" type="Script" id=1] [ext_resource path="res://theme/menu_theme.tres" type="Theme" id=2] +[sub_resource type="InputEventKey" id=3] +pressed = true +scancode = 82 +physical_scancode = 82 + +[sub_resource type="ShortCut" id=4] +shortcut = SubResource( 3 ) + +[sub_resource type="InputEventKey" id=1] +pressed = true +scancode = 84 +physical_scancode = 84 + +[sub_resource type="ShortCut" id=2] +shortcut = SubResource( 1 ) + [node name="battle_sprites" type="Control"] theme = ExtResource( 2 ) script = ExtResource( 1 ) -[node name="OptionButton" type="OptionButton" parent="."] +[node name="btn_anim_choice" type="OptionButton" parent="."] anchor_bottom = 0.67 margin_top = 160.0 margin_right = 100.0 @@ -16,4 +32,21 @@ text = "Stand" items = [ "Stand", null, false, 0, null, "Guard", null, false, 1, null, "Walk", null, false, 2, null, "Down", null, false, 3, null, "R_Swing", null, false, 4, null, "L_Swing", null, false, 5, null, "Punch", null, false, 6, null, "Cheer", null, false, 7, null, "Recoil", null, false, 8, null, "Chant", null, false, 9, null ] selected = 0 -[connection signal="item_selected" from="OptionButton" to="." method="_on_OptionButton_item_selected"] +[node name="btn_prev" type="Button" parent="."] +margin_top = 196.0 +margin_right = 48.0 +margin_bottom = 218.0 +shortcut = SubResource( 4 ) +text = "P[r]ev" + +[node name="btn_next" type="Button" parent="."] +margin_left = 52.0 +margin_top = 196.0 +margin_right = 100.0 +margin_bottom = 218.0 +shortcut = SubResource( 2 ) +text = "Nex[t]" + +[connection signal="item_selected" from="btn_anim_choice" to="." method="_on_OptionButton_item_selected"] +[connection signal="pressed" from="btn_prev" to="." method="_on_btn_prev_pressed"] +[connection signal="pressed" from="btn_next" to="." method="_on_btn_next_pressed"]