From 686e2e9159b16b09d113ff57094614abd4b2f7f1 Mon Sep 17 00:00:00 2001 From: Techwizz Date: Fri, 17 Mar 2023 12:11:47 -0600 Subject: [PATCH] Bandage for #35 --- characters/teddy/Teddy.gd | 31 ++++++++++++++++--------------- scenes/settings.tscn | 1 + scripts/global.gd | 29 +++++++++++++++++++++++++++++ scripts/mainmenu.gd | 3 +-- scripts/networking.gd | 22 +++++++++++++--------- scripts/sceneChangerConfirm.gd | 1 + 6 files changed, 61 insertions(+), 26 deletions(-) diff --git a/characters/teddy/Teddy.gd b/characters/teddy/Teddy.gd index c3d01c2..867dd9b 100644 --- a/characters/teddy/Teddy.gd +++ b/characters/teddy/Teddy.gd @@ -61,23 +61,24 @@ func _unhandled_input(event): # Clamps the camera camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-50), deg_to_rad(60)) - if menuOpen == false: + if menuOpen == false: + if Input.is_action_just_pressed("menu"): + menuOpen = true + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + var scene_trs = load("res://scenes/mainmenu.tscn") + var scene = scene_trs.instantiate() + globalscene = scene + add_child(scene) + elif menuOpen == true: + if Global.miniMenuResume == true: + menuOpen = false + Global.miniMenuResume = false + elif Global.miniMenuResume == false: if Input.is_action_just_pressed("menu"): - menuOpen = true - var scene_trs = load("res://scenes/mainmenu.tscn") - var scene = scene_trs.instantiate() - globalscene = scene - add_child(scene) - elif menuOpen == true: - if Global.miniMenuResume == true: menuOpen = false - Global.miniMenuResume = false - elif Global.miniMenuResume == false: - if Input.is_action_just_pressed("menu"): - menuOpen = false - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - if globalscene: - globalscene.queue_free() + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + if globalscene: + globalscene.queue_free() func _physics_process(delta): if is_multiplayer_authority(): diff --git a/scenes/settings.tscn b/scenes/settings.tscn index 4476c9e..0d2c5e9 100644 --- a/scenes/settings.tscn +++ b/scenes/settings.tscn @@ -68,6 +68,7 @@ offset_bottom = 369.0 text = "Master Volume" [node name="volumeSlider" type="HSlider" parent="."] +layout_mode = 0 offset_left = 487.0 offset_top = 380.0 offset_right = 671.0 diff --git a/scripts/global.gd b/scripts/global.gd index 81bf3b2..474c857 100644 --- a/scripts/global.gd +++ b/scripts/global.gd @@ -75,6 +75,35 @@ func reset_variables(): playerAlive = true playerPleaseRespawn = false +func reset_variables_hard(): + print("Variables were HARD reset") + fatigue = 100 + playerHealth = 100 + playerDead = false + playerAlive = true + playerPleaseRespawn = false + connectedPlayers = [] + Networking.connected_peers = [] + connectedPlayersByPeerID = [] + roundInSession = false + playingGame = false + consoleOpen = false + godMode = false + multiplayerCurrent = false + teddyAuthorityID = null + miniMenuResume = false + HUDStartLabelText = "" + lastPersonToHitMe = 0 + HUDPlayerDied = false + respawnTimeModifier = 1.0 + menuLightSwitch = false + gamemode = "Deathmatch" + chosenRunner = null + iAmRunner = false + runnerDead = false + roundTimer = 300.0 + spawnCoordsInitalized = false + func save_data(): SettingsFile.save_data(mouseSensitivity, playerName, volumeModifer) diff --git a/scripts/mainmenu.gd b/scripts/mainmenu.gd index 3361a4a..7eb9eab 100644 --- a/scripts/mainmenu.gd +++ b/scripts/mainmenu.gd @@ -17,8 +17,7 @@ func _ready(): $Button.disabled = false $AudioStreamPlayer.playing = false if Global.playingGame == false: - Global.connectedPlayers = [] - Networking.connected_peers = [] + Global.reset_variables_hard() $musicPanel.visible = true $musicPanel/playingLabel.text = musicName $musicPanel/authorLabel.text = musicAuthor diff --git a/scripts/networking.gd b/scripts/networking.gd index 5d1b09c..b5adbb2 100644 --- a/scripts/networking.gd +++ b/scripts/networking.gd @@ -19,19 +19,23 @@ func create_server(port, maxPlayers): peer.peer_connected.connect( func(new_peer_id): - print("NEW CONNECTION FROM ", new_peer_id) await get_tree().create_timer(0.5).timeout ## REQUIRED, THE RPC IS MADE BEFORE THE CLIENT IS FULLY CONNECTED - rpc_id(new_peer_id, "sync_names", Global.connectedPlayers) - rpc_id(new_peer_id, "sync_respawn_speed", Global.respawnTimeModifier) - rpc_id(new_peer_id, "sync_gamemode", Global.gamemode) - rpc_id(new_peer_id, "sync_mapName", Global.mapName) - rpc("add_newly_connected_player_character", new_peer_id) - rpc_id(new_peer_id, "add_previously_connected_player_characters", connected_peers) - add_player_node(new_peer_id) + if connected_peers.has(new_peer_id): + print("CONFLICT ID FOUND") + return + else: + print("NEW CONNECTION FROM ", new_peer_id) + rpc_id(new_peer_id, "sync_names", Global.connectedPlayers) + rpc_id(new_peer_id, "sync_respawn_speed", Global.respawnTimeModifier) + rpc_id(new_peer_id, "sync_gamemode", Global.gamemode) + rpc_id(new_peer_id, "sync_mapName", Global.mapName) + rpc("add_newly_connected_player_character", new_peer_id) + rpc_id(new_peer_id, "add_previously_connected_player_characters", connected_peers) + add_player_node(new_peer_id) ) ### NOT WORKING YET - peer.peer_disconnected.disconnect( + peer.peer_disconnected.connect( func(peer_id): rpc("disconnect_peer", peer_id) ) diff --git a/scripts/sceneChangerConfirm.gd b/scripts/sceneChangerConfirm.gd index 5772d0b..1323598 100644 --- a/scripts/sceneChangerConfirm.gd +++ b/scripts/sceneChangerConfirm.gd @@ -10,6 +10,7 @@ func _process(delta): func _on_yes_button_pressed(): + Networking.peer.close() Global.playingGame = false get_tree().change_scene_to_file(Global.goScene)