Refactor cutscene queue

This commit is contained in:
2026-01-11 16:40:54 -06:00
parent 99ecc2cfc7
commit 6ecbc33cc2
16 changed files with 190 additions and 32 deletions

View File

@@ -2,9 +2,6 @@ class_name BattleSingleton extends Node
var battleScene:BattleScene = null
func startBattle(
fighters:Dictionary[BattleScene.BattlePosition, BattleFighter]
) -> void:
func startBattle(params) -> void:
assert(battleScene != null)
battleScene.startBatle(fighters
)
battleScene.startBattle(params)

View File

@@ -1,4 +1,5 @@
class_name BattleScene extends BattleFighterScene
const CutsceneBattleAction = preload("res://cutscene/battle/CutsceneBattleAction.gd")
enum BattlePosition {
LEFT_TOP_BACK,
@@ -16,8 +17,11 @@ enum BattlePosition {
RIGHT_BOTTOM_FRONT
}
var active:bool = false
var fighterMap:Dictionary[BattlePosition, BattleFighterScene] = {}
@export var actionBox:ActionBox = null
@export var fighterTopLeftBack:BattleFighterScene = null:
get:
return fighterMap.get(BattlePosition.LEFT_TOP_BACK, null)
@@ -94,8 +98,48 @@ func _init() ->void:
BATTLE.battleScene = self
pass
func startBatle(fighters:Dictionary[BattlePosition, BattleFighter]) -> void:
for position in fighters.keys():
var fighterScene:BattleFighterScene = fighterMap.get(position, null)
func getFigheterAtPosition(battlePos:BattlePosition) -> BattleFighterScene:
return fighterMap.get(battlePos, null)
func getPositionForFighterScene(fighterScene:BattleFighterScene) -> BattlePosition:
for battlePos in fighterMap.keys():
var scene:BattleFighterScene = fighterMap[battlePos]
if scene == fighterScene:
return battlePos
assert(false)
return BattlePosition.LEFT_TOP_BACK
func getPositionForFighter(fighter:BattleFighter) -> BattlePosition:
for battlePos in fighterMap.keys():
var fighterScene:BattleFighterScene = fighterMap[battlePos]
if fighterScene.fighter == fighter:
return battlePos
assert(false)
return BattlePosition.LEFT_TOP_BACK
func getFighterSceneForFighter(fighter:BattleFighter) -> BattleFighterScene:
for battlePos in fighterMap.keys():
var fighterScene:BattleFighterScene = fighterMap[battlePos]
if fighterScene.fighter == fighter:
return fighterScene
return null
func startBattle(params:Dictionary) -> void:
assert(params.has('fighters'))
assert(!active)
var cutscene:Cutscene = params.get('cutscene', Cutscene.new())
for battlePos in params['fighters'].keys():
var fighterScene:BattleFighterScene = fighterMap.get(battlePos, null)
assert(fighterScene != null)
fighterScene.setFighter(fighters[position])
fighterScene.setFighter(params['fighters'][battlePos])
# Initial cutscene elements. In future I may need to make this editable
# somehow?
cutscene.addCallable({ "function": CutsceneBattleAction.playerDecision })
if !cutscene.running:
cutscene.start()
active = true

View File

@@ -1,10 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://dy54m7dvjgqta"]
[gd_scene load_steps=4 format=3 uid="uid://dy54m7dvjgqta"]
[ext_resource type="PackedScene" uid="uid://d1xyb0hdf1yeh" path="res://battle/fighter/BattleFighterScene.tscn" id="1_abr1f"]
[ext_resource type="Script" uid="uid://dihfp05x6pktn" path="res://battle/BattleScene.gd" id="1_acaen"]
[ext_resource type="PackedScene" uid="uid://ktmvnapibv2q" path="res://battle/ui/ActionBox.tscn" id="2_c3ndu"]
[node name="BattleScene" type="Node3D" node_paths=PackedStringArray("fighterTopLeftBack", "fighterTopLeftFront", "fighterMiddleLeftBack", "fighterMiddleLeftFront", "fighterBottomLeftBack", "fighterBottomLeftFront", "fighterTopRightBack", "fighterTopRightFront", "fighterMiddleRightBack", "fighterMiddleRightFront", "fighterBottomRightBack", "fighterBottomRightFront")]
[node name="BattleScene" type="Node3D" node_paths=PackedStringArray("actionBox", "fighterTopLeftBack", "fighterTopLeftFront", "fighterMiddleLeftBack", "fighterMiddleLeftFront", "fighterBottomLeftBack", "fighterBottomLeftFront", "fighterTopRightBack", "fighterTopRightFront", "fighterMiddleRightBack", "fighterMiddleRightFront", "fighterBottomRightBack", "fighterBottomRightFront")]
script = ExtResource("1_acaen")
actionBox = NodePath("UI/ActionBox")
fighterTopLeftBack = NodePath("Fighters/LeftTopBack")
fighterTopLeftFront = NodePath("Fighters/LeftTopFront")
fighterMiddleLeftBack = NodePath("Fighters/LeftMiddleBack")
@@ -19,13 +21,18 @@ fighterBottomRightBack = NodePath("Fighters/RightBottomBack")
fighterBottomRightFront = NodePath("Fighters/RightBottomFront")
metadata/_custom_type_script = "uid://dihfp05x6pktn"
[node name="Control" type="Control" parent="."]
[node name="UI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="Control"]
[node name="ActionBox" parent="UI" instance=ExtResource("2_c3ndu")]
layout_mode = 1
[node name="Battle" type="Label" parent="UI"]
layout_mode = 0
offset_right = 40.0
offset_bottom = 12.0

View File

@@ -23,6 +23,10 @@ func _init(params:Dictionary) -> void:
self.moveType = params.get("moveType", MoveType.PHYSICAL)
self.fieldUse = params.get("fieldUse", false)
func start(_params:Dictionary) -> void:
# Implement move execution logic here
await UI.TEXTBOX.setTextAndWait("Action")
# Moves
static var MOVE_PUNCH = BattleMove.new({
"name": "Punch",

View File

@@ -0,0 +1 @@
uid://gb08hhwk0paw

26
battle/ui/ActionBox.gd Normal file
View File

@@ -0,0 +1,26 @@
class_name ActionBox extends GridContainer
const BattleMove = preload("res://battle/fighter/BattleMove.gd")
@export var btnAttack:Button
@export var btnMagic:Button
@export var btnItem:Button
signal decisionMade(move:BattleMove)
func _ready() -> void:
btnAttack.pressed.connect(onAttackPressed)
btnMagic.pressed.connect(onMagicPressed)
btnItem.pressed.connect(onItemPressed)
self.visible = false
func onAttackPressed() -> void:
print("Attack button pressed")
decisionMade.emit(null)
func onMagicPressed() -> void:
print("Magic button pressed")
decisionMade.emit(null)
func onItemPressed() -> void:
print("Item button pressed")
decisionMade.emit(null)

View File

@@ -0,0 +1 @@
uid://27274005hbgh

36
battle/ui/ActionBox.tscn Normal file
View File

@@ -0,0 +1,36 @@
[gd_scene load_steps=2 format=3 uid="uid://ktmvnapibv2q"]
[ext_resource type="Script" uid="uid://27274005hbgh" path="res://battle/ui/ActionBox.gd" id="1_w5s71"]
[node name="ActionBox" type="GridContainer" node_paths=PackedStringArray("btnAttack", "btnMagic", "btnItem")]
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -86.0
offset_top = -44.0
grow_horizontal = 0
grow_vertical = 0
columns = 2
script = ExtResource("1_w5s71")
btnAttack = NodePath("Attack")
btnMagic = NodePath("Magic")
btnItem = NodePath("Items")
metadata/_custom_type_script = "uid://27274005hbgh"
[node name="Attack" type="Button" parent="."]
layout_mode = 2
text = "Attack"
[node name="Magic" type="Button" parent="."]
layout_mode = 2
text = "Magic"
[node name="Items" type="Button" parent="."]
layout_mode = 2
text = "Items"
[node name="idk" type="Button" parent="."]
layout_mode = 2
text = "idk"