Phase 14 - Organized directories.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
class_name CliSceneLauncher
|
||||
extends RefCounted
|
||||
## Pure command-line argument parser for the Sandbox Stage scene loader.
|
||||
## No scene-tree or OS access, so it is directly unit-testable. Parses
|
||||
## OS.get_cmdline_user_args() output into a structured {scene_path, play, error}
|
||||
## result; the caller (SandboxStage) is responsible for the error dialog and
|
||||
## autosave policy.
|
||||
|
||||
const CONTENT_PATHS := preload("res://scripts/shared/content_paths.gd")
|
||||
|
||||
static func parse(args: Array) -> Dictionary:
|
||||
var scene_path := ""
|
||||
var play := false
|
||||
var used_scene_flag := false
|
||||
var used_positional := false
|
||||
var error := ""
|
||||
var i := 0
|
||||
while i < args.size():
|
||||
var token := String(args[i])
|
||||
if token == "--play":
|
||||
play = true
|
||||
elif token == "--scene":
|
||||
used_scene_flag = true
|
||||
if i + 1 >= args.size():
|
||||
return {"scene_path": "", "play": play, "error": "--scene requires a path."}
|
||||
var value := String(args[i + 1])
|
||||
if value.is_empty():
|
||||
return {"scene_path": "", "play": play, "error": "--scene requires a path."}
|
||||
scene_path = value
|
||||
i += 1
|
||||
elif token.begins_with("--scene="):
|
||||
used_scene_flag = true
|
||||
var value := token.substr("--scene=".length())
|
||||
if value.is_empty():
|
||||
return {"scene_path": "", "play": play, "error": "--scene requires a path."}
|
||||
scene_path = value
|
||||
elif token.begins_with("--"):
|
||||
return {"scene_path": "", "play": play, "error": "Unknown option: %s" % token}
|
||||
else:
|
||||
if used_positional:
|
||||
return {"scene_path": "", "play": play, "error": "Specify the scene with either --scene or a single positional path."}
|
||||
used_positional = true
|
||||
scene_path = token
|
||||
i += 1
|
||||
if used_scene_flag and used_positional:
|
||||
error = "Specify the scene with either --scene or a single positional path."
|
||||
elif play and scene_path.is_empty():
|
||||
error = "--play requires --scene <path>."
|
||||
return {"scene_path": CONTENT_PATHS.canonicalize(scene_path), "play": play, "error": error}
|
||||
Reference in New Issue
Block a user