game.gd 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. extends Node
  2. const PLAYER_WIN = "res://dialogue/dialogue_data/player_won.json"
  3. const PLAYER_LOSE = "res://dialogue/dialogue_data/player_lose.json"
  4. @export var combat_screen: Node
  5. @export var exploration_screen: Node
  6. func _ready():
  7. combat_screen.combat_finished.connect(_on_combat_finished)
  8. for n in $Exploration/Grid.get_children():
  9. if not n.type == n.CellType.ACTOR:
  10. continue
  11. if not n.has_node("DialoguePlayer"):
  12. continue
  13. n.get_node("DialoguePlayer").dialogue_finished.connect(_on_opponent_dialogue_finished.bind(n))
  14. remove_child(combat_screen)
  15. func start_combat(combat_actors):
  16. remove_child($Exploration)
  17. $AnimationPlayer.play("fade")
  18. await $AnimationPlayer.animation_finished
  19. add_child(combat_screen)
  20. combat_screen.show()
  21. combat_screen.initialize(combat_actors)
  22. $AnimationPlayer.play_backwards("fade")
  23. func _on_opponent_dialogue_finished(opponent):
  24. if opponent.lost:
  25. return
  26. var player = $Exploration/Grid/Player
  27. var combatants = [player.combat_actor, opponent.combat_actor]
  28. start_combat(combatants)
  29. func _on_combat_finished(winner, _loser):
  30. remove_child(combat_screen)
  31. $AnimationPlayer.play_backwards("fade")
  32. add_child(exploration_screen)
  33. var dialogue = load("res://dialogue/dialogue_player/dialogue_player.tscn").instantiate()
  34. if winner.name == "Player":
  35. dialogue.dialogue_file = PLAYER_WIN
  36. else:
  37. dialogue.dialogue_file = PLAYER_LOSE
  38. await $AnimationPlayer.animation_finished
  39. var player = $Exploration/Grid/Player
  40. exploration_screen.get_node("DialogueUI").show_dialogue(player, dialogue)
  41. combat_screen.clear_combat()
  42. await dialogue.dialogue_finished
  43. dialogue.queue_free()