summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-12-26 13:43:03 +0100
committermetamuffin <metamuffin@disroot.org>2024-12-26 13:43:03 +0100
commite73d6273e969f9720b9ce730c3c5825126ae892b (patch)
tree386c13a5a582e9593605dcef9b6dab7cf6b15620 /client
parent01811610b169a0572417c1493ea606353fd1a327 (diff)
downloadhurrycurry-e73d6273e969f9720b9ce730c3c5825126ae892b.tar
hurrycurry-e73d6273e969f9720b9ce730c3c5825126ae892b.tar.bz2
hurrycurry-e73d6273e969f9720b9ce730c3c5825126ae892b.tar.zst
generalize services and add editor to play menu
Diffstat (limited to 'client')
-rw-r--r--client/menu/play.gd58
-rw-r--r--client/menu/play.tscn17
-rw-r--r--client/project.godot3
-rw-r--r--client/service/editor.gd31
-rw-r--r--client/service/server.gd44
-rw-r--r--client/service/service.gd (renamed from client/server.gd)59
-rw-r--r--client/settings.gd1
7 files changed, 165 insertions, 48 deletions
diff --git a/client/menu/play.gd b/client/menu/play.gd
index 50e8a633..894ea4bc 100644
--- a/client/menu/play.gd
+++ b/client/menu/play.gd
@@ -26,6 +26,8 @@ var url_regex: RegEx = RegEx.new()
@onready var server = $side/margin/options/second/server
@onready var server_control = $side/margin/options/second/server/control
@onready var server_connect = $side/margin/options/second/server/connect
+@onready var editor_control = $side/margin/options/second/editor/control
+@onready var editor_connect = $side/margin/options/second/editor/connect
func _ready():
url_regex.compile("^(?:(ws|wss)://)?([^:]+)(?::([0-9]+))?$")
@@ -127,40 +129,74 @@ func connect_to(url: String):
print("Connecting to %s" % url)
get_parent().replace_menu("res://menu/game.tscn", url)
-func _on_server_pressed():
+func _on_server_control_pressed():
match Server.state:
- Server.State.RUNNING: Server.stop()
- Server.State.STOPPED: Server.start()
- Server.State.FAILED: Server.start()
+ Service.State.RUNNING: Server.stop()
+ Service.State.STOPPED: Server.start()
+ Service.State.FAILED: Server.start()
+
+func _on_editor_control_pressed():
+ match Editor.state:
+ Service.State.RUNNING: Editor.stop()
+ Service.State.STOPPED: Editor.start(); Server.start()
+ Service.State.FAILED: Editor.start()
func _on_server_connect_pressed():
connect_to("ws://127.0.0.1:27032/")
+func _on_editor_connect_pressed():
+ connect_to("ws://127.0.0.1:27035/")
+
func _process(_delta):
server_control.disabled = false
- server_connect.visible = Server.state == Server.State.RUNNING
+ server_connect.visible = Server.state == Service.State.RUNNING
server_control.modulate = Color.WHITE
match Server.state:
- Server.State.RUNNING:
+ Service.State.RUNNING:
server_control.text = tr("c.menu.play.server_stop")
server_control.modulate = Color.AQUAMARINE
- Server.State.TESTING:
+ Service.State.TESTING:
server_control.text = tr("c.menu.play.server_testing")
server_control.disabled = true
- Server.State.STARTING:
+ Service.State.STARTING:
server_control.text = tr("c.menu.play.server_starting")
server_control.disabled = true
- Server.State.STOPPED:
+ Service.State.STOPPED:
server_control.text = tr("c.menu.play.server_start")
- Server.State.FAILED:
+ Service.State.FAILED:
server_control.text = tr("c.menu.play.server_failed")
server_control.modulate = Color(1, 0.4, 0.5)
server_control.tooltip_text = tr("c.menu.play.server_failed_tooltip")
- Server.State.UNAVAILABLE:
+ Service.State.UNAVAILABLE:
server_control.text = tr("c.menu.play.server_unavailable")
server_control.disabled = true
server_control.tooltip_text = tr("c.menu.play.server_binary_not_found")
+ editor_control.disabled = false
+ editor_connect.visible = Editor.state == Service.State.RUNNING
+ editor_control.modulate = Color.WHITE
+ match Editor.state:
+ Service.State.RUNNING:
+ editor_control.text = tr("c.menu.play.editor_stop")
+ editor_control.modulate = Color.AQUAMARINE
+ Service.State.TESTING:
+ editor_control.text = tr("c.menu.play.editor_testing")
+ editor_control.disabled = true
+ Service.State.STARTING:
+ editor_control.text = tr("c.menu.play.editor_starting")
+ editor_control.disabled = true
+ Service.State.STOPPED:
+ editor_control.text = tr("c.menu.play.editor_start")
+ Service.State.FAILED:
+ editor_control.text = tr("c.menu.play.editor_failed")
+ editor_control.modulate = Color(1, 0.4, 0.5)
+ editor_control.tooltip_text = tr("c.menu.play.server_failed_tooltip")
+ Service.State.UNAVAILABLE:
+ editor_control.text = tr("c.menu.play.editor_unavailable")
+ editor_control.disabled = true
+ editor_control.tooltip_text = tr("c.menu.play.server_binary_not_found")
+
+
func _on_uri_text_changed(new_text):
connect_uri.modulate = Color.WHITE if url_regex.search(new_text) else Color.RED
diff --git a/client/menu/play.tscn b/client/menu/play.tscn
index 43a3414f..47b45d69 100644
--- a/client/menu/play.tscn
+++ b/client/menu/play.tscn
@@ -113,6 +113,19 @@ alignment = 0
layout_mode = 2
text = "c.menu.play.connect"
+[node name="editor" type="HBoxContainer" parent="side/margin/options/second"]
+layout_mode = 2
+
+[node name="control" type="Button" parent="side/margin/options/second/editor"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "c.menu.play.editor"
+alignment = 0
+
+[node name="connect" type="Button" parent="side/margin/options/second/editor"]
+layout_mode = 2
+text = "c.menu.play.connect"
+
[node name="spacer2" type="Control" parent="side/margin/options/second"]
custom_minimum_size = Vector2(0, 10)
layout_mode = 2
@@ -127,6 +140,8 @@ layout_mode = 2
[connection signal="text_changed" from="side/margin/options/second/connect/uri" to="." method="_on_uri_text_changed"]
[connection signal="pressed" from="side/margin/options/second/connect/connect" to="." method="_on_connect_pressed"]
-[connection signal="pressed" from="side/margin/options/second/server/control" to="." method="_on_server_pressed"]
+[connection signal="pressed" from="side/margin/options/second/server/control" to="." method="_on_server_control_pressed"]
[connection signal="pressed" from="side/margin/options/second/server/connect" to="." method="_on_server_connect_pressed"]
+[connection signal="pressed" from="side/margin/options/second/editor/control" to="." method="_on_editor_control_pressed"]
+[connection signal="pressed" from="side/margin/options/second/editor/connect" to="." method="_on_editor_connect_pressed"]
[connection signal="pressed" from="side/margin/options/second/back" to="." method="_on_back_pressed"]
diff --git a/client/project.godot b/client/project.godot
index 2239120b..3d45924f 100644
--- a/client/project.godot
+++ b/client/project.godot
@@ -20,11 +20,12 @@ config/icon="res://icons/main.png"
[autoload]
Global="*res://global.gd"
-Server="*res://server.gd"
Sound="*res://audio/sound.tscn"
DisableWrongJoypads="*res://disable_wrong_joypads.gd"
InputManager="*res://menu/settings/input/input_manager.gd"
ServerList="*res://server_list.gd"
+Server="*res://service/server.gd"
+Editor="*res://service/editor.gd"
[debug]
diff --git a/client/service/editor.gd b/client/service/editor.gd
new file mode 100644
index 00000000..c600b715
--- /dev/null
+++ b/client/service/editor.gd
@@ -0,0 +1,31 @@
+# Hurry Curry! - a game about cooking
+# Copyright 2024 metamuffin
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, version 3 of the License only.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+class_name EditorService
+extends Service
+
+func name():
+ return "Editor"
+
+func arguments():
+ return []
+
+func exe_path() -> String:
+ var path: String = Global.get_setting("server.editor_binary_path")
+ if path != "": return path
+ else: return "hurrycurry-editor"
+
+func test_port():
+ return 27035
diff --git a/client/service/server.gd b/client/service/server.gd
new file mode 100644
index 00000000..b2db04de
--- /dev/null
+++ b/client/service/server.gd
@@ -0,0 +1,44 @@
+# Hurry Curry! - a game about cooking
+# Copyright 2024 metamuffin
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, version 3 of the License only.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+class_name ServerService
+extends Service
+
+func name():
+ return "Server"
+
+func arguments():
+ var args = []
+ if Global.get_setting("server.data_path") != "":
+ args.push_back("--data-dir")
+ args.push_back(Global.get_setting("server.data_path"))
+ if Global.get_setting("server.name") != "":
+ args.push_back("--server-name")
+ args.push_back(Global.get_setting("server.name"))
+ if Global.get_setting("server.mdns"):
+ args.push_back("--mdns")
+ if Global.get_setting("server.upnp"):
+ args.push_back("--upnp")
+ if Global.get_setting("server.register"):
+ args.push_back("--register")
+ return args
+
+func exe_path() -> String:
+ var path: String = Global.get_setting("server.binary_path")
+ if path != "": return path
+ else: return "hurrycurry-server"
+
+func test_port():
+ return 27032
diff --git a/client/server.gd b/client/service/service.gd
index 4378c02d..f19364c7 100644
--- a/client/server.gd
+++ b/client/service/service.gd
@@ -15,9 +15,19 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
-class_name GameServer
+class_name Service
extends Node
+
+func name():
+ return "Unknown"
+func arguments():
+ return []
+func exe_path():
+ return "false"
+func test_port():
+ return 25565
+
var thread = null
var pid = null
@@ -44,7 +54,7 @@ func test():
func start():
if state != State.STOPPED and state != State.FAILED:
- push_error("server cant be started")
+ push_error(name() + " can't be started")
return
state = State.STARTING
thread = Thread.new()
@@ -52,23 +62,25 @@ func start():
func stop():
if state != State.RUNNING:
- push_error("server cant be stopped")
+ push_error(name() + " can't be stopped")
return
OS.kill(pid)
func _test_server():
var output = []
- thread_result = OS.execute(get_server_path(), ["-v"], output, true, false)
+ print(name() + ": Binary path is " + exe_path())
+ thread_result = OS.execute(exe_path(), ["-v"], output, true, false)
+ print(output)
sem.post()
func _server_exec():
- var args = prepare_args()
- thread_result = OS.create_process(get_server_path(), args, false)
+ var args = arguments()
+ thread_result = OS.create_process(exe_path(), args, false)
if thread_result >= 0:
var ok = false
while not ok:
var conn = StreamPeerTCP.new()
- if conn.connect_to_host("127.0.0.1", 27032) == OK:
+ if conn.connect_to_host("127.0.0.1", test_port()) == OK:
while conn.poll() == OK:
if conn.get_status() == StreamPeerTCP.STATUS_ERROR: break
elif conn.get_status() == StreamPeerTCP.STATUS_CONNECTED: ok = true; break
@@ -79,34 +91,11 @@ func _server_exec():
break
sem.post()
-func prepare_args():
- var args = []
- if Global.get_setting("server.data_path") != "":
- args.push_back("--data-dir")
- args.push_back(Global.get_setting("server.data_path"))
- if Global.get_setting("server.name") != "":
- args.push_back("--server-name")
- args.push_back(Global.get_setting("server.name"))
- if Global.get_setting("server.mdns"):
- args.push_back("--mdns")
- if Global.get_setting("server.upnp"):
- args.push_back("--upnp")
- if Global.get_setting("server.register"):
- args.push_back("--register")
- return args
-
-func get_server_path() -> String:
- var path: String = Global.get_setting("server.binary_path")
- if path != "":
- return path
- else:
- return "hurrycurry-server"
-
func _process(_delta):
match state:
State.TESTING:
if sem.try_wait():
- print("Server: Test result=", thread_result)
+ print(name() + ": Test result=", thread_result)
if thread_result == 0: state = State.STOPPED
else: state = State.UNAVAILABLE
thread.wait_to_finish()
@@ -116,18 +105,18 @@ func _process(_delta):
if thread_result >= 0:
state = State.RUNNING
pid = thread_result
- print("Server: Started pid=", thread_result)
+ print(name() + ": Started pid=", thread_result)
else:
state = State.FAILED
- print("Server: Failed")
+ print(name() + ": Failed")
thread.wait_to_finish()
thread = null
State.RUNNING:
if not OS.is_process_running(pid):
- print("Server: Stopped")
+ print(name() + ": Stopped")
state = State.STOPPED
pid = null
func _exit_tree():
- if thread != null: thread.wait_to_finish()
if pid != null: OS.kill(pid)
+ if thread != null: thread.wait_to_finish()
diff --git a/client/settings.gd b/client/settings.gd
index 80984b22..409e4b6b 100644
--- a/client/settings.gd
+++ b/client/settings.gd
@@ -66,6 +66,7 @@ static func get_root():
),
SettingsCategory.new("server", [
TextSetting.new("binary_path", ""),
+ TextSetting.new("editor_binary_path", ""),
TextSetting.new("data_path", ""),
TextSetting.new("name", "A Hurry Curry! Server"),
ToggleSetting.new("upnp", false),