Phase 1a: GameState-Logik, Save/Load, Hauptmenue, Imogen-Testfall
- GameState: Stats, Klinge-Herz-Achse, Beziehungen, Menschlichkeit, Permadeath inkl. Klemmung, Signalen und Save-Serialisierung - RelationshipSystem als Zugriffs-Fassade ueber GameState - SaveSystem: JSON-Save/Load nach user:// mit Fehlerbehandlung - Hauptmenue (neue Main Scene): Start/Fortsetzen/Beenden, fokus-navigierbar mit Tastatur und Controller, Fortsetzen nur bei vorhandenem Save - Imogen-Platzhalter in test_ground: Area3D-Trigger, Prompt, Konsolen-Zeile, Beziehungs-Zuwachs (NPC-ID imogen) mit 2-s-Cooldown - Debug-Overlay: Stats, Klinge-Herz, Beziehung Imogen, Permadeath - Interim: menu-Action in der Testszene speichert und kehrt ins Menue zurueck - Input-Map: slide (C/L2) und jump (Leertaste/A-Kreuz) laut neuer SPEC 9 verdrahtet, Mechanik folgt in Phase 1b - SPEC-Update (Roadmap, slide/jump) und Phase-1a-Prompt eingecheckt Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
06ab09dfdd
commit
df795ef40d
12 changed files with 523 additions and 28 deletions
|
|
@ -1,7 +1,128 @@
|
|||
extends Node
|
||||
## Zentraler Spielzustand (Autoload, SPEC.md Abschnitt 8).
|
||||
## Zentraler Spielzustand (Autoload, SPEC.md Abschnitte 6 und 8).
|
||||
##
|
||||
## Hält ab Phase 1 den Zustand eines Durchlaufs: Spieler-Stats (Kraft,
|
||||
## Schnelligkeit, Verstand), den Klinge-↔-Herz-Ton-Wert (-100..+100), den
|
||||
## verdeckten Menschlichkeits-Messwert, den Permadeath-Toggle (Default AN)
|
||||
## sowie globale Spiel-Flags. Phase 0: leeres Skelett ohne Logik.
|
||||
## Hält den Zustand eines Durchlaufs: Stats (Kraft/Schnelligkeit/Verstand),
|
||||
## Klinge-↔-Herz-Ton-Wert, Beziehungswerte pro NPC, den verdeckten
|
||||
## Menschlichkeits-Messwert und den Permadeath-Toggle. Die Beziehungsdaten
|
||||
## liegen laut SPEC-Roadmap (Phase 1) hier; RelationshipSystem ist die
|
||||
## Zugriffs-Fassade darüber. SaveSystem serialisiert den kompletten Zustand
|
||||
## über to_save_dict()/apply_save_dict(). Startwerte nach SPEC Abschnitt 4:
|
||||
## solide Kraft und Schnelligkeit, Verstand wächst übers Spiel.
|
||||
|
||||
signal blade_heart_tone_changed(new_tone: int)
|
||||
signal relationship_changed(npc_id: String, new_value: int)
|
||||
|
||||
const STAT_MIN := 0
|
||||
const STAT_MAX := 100
|
||||
const TONE_MIN := -100
|
||||
const TONE_MAX := 100
|
||||
const RELATIONSHIP_MIN := -100
|
||||
const RELATIONSHIP_MAX := 100
|
||||
const HUMANITY_MIN := -100
|
||||
const HUMANITY_MAX := 100
|
||||
const DEFAULT_STRENGTH := 35
|
||||
const DEFAULT_AGILITY := 35
|
||||
const DEFAULT_INTELLECT := 15
|
||||
|
||||
var strength := DEFAULT_STRENGTH
|
||||
var agility := DEFAULT_AGILITY
|
||||
var intellect := DEFAULT_INTELLECT
|
||||
var blade_heart_tone := 0
|
||||
var humanity := 0
|
||||
var relationships: Dictionary = {}
|
||||
var is_permadeath_enabled := true
|
||||
|
||||
|
||||
## Setzt alle Werte auf die Startwerte eines neuen Spiels zurück.
|
||||
func reset() -> void:
|
||||
strength = DEFAULT_STRENGTH
|
||||
agility = DEFAULT_AGILITY
|
||||
intellect = DEFAULT_INTELLECT
|
||||
blade_heart_tone = 0
|
||||
humanity = 0
|
||||
relationships.clear()
|
||||
is_permadeath_enabled = true
|
||||
blade_heart_tone_changed.emit(blade_heart_tone)
|
||||
|
||||
|
||||
## Erhöht einen Stat um amount (negativ = senken) und klemmt ihn auf
|
||||
## STAT_MIN..STAT_MAX. Gültige Namen: "strength", "agility", "intellect".
|
||||
func increase_stat(stat_name: String, amount: int) -> void:
|
||||
match stat_name:
|
||||
"strength":
|
||||
strength = clampi(strength + amount, STAT_MIN, STAT_MAX)
|
||||
"agility":
|
||||
agility = clampi(agility + amount, STAT_MIN, STAT_MAX)
|
||||
"intellect":
|
||||
intellect = clampi(intellect + amount, STAT_MIN, STAT_MAX)
|
||||
_:
|
||||
push_warning("Unbekannter Stat: %s" % stat_name)
|
||||
|
||||
|
||||
## Verschiebt den Klinge-↔-Herz-Ton-Wert um amount (negativ = Klinge,
|
||||
## positiv = Herz), klemmt auf TONE_MIN..TONE_MAX und meldet Änderungen
|
||||
## über blade_heart_tone_changed.
|
||||
func shift_blade_heart_tone(amount: int) -> void:
|
||||
var new_tone := clampi(blade_heart_tone + amount, TONE_MIN, TONE_MAX)
|
||||
if new_tone != blade_heart_tone:
|
||||
blade_heart_tone = new_tone
|
||||
blade_heart_tone_changed.emit(blade_heart_tone)
|
||||
|
||||
|
||||
## Verschiebt den verdeckten Menschlichkeits-Messwert mit Klemmung.
|
||||
## Bewusst ohne Signal und ohne UI-Anzeige: in v1 wird der Wert laut SPEC
|
||||
## nur gesammelt.
|
||||
func shift_humanity(amount: int) -> void:
|
||||
humanity = clampi(humanity + amount, HUMANITY_MIN, HUMANITY_MAX)
|
||||
|
||||
|
||||
## Liefert den Beziehungswert zur NPC-ID, 0 für unbekannte NPCs.
|
||||
func get_relationship(npc_id: String) -> int:
|
||||
return relationships.get(npc_id, 0)
|
||||
|
||||
|
||||
## Setzt den Beziehungswert absolut, klemmt auf RELATIONSHIP_MIN..MAX und
|
||||
## meldet Änderungen über relationship_changed.
|
||||
func set_relationship(npc_id: String, value: int) -> void:
|
||||
var new_value := clampi(value, RELATIONSHIP_MIN, RELATIONSHIP_MAX)
|
||||
if get_relationship(npc_id) != new_value:
|
||||
relationships[npc_id] = new_value
|
||||
relationship_changed.emit(npc_id, new_value)
|
||||
|
||||
|
||||
## Verschiebt den Beziehungswert relativ um amount (mit Klemmung).
|
||||
func adjust_relationship(npc_id: String, amount: int) -> void:
|
||||
set_relationship(npc_id, get_relationship(npc_id) + amount)
|
||||
|
||||
|
||||
## Serialisiert den kompletten Zustand als Dictionary für das SaveSystem.
|
||||
func to_save_dict() -> Dictionary:
|
||||
return {
|
||||
"strength": strength,
|
||||
"agility": agility,
|
||||
"intellect": intellect,
|
||||
"blade_heart_tone": blade_heart_tone,
|
||||
"humanity": humanity,
|
||||
"relationships": relationships.duplicate(),
|
||||
"is_permadeath_enabled": is_permadeath_enabled,
|
||||
}
|
||||
|
||||
|
||||
## Stellt den Zustand aus einem Save-Dictionary wieder her. Fehlende
|
||||
## Schlüssel fallen auf Startwerte zurück, JSON-Zahlen werden auf int
|
||||
## normalisiert und alle Werte geklemmt; Änderungs-Signale werden nach dem
|
||||
## Laden ausgelöst.
|
||||
func apply_save_dict(data: Dictionary) -> void:
|
||||
strength = clampi(int(data.get("strength", DEFAULT_STRENGTH)), STAT_MIN, STAT_MAX)
|
||||
agility = clampi(int(data.get("agility", DEFAULT_AGILITY)), STAT_MIN, STAT_MAX)
|
||||
intellect = clampi(int(data.get("intellect", DEFAULT_INTELLECT)), STAT_MIN, STAT_MAX)
|
||||
blade_heart_tone = clampi(int(data.get("blade_heart_tone", 0)), TONE_MIN, TONE_MAX)
|
||||
humanity = clampi(int(data.get("humanity", 0)), HUMANITY_MIN, HUMANITY_MAX)
|
||||
is_permadeath_enabled = bool(data.get("is_permadeath_enabled", true))
|
||||
relationships.clear()
|
||||
var saved_relationships: Dictionary = data.get("relationships", {})
|
||||
for npc_id in saved_relationships:
|
||||
relationships[String(npc_id)] = clampi(int(saved_relationships[npc_id]), RELATIONSHIP_MIN, RELATIONSHIP_MAX)
|
||||
blade_heart_tone_changed.emit(blade_heart_tone)
|
||||
for npc_id in relationships:
|
||||
relationship_changed.emit(npc_id, relationships[npc_id])
|
||||
|
|
|
|||
|
|
@ -1,7 +1,25 @@
|
|||
extends Node
|
||||
## Beziehungswerte pro NPC (Autoload, SPEC.md Abschnitte 6 und 8).
|
||||
## Zugriffs-Fassade für NPC-Beziehungswerte (Autoload, SPEC.md Abschnitte 6
|
||||
## und 8).
|
||||
##
|
||||
## Führt ab Phase 4 pro NPC einen Beziehungswert (-100..+100), der durch
|
||||
## Dialoge und Aktivitäten steigt oder fällt und Reaktionen sowie
|
||||
## Story-Verzweigungen färbt (z. B. Imogen unter Druck, Wren-Bindung).
|
||||
## Phase 0: leeres Skelett ohne Logik.
|
||||
## Die Beziehungsdaten selbst liegen laut SPEC-Roadmap (Phase 1) im
|
||||
## GameState und werden dort gespeichert und geladen. Gameplay-Code greift
|
||||
## ausschließlich über diese Fassade zu; ab Phase 2 wächst sie um Logik wie
|
||||
## Schwellenwerte und Reaktionsstufen. Änderungen meldet
|
||||
## GameState.relationship_changed. NPC-IDs sind snake_case-Strings, z. B.
|
||||
## "imogen".
|
||||
|
||||
|
||||
## Liefert den Beziehungswert (-100..100) zur NPC-ID, 0 für unbekannte NPCs.
|
||||
func get_relationship(npc_id: String) -> int:
|
||||
return GameState.get_relationship(npc_id)
|
||||
|
||||
|
||||
## Setzt den Beziehungswert absolut (geklemmt auf -100..100).
|
||||
func set_relationship(npc_id: String, value: int) -> void:
|
||||
GameState.set_relationship(npc_id, value)
|
||||
|
||||
|
||||
## Verschiebt den Beziehungswert relativ um amount (geklemmt auf -100..100).
|
||||
func adjust_relationship(npc_id: String, amount: int) -> void:
|
||||
GameState.adjust_relationship(npc_id, amount)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,50 @@
|
|||
extends Node
|
||||
## Speichern und Laden von Spielständen (Autoload, SPEC.md Abschnitte 6 und 8).
|
||||
## Speichern und Laden von Spielständen (Autoload, SPEC.md Abschnitte 6
|
||||
## und 8).
|
||||
##
|
||||
## Serialisiert ab Phase 1 den Zustand der übrigen Systeme in Spielstände und
|
||||
## stellt ihn wieder her. Berücksichtigt später den Permadeath-Modus (Ironman)
|
||||
## gegenüber dem Story-Modus mit Checkpoints. Phase 0: leeres Skelett ohne
|
||||
## Logik.
|
||||
## Serialisiert den kompletten GameState (Stats, Klinge-↔-Herz-Ton-Wert,
|
||||
## Beziehungen, Menschlichkeit, Permadeath-Flag) als JSON nach user://.
|
||||
## Die Unterscheidung Ironman vs. Story-Modus mit Checkpoints folgt in einer
|
||||
## späteren Phase.
|
||||
|
||||
const SAVE_PATH := "user://savegame.json"
|
||||
|
||||
|
||||
## Gibt zurück, ob ein Spielstand existiert.
|
||||
func has_save() -> bool:
|
||||
return FileAccess.file_exists(SAVE_PATH)
|
||||
|
||||
|
||||
## Schreibt den kompletten GameState als JSON nach SAVE_PATH.
|
||||
## Liefert true bei Erfolg, sonst false mit Fehlermeldung im Log.
|
||||
func save_game() -> bool:
|
||||
var file := FileAccess.open(SAVE_PATH, FileAccess.WRITE)
|
||||
if file == null:
|
||||
push_error("Spielstand konnte nicht geschrieben werden: %s" % error_string(FileAccess.get_open_error()))
|
||||
return false
|
||||
file.store_string(JSON.stringify(GameState.to_save_dict(), "\t"))
|
||||
file.close()
|
||||
print("Spielstand gespeichert: %s" % SAVE_PATH)
|
||||
return true
|
||||
|
||||
|
||||
## Lädt den Spielstand aus SAVE_PATH in den GameState. Liefert false, wenn
|
||||
## keine Datei existiert, sie nicht lesbar ist oder kein gültiges
|
||||
## JSON-Objekt enthält.
|
||||
func load_game() -> bool:
|
||||
if not has_save():
|
||||
push_warning("Kein Spielstand vorhanden unter %s" % SAVE_PATH)
|
||||
return false
|
||||
var file := FileAccess.open(SAVE_PATH, FileAccess.READ)
|
||||
if file == null:
|
||||
push_error("Spielstand konnte nicht geöffnet werden: %s" % error_string(FileAccess.get_open_error()))
|
||||
return false
|
||||
var raw_text := file.get_as_text()
|
||||
file.close()
|
||||
var parsed: Variant = JSON.parse_string(raw_text)
|
||||
if not (parsed is Dictionary):
|
||||
push_error("Spielstand ist beschädigt (kein gültiges JSON-Objekt): %s" % SAVE_PATH)
|
||||
return false
|
||||
GameState.apply_save_dict(parsed)
|
||||
print("Spielstand geladen: %s" % SAVE_PATH)
|
||||
return true
|
||||
|
|
|
|||
60
scripts/gameplay/npc_placeholder.gd
Normal file
60
scripts/gameplay/npc_placeholder.gd
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
extends StaticBody3D
|
||||
## Platzhalter-NPC für Phase 1a — minimaler Testfall für die
|
||||
## Beziehungswerte, bewusst ohne das Dialog-System aus Phase 2.
|
||||
##
|
||||
## Zeigt in Reichweite (Area3D-Trigger) einen Interaktions-Prompt, gibt bei
|
||||
## der interact-Action eine fest hinterlegte Zeile in der Godot-Konsole aus
|
||||
## und erhöht den Beziehungswert der konfigurierten NPC-ID über
|
||||
## RelationshipSystem um relationship_gain. Ein Cooldown verhindert, dass
|
||||
## Spam-Interaktion den Wert durchknallt. NPC-ID-Konvention für Phase 2:
|
||||
## snake_case, z. B. "imogen".
|
||||
|
||||
const INTERACTION_COOLDOWN_MS := 2000
|
||||
|
||||
@export var npc_id := "imogen"
|
||||
@export var display_name := "Imogen"
|
||||
@export var placeholder_line := "Immer noch in einem Stück? Gut. Erspar mir die Sorge, Tyrveil."
|
||||
@export var relationship_gain := 2
|
||||
|
||||
var _is_player_in_range := false
|
||||
var _last_interaction_ms := -INTERACTION_COOLDOWN_MS
|
||||
|
||||
@onready var _prompt_label: Label3D = $PromptLabel
|
||||
@onready var _interaction_area: Area3D = $InteractionArea
|
||||
|
||||
|
||||
## Verbindet die Reichweiten-Signale des Area3D-Triggers.
|
||||
func _ready() -> void:
|
||||
_interaction_area.body_entered.connect(_on_body_entered)
|
||||
_interaction_area.body_exited.connect(_on_body_exited)
|
||||
|
||||
|
||||
## Löst die Interaktion aus, wenn der Spieler in Reichweite ist, interact
|
||||
## gedrückt wird und der Cooldown abgelaufen ist.
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if not _is_player_in_range:
|
||||
return
|
||||
if not event.is_action_pressed("interact"):
|
||||
return
|
||||
if Time.get_ticks_msec() - _last_interaction_ms < INTERACTION_COOLDOWN_MS:
|
||||
return
|
||||
_interact()
|
||||
|
||||
|
||||
## Konsolen-Ausgabe als Dialog-Platzhalter plus Beziehungs-Zuwachs.
|
||||
func _interact() -> void:
|
||||
_last_interaction_ms = Time.get_ticks_msec()
|
||||
print("%s: %s" % [display_name, placeholder_line])
|
||||
RelationshipSystem.adjust_relationship(npc_id, relationship_gain)
|
||||
|
||||
|
||||
## Blendet den Prompt ein, sobald der Spieler die Reichweite betritt.
|
||||
func _on_body_entered(_body: Node3D) -> void:
|
||||
_is_player_in_range = true
|
||||
_prompt_label.visible = true
|
||||
|
||||
|
||||
## Blendet den Prompt aus, wenn der Spieler die Reichweite verlässt.
|
||||
func _on_body_exited(_body: Node3D) -> void:
|
||||
_is_player_in_range = false
|
||||
_prompt_label.visible = false
|
||||
15
scripts/gameplay/test_ground.gd
Normal file
15
scripts/gameplay/test_ground.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extends Node3D
|
||||
## Ablauf-Steuerung der Greybox-Testszene (Phase 1a).
|
||||
##
|
||||
## Interims-Lösung, bis Phase 1b den Greybox-Hub mit Schlafsaal-Save
|
||||
## bringt: Die menu-Action (Tab/Start) speichert den Spielstand über das
|
||||
## SaveSystem und kehrt ins Hauptmenü zurück.
|
||||
|
||||
const MAIN_MENU_SCENE := "res://scenes/ui/main_menu.tscn"
|
||||
|
||||
|
||||
## Speichert bei menu und wechselt zurück ins Hauptmenü.
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("menu"):
|
||||
SaveSystem.save_game()
|
||||
get_tree().change_scene_to_file(MAIN_MENU_SCENE)
|
||||
|
|
@ -2,11 +2,15 @@ extends CanvasLayer
|
|||
## Debug-Overlay für Phase 0.
|
||||
##
|
||||
## Zeigt FPS, das zuletzt benutzte Eingabegerät (Tastatur/Maus, Xbox- oder
|
||||
## PS5-Controller), die Spielerposition und die aktuelle Kamera-Distanz an.
|
||||
## PS5-Controller), die Spielerposition, die aktuelle Kamera-Distanz sowie
|
||||
## seit Phase 1a die GameState-Werte: Stats, Klinge-↔-Herz-Ton-Wert,
|
||||
## Beziehungswert zu Imogen und Permadeath-Status. Der verdeckte
|
||||
## Menschlichkeits-Messwert wird laut SPEC bewusst NICHT angezeigt.
|
||||
## Die provisorische Geräteerkennung wandert in einer späteren Phase in das
|
||||
## Autoload InputPrompts (dynamische Button-Prompts, SPEC.md Abschnitt 2).
|
||||
|
||||
const JOY_MOTION_THRESHOLD := 0.2
|
||||
const IMOGEN_NPC_ID := "imogen"
|
||||
const PLAYSTATION_NAME_HINTS: Array[String] = [
|
||||
"ps5", "ps4", "dualsense", "dualshock", "sony", "playstation",
|
||||
]
|
||||
|
|
@ -45,6 +49,10 @@ func _process(_delta: float) -> void:
|
|||
lines.append("Position: (%.1f, %.1f, %.1f)" % [pos.x, pos.y, pos.z])
|
||||
if _player.has_method("get_camera_zoom"):
|
||||
lines.append("Kamera-Zoom: %.1f m" % _player.get_camera_zoom())
|
||||
lines.append("Kraft: %d Schnelligkeit: %d Verstand: %d" % [GameState.strength, GameState.agility, GameState.intellect])
|
||||
lines.append("Klinge <-> Herz: %+d" % GameState.blade_heart_tone)
|
||||
lines.append("Beziehung Imogen: %+d" % RelationshipSystem.get_relationship(IMOGEN_NPC_ID))
|
||||
lines.append("Permadeath: %s" % ("AN" if GameState.is_permadeath_enabled else "AUS"))
|
||||
_info_label.text = "\n".join(lines)
|
||||
|
||||
|
||||
|
|
|
|||
50
scripts/ui/main_menu.gd
Normal file
50
scripts/ui/main_menu.gd
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
extends Control
|
||||
## Minimalistisches Hauptmenü (Phase 1a, SPEC.md Phasen-Roadmap).
|
||||
##
|
||||
## Start setzt den GameState auf ein neues Spiel zurück und lädt die
|
||||
## Greybox-Testszene. Fortsetzen ist nur sichtbar, wenn ein Spielstand
|
||||
## existiert, und lädt ihn über SaveSystem. Beenden schließt das Spiel.
|
||||
## Vollständig fokus-navigierbar mit Tastatur und Controller: Die
|
||||
## confirm-Belegung (Enter/Ⓐ/✕) deckt sich physisch mit Godots ui_accept,
|
||||
## Pfeiltasten/D-Pad/linker Stick bewegen den Fokus, cancel (Esc/Ⓑ/◯)
|
||||
## springt auf den Beenden-Button.
|
||||
|
||||
const GAME_SCENE := "res://scenes/test_ground.tscn"
|
||||
|
||||
@onready var _start_button: Button = $CenterContainer/VBoxContainer/StartButton
|
||||
@onready var _continue_button: Button = $CenterContainer/VBoxContainer/ContinueButton
|
||||
@onready var _quit_button: Button = $CenterContainer/VBoxContainer/QuitButton
|
||||
|
||||
|
||||
## Gibt die Maus frei, blendet Fortsetzen je nach Save-Existenz ein,
|
||||
## verbindet die Buttons und setzt den Start-Fokus.
|
||||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
_continue_button.visible = SaveSystem.has_save()
|
||||
_start_button.pressed.connect(_on_start_pressed)
|
||||
_continue_button.pressed.connect(_on_continue_pressed)
|
||||
_quit_button.pressed.connect(_on_quit_pressed)
|
||||
_start_button.grab_focus()
|
||||
|
||||
|
||||
## Springt mit cancel auf den Beenden-Button.
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("cancel"):
|
||||
_quit_button.grab_focus()
|
||||
|
||||
|
||||
## Startet ein neues Spiel mit frisch zurückgesetztem GameState.
|
||||
func _on_start_pressed() -> void:
|
||||
GameState.reset()
|
||||
get_tree().change_scene_to_file(GAME_SCENE)
|
||||
|
||||
|
||||
## Lädt den Spielstand und wechselt bei Erfolg in die Testszene.
|
||||
func _on_continue_pressed() -> void:
|
||||
if SaveSystem.load_game():
|
||||
get_tree().change_scene_to_file(GAME_SCENE)
|
||||
|
||||
|
||||
## Beendet das Spiel.
|
||||
func _on_quit_pressed() -> void:
|
||||
get_tree().quit()
|
||||
Loading…
Add table
Add a link
Reference in a new issue