online multiplayer chess game (note server currently down)
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | Debug.gd | 8 | ||||
| -rw-r--r-- | Utils.gd | 88 | ||||
| l--------- | addons/gdcli | 1 | ||||
| -rw-r--r-- | html/.gdignore | 0 | ||||
| -rw-r--r-- | networking/PacketHandler.gd | 2 | ||||
| -rw-r--r-- | project.godot | 12 | ||||
| -rw-r--r-- | submodules/.gdignore | 0 | ||||
| m--------- | submodules/gdcli | 0 | ||||
| -rw-r--r-- | ui/menus/settings/Settings.gd | 2 |
10 files changed, 68 insertions, 48 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..68b663d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "gdcli"] + path = submodules/gdcli + url = https://github.com/bend-n/gdcli @@ -11,13 +11,6 @@ const offset := Vector2(10, 10) const vertical := 15 -static func is_debug() -> bool: - var args := Utils.get_args() - if "debug" in args: - return Utils.str_bool(args.debug) - return OS.is_debug_build() - - func _ready() -> void: z_index = 5 # put on top add_child(timer) @@ -25,7 +18,6 @@ func _ready() -> void: timer.start(.1) # only redraw every .1 seconds font = font.duplicate() font.size = vertical * 0.8 - debug = is_debug() visible = debug @@ -17,40 +17,66 @@ func expand_color(color: String) -> String: return "white" if color == "w" else "black" -func get_args() -> Dictionary: - var arguments := {} - for argument in OS.get_cmdline_args(): - var key_value = argument.split("=") - if len(key_value) == 2: - arguments[key_value[0].lstrip("--")] = key_value[1] - else: - arguments[key_value[0].lstrip("--")] = "true" - return arguments - - func _ready() -> void: request() # check internet ok? cli() func cli() -> void: - var args = get_args() - if "help" in args or "h" in args: - print("usage: ./chess%s [-help] [-debug [enabled]] [--host=gamecode | --join=gamecode]" % exec_ext()) - var options = """options: - --help: show this help message and exit - --debug=enabled: enable/disable debug mode - --host=game_code: host a game with the given game code - --join=game_code: join a game with the given game code - """ - print(options) + var parser := Parser.new() + parser.add_argument( + Arg.new( + { + triggers = ["--help", "-h", "-?"], + n_args = 0, + help = "show this help message and exit", + action = "store_true", + } + ) + ) + parser.add_argument( + Arg.new( + { + triggers = ["--host", "-h"], + n_args = 1, + default = "game_code", + help = "host a game", + arg_names = "game code" + } + ) + ) + parser.add_argument( + Arg.new( + { + triggers = ["--join", "-j"], + n_args = 1, + default = "game_code", + help = "join a game", + arg_names = "game code" + } + ) + ) + parser.add_argument( + Arg.new( + { + triggers = ["--debug", "-d"], + n_args = 1, + help = "toggle debug mode", + arg_names = "enabled", + } + ) + ) + var args = parser.parse_arguments() + Debug.debug = str_bool(args["debug"]) if args.has("debug") else OS.is_debug_build() + if args.has("help") and args["help"]: + print(parser.help("chess game")) get_tree().quit() # dont wait - if "host" in args or "join" in args: + elif args.has("host") or args.has("join"): if !internet: printerr("No internet") get_tree().quit() yield(PacketHandler, "connection_established") - if "host" in args && args.host: + if args.has("host") and args.host: print("hosting game: %s" % args.host) if PacketHandler.lobby.validate_text(args.host): var move_list = Pgn.parse(OS.get_environment("MOVES"), false).moves @@ -58,27 +84,13 @@ func cli() -> void: print("with moves: %s" % move_list) PacketHandler.host_game(args.host, true, move_list) return - elif "join" in args && args.join: + elif args.has("join") and args.join: print("joining game: %s" % args.join) if PacketHandler.lobby.validate_text(args.join): PacketHandler.join_game(args.join) return - PacketHandler.lobby.set_buttons(true) printerr("error: invalid game code") get_tree().quit() # dont wait - # "debug" is handled by Debug.gd - - -static func exec_ext() -> String: - if OS.has_feature("Windows"): - return ".exe" - elif OS.has_feature("OSX"): - return ".app/Contents/MacOS/chess" - elif OS.has_feature("X11"): - return ".x86_64" - elif OS.has_feature("web"): - return ".html" - return "" func request() -> int: # returns err diff --git a/addons/gdcli b/addons/gdcli new file mode 120000 index 0000000..ac119d8 --- /dev/null +++ b/addons/gdcli @@ -0,0 +1 @@ +../submodules/gdcli/addons/gdcli/
\ No newline at end of file diff --git a/html/.gdignore b/html/.gdignore new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/html/.gdignore diff --git a/networking/PacketHandler.gd b/networking/PacketHandler.gd index 8f7803e..a10ffd1 100644 --- a/networking/PacketHandler.gd +++ b/networking/PacketHandler.gd @@ -192,7 +192,7 @@ func join_game(game: String = game_code) -> void: func host_game(game: String = game_code, white := true, moves_array: PoolStringArray = []) -> void: - var pckt := Utils.append_dict(Creds.get_public(), {team = white, moves = moves_array}) + var pckt = Utils.append_dict(Creds.get_public(), {team = white, moves = moves_array}) send_gamecode_packet(pckt, HEADERS.hostrequest, game) diff --git a/project.godot b/project.godot index 48c6dc9..254d4a5 100644 --- a/project.godot +++ b/project.godot @@ -9,6 +9,11 @@ config_version=4 _global_script_classes=[ { +"base": "Reference", +"class": "Arg", +"language": "GDScript", +"path": "res://addons/gdcli/Arg.gd" +}, { "base": "Button", "class": "BackButton", "language": "GDScript", @@ -154,6 +159,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://PGN/PGN.gd" }, { +"base": "Reference", +"class": "Parser", +"language": "GDScript", +"path": "res://addons/gdcli/Parser.gd" +}, { "base": "Control", "class": "Piece", "language": "GDScript", @@ -215,6 +225,7 @@ _global_script_classes=[ { "path": "res://ui/menus/account/usernamepass.gd" } ] _global_script_class_icons={ +"Arg": "", "BackButton": "", "BackgroundSquare": "", "BarTextureButton": "", @@ -244,6 +255,7 @@ _global_script_class_icons={ "OldColorView": "", "OpeningLabel": "", "PGN": "", +"Parser": "", "Piece": "", "Preview": "", "PromotionPreview": "", diff --git a/submodules/.gdignore b/submodules/.gdignore new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/submodules/.gdignore diff --git a/submodules/gdcli b/submodules/gdcli new file mode 160000 +Subproject 7f582e8d3a3328023b6d0743597e6e2d09a02a4 diff --git a/ui/menus/settings/Settings.gd b/ui/menus/settings/Settings.gd index 7c23b8a..79bf0f6 100644 --- a/ui/menus/settings/Settings.gd +++ b/ui/menus/settings/Settings.gd @@ -2,7 +2,7 @@ extends Control const file = "user://chess.settings" -onready var piece_sets := Utils.walk_dir() +onready var piece_sets: PoolStringArray = Utils.walk_dir() onready var piece_set_button: GridMenuButton = find_node("PieceSet") onready var fullscreenbutton := find_node("FullscreenButton") onready var vsyncbutton := find_node("VsyncButton") |