Added argument parser, globalized variables
This commit is contained in:
parent
29f522ebb8
commit
cb24b0b629
6 changed files with 52 additions and 28 deletions
|
@ -11,6 +11,7 @@ config_version=5
|
|||
[application]
|
||||
|
||||
config/name="Hotel Madness"
|
||||
run/main_scene="res://start.tscn"
|
||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
|
@ -18,7 +19,7 @@ config/icon="res://icon.svg"
|
|||
|
||||
Log="*res://scripts/utils/log.gd"
|
||||
Networking="*res://scripts/utils/networking.gd"
|
||||
Test="*res://scripts/utils/test.gd"
|
||||
Game="*res://scripts/utils/game.gd"
|
||||
|
||||
[debug]
|
||||
|
||||
|
@ -64,3 +65,7 @@ gdscript/warnings/confusable_capture_reassignment=2
|
|||
gdscript/warnings/property_used_as_function=2
|
||||
gdscript/warnings/constant_used_as_function=2
|
||||
gdscript/warnings/function_used_as_property=2
|
||||
|
||||
[editor]
|
||||
|
||||
run/main_run_args="--testmode --logmode 4"
|
||||
|
|
36
scripts/utils/game.gd
Normal file
36
scripts/utils/game.gd
Normal file
|
@ -0,0 +1,36 @@
|
|||
extends Node
|
||||
|
||||
var testmode: bool = true
|
||||
var errortest: bool = true
|
||||
|
||||
var logmode: int = 4
|
||||
|
||||
const IP_ADDRESS: String = "127.0.0.1"
|
||||
const PORT: int = 25262
|
||||
const MAX_CLIENTS: int = 1024
|
||||
|
||||
func _ready() -> void:
|
||||
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]:
|
||||
"--testmode":
|
||||
testmode = true
|
||||
"--errortest":
|
||||
errortest = true
|
||||
"--logmode":
|
||||
logmode = int(args[i+1])
|
||||
skip = true
|
||||
_:
|
||||
Log.warning("Unknown argument: %s!" % args[i])
|
||||
run_tests()
|
||||
|
||||
func run_tests() -> void:
|
||||
if testmode:
|
||||
Log.info("Starting singleton tests.")
|
||||
Networking.test()
|
||||
Log.test()
|
||||
if errortest:
|
||||
Log.error("Test", "Test")
|
|
@ -6,7 +6,6 @@ extends Node
|
|||
# 2 -> Errors/Warnings
|
||||
# 3 -> Errors/Warnings/Infos
|
||||
# 4 -> All
|
||||
var logmode: int = 4
|
||||
|
||||
func test() -> void:
|
||||
debug("Test")
|
||||
|
@ -17,7 +16,7 @@ func test() -> void:
|
|||
func error(message: String, alert_message: String) -> void:
|
||||
if message == "":
|
||||
message = "Empty message string passed to an error message!"
|
||||
if logmode >= 1:
|
||||
if Game.logmode >= 1:
|
||||
printerr("[ERROR] " + message)
|
||||
OS.alert(alert_message, "Error!")
|
||||
if OS.shell_open(OS.get_user_data_dir()) != OK:
|
||||
|
@ -30,7 +29,7 @@ func error(message: String, alert_message: String) -> void:
|
|||
func warning(message: String) -> void:
|
||||
if message == "":
|
||||
message = "Empty message string passed to a warning message!"
|
||||
if logmode >= 2:
|
||||
if Game.logmode >= 2:
|
||||
printerr("[WARNING] " + message)
|
||||
|
||||
# Used for simple info.
|
||||
|
@ -38,7 +37,7 @@ func info(message: String) -> void:
|
|||
if message == "":
|
||||
warning("Empty message string passed to an info message!")
|
||||
return
|
||||
if logmode >= 3:
|
||||
if Game.logmode >= 3:
|
||||
print("[INFO] " + message)
|
||||
|
||||
# Used for debugging.
|
||||
|
@ -46,5 +45,5 @@ func debug(message: String) -> void:
|
|||
if message == "":
|
||||
warning("Empty message string passed to a debug message!")
|
||||
return
|
||||
if logmode >= 4:
|
||||
if Game.logmode >= 4:
|
||||
print("[DEBUG] " + message)
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
extends Node
|
||||
|
||||
const IP_ADDRESS: String = "127.0.0.1"
|
||||
const PORT: int = 25262
|
||||
const MAX_CLIENTS: int = 1024
|
||||
|
||||
func test() -> void:
|
||||
start_server()
|
||||
join_server()
|
||||
|
@ -12,20 +8,20 @@ func test() -> void:
|
|||
# Start the network listener.
|
||||
func start_server() -> void:
|
||||
var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
|
||||
if peer.create_server(PORT, MAX_CLIENTS) != OK:
|
||||
Log.warning("Couldn't create the server at port %d!" % PORT)
|
||||
if peer.create_server(Game.PORT, Game.MAX_CLIENTS) != OK:
|
||||
Log.warning("Couldn't create the server at port %d!" % Game.PORT)
|
||||
return
|
||||
multiplayer.multiplayer_peer = peer
|
||||
Log.info("Created the server at port %d." % PORT)
|
||||
Log.info("Created the server at port %d." % Game.PORT)
|
||||
|
||||
# Connect to a server.
|
||||
func join_server() -> void:
|
||||
var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
|
||||
if peer.create_client(IP_ADDRESS, PORT) != OK:
|
||||
Log.warning("Couldn't connect to the server at %s:%d!" % [IP_ADDRESS, PORT])
|
||||
if peer.create_client(Game.IP_ADDRESS, Game.PORT) != OK:
|
||||
Log.warning("Couldn't connect to the server at %s:%d!" % [Game.IP_ADDRESS, Game.PORT])
|
||||
return
|
||||
multiplayer.multiplayer_peer = peer
|
||||
Log.info("Connected to the server at %s:%d." % [IP_ADDRESS, PORT])
|
||||
Log.info("Connected to the server at %s:%d." % [Game.IP_ADDRESS, Game.PORT])
|
||||
|
||||
# Close all network connections.
|
||||
func close_network() -> void:
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
extends Node
|
||||
|
||||
const testmode: bool = true
|
||||
const errortest: bool = true
|
||||
|
||||
func _ready() -> void:
|
||||
if testmode:
|
||||
Log.info("Starting singleton tests.")
|
||||
Networking.test()
|
||||
Log.test()
|
||||
if errortest:
|
||||
Log.error("Test", "Test")
|
Loading…
Reference in a new issue