From e2f5f2e38a00fa4b0688440b5f0e560a552b162a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 15 Oct 2025 23:02:34 +0200 Subject: Camera recorder cli --- client/game.gd | 2 +- client/player/camera_recorder.gd | 6 ++++-- client/player/follow_camera.tscn | 2 +- client/system/cli.gd | 15 ++++++++++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/client/game.gd b/client/game.gd index b4221fd3..8edd4f8c 100644 --- a/client/game.gd +++ b/client/game.gd @@ -420,7 +420,7 @@ func _process(delta): update_center() if is_replay and mp != null: - mp.send_replay_tick(delta) + mp.send_replay_tick(delta * float(Cli.opts.get("timescale", "1"))) func get_tile_collision(pos: Vector2i) -> bool: var t = map.get_tile_name(pos) diff --git a/client/player/camera_recorder.gd b/client/player/camera_recorder.gd index 8f398c2b..a599af7b 100644 --- a/client/player/camera_recorder.gd +++ b/client/player/camera_recorder.gd @@ -25,7 +25,9 @@ var time = 0. var keyframes = [] # Array<[float, Transform3D]> func _ready() -> void: - if record and replay: return push_error("concurrent ecord and replay is not supported") + if Cli.opts.has("record-camera"): record = true; recording_path = Cli.opts["record-camera"] + if Cli.opts.has("replay-camera"): replay = true; recording_path = Cli.opts["replay-camera"] + if record and replay: return push_error("concurrent record and replay is not supported") if replay: load_recording() func _exit_tree() -> void: @@ -80,7 +82,7 @@ func parse_transform(s: String) -> Transform3D: func _process(dt: float): if Global.game_paused: return - time += dt + time += dt * float(Cli.opts.get("timescale", "1")) if record: keyframes.push_back([time, camera.global_transform, camera.fov]) if replay: var index = keyframes.bsearch_custom([time], func (a, b): return a[0] < b[0]) diff --git a/client/player/follow_camera.tscn b/client/player/follow_camera.tscn index f2f1138c..ac0040c9 100644 --- a/client/player/follow_camera.tscn +++ b/client/player/follow_camera.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=3 uid="uid://b31mlnao6ybt8"] [ext_resource type="Script" uid="uid://eieoab04mpqc" path="res://player/follow_camera.gd" id="1_qipju"] -[ext_resource type="Script" path="res://player/camera_recorder.gd" id="2_12um7"] +[ext_resource type="Script" uid="uid://b7wqp72o1bxvu" path="res://player/camera_recorder.gd" id="2_12um7"] [node name="FollowCamera" type="Camera3D"] fov = 45.0 diff --git a/client/system/cli.gd b/client/system/cli.gd index d503d536..befd9f10 100644 --- a/client/system/cli.gd +++ b/client/system/cli.gd @@ -33,6 +33,10 @@ static var OPTIONS := [ Option.new(null, "render-tiles", Mode.OPTION, "Render tiles from text file to images"), Option.new(null, "render-resolution", Mode.OPTION, "Resolution for rendering items or tiles"), Option.new(null, "render-output", Mode.OPTION, "Output directory for rendering items or tiles"), + Option.new(null, "record-camera", Mode.OPTION, "Record camera movement to file"), + Option.new(null, "replay-camera", Mode.OPTION, "Replay camera movement"), + Option.new(null, "timescale", Mode.OPTION, "Time scaling factor for replay playback and camera recorder"), + Option.new(null, "render-output", Mode.OPTION, "Output directory for rendering items or tiles"), Option.new(null, "connect_address", Mode.POSITIONAL, "Connect to a server directly without menu interaction") ] @@ -60,10 +64,11 @@ static func print_help(): line += " " + opt.help print(line) +static var args: Array static func parse() -> bool: - var args := OS.get_cmdline_user_args() + args = Array(OS.get_cmdline_user_args()) while not args.is_empty(): - var arg := args[0] + var arg = args[0] args.remove_at(0) if arg.begins_with("--"): var long = arg.trim_prefix("--") @@ -71,14 +76,14 @@ static func parse() -> bool: if opt_index == -1: push_error("unknown long option \"%s\"" % long) return false - if not _parse_opt(args, OPTIONS[opt_index]): return false + if not _parse_opt(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 + if not _parse_opt(OPTIONS[opt_index]): return false else: var opt_index = OPTIONS.find_custom(func(x): return x.mode == Mode.POSITIONAL) if opt_index == -1: @@ -90,7 +95,7 @@ static func parse() -> bool: print("Parsed options: ", opts) return true -static func _parse_opt(args: Array[String], opt: Option) -> bool: +static func _parse_opt(opt: Option) -> bool: match opt.mode: Mode.FLAG: opts[opt.long] = true -- cgit v1.3