|
|
@ -24,11 +24,11 @@ signal game_ended() |
|
|
|
remote func set_player(id, new_name:String = " ", new_color:Color = Color.black, new_ready:bool = false): |
|
|
|
players[id] = {"name" : new_name, "color" : new_color, "ready" : new_ready, "prepared" : false} |
|
|
|
emit_signal("players_changed", players) |
|
|
|
|
|
|
|
|
|
|
|
if get_tree().is_network_server(): |
|
|
|
var all_ready = true |
|
|
|
for p_id in players: |
|
|
|
rpc_id(id, "set_player", p_id, players[p_id].name, players[p_id].color, players[p_id].ready) |
|
|
|
for p_id in players: |
|
|
|
rpc_id(id, "set_player", p_id, players[p_id].name, players[p_id].color, players[p_id].ready) |
|
|
|
rpc_id(p_id, "set_player", id, new_name, new_color, new_ready) |
|
|
|
all_ready = all_ready && players[p_id].ready |
|
|
|
rpc("game_ready", all_ready) |
|
|
@ -43,12 +43,12 @@ func update_player(new_name:String = " ", new_color:Color = Color.black, new_rea |
|
|
|
|
|
|
|
remotesync func remove_player(id): |
|
|
|
players.erase(id) |
|
|
|
|
|
|
|
|
|
|
|
if game != null: |
|
|
|
var game_players = game.get_node("players") |
|
|
|
if game_players.has_node(str(id)): |
|
|
|
game_players.remove_child(game_players.get_node(str(id))) |
|
|
|
|
|
|
|
|
|
|
|
emit_signal("players_changed", players) |
|
|
|
|
|
|
|
|
|
|
@ -63,34 +63,35 @@ remotesync func game_ready(all_ready:bool): |
|
|
|
|
|
|
|
remotesync func prepare_game(): |
|
|
|
get_tree().set_pause(true) |
|
|
|
|
|
|
|
|
|
|
|
game = Game.instance() |
|
|
|
get_tree().get_root().add_child(game) |
|
|
|
|
|
|
|
get_tree().get_root().get_node("main_menu").hide() |
|
|
|
|
|
|
|
|
|
|
|
for p_id in players: |
|
|
|
var controls |
|
|
|
var player = players[p_id] |
|
|
|
|
|
|
|
|
|
|
|
var player_scene = Player.instance() |
|
|
|
player_scene.set_network_master(p_id) |
|
|
|
player_scene.set_name(str(p_id)) |
|
|
|
game.get_node("players").add_child(player_scene) |
|
|
|
player_scene.set_player_name(player.name) |
|
|
|
player_scene.set_player_color(player.color) |
|
|
|
|
|
|
|
|
|
|
|
if p_id == get_tree().get_network_unique_id(): |
|
|
|
controls = HumanPlayer.instance() |
|
|
|
controls.set_name("HumanControl_" + str(p_id)) |
|
|
|
game.add_child(controls) |
|
|
|
controls.set_player(player_scene.get_path()) |
|
|
|
controls.set_network_master(p_id) |
|
|
|
|
|
|
|
|
|
|
|
player_scene.set_start(player_scene.get_index()) |
|
|
|
|
|
|
|
|
|
|
|
if bots: |
|
|
|
for index in range(MAX_PEERS-players.size()): |
|
|
|
# for index in range(MAX_PEERS-players.size()): # DEBUG |
|
|
|
for index in range(1): |
|
|
|
var bot_index = players.size() + index |
|
|
|
var player_scene = Player.instance() |
|
|
|
player_scene.set_name("bot_player" + str(bot_index)) |
|
|
@ -119,7 +120,7 @@ remotesync func player_prepared(id): |
|
|
|
if get_tree().is_network_server(): |
|
|
|
players[id].prepared = true |
|
|
|
var all_prepared = true |
|
|
|
for p_id in players: |
|
|
|
for p_id in players: |
|
|
|
all_prepared = all_prepared && players[p_id].prepared |
|
|
|
if all_prepared: |
|
|
|
rpc("post_start_game") |
|
|
@ -135,7 +136,7 @@ remotesync func set_bots(has_bots:bool): |
|
|
|
|
|
|
|
|
|
|
|
func quit_game(): |
|
|
|
if game != null: |
|
|
|
if game != null: |
|
|
|
game.queue_free() |
|
|
|
game = null |
|
|
|
|
|
|
@ -148,5 +149,5 @@ func quit_game(): |
|
|
|
game_running = false |
|
|
|
bots = false |
|
|
|
game_name = "" |
|
|
|
|
|
|
|
|
|
|
|
emit_signal("game_ended") |