diff --git a/client/ClientEntry.gd b/client/ClientEntry.gd index 3753f172..6e34385b 100644 --- a/client/ClientEntry.gd +++ b/client/ClientEntry.gd @@ -17,6 +17,10 @@ func _ready(): #go_to_mobile_vr() go_to_flat() + # Note that this one time handling of command line arguments is intentionally + # happening after the MainMenu for a given client is initialized: those scenes have + # handlers for join that need to be ready in order for the game to process the join command + # correctly. handle_commandline_args() diff --git a/client/game/mode/fugitive/FugitiveGame-dev-vr.gd b/client/game/mode/fugitive/FugitiveGame-dev-vr.gd index 69b18f23..9d77432b 100644 --- a/client/game/mode/fugitive/FugitiveGame-dev-vr.gd +++ b/client/game/mode/fugitive/FugitiveGame-dev-vr.gd @@ -19,13 +19,13 @@ func _enter_tree(): # Add our fake players, the normal spawn system will actually spawn these guys if be_seeker: - GameData.add_player(GameData.create_new_player(1, "real player", FugitiveTeamResolver.PlayerType.Seeker)) - GameData.add_player(GameData.create_new_player(10, "dumb donkey 0", FugitiveTeamResolver.PlayerType.Hider)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(1, "real player", FugitiveTeamResolver.PlayerType.Seeker)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(10, "dumb donkey 0", FugitiveTeamResolver.PlayerType.Hider)) else: - GameData.add_player(GameData.create_new_player(1, "real player", FugitiveTeamResolver.PlayerType.Hider)) - GameData.add_player(GameData.create_new_player(10, "dumb donkey 0", FugitiveTeamResolver.PlayerType.Seeker)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(1, "real player", FugitiveTeamResolver.PlayerType.Hider)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(10, "dumb donkey 0", FugitiveTeamResolver.PlayerType.Seeker)) - GameData.add_player(GameData.create_new_player(11, "dumb donkey 1", FugitiveTeamResolver.PlayerType.Hider)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(11, "dumb donkey 1", FugitiveTeamResolver.PlayerType.Hider)) func _ready(): diff --git a/client/game/mode/fugitive/FugitiveGame-dev.gd b/client/game/mode/fugitive/FugitiveGame-dev.gd index 5fabd0d4..a4f92642 100644 --- a/client/game/mode/fugitive/FugitiveGame-dev.gd +++ b/client/game/mode/fugitive/FugitiveGame-dev.gd @@ -19,14 +19,14 @@ func _enter_tree(): # Add our fake players, the normal spawn system will actually spawn these guys if be_seeker: - GameData.add_player(GameData.create_new_player(1, "real player", FugitiveTeamResolver.PlayerType.Seeker)) - GameData.add_player(GameData.create_new_player(10, "dumb donkey 0", FugitiveTeamResolver.PlayerType.Hider)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(1, "real player", FugitiveTeamResolver.PlayerType.Seeker)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(10, "dumb donkey 0", FugitiveTeamResolver.PlayerType.Hider)) else: - GameData.add_player(GameData.create_new_player(1, "real player", FugitiveTeamResolver.PlayerType.Hider)) - GameData.add_player(GameData.create_new_player(10, "dumb donkey 0", FugitiveTeamResolver.PlayerType.Seeker)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(1, "real player", FugitiveTeamResolver.PlayerType.Hider)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(10, "dumb donkey 0", FugitiveTeamResolver.PlayerType.Seeker)) - GameData.add_player(GameData.create_new_player(11, "dumb donkey 1", FugitiveTeamResolver.PlayerType.Hider)) - GameData.add_player(GameData.create_new_player(12, "dumb donkey 2", FugitiveTeamResolver.PlayerType.Seeker)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(11, "dumb donkey 1", FugitiveTeamResolver.PlayerType.Hider)) + GameData.add_player_from_raw_data(GameData.create_new_player_raw_data(12, "dumb donkey 2", FugitiveTeamResolver.PlayerType.Seeker)) func _ready(): diff --git a/client/game/mode/fugitive/hud/EndGameHud.gd b/client/game/mode/fugitive/hud/EndGameHud.gd index 2eed0eb1..d8932590 100644 --- a/client/game/mode/fugitive/hud/EndGameHud.gd +++ b/client/game/mode/fugitive/hud/EndGameHud.gd @@ -3,18 +3,18 @@ extends Control func _ready(): hide() - func team_won(winningTeam: int): var winningTeamName = GameData.currentGame.get_team_name(winningTeam) $Container/WinnerLabel.text = "%ss won!" % winningTeamName for playerInfo in GameData.get_players(): + var playerInfoData := playerInfo as PlayerData var node := Label.new() - var playerType := playerInfo[GameData.PLAYER_TYPE] as int + var playerType := playerInfoData.get_type() var team = GameData.currentGame.get_team_name(playerType) - var playerObj := GameData.currentGame.get_player(playerInfo[GameData.PLAYER_ID]) as FugitivePlayer + var playerObj := GameData.currentGame.get_player(playerInfoData.get_id()) as FugitivePlayer if playerObj != null: var frozen: String if playerObj.frozen: @@ -23,9 +23,9 @@ func team_won(winningTeam: int): frozen = "ESCAPED!" if playerType == FugitiveTeamResolver.PlayerType.Hider: - node.text = "[%s] %s - %s" % [team, playerInfo[GameData.PLAYER_NAME], frozen] + node.text = "[%s] %s - %s" % [team, playerInfo.get_name(), frozen] else: - node.text = "[%s] %s" % [team, playerInfo[GameData.PLAYER_NAME]] + node.text = "[%s] %s" % [team, playerInfo.get_name()] $Container/PlayerList.add_child(node) diff --git a/common/game/mode/fugitive/FugitiveGame.gd b/common/game/mode/fugitive/FugitiveGame.gd index 9cc773c5..392b2af3 100644 --- a/common/game/mode/fugitive/FugitiveGame.gd +++ b/common/game/mode/fugitive/FugitiveGame.gd @@ -114,14 +114,14 @@ func spawn_player(playerId: int, hiderSpawns: Array, seekerSpawns: Array): var localPlayerId := get_tree().get_network_unique_id() var localPlayerType: int if GameData.players.has(localPlayerId): - localPlayerType = GameData.players[localPlayerId][GameData.PLAYER_TYPE] + localPlayerType = GameData.players[localPlayerId].get_type() else: localPlayerType = FugitiveTeamResolver.PlayerType.Unset # Extract the player data - var player = GameData.players[playerId] - var playerName := player[GameData.PLAYER_NAME] as String - var playerType := player[GameData.PLAYER_TYPE] as int + var player := GameData.players[playerId] as PlayerData + var playerName := player.get_name() + var playerType := player.get_type() # This is the node for the PlayerController var pcNode: Node diff --git a/common/lobby/Lobby.gd b/common/lobby/Lobby.gd index 2bec6515..141a625a 100644 --- a/common/lobby/Lobby.gd +++ b/common/lobby/Lobby.gd @@ -34,13 +34,13 @@ func populate_map_list(): func create_player(playerId: int): - var existingPlayer := find_player_node(playerId) - if existingPlayer != null: + var existingPlayerNode := find_player_node(playerId) + if existingPlayerNode != null: return print("Creating player in lobby") - var player = GameData.players[playerId] + var player := GameData.players[playerId] as PlayerData var mode = Maps.get_mode_for_map(GameData.general[GameData.GENERAL_MAP]) var playerListItem = preload("res://common/lobby/PlayerListItem.tscn") @@ -76,7 +76,7 @@ func remove_player(playerId: int): func repopulate_player(playerId: int): - var player = GameData.players[playerId] + var player := GameData.players[playerId] as PlayerData var mode = Maps.get_mode_for_map(GameData.general[GameData.GENERAL_MAP]) var node := find_player_node(playerId) @@ -157,7 +157,7 @@ func can_start() -> bool: if not players.empty(): for player in players: - var playerteam = player[GameData.PLAYER_TYPE] + var playerteam = player.get_type() actualTeamSizes[playerteam] += 1 var teamSizesAreValid = true @@ -181,8 +181,8 @@ func on_start_game(): # Update if this local client is the host func update_host(): - var host := GameData.get_host() - if host != null and host[GameData.PLAYER_ID] == get_tree().get_network_unique_id(): + var host := GameData.get_host() as PlayerData + if host != null and host.get_id() == get_tree().get_network_unique_id(): is_host = true else: is_host = false diff --git a/common/lobby/PlayerListItem.gd b/common/lobby/PlayerListItem.gd index 9db7837f..f3819107 100644 --- a/common/lobby/PlayerListItem.gd +++ b/common/lobby/PlayerListItem.gd @@ -1,17 +1,16 @@ extends Control -var playerInfo = null +var playerInfo: PlayerData = null onready var teamButton := $TeamButton as OptionButton var curTeamResolver = null -func populate(player, is_starting: bool, is_host: bool, game_mode: Dictionary): +func populate(player: PlayerData, is_starting: bool, is_host: bool, game_mode: Dictionary): playerInfo = player + var playerId = player.get_id() - var playerId = playerInfo[GameData.PLAYER_ID] - - $NameLabel.text = playerInfo[GameData.PLAYER_NAME] - $HostLabel.visible = playerInfo[GameData.PLAYER_HOST] + $NameLabel.text = player.get_name() + $HostLabel.visible = player.get_is_host() curTeamResolver = game_mode[Maps.MODE_TEAM_RESOLVER] @@ -21,7 +20,7 @@ func populate(player, is_starting: bool, is_host: bool, game_mode: Dictionary): var teamname = curTeamResolver.get_team_name(ii) teamButton.add_item(teamname, ii) - var playerType = playerInfo[GameData.PLAYER_TYPE] + var playerType := player.get_type() teamButton.selected = playerType if (is_host or ClientNetwork.is_local_player(playerId)) and not is_starting: @@ -31,4 +30,4 @@ func populate(player, is_starting: bool, is_host: bool, game_mode: Dictionary): func _on_TeamButton_item_selected(id): - ServerNetwork.change_player_type(playerInfo[GameData.PLAYER_ID], id) + ServerNetwork.change_player_type(playerInfo.get_id(), id) diff --git a/networking/ClientNetwork.gd b/networking/ClientNetwork.gd index 4cc72d84..93605203 100644 --- a/networking/ClientNetwork.gd +++ b/networking/ClientNetwork.gd @@ -40,27 +40,27 @@ func on_disconnected_from_server(): get_tree().disconnect('server_disconnected', self, 'on_disconnected_from_server') -func register_player(recipientId: int, player: Dictionary): - rpc_id(recipientId, "on_register_player", player) - +func register_player(recipientId: int, player: PlayerData): + rpc_id(recipientId, "on_register_player", player.player_data_dictionary) + +func register_player_from_raw_data(recipientId: int, playerDataDictionary: Dictionary): + rpc_id(recipientId, "on_register_player", playerDataDictionary) remote func on_register_player(player: Dictionary): - var playerId = player[GameData.PLAYER_ID] - var playerName = player[GameData.PLAYER_NAME] + var playerId = player.id + var playerName = player.name print("on_register_player: %d - %s" % [playerId, playerName] ) - GameData.add_player(player) + GameData.add_player_from_raw_data(player) emit_signal("create_player", playerId) print("Total players: %d" % GameData.players.size()) +func update_player(playerData: PlayerData): + rpc("on_update_player", playerData.player_data_dictionary) -func update_player(playerInfo): - rpc("on_update_player", playerInfo) - - -remotesync func on_update_player(playerInfo): - GameData.update_player(playerInfo) - emit_signal("update_player", playerInfo[GameData.PLAYER_ID]) +remotesync func on_update_player(playerInfoDictionary: Dictionary): + GameData.update_player_from_raw_data(playerInfoDictionary) + emit_signal("update_player", playerInfoDictionary.id) func update_game_data(): diff --git a/networking/GameData.gd b/networking/GameData.gd index e772651d..8b1d7b6f 100644 --- a/networking/GameData.gd +++ b/networking/GameData.gd @@ -1,10 +1,5 @@ extends Node -const PLAYER_ID = "id" -const PLAYER_NAME = "name" -const PLAYER_TYPE = "type" -const PLAYER_HOST = "host" - var players = {} var currentGame: GameMode = null @@ -23,25 +18,27 @@ func get_players() -> Array: return players.values() -func get_player(playerId: int): +func get_player(playerId: int) -> PlayerData: if players.has(playerId): - return players[playerId] + return players[playerId] as PlayerData else: return null -func create_new_player(playerId: int, playerName: String, playerType: int) -> Dictionary: +func create_new_player_raw_data(playerId: int, playerName: String, playerType: int) -> Dictionary: return { - PLAYER_ID: playerId, - PLAYER_NAME: playerName, - PLAYER_TYPE: playerType, - PLAYER_HOST: false + id = playerId, + name = playerName, + type = playerType, + is_host = false } - -func add_player(newPlayer: Dictionary) -> bool: - var playerId = newPlayer[PLAYER_ID] +func add_player_from_raw_data(newPlayerDictionary: Dictionary) -> bool: + var playerId = newPlayerDictionary.id if not self.players.has(playerId): + var newPlayer := load("res://networking/PlayerData.gd").new() as PlayerData + newPlayer.load(newPlayerDictionary) + self.players[playerId] = newPlayer return true else: @@ -52,32 +49,33 @@ func reset(): self.players = {} -func get_current_player(): +func get_current_player() -> PlayerData: var id := get_tree().get_network_unique_id() if players.has(id): - return players[id] + return players[id] as PlayerData else: return null func get_current_player_type() -> int: - var curPlayer = get_current_player() + var curPlayer := get_current_player() if curPlayer != null: - return curPlayer[PLAYER_TYPE] + return curPlayer.get_type() else: return -1 -func update_player(player): - var playerId = player[PLAYER_ID] - players[playerId] = player - +func update_player_from_raw_data(player_data_dictionary: Dictionary): + var playerId = player_data_dictionary.id + get_player(playerId).load(player_data_dictionary) -func get_host() -> Player: +func get_host() -> PlayerData: var host = null for player in GameData.players.values(): - if player[GameData.PLAYER_HOST] == true: + var playerData := player as PlayerData + + if playerData.get_is_host() == true: host = player break diff --git a/networking/PlayerData.gd b/networking/PlayerData.gd new file mode 100644 index 00000000..14c0d31c --- /dev/null +++ b/networking/PlayerData.gd @@ -0,0 +1,33 @@ +extends Node + +var player_data_dictionary: Dictionary + +func _ready(): + pass + +func load(new_player_data_dictionary: Dictionary): + player_data_dictionary = new_player_data_dictionary + +func get_id() -> int: + return player_data_dictionary.id + +func set_id(id: int): + player_data_dictionary.id = id + +func get_name() -> String: + return player_data_dictionary.name + +func set_name(name: String): + player_data_dictionary.name = name + +func get_type() -> int: + return player_data_dictionary.type + +func set_type(type: int): + player_data_dictionary.type = type + +func get_is_host() -> bool: + return player_data_dictionary.is_host + +func set_is_host(is_host: bool): + player_data_dictionary.is_host = is_host diff --git a/networking/ServerNetwork.gd b/networking/ServerNetwork.gd index 548f0610..bc661527 100644 --- a/networking/ServerNetwork.gd +++ b/networking/ServerNetwork.gd @@ -26,7 +26,7 @@ func _player_disconnected(id): # No host, make the first player the new host if GameData.get_host() == null: var newHost = GameData.players.values().front() - make_host(newHost[GameData.PLAYER_ID]) + make_host(newHost.get_id()) # Called by clients when they connect @@ -43,14 +43,14 @@ remote func on_register_self(playerId: int, playerName: String, gameVersion: int # Default to team 0 var playerType := 0 - var playerData = GameData.create_new_player(playerId, playerName, playerType) + var playerData = GameData.create_new_player_raw_data(playerId, playerName, playerType) # Register this client with the server ClientNetwork.on_register_player(playerData) # Register the new player with all existing clients for curPlayerId in GameData.players: - ClientNetwork.register_player(curPlayerId, playerData) + ClientNetwork.register_player_from_raw_data(curPlayerId, playerData) # Catch the new player up on who is already here for curPlayerId in GameData.players: @@ -60,7 +60,6 @@ remote func on_register_self(playerId: int, playerName: String, gameVersion: int ClientNetwork.update_game_data() - # If there is no host, make this player the host if GameData.get_host() == null: make_host(playerId) @@ -68,11 +67,10 @@ remote func on_register_self(playerId: int, playerName: String, gameVersion: int func make_host(playerId: int): print("Server: Making %d host" % playerId) - var playerInfo = GameData.get_player(playerId) - playerInfo[GameData.PLAYER_HOST] = true + var playerInfo := GameData.get_player(playerId) as PlayerData + playerInfo.set_is_host(true) ClientNetwork.update_player(playerInfo) - func is_hosting() -> bool: if get_tree().network_peer != null and get_tree().network_peer.get_connection_status() != 0: # NetworkedMultiplayerPeer.ConnectionStatus.CONNECTION_DISCONNECTED return true @@ -107,9 +105,9 @@ func change_player_type(playerId: int, playerType: int): remote func on_change_player_type(playerId: int, playerType: int): - var player = GameData.get_player(playerId) + var player = GameData.get_player(playerId) as PlayerData if player != null: - player[GameData.PLAYER_TYPE] = playerType + player.set_type(playerType) ClientNetwork.update_player(player) else: print("ERROR: on_change_player_type() player not found for ID: %d" % playerId) diff --git a/project.godot b/project.godot index b0e1b348..0145b62d 100644 --- a/project.godot +++ b/project.godot @@ -190,6 +190,7 @@ GameData="*res://networking/GameData.gd" vr="*res://addons/OQ_Toolkit/vr_autoload.gd" UserData="*res://common/UserData.gd" Maps="*res://common/game/maps/MapDirectory.gd" +PlayerData="*res://networking/PlayerData.gd" [debug] diff --git a/server/lobby/ServerLobby.gd b/server/lobby/ServerLobby.gd index aa41454b..1cea51ba 100644 --- a/server/lobby/ServerLobby.gd +++ b/server/lobby/ServerLobby.gd @@ -67,7 +67,7 @@ func get_name() -> String: # Parse command line port in the form of: # --port xxxxx func get_port() -> int: - var port := ServerNetwork.SERVER_PORT + var port = ServerNetwork.SERVER_PORT var args := OS.get_cmdline_args() for ii in range(args.size()):