ab81f66ef0
F2 wechselt im Spiel den Stil und meldet ihn, --style=NAME wählt ihn beim Start, und das Spiel merkt sich die Wahl in den Einstellungen. Das Bildschirmfoto-Werkzeug nimmt Bilder in einem bestimmten Stil und von der Vitrine auf und zeigt eine zweite Figur mit Namen. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
84 lines
2.8 KiB
GDScript
84 lines
2.8 KiB
GDScript
class_name LaunchOptions
|
|
extends RefCounted
|
|
## What the command line asks for. Godot passes the arguments after "--":
|
|
## --profile=NAME keeps key, save and recordings in a folder of their own,
|
|
## so that two windows on one machine are two players
|
|
## --name=NAME the player's name; like a name typed in the menu, it is
|
|
## remembered for the next start
|
|
## --solo starts playing alone at once, without the menu
|
|
## --host opens the world for guests at once
|
|
## --port=PORT the port an open world listens on
|
|
## --join=ADDRESS joins a host at once; ADDRESS may end in ":PORT"
|
|
## --style=NAME draws the playing field in the style NAME: warm,
|
|
## pastel or glow
|
|
|
|
## Longest profile name.
|
|
const MAX_PROFILE_LENGTH := 32
|
|
## Characters a profile name may contain.
|
|
const PROFILE_CHARACTERS := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
|
|
|
|
var profile := ""
|
|
var player_name := ""
|
|
## How to start without the menu: "", "solo", "host" or "join".
|
|
var start := ""
|
|
var port := NetLink.DEFAULT_PORT
|
|
var address := ""
|
|
## The style to draw in, or empty for the one in the settings.
|
|
var style := &""
|
|
## Arguments that were not understood and are ignored.
|
|
var ignored := PackedStringArray()
|
|
|
|
|
|
## Reads `arguments`. Unknown arguments and bad values end up in `ignored`.
|
|
static func parse(arguments: PackedStringArray) -> LaunchOptions:
|
|
var options := LaunchOptions.new()
|
|
for argument in arguments:
|
|
var value := argument.get_slice("=", 1) if argument.contains("=") else ""
|
|
match argument.get_slice("=", 0):
|
|
"--profile":
|
|
if is_valid_profile(value):
|
|
options.profile = value
|
|
else:
|
|
options.ignored.append(argument)
|
|
"--name":
|
|
options.player_name = value
|
|
"--solo":
|
|
options.start = "solo"
|
|
"--host":
|
|
options.start = "host"
|
|
"--port":
|
|
if value.is_valid_int() and value.to_int() >= 0 and value.to_int() <= 65535:
|
|
options.port = value.to_int()
|
|
else:
|
|
options.ignored.append(argument)
|
|
"--join":
|
|
options.start = "join"
|
|
options.address = value
|
|
"--style":
|
|
if Art.style_keys().has(StringName(value)):
|
|
options.style = StringName(value)
|
|
else:
|
|
options.ignored.append(argument)
|
|
_:
|
|
options.ignored.append(argument)
|
|
return options
|
|
|
|
|
|
## Whether `name` can name a profile folder: up to 32 of the letters A to Z,
|
|
## digits, "-" and "_".
|
|
static func is_valid_profile(name: String) -> bool:
|
|
if name.is_empty() or name.length() > MAX_PROFILE_LENGTH:
|
|
return false
|
|
for character in name:
|
|
if not PROFILE_CHARACTERS.contains(character):
|
|
return false
|
|
return true
|
|
|
|
|
|
## The folder for the player's files. The default profile uses the user
|
|
## folder itself, so that saves of earlier versions stay where they are.
|
|
func storage_dir() -> String:
|
|
if profile.is_empty():
|
|
return "user://"
|
|
return "user://profiles".path_join(profile)
|