Refactored to allow hotseat and multiplayer. TODO: Create interface class for webrtc/enet multiplayer

This commit is contained in:
Sch1nken 2024-03-22 01:37:05 +01:00
parent d688eaf9c6
commit 5fe8f22ccb
27 changed files with 798 additions and 135 deletions

View file

@ -40,7 +40,20 @@ var selected_for_action: bool = false
var can_be_selected: bool = false
func is_players_turn() -> bool:
return is_blacks_turn == GameData.is_player_black or GameData.debug
return is_blacks_turn == is_black
# Have a functions that checks if we're the "owner"
func is_owner() -> bool:
# TODO: Only use multiplayer authority
# According to https://docs.godotengine.org/en/stable/classes/class_offlinemultiplayerpeer.html
# Even without active multiplayer, the normal calls just work as expected
#if GameData.is_hot_seat:
# return true
#elif GameData.is_player_black == is_black: # we could use multiplayer authority here
# return true
#return false
return is_multiplayer_authority()
func _ready() -> void:
if is_black:
@ -65,9 +78,9 @@ func _ready() -> void:
func _on_turn_started(turn_num: int, map: HexGrid, _is_blacks_turn: bool) -> void:
is_blacks_turn = _is_blacks_turn
can_be_selected = GameData.has_bee_been_placed
print(GameData.has_bee_been_placed)
if turn_num >= 7 and not GameData.has_bee_been_placed:
can_be_selected = GameData.bees_placed.has(is_black)
#print(GameData.has_bee_been_placed)
if turn_num >= 7 and not GameData.bees_placed.has(is_black):
can_be_selected = true
func _on_tiles_selected_for_action(source_pos: Vector4i, targets: Array[InsectTile]) -> void:
@ -116,9 +129,9 @@ func _process(delta):
if not hovered:
return
if not GameData.is_player_black == is_black:
if not is_owner():
return
if not is_players_turn():
return
@ -138,7 +151,7 @@ func _process(delta):
GameEvents.insect_tile_selected.emit(self)
func hover() -> void:
if GameData.is_player_black != is_black:
if is_blacks_turn != is_black:
return
if tween != null:
@ -155,7 +168,7 @@ func tween_hover_shader(color: Color) -> void:
mat.next_pass.set_shader_parameter("emission_color", color)
func unhover() -> void:
if GameData.is_player_black != is_black:
if is_blacks_turn != is_black:
return
if tween != null: