2024-12-10 22:11:05 +01:00
|
|
|
## SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
## Copyright (c) 2024 interstellardevelopment.org
|
|
|
|
|
2024-12-04 09:42:04 +01:00
|
|
|
extends Node
|
|
|
|
|
2024-12-06 11:11:51 +01:00
|
|
|
# This tells the game what the logmode is.
|
|
|
|
# 0 -> None
|
|
|
|
# 1 -> Errors
|
|
|
|
# 2 -> Errors/Warnings
|
|
|
|
# 3 -> Errors/Warnings/Infos
|
|
|
|
# 4 -> All
|
2024-12-10 22:41:47 +01:00
|
|
|
var logmode: int = 3
|
2024-12-04 09:42:04 +01:00
|
|
|
|
2024-12-04 21:01:24 +01:00
|
|
|
var ip: String = "127.0.0.1"
|
|
|
|
var port: int = 25262
|
|
|
|
var max_clients: int = 1024
|
|
|
|
|
2024-12-20 19:51:46 +01:00
|
|
|
var roomname: String = ""
|
|
|
|
var username: String = ""
|
2024-12-06 19:48:11 +01:00
|
|
|
var mapname: String = "Testmap"
|
2024-12-04 09:42:04 +01:00
|
|
|
|
2024-12-10 22:34:53 +01:00
|
|
|
var launchmode: int = 0
|
|
|
|
|
2024-12-04 09:42:04 +01:00
|
|
|
func _ready() -> void:
|
2024-12-10 22:41:47 +01:00
|
|
|
Log.info("Running on: %s %s (%s)" % [OS.get_distribution_name(), OS.get_version(), OS.get_name()])
|
2024-12-20 19:51:46 +01:00
|
|
|
randomize()
|
|
|
|
load_settings()
|
2024-12-04 09:42:04 +01:00
|
|
|
var args: PackedStringArray = OS.get_cmdline_args()
|
|
|
|
var skip: bool = false
|
|
|
|
for i: int in range(args.size()):
|
|
|
|
if !skip:
|
|
|
|
Log.info("Argument %s passed." % args[i])
|
|
|
|
match args[i]:
|
|
|
|
"--logmode":
|
|
|
|
logmode = int(args[i+1])
|
|
|
|
skip = true
|
2024-12-05 19:39:07 +01:00
|
|
|
"--username":
|
|
|
|
username = args[i+1]
|
|
|
|
skip = true
|
2024-12-04 21:01:24 +01:00
|
|
|
"--server":
|
2024-12-10 22:34:53 +01:00
|
|
|
launchmode = 2
|
2024-12-04 21:01:24 +01:00
|
|
|
"--client":
|
2024-12-10 22:34:53 +01:00
|
|
|
launchmode = 1
|
2024-12-05 10:34:01 +01:00
|
|
|
"res://start.tscn":
|
|
|
|
pass # Catch in order to prevent a warning.
|
2024-12-04 09:42:04 +01:00
|
|
|
_:
|
|
|
|
Log.warning("Unknown argument: %s!" % args[i])
|
2024-12-05 19:39:07 +01:00
|
|
|
else:
|
|
|
|
skip = false
|
2024-12-10 22:34:53 +01:00
|
|
|
|
|
|
|
if DisplayServer.get_name() == "headless":
|
|
|
|
launchmode = 2
|
|
|
|
|
|
|
|
if OS.is_debug_build():
|
|
|
|
logmode = 4
|
|
|
|
|
|
|
|
match launchmode:
|
|
|
|
0:
|
2024-12-12 15:23:16 +01:00
|
|
|
# Menu
|
2024-12-20 19:51:46 +01:00
|
|
|
if get_tree().change_scene_to_file("res://scenes/ui/main_menu.tscn") != OK:
|
|
|
|
Log.error("Couldn't change to the main menu scene! Closing application.", "Couldn't change to the main menu scene!")
|
2024-12-10 22:34:53 +01:00
|
|
|
1:
|
|
|
|
# Client with direct join
|
|
|
|
Networking.join_room()
|
|
|
|
2:
|
|
|
|
# Server
|
|
|
|
if Networking.start_server() != OK:
|
|
|
|
Log.error("Failed to start server! Closing application.", "Failed to start server!")
|
2024-12-20 19:51:46 +01:00
|
|
|
|
|
|
|
func save_settings() -> void:
|
|
|
|
var to_save: Dictionary = {
|
|
|
|
"ip": ip,
|
|
|
|
"roomname": roomname,
|
|
|
|
"username": username,
|
|
|
|
}
|
|
|
|
var to_save_string: String = JSON.stringify(to_save)
|
|
|
|
var save_file: FileAccess = FileAccess.open("user://save.json", FileAccess.WRITE)
|
|
|
|
if save_file == null:
|
|
|
|
Log.warning("Couldn't save the json.")
|
|
|
|
return
|
|
|
|
save_file.store_string(to_save_string)
|
|
|
|
|
|
|
|
func load_settings() -> void:
|
|
|
|
var save_file: FileAccess = FileAccess.open("user://save.json", FileAccess.READ)
|
|
|
|
if save_file == null:
|
|
|
|
Log.warning("Couldn't open the json save.")
|
|
|
|
return
|
|
|
|
var json_string: String = save_file.get_as_text()
|
|
|
|
var json: JSON = JSON.new()
|
|
|
|
if json.parse(json_string) != OK:
|
|
|
|
Log.warning("Couldn't parse the json save.")
|
|
|
|
return
|
|
|
|
var data: Dictionary = json.data
|
|
|
|
ip = data["ip"]
|
|
|
|
roomname = data["roomname"]
|
|
|
|
username = data["username"]
|