Initial commit

This commit is contained in:
2026-01-21 23:51:53 +01:00
commit 60b208fee0
1703 changed files with 100223 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
Copyright 2023 Gálffy Tamás
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1 @@
uid://vj6t63oapvo4

View File

@@ -0,0 +1 @@
uid://tt3j25a05n7c

View File

@@ -0,0 +1,168 @@
extends Control
class_name Main
@onready var start_btn : Button = $Mainmenu/Menu/MarginContainer/VBoxContainer/HBoxContainer4/VBoxContainer3/Start
@onready var disconnect_btn : Button = $Pausemenu/Menu/MarginContainer/VBoxCurrentLobby/Disconnect
@onready var name_edit : = $Mainmenu/Menu/MarginContainer/VBoxContainer/HBoxContainer4/VBoxContainer2/NameEdit
@onready var disconnectDialog = $Dialogs/DisconnectDialog
@onready var pausemenu = $Pausemenu
@onready var mainmenu = $Mainmenu
@onready var hud = $Hud
@onready var mapsParent: Node3D = $Maps
@onready var playersParent: Node3D = $Players
var peer = WebSocketMultiplayerPeer.new()
var lobby: PackedScene = preload("res://Maps/Lobby/Lobby.tscn")
var player: PackedScene = preload("res://actors/Player/player_character.tscn")
func _init():
peer.supported_protocols = ["ludus"]
Steamworks.initialize()
func _ready():
await Multiplayer.noray_connected
multiplayer.peer_connected.connect(peer_connected)
multiplayer.peer_disconnected.connect(peer_disconnected)
multiplayer.server_disconnected.connect(close_network)
multiplayer.connection_failed.connect(close_network)
multiplayer.connected_to_server.connect(connected)
# Set the player name according to the system username. Fallback to the path.
if Steamworks.is_initiallized:
get_tree().auto_accept_quit = false
Steamworks.create_lobby()
name_edit.text = Steam.getPersonaName()
elif false: #TODO: Set text to saved value
name_edit.text = ""
disableMultiplayer()
else:
name_edit.text = "Spacebots Player"
disableMultiplayer()
func _process(delta: float):
if Input.is_action_just_pressed("pause") and playersParent.get_child_count() > 0 and %Settingsmenu.visible == false:
if not pausemenu.visible:
pausemenu.show()
pausemenu.grab_focus() #TODO: fix
hud.hide()
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
else:
hud.show()
pausemenu.hide()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func disableMultiplayer() -> void:
$/root/Main/Mainmenu/Menu/MarginContainer/VBoxContainer/HBoxContainer/VBoxMultiplayerDisabled.show()
$/root/Main/Mainmenu/Menu/MarginContainer/VBoxContainer/HBoxContainer/VBoxLobbylist.hide()
func start_game():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
mainmenu.hide()
start_btn.disabled = true
disconnect_btn.disabled = false
hud.show()
@rpc("authority","call_local","reliable")
func changeMap(newMap: PackedScene) -> void:
var map = newMap.instantiate()
if mapsParent.get_child_count() > 0:
if Multiplayer.getCurrentMapLogic().is_connected(StringName("missionLost"),missionLost):
Multiplayer.getCurrentMapLogic().disconnect(StringName("missionLost"),missionLost)
mapsParent.get_child(0).queue_free()
mapsParent.add_child(map)
initiatePlayerPosition(map.playerStartPos)
Multiplayer.setCurrentMapLogic(map)
map.missionLost.connect(missionLost)
func initiatePlayerPosition(pos: Vector3) -> void:
for p in Multiplayer.playerDict.values():
if p.is_multiplayer_authority():
p.global_position = pos
print(p)
func missionLost() -> void:
changeMap(lobby)
func stop_game():
disconnect_btn.disabled = true
mainmenu.show()
pausemenu.hide()
hud.hide()
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
#Steamworks.stop()
var currentMaps = mapsParent.get_children()
for child in currentMaps:
child.queue_free()
var players = playersParent.get_children()
for child in players:
child.set_process(false)
child.queue_free()
await get_tree().process_frame
start_btn.disabled = false
func close_network():
peer.close()
stop_game()
disconnectDialog.popup_centered()
disconnectDialog.get_ok_button().grab_focus()
multiplayer.multiplayer_peer = null
Multiplayer.currentMapLogic = null
Multiplayer.playerDict = {}
Multiplayer.alivePlayerDict = {}
Multiplayer.is_host = false
Steamworks.lobby_id = 0
Steamworks.lobby_members = []
Steamworks.lobby_members_max = 5
Steamworks.steam_id = 0
Steamworks.steam_username = ""
func connected():
if Multiplayer.is_host == false:
add_player.rpc_id(1, multiplayer.get_unique_id())
func peer_connected(_id):
pass
#Steamworks.on_peer_add(id)
func peer_disconnected(id):
if Multiplayer.is_host:
remove_player(id)
func on_server_disconnected():
on_Disconnect_pressed()
func on_Start_pressed():
Multiplayer.host()
start_game()
changeMap(lobby)
add_player(multiplayer.get_unique_id())
func on_Disconnect_pressed():
if Steamworks.lobby_members.size() > 1:
Steam.leaveLobby(Steamworks.lobby_id)
close_network()
func on_Connect(norayid: String):
start_btn.disabled = true
disconnect_btn.disabled = false
start_game()
Multiplayer.join(norayid)
@rpc("any_peer")
func add_player(id):
var player_instance: CharacterBody3D = player.instantiate()
player_instance.name = str(id)
playersParent.add_child(player_instance)
@rpc("any_peer")
func remove_player(id):
if playersParent.get_node(str(id)):
playersParent.get_node(str(id)).queue_free()