aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/gui/menus/entry.gd8
-rw-r--r--client/project.godot6
-rw-r--r--client/system/cli.gd112
-rw-r--r--client/system/cli.gd.uid1
-rw-r--r--client/system/disable_wrong_joypads.gd (renamed from client/disable_wrong_joypads.gd)0
-rw-r--r--client/system/disable_wrong_joypads.gd.uid (renamed from client/disable_wrong_joypads.gd.uid)0
-rw-r--r--client/system/profile.gd (renamed from client/profile.gd)0
-rw-r--r--client/system/profile.gd.uid (renamed from client/profile.gd.uid)0
-rw-r--r--client/system/server_list.gd (renamed from client/server_list.gd)0
-rw-r--r--client/system/server_list.gd.uid (renamed from client/server_list.gd.uid)0
-rw-r--r--client/system/settings.gd (renamed from client/settings.gd)0
-rw-r--r--client/system/settings.gd.uid (renamed from client/settings.gd.uid)0
-rw-r--r--client/system/translation_manager.gd (renamed from client/translation_manager.gd)0
-rw-r--r--client/system/translation_manager.gd.uid (renamed from client/translation_manager.gd.uid)0
14 files changed, 122 insertions, 5 deletions
diff --git a/client/gui/menus/entry.gd b/client/gui/menus/entry.gd
index d9e3dd29..b6e5523b 100644
--- a/client/gui/menus/entry.gd
+++ b/client/gui/menus/entry.gd
@@ -20,9 +20,13 @@ func _ready():
super()
get_window().title = "Hurry Curry!"
+ if not Cli.init():
+ get_tree().quit()
+ return
+
var args = OS.get_cmdline_user_args()
- if args.size() == 1:
- await submenu("res://gui/menus/game.tscn", args[0])
+ if Cli.opts.has("connect_address"):
+ await submenu("res://gui/menus/game.tscn", Cli.opts["connect_address"])
elif not Settings.read("gameplay.setup_completed"):
await submenu("res://gui/menus/setup/setup.tscn")
else:
diff --git a/client/project.godot b/client/project.godot
index 56af7dca..1111d50a 100644
--- a/client/project.godot
+++ b/client/project.godot
@@ -19,12 +19,12 @@ config/icon="res://icons/main.png"
[autoload]
-TranslationManager="*res://translation_manager.gd"
+TranslationManager="*res://system/translation_manager.gd"
Global="*res://global.gd"
Sound="*res://audio/sound.tscn"
-DisableWrongJoypads="*res://disable_wrong_joypads.gd"
+DisableWrongJoypads="*res://system/disable_wrong_joypads.gd"
InputManager="*res://gui/menus/settings/input/input_manager.gd"
-ServerList="*res://server_list.gd"
+ServerList="*res://system/server_list.gd"
Server="*res://service/server.gd"
Editor="*res://service/editor.gd"
Discover="*res://service/discover.gd"
diff --git a/client/system/cli.gd b/client/system/cli.gd
new file mode 100644
index 00000000..b6ba8eef
--- /dev/null
+++ b/client/system/cli.gd
@@ -0,0 +1,112 @@
+# Hurry Curry! - a game about cooking
+# Copyright (C) 2025 Hurry Curry! contributors
+#
+# 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/>.
+#
+extends Node
+class_name Cli
+
+enum Mode { FLAG, OPTION, MULTI_OPTION, POSITIONAL }
+class Option:
+ var short #: String?
+ var long: String
+ var mode: Mode
+ var help: String
+ func _init(s, l: String, m: Mode, h: String):
+ short = s; long = l; mode = m; help = h
+
+static var OPTIONS := [
+ Option.new("h", "help", Mode.FLAG, "Show help"),
+ Option.new("s", "setting", Mode.MULTI_OPTION, "Per-launch setting override"),
+ Option.new(null, "connect_address", Mode.POSITIONAL, "Connect to a server directly without menu interaction")
+]
+
+static var opts = {} #: Dictionary[String, Variant]
+
+static func init() -> bool:
+ if not parse(): return false
+ if opts.has("help"):
+ print_help()
+ return false
+ return true
+
+static func print_help():
+ print("OPTIONS:\n")
+ for opt in OPTIONS:
+ var line = ""
+ if opt.mode == Mode.POSITIONAL:
+ line += "<" + opt.long.to_upper() + ">"
+ else:
+ if opt.short: line += "-" + opt.short + ", "
+ line += "--" + opt.long
+ if opt.mode == Mode.OPTION or opt.mode == Mode.MULTI_OPTION:
+ line += " <VALUE>"
+ while line.length() < 25: line += " "
+ line += " " + opt.help
+ print(line)
+
+static func parse() -> bool:
+ var args := OS.get_cmdline_user_args()
+ while not args.is_empty():
+ var arg := args[0]
+ args.remove_at(0)
+ if arg.begins_with("--"):
+ var long = arg.trim_prefix("--")
+ var opt_index = OPTIONS.find_custom(func(x): return x.long == long)
+ if opt_index == -1:
+ push_error("unknown long option \"%s\"" % long)
+ return false
+ if not _parse_opt(args, OPTIONS[opt_index]): return false
+ elif arg.begins_with("-"):
+ for short in arg.trim_prefix("-"):
+ var opt_index = OPTIONS.find_custom(func(x): return x.short == short)
+ if opt_index == -1:
+ push_error("unknown short option \"%s\"" % short)
+ return false
+ if not _parse_opt(args, OPTIONS[opt_index]): return false
+ else:
+ var opt_index = OPTIONS.find_custom(func(x): return x.mode == Mode.POSITIONAL)
+ if opt_index == -1:
+ push_error("no positional arguments")
+ return false
+ var opt = OPTIONS[opt_index]
+ opts[opt.long] = arg
+
+ print("Parsed options: ", opts)
+ return true
+
+static func _parse_opt(args: Array[String], opt: Option) -> bool:
+ match opt.mode:
+ Mode.FLAG:
+ opts[opt.long] = true
+ return true
+ Mode.OPTION:
+ if args.is_empty():
+ push_error("missing option value")
+ return false
+ opts[opt.long] = args[0]
+ args.remove_at(0)
+ return true
+ Mode.MULTI_OPTION:
+ if args.is_empty():
+ push_error("missing option value")
+ return false
+ if not opts.has(opt.long): opts[opt.long] = []
+ opts[opt.long].push_back(args[0])
+ args.remove_at(0)
+ return true
+ Mode.POSITIONAL:
+ push_error("positional arg doesnt need flag")
+ return false
+ push_error("unreachable")
+ return false
diff --git a/client/system/cli.gd.uid b/client/system/cli.gd.uid
new file mode 100644
index 00000000..031e72be
--- /dev/null
+++ b/client/system/cli.gd.uid
@@ -0,0 +1 @@
+uid://b26r6mw82umnc
diff --git a/client/disable_wrong_joypads.gd b/client/system/disable_wrong_joypads.gd
index 029768b3..029768b3 100644
--- a/client/disable_wrong_joypads.gd
+++ b/client/system/disable_wrong_joypads.gd
diff --git a/client/disable_wrong_joypads.gd.uid b/client/system/disable_wrong_joypads.gd.uid
index dbf5f234..dbf5f234 100644
--- a/client/disable_wrong_joypads.gd.uid
+++ b/client/system/disable_wrong_joypads.gd.uid
diff --git a/client/profile.gd b/client/system/profile.gd
index 438e8e66..438e8e66 100644
--- a/client/profile.gd
+++ b/client/system/profile.gd
diff --git a/client/profile.gd.uid b/client/system/profile.gd.uid
index 5cd63b28..5cd63b28 100644
--- a/client/profile.gd.uid
+++ b/client/system/profile.gd.uid
diff --git a/client/server_list.gd b/client/system/server_list.gd
index 77b5ee0c..77b5ee0c 100644
--- a/client/server_list.gd
+++ b/client/system/server_list.gd
diff --git a/client/server_list.gd.uid b/client/system/server_list.gd.uid
index e5479756..e5479756 100644
--- a/client/server_list.gd.uid
+++ b/client/system/server_list.gd.uid
diff --git a/client/settings.gd b/client/system/settings.gd
index 1cacfce9..1cacfce9 100644
--- a/client/settings.gd
+++ b/client/system/settings.gd
diff --git a/client/settings.gd.uid b/client/system/settings.gd.uid
index ca85e233..ca85e233 100644
--- a/client/settings.gd.uid
+++ b/client/system/settings.gd.uid
diff --git a/client/translation_manager.gd b/client/system/translation_manager.gd
index 9aa374b2..9aa374b2 100644
--- a/client/translation_manager.gd
+++ b/client/system/translation_manager.gd
diff --git a/client/translation_manager.gd.uid b/client/system/translation_manager.gd.uid
index ea5fd7da..ea5fd7da 100644
--- a/client/translation_manager.gd.uid
+++ b/client/system/translation_manager.gd.uid