Init commit

This commit is contained in:
2025-02-06 09:56:39 +01:00
commit 8f61ab6c6b
48 changed files with 5511 additions and 0 deletions

View File

@ -0,0 +1,78 @@
extends Node
class_name GameRoot
signal load_map(name: String)
# -- config from args
var config_file: String = ""
const MAIN_MENU_SCENE := "res://scenes/menus/main/main_menu.tscn"
@onready var level_root: Node3D = $LevelLoader/Level
@onready var level_spawner: MultiplayerSpawner = $LevelLoader/MultiplayerSpawner
func _parse_args() -> void:
var args := Array(OS.get_cmdline_args())
var config_arg: String = "--config"
if args.has(config_arg):
var index := args.find(config_arg)
config_file = args[index + 1]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
_parse_args()
if OS.has_feature("dedicated_server") or DisplayServer.get_name() == "headless":
var err := _start_dedicated_server()
if err != OK:
logger.error("couldn't start the server, err is " + str(err))
else:
var err := _start_game()
if err != OK:
logger.error("couldn't start the game, err is " + str(err))
func _start_dedicated_server() -> Error:
if config_file != "":
logger.info("reading config from the file: " + config_file)
logger.info("starting in the dedicated server mode")
return OK
func _start_game() -> Error:
logger.info("starting in the game mode")
if not ResourceLoader.exists(MAIN_MENU_SCENE):
return ERR_DOES_NOT_EXIST
var scene: PackedScene = ResourceLoader.load(MAIN_MENU_SCENE)
if not scene.can_instantiate():
return ERR_CANT_OPEN
var node: MainMenu = scene.instantiate()
add_child(node)
return OK
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_load_map(map_name: String) -> void:
for c in level_root.get_children():
level_root.remove_child(c)
c.queue_free()
var path_tmpl := "res://scenes/maps/maps/%s"
var path := path_tmpl % map_name
if not ResourceLoader.exists(path):
logger.error("map " + map_name + " doesn't exist")
var scene: PackedScene = ResourceLoader.load(path)
if scene.can_instantiate():
var node: Node3D = scene.instantiate()
logger.info("loading map: " + map_name)
level_root.add_child(node)
else:
logger.error("Can't initialize")

View File

@ -0,0 +1,18 @@
[gd_scene load_steps=2 format=3 uid="uid://d3qjxw4rk4yn4"]
[ext_resource type="Script" path="res://scenes/game_root/game_root.gd" id="1_eb14f"]
[node name="GameRoot" type="Node"]
editor_description = "This node serves a starting point for the game. When the game is running as a dedicated server it's supposed to read the config file and start the server, when the game is running in a default mode, it should render the main menu"
script = ExtResource("1_eb14f")
[node name="LevelLoader" type="Node" parent="."]
editor_description = "This node is supposed to make it possible to sync the server data across all the possible players"
[node name="Level" type="Node3D" parent="LevelLoader"]
[node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="LevelLoader"]
_spawnable_scenes = PackedStringArray("res://scenes/maps/maps/lowpoly_tdm_1.tscn")
spawn_path = NodePath("../Level")
[connection signal="load_map" from="." to="." method="_on_load_map"]