52 lines
1.7 KiB
GDScript
52 lines
1.7 KiB
GDScript
extends Node3D
|
|
|
|
var is_blacks_turn: bool = false
|
|
|
|
var current_turn: int = 1
|
|
|
|
@onready var map: HexGrid = $HexGrid
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
GameEvents.insect_tile_finished_moving.connect(_on_insect_tile_finished_moving)
|
|
GameEvents.insect_tile_created.connect(_on_insect_tile_created)
|
|
|
|
# since we sealed in webrtc,
|
|
# and limited players to 1 in enet
|
|
# this should only happen when the opponent disconnects
|
|
# as opposed to someone (3rd) connecting DURING the game
|
|
# and disconnecting again
|
|
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
|
|
#multiplayer.server_disconnected.connect(_on_server_disconnected)
|
|
|
|
GameEvents.game_started.emit()
|
|
|
|
func _on_peer_disconnected(id: int) -> void:
|
|
GameData.disconnect_reason = "Connection to other peer closed unexpectedly"
|
|
#Networking.disconnect_all()
|
|
get_tree().change_scene_to_file("res://UI/main_menu.tscn")
|
|
|
|
#func _on_server_disconnected() -> void:
|
|
# GameData.disconnect_reason = "Connection to other peer closed unexpectedly"
|
|
#Networking.disconnect_all()
|
|
# get_tree().change_scene_to_file("res://UI/main_menu.tscn")
|
|
|
|
func advance_turn():
|
|
GameEvents.turn_ended.emit(current_turn, map)
|
|
is_blacks_turn = !is_blacks_turn
|
|
current_turn = current_turn + 1
|
|
print(current_turn)
|
|
GameEvents.turn_started.emit(current_turn, map, is_blacks_turn)
|
|
|
|
func _on_insect_tile_finished_moving(tile: InsectTile, target: Vector4i) -> void:
|
|
print("moved")
|
|
print(multiplayer.is_server())
|
|
advance_turn()
|
|
|
|
func _on_insect_tile_created(tile: InsectTile, pos: Vector4i) -> void:
|
|
print("created")
|
|
advance_turn()
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
pass
|