Refactoring action system

combat_refactor
Joey Pollack 2 years ago
parent 7e599a5f97
commit c333930b4e

@ -1,5 +1,8 @@
extends Action
class_name Attack
func _ready():
ActionName = "Attack"
var timer
func execute():

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bbbyup8pp6uam"]
[ext_resource type="Script" path="res://Test Scenes/Test Player Actions/Scripts/attack.gd" id="1_nmi0m"]
[ext_resource type="Script" path="res://Systems/Combat/Actions/Standard Actions/attack.gd" id="1_nmi0m"]
[node name="attack" type="Node"]
script = ExtResource("1_nmi0m")

@ -4,7 +4,6 @@ class_name Combatant
# @export var Behavior:
@export var Stats: CombatStats
@export var Actions: Array[Action] = []
@export var ATBSpeedCoeffecient = 25
var is_init = false
@ -15,6 +14,11 @@ func _ready():
pass
func next_turn():
ATBCurrent = 0
# TODO: Tick status effects
func tick_atb(delta):
if ATBCurrent >= 100:
@ -23,9 +27,6 @@ func tick_atb(delta):
ATBCurrent += Stats.Speed * delta * ATBSpeedCoeffecient
func execute_action(index: int):
Actions[index].execute()
ATBCurrent = 0
#func _process(delta):
# if not is_init:

@ -1,25 +1,26 @@
extends Control
class_name BattleMenu
var items: Array[MenuItem] = []
var top_margin = 100
var item_padding = 10
var next_y_pos = 0
func _ready():
next_y_pos = top_margin
enum ACTION { ATTACK, DEFEND, ITEM }
func add_action(action: Action):
var item = preload("res://Systems/UI/Menu System/menu_item.tscn").instantiate()
items.push_back(item)
item.label = action.ActionName
item.action = action
item.position.y = next_y_pos
next_y_pos += item.get_node("Button").size.y + item_padding
var panel = $Panel
# var button = item.get_node("Button")
panel.add_child(item)
return item
signal action_selected(action)
func _on_attack_pressed():
action_selected.emit("attack")
func _on_defend_pressed():
action_selected.emit("defend")
func _on_item_pressed():
pass # GO TO SUBMENU HERE
func _on_tech_pressed():
pass # GO TO SUBMENU HERE

@ -37,3 +37,69 @@ offset_bottom = 45.0
grow_horizontal = 2
text = "Battle Menu"
horizontal_alignment = 1
[node name="Attack" type="Button" parent="Panel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -33.0
offset_top = -85.0
offset_right = 25.0
offset_bottom = -54.0
grow_horizontal = 2
grow_vertical = 2
text = "Attack
"
[node name="Defend" type="Button" parent="Panel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -36.5
offset_top = -35.0
offset_right = 28.5
offset_bottom = -4.0
grow_horizontal = 2
grow_vertical = 2
text = "Defend"
[node name="Tech" type="Button" parent="Panel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -26.5
offset_top = 15.0
offset_right = 18.5
offset_bottom = 46.0
grow_horizontal = 2
grow_vertical = 2
text = "Tech"
[node name="Item" type="Button" parent="Panel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -26.0
offset_top = 65.0
offset_right = 18.0
offset_bottom = 96.0
grow_horizontal = 2
grow_vertical = 2
text = "Item"
[connection signal="pressed" from="Panel/Attack" to="." method="_on_attack_pressed"]
[connection signal="pressed" from="Panel/Defend" to="." method="_on_defend_pressed"]
[connection signal="pressed" from="Panel/Tech" to="." method="_on_tech_pressed"]
[connection signal="pressed" from="Panel/Item" to="." method="_on_item_pressed"]

@ -1,19 +1,13 @@
extends Sprite2D
@export var SpecialActions: Array[Action] = []
@onready var ATB = $battle_menu/ATB
@onready var ActionState = $battle_menu/ActionState
@onready var ActionState = $battle_menu/ActionPanel/ActionState
@onready var Actions = $Combatant/Actions
var NextAction
var ActionReady = false
func _ready():
var menu = $battle_menu
var item = menu.add_action($Combatant/Actions/attack)
item.action_selected.connect(do_action)
item.action.action_finished.connect(action_done)
item = menu.add_action($Combatant/Actions/spin_attack)
item.action_selected.connect(do_action)
item.action.action_finished.connect(action_done)
func _process(delta):
@ -31,7 +25,13 @@ func _process(delta):
ATB.value = combatant.ATBCurrent
func do_action(action):
func do_action(a):
var action = Actions.get_node(a)
if !action:
push_error("Unknown battle action: %s" % a)
return
ActionState.text = "Action Queued: %s" % action.ActionName
NextAction = action
ActionReady = true

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://b2iq5inxeoe82"]
[gd_scene load_steps=10 format=3 uid="uid://b2iq5inxeoe82"]
[ext_resource type="Texture2D" uid="uid://dedauf4ntkthu" path="res://icon.svg" id="1_d15px"]
[ext_resource type="Script" path="res://Test Scenes/Player.gd" id="2_8b3bs"]
@ -6,8 +6,7 @@
[ext_resource type="Texture2D" uid="uid://dqf1p1mfki3vc" path="res://assets/art/ui/bar_under.png" id="4_afpwe"]
[ext_resource type="PackedScene" uid="uid://ch1sc85jxy1r7" path="res://Systems/Combat/Combatant.tscn" id="4_w3vb5"]
[ext_resource type="Texture2D" uid="uid://bnp5t7o26kb0c" path="res://assets/art/ui/bar_over.png" id="5_5mhew"]
[ext_resource type="PackedScene" uid="uid://bbbyup8pp6uam" path="res://Test Scenes/Test Player Actions/attack.tscn" id="5_17k7n"]
[ext_resource type="PackedScene" uid="uid://bmot4y61f1r8f" path="res://Test Scenes/Test Player Actions/spin_attack.tscn" id="6_yaobw"]
[ext_resource type="PackedScene" uid="uid://bbbyup8pp6uam" path="res://Systems/Combat/Actions/Standard Actions/attack.tscn" id="5_17k7n"]
[ext_resource type="Script" path="res://Systems/Combat/Scripts/combat_stats.gd" id="7_ynhjd"]
[sub_resource type="Resource" id="Resource_28c5l"]
@ -47,23 +46,41 @@ texture_under = ExtResource("4_afpwe")
texture_progress = ExtResource("5_5mhew")
texture_progress_offset = Vector2(16, 8)
[node name="ActionState" type="Label" parent="battle_menu"]
layout_mode = 0
[node name="ActionPanel" type="Panel" parent="battle_menu"]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -36.0
offset_top = 237.0
offset_right = 170.0
offset_bottom = 280.0
offset_top = 132.0
offset_right = 44.0
offset_bottom = 170.0
grow_horizontal = 2
grow_vertical = 0
[node name="ActionState" type="Label" parent="battle_menu/ActionPanel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -103.0
offset_top = -21.5
offset_right = 103.0
offset_bottom = 21.5
grow_horizontal = 2
grow_vertical = 2
horizontal_alignment = 1
vertical_alignment = 1
[node name="Combatant" parent="." node_paths=PackedStringArray("Actions") instance=ExtResource("4_w3vb5")]
[node name="Combatant" parent="." instance=ExtResource("4_w3vb5")]
Stats = SubResource("Resource_28c5l")
Actions = [null, null]
[node name="Actions" type="Node" parent="Combatant"]
[node name="attack" parent="Combatant/Actions" instance=ExtResource("5_17k7n")]
ActionName = "Attack"
ActionText = "Attack"
[node name="spin_attack" parent="Combatant/Actions" instance=ExtResource("6_yaobw")]
ActionName = "Spin Attack"
ActionText = "Spin Attack"
[connection signal="action_selected" from="battle_menu" to="." method="do_action"]
[connection signal="action_finished" from="Combatant/Actions/attack" to="." method="action_done"]

Loading…
Cancel
Save