Game.gd 1.7 KB

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