feat: Implement initial main game scene with gridmap, player, and core managers.

This commit is contained in:
Yogi Wiguna
2026-03-12 12:30:29 +08:00
parent 412e7bdcdd
commit 3853962e4a
7 changed files with 1892 additions and 248 deletions
-112
View File
@@ -417,7 +417,6 @@ func _process(delta):
if multiplayer.is_server() and GameStateManager.is_game_started():
if TurnManager.turn_based_mode:
rpc("sync_turn_index", TurnManager.current_turn_index)
update_all_players_goals()
_connection_check_timer += delta
if _connection_check_timer >= 5.0:
@@ -493,9 +492,6 @@ func _setup_host_game():
rpc("sync_preset_goals", GoalManager.preset_goals)
# Update the goals UI immediately for the host
var panel = $AllPlayerGoals.get_child(0)
panel.visible = true
_update_player_goals_ui(0, host_goals)
ui_manager.update_playerboard_ui()
# Set goals for lobby client players
@@ -1281,28 +1277,7 @@ func _deferred_set_player_goals(player_id: int, goals: Array):
var player = get_node_or_null(str(player_id))
if player and player.race_manager:
player.goals = goals.duplicate()
# Update the goals UI for all clients
_update_goals_ui_for_player(player_id, goals)
func _update_goals_ui_for_player(player_id: int, goals: Array):
# Find the player index among all players
var all_players = get_tree().get_nodes_in_group("Players")
all_players.sort_custom(func(a, b):
var a_id = int(String(a.name).get_slice("@", 0))
var b_id = int(String(b.name).get_slice("@", 0))
return a_id < b_id
)
var player_idx = -1
for i in range(all_players.size()):
if all_players[i].name == str(player_id):
player_idx = i
break
# Changed >= 0 to include index 0 (host player)
if player_idx != -1 and player_idx < $AllPlayerGoals.get_child_count():
$AllPlayerGoals.get_child(player_idx).visible = true
_update_player_goals_ui(player_idx, goals)
@rpc("any_peer", "call_local")
func sync_playerboard(player_id: int, new_playerboard: Array):
@@ -1314,76 +1289,9 @@ func sync_playerboard(player_id: int, new_playerboard: Array):
# Update UI for local player
if player_id == multiplayer.get_unique_id() and GameStateManager.local_player_character:
ui_manager.update_playerboard_ui()
update_all_players_boards()
# =============================================================================
# UI Update Functions
# =============================================================================
func update_all_players_goals():
if not GameStateManager.is_game_started():
return
var all_players = get_tree().get_nodes_in_group("Players")
all_players.sort_custom(func(a, b):
var a_id = int(String(a.name).get_slice("@", 0))
var b_id = int(String(b.name).get_slice("@", 0))
return a_id < b_id
)
for i in range($AllPlayerGoals.get_child_count()):
$AllPlayerGoals.get_child(i).visible = false
var max_panels = $AllPlayerGoals.get_child_count()
for i in range(min(all_players.size(), max_panels)):
var player = all_players[i]
if player and player.goals.size() > 0:
$AllPlayerGoals.get_child(i).visible = true
_update_player_goals_ui(i, player.goals)
func _update_player_goals_ui(player_idx: int, goals: Array):
if player_idx < 0 or player_idx >= $AllPlayerGoals.get_child_count():
return
var panel = $AllPlayerGoals.get_child(player_idx)
if not panel.has_node("MarginContainer/Playergoals"):
return
var goals_grid = panel.get_node("MarginContainer/Playergoals")
for slot_idx in range(9):
if slot_idx >= goals_grid.get_child_count():
break
var slot = goals_grid.get_child(slot_idx)
var goal_value = goals[slot_idx] if slot_idx < goals.size() else -1
for tile_name in ["TileHeart", "TileDiamond", "TileStar", "TileCoin"]:
if slot.has_node(tile_name):
slot.get_node(tile_name).hide()
match goal_value:
7:
if slot.has_node("TileHeart"):
slot.get_node("TileHeart").show()
8:
if slot.has_node("TileDiamond"):
slot.get_node("TileDiamond").show()
9:
if slot.has_node("TileStar"):
slot.get_node("TileStar").show()
10:
if slot.has_node("TileCoin"):
slot.get_node("TileCoin").show()
func update_all_players_boards():
if not GameStateManager.is_game_started():
return
var all_players = get_tree().get_nodes_in_group("Players")
var all_player_boards = $AllPlayerBoards
# Update boards (simplified version - full implementation would mirror original)
pass
# =============================================================================
# Connection Verification
@@ -1502,26 +1410,6 @@ func create_specific_player(data: Dictionary):
if is_local_player:
ui_manager.update_playerboard_ui()
# Update goals UI for this player - use direct panel update
if goals_to_set.size() > 0:
# Find the correct panel index for this player
var all_players = get_tree().get_nodes_in_group("Players")
all_players.sort_custom(func(a, b):
var a_id = int(String(a.name).get_slice("@", 0))
var b_id = int(String(b.name).get_slice("@", 0))
return a_id < b_id
)
var player_idx = -1
for i in range(all_players.size()):
var player_name_id = int(String(all_players[i].name).get_slice("@", 0))
if player_name_id == peer_id:
player_idx = i
break
if player_idx != -1 and player_idx < $AllPlayerGoals.get_child_count():
$AllPlayerGoals.get_child(player_idx).visible = true
_update_player_goals_ui(player_idx, goals_to_set)
# =============================================================================
# Grid Item Randomization