A Godot v4 game about working in an office
class_name Combat
extends Node2D

@onready var player: BattlePlayer = $Player
@onready var enemy: BattleEnemy = $Enemy
@onready var dialog_box: DialogBox = $DialogBox

var enemy_turn := false
# combatData:
#{
#	player: {
#		health: 50,
#		max_health: 50,
#		focus: 20,
#		max_focus: 20,
#	},
#	enemy: {
#		health: 10,
#		max_health: 10,
#	},
#	startDialog: [
#		"How about this weather?"
#	]
#}
func initialize(combatData) -> void:
	player.initialize(combatData.player)
	enemy.initialize(combatData.enemy)
	if combatData.startDialog.size() > 0:
		show_dialog(combatData.startDialog)
		await dialog_box.dialog_hidden
	start_player_turn()

func show_dialog(dialog: Array) -> void:
	print("Initializing dialog: %s" % dialog)
	dialog_box.initialize(dialog)

func start_player_turn():
	player.start_turn()

func start_enemy_turn():
	enemy.start_turn()

func _on_player_turn_end():
	enemy.start_turn()

func _on_enemy_turn_end():
	player.start_turn()

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	player.turn_ended.connect(_on_player_turn_end)
	enemy.turn_ended.connect(_on_enemy_turn_end)
	
	initialize({
		"player": {
			"health": 50,
			"max_health": 75,
			"focus": 5,
			"max_focus": 30
		},
		"enemy": {
			"health": 12,
			"max_health": 12
		},
		"startDialog": ["How about this weather? Pretty crazy, right??"]
	})
	dialog_box.dialog_finished.connect(_on_dialog_finished)


func _on_dialog_finished():
	print("dialog finished!")