Log fixups, initial networking setup and testing system.
This commit is contained in:
parent
1607fe62cc
commit
29f522ebb8
4 changed files with 60 additions and 2 deletions
|
@ -17,6 +17,8 @@ config/icon="res://icon.svg"
|
||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
Log="*res://scripts/utils/log.gd"
|
Log="*res://scripts/utils/log.gd"
|
||||||
|
Networking="*res://scripts/utils/networking.gd"
|
||||||
|
Test="*res://scripts/utils/test.gd"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
|
|
||||||
|
|
|
@ -8,32 +8,43 @@ extends Node
|
||||||
# 4 -> All
|
# 4 -> All
|
||||||
var logmode: int = 4
|
var logmode: int = 4
|
||||||
|
|
||||||
func _ready() -> void:
|
func test() -> void:
|
||||||
debug("Test")
|
debug("Test")
|
||||||
info("Test")
|
info("Test")
|
||||||
warning("Test")
|
warning("Test")
|
||||||
error("Test", "Test Message")
|
|
||||||
|
|
||||||
# Used for errors.
|
# Used for errors.
|
||||||
func error(message: String, alert_message: String) -> void:
|
func error(message: String, alert_message: String) -> void:
|
||||||
|
if message == "":
|
||||||
|
message = "Empty message string passed to an error message!"
|
||||||
if logmode >= 1:
|
if logmode >= 1:
|
||||||
printerr("[ERROR] " + message)
|
printerr("[ERROR] " + message)
|
||||||
OS.alert(alert_message, "Error!")
|
OS.alert(alert_message, "Error!")
|
||||||
|
if OS.shell_open(OS.get_user_data_dir()) != OK:
|
||||||
|
Log.warning("Couldn't open file explorer!")
|
||||||
else:
|
else:
|
||||||
OS.alert("An error has occured. The program will now exit.", "Error!")
|
OS.alert("An error has occured. The program will now exit.", "Error!")
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
# Used for warnings.
|
# Used for warnings.
|
||||||
func warning(message: String) -> void:
|
func warning(message: String) -> void:
|
||||||
|
if message == "":
|
||||||
|
message = "Empty message string passed to a warning message!"
|
||||||
if logmode >= 2:
|
if logmode >= 2:
|
||||||
printerr("[WARNING] " + message)
|
printerr("[WARNING] " + message)
|
||||||
|
|
||||||
# Used for simple info.
|
# Used for simple info.
|
||||||
func info(message: String) -> void:
|
func info(message: String) -> void:
|
||||||
|
if message == "":
|
||||||
|
warning("Empty message string passed to an info message!")
|
||||||
|
return
|
||||||
if logmode >= 3:
|
if logmode >= 3:
|
||||||
print("[INFO] " + message)
|
print("[INFO] " + message)
|
||||||
|
|
||||||
# Used for debugging.
|
# Used for debugging.
|
||||||
func debug(message: String) -> void:
|
func debug(message: String) -> void:
|
||||||
|
if message == "":
|
||||||
|
warning("Empty message string passed to a debug message!")
|
||||||
|
return
|
||||||
if logmode >= 4:
|
if logmode >= 4:
|
||||||
print("[DEBUG] " + message)
|
print("[DEBUG] " + message)
|
||||||
|
|
33
scripts/utils/networking.gd
Normal file
33
scripts/utils/networking.gd
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
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()
|
||||||
|
close_network()
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
return
|
||||||
|
multiplayer.multiplayer_peer = peer
|
||||||
|
Log.info("Created the server at port %d." % 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])
|
||||||
|
return
|
||||||
|
multiplayer.multiplayer_peer = peer
|
||||||
|
Log.info("Connected to the server at %s:%d." % [IP_ADDRESS, PORT])
|
||||||
|
|
||||||
|
# Close all network connections.
|
||||||
|
func close_network() -> void:
|
||||||
|
multiplayer.multiplayer_peer = null
|
||||||
|
Log.info("Closed all network connections.")
|
12
scripts/utils/test.gd
Normal file
12
scripts/utils/test.gd
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
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