game: Engine-Gerüst mit datengetriebenen Inhalten; Titelgrafik über fal
Godot-Projekt nach docs/engine.md: 640x360-Viewport, stretch=viewport, scale_mode=integer, 1x-Assets in game/assets/. Autoloads Content (laden und prüfen), Rules (Effekt-Vokabel), Game (Party, Ort, abgeleitete Werte), Saves (versionierter Spielstand, nur Eingaben). Inhalte liegen vollständig als JSON in game/data/ und werden gegen _schema.json geprüft: 4 Völker, 4 Klassen, 9 Fertigkeiten, 16 Fähigkeiten, 18 Zauber, 11 Gegenstände, 8 Gegner, 4 Begegnungen, 3 NSC, 1 Karte (20x11). Die Engine nennt keine Klasse und keinen Zauber beim Namen — alles über ids, Verhalten ausschließlich über 13 Effekt-ops. Beim ersten Content-Durchlauf ist die Vokabel um turn_undead und immunity gewachsen, bonus kennt multiplier; genau das war der Zweck der Übung. Zwei Prüfer, eine Wahrheit: tools/validate_data.py (ohne Godot, für Commit/CI) und ContentDB beim Start. Beide lesen dieselbe _schema.json; unbekanntes op oder fehlender Verweis bricht ab statt still zu wirken. Selbstprüfung im Projekt (godot --headless --path game -- --check) ist grün: Daten geladen, Würfel 2d6+1, Modifikator, Effekt Magisches Geschoss, Spielstand schreiben/lesen/identisch, Font im Engine-Raster (2 Zeichen = 16 px, Zeile 12). Letzteres belegt erstmals, dass der BMFont-Export aus art/final/Font in der Engine sitzt. Titelgrafik über fal (FLUX.2 [pro], 1536x864, Seed 771201, 0,04 USD, request_id 01a1dc5a-871a-7511-b8f8-571988a47c18): zwei vermummte Pilger vor dem Tor von Garana. Der erste Lauf (Seed 20261115) zeigte moderne Wanderer mit Rucksäcken und ist verworfen; beide stehen im Lizenzlog. pixelize.py bekam --crop, weil das Modell eine Signatur in die Ecke malt. Achtung: das Projekt wurde headless importiert (godot --import); die *.import-Dateien gehören ins Repo, .godot/ nicht. Für den Export muss include_filter="*.json" gesetzt werden, sonst fehlen die Inhalte im Build.
This commit is contained in:
parent
8ed8f4bbf6
commit
6114bef956
99 changed files with 4777 additions and 28 deletions
59
game/scripts/core/dice.gd
Normal file
59
game/scripts/core/dice.gd
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
class_name Dice
|
||||
extends RefCounted
|
||||
## Würfelausdrücke aus Daten: "d20", "1d8", "2d6+1", "1d4-1".
|
||||
##
|
||||
## Alles, was in game/data/ als Schaden, Heilung oder Zauberwurf steht, geht
|
||||
## durch `roll()`. Ein Ausdruck, der nicht passt, ist ein Datenfehler und
|
||||
## bricht laut ab — nicht still auf 0.
|
||||
|
||||
## "2d6+1" -> {"count": 2, "sides": 6, "bonus": 1}
|
||||
static func parse(expr: String) -> Dictionary:
|
||||
var text := expr.strip_edges().to_lower()
|
||||
var bonus := 0
|
||||
var split_at := text.find("+")
|
||||
if split_at < 0:
|
||||
split_at = text.find("-")
|
||||
if split_at > 0:
|
||||
bonus = int(text.substr(split_at))
|
||||
text = text.substr(0, split_at)
|
||||
var parts := text.split("d")
|
||||
assert(parts.size() == 2, "Würfelausdruck unbrauchbar: %s" % expr)
|
||||
var count := 1 if parts[0] == "" else int(parts[0])
|
||||
var sides := int(parts[1])
|
||||
assert(count >= 1 and sides >= 2, "Würfelausdruck unbrauchbar: %s" % expr)
|
||||
return {"count": count, "sides": sides, "bonus": bonus}
|
||||
|
||||
|
||||
static func roll(expr: String) -> int:
|
||||
var d := parse(expr)
|
||||
var total: int = int(d["bonus"])
|
||||
for i in int(d["count"]):
|
||||
total += randi_range(1, d["sides"])
|
||||
return total
|
||||
|
||||
|
||||
static func minimum(expr: String) -> int:
|
||||
var d := parse(expr)
|
||||
return int(d["count"]) + int(d["bonus"])
|
||||
|
||||
|
||||
static func maximum(expr: String) -> int:
|
||||
var d := parse(expr)
|
||||
return int(d["count"]) * int(d["sides"]) + int(d["bonus"])
|
||||
|
||||
|
||||
## Attributsmodifikator 3-18 -> -3..+3 (docs/systeme.md §1).
|
||||
static func modifier(value: int) -> int:
|
||||
if value <= 3:
|
||||
return -3
|
||||
if value <= 5:
|
||||
return -2
|
||||
if value <= 8:
|
||||
return -1
|
||||
if value <= 12:
|
||||
return 0
|
||||
if value <= 15:
|
||||
return 1
|
||||
if value <= 17:
|
||||
return 2
|
||||
return 3
|
||||
1
game/scripts/core/dice.gd.uid
Normal file
1
game/scripts/core/dice.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://clykeriu40x5n
|
||||
205
game/scripts/data/content_db.gd
Normal file
205
game/scripts/data/content_db.gd
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
extends Node
|
||||
## ContentDB (Autoload `Content`) — lädt game/data/ und prüft, bevor gespielt wird.
|
||||
##
|
||||
## Aufbau und Begründung: docs/engine.md §3/§4. Geprüft wird gegen dieselbe
|
||||
## `_schema.json` wie tools/validate_data.py (dort ausführlicher; hier nur das,
|
||||
## was beim Start knallen muss): Pflichtfelder, Enum-Werte, Verweise, Effekt-ops.
|
||||
##
|
||||
## Ein Fehler ist kein Hinweis, sondern ein Abbruch: ein Datensatz, der nicht
|
||||
## validiert, existiert nicht.
|
||||
|
||||
const DATEN := "res://data"
|
||||
|
||||
var schema: Dictionary = {}
|
||||
var tables: Dictionary = {} ## typ -> {id: eintrag}
|
||||
var fehler: PackedStringArray = []
|
||||
|
||||
func _ready() -> void:
|
||||
load_all()
|
||||
if not fehler.is_empty():
|
||||
for f in fehler:
|
||||
push_error("Content: " + f)
|
||||
assert(false, "Content: %d Fehler in game/data — siehe Ausgabe" % fehler.size())
|
||||
|
||||
# ------------------------------------------------------------------- laden --
|
||||
|
||||
func load_all() -> void:
|
||||
schema = _lies_json(DATEN + "/_schema.json")
|
||||
if schema.is_empty():
|
||||
fehler.append("_schema.json fehlt oder ist kein JSON")
|
||||
return
|
||||
for typ in schema["typen"]:
|
||||
tables[typ] = {}
|
||||
var spec: Dictionary = schema["typen"][typ]
|
||||
for pfad in _dateien(spec):
|
||||
var roh := _lies_json(pfad)
|
||||
if roh.is_empty():
|
||||
fehler.append("%s: kein gültiges JSON" % pfad)
|
||||
continue
|
||||
if int(roh.get("schema", 0)) != int(schema["schema"]):
|
||||
fehler.append("%s: schema %s, erwartet %s" % [
|
||||
pfad, roh.get("schema"), schema["schema"]])
|
||||
var eintraege: Dictionary = roh.get("entries", {})
|
||||
if eintraege.is_empty():
|
||||
fehler.append("%s: entries fehlt oder leer" % pfad)
|
||||
continue
|
||||
for id in eintraege:
|
||||
if tables[typ].has(id):
|
||||
fehler.append("%s: doppelte id %s" % [pfad, id])
|
||||
tables[typ][id] = eintraege[id]
|
||||
_pruefe_eintrag(pfad, "%s.%s" % [typ, id], eintraege[id],
|
||||
spec["felder"])
|
||||
_pruefe_verweise()
|
||||
|
||||
func _dateien(spec: Dictionary) -> Array[String]:
|
||||
var pfade: Array[String] = []
|
||||
if spec.has("glob"):
|
||||
var ordner := DATEN + "/" + str(spec["glob"]).get_base_dir()
|
||||
for datei in DirAccess.get_files_at(ordner):
|
||||
if datei.ends_with(".json"):
|
||||
pfade.append(ordner + "/" + datei)
|
||||
else:
|
||||
var pfad := DATEN + "/" + str(spec["datei"])
|
||||
if FileAccess.file_exists(pfad):
|
||||
pfade.append(pfad)
|
||||
else:
|
||||
fehler.append("%s fehlt" % pfad)
|
||||
return pfade
|
||||
|
||||
func _lies_json(pfad: String) -> Dictionary:
|
||||
if not FileAccess.file_exists(pfad):
|
||||
return {}
|
||||
var text := FileAccess.get_file_as_string(pfad)
|
||||
var wert: Variant = JSON.parse_string(text)
|
||||
if typeof(wert) != TYPE_DICTIONARY:
|
||||
return {}
|
||||
return wert
|
||||
|
||||
# ---------------------------------------------------------------- prüfen ----
|
||||
|
||||
func _pruefe_eintrag(datei: String, pfad: String, eintrag: Variant,
|
||||
felder: Dictionary) -> void:
|
||||
if typeof(eintrag) != TYPE_DICTIONARY:
|
||||
fehler.append("%s: %s ist kein Objekt" % [datei, pfad])
|
||||
return
|
||||
for name in felder:
|
||||
var regel: Dictionary = felder[name]
|
||||
if not eintrag.has(name):
|
||||
if regel.get("pflicht", false):
|
||||
fehler.append("%s: %s.%s fehlt (Pflichtfeld)" % [datei, pfad, name])
|
||||
continue
|
||||
_pruefe_wert(datei, "%s.%s" % [pfad, name], eintrag[name], regel, eintrag)
|
||||
|
||||
func _pruefe_wert(datei: String, pfad: String, wert: Variant, regel: Dictionary,
|
||||
eintrag: Dictionary) -> void:
|
||||
match str(regel.get("typ", "")):
|
||||
"string":
|
||||
if typeof(wert) != TYPE_STRING:
|
||||
fehler.append("%s: %s ist kein String" % [datei, pfad])
|
||||
return
|
||||
if regel.has("enum") and not _enum(regel["enum"]).has(wert):
|
||||
fehler.append("%s: %s = %s ist nicht in %s" % [
|
||||
datei, pfad, wert, regel["enum"]])
|
||||
if regel.has("verweis"):
|
||||
_merke_verweis(str(regel["verweis"]), wert, datei, pfad)
|
||||
"int":
|
||||
if typeof(wert) != TYPE_INT and typeof(wert) != TYPE_FLOAT:
|
||||
fehler.append("%s: %s ist keine Zahl" % [datei, pfad])
|
||||
"asset":
|
||||
var ordner := "res://assets/%s/%s.png" % [regel["asset"], wert]
|
||||
if not ResourceLoader.exists(ordner):
|
||||
fehler.append("%s: %s -> %s fehlt" % [datei, pfad, ordner])
|
||||
"list":
|
||||
if typeof(wert) != TYPE_ARRAY:
|
||||
fehler.append("%s: %s ist keine Liste" % [datei, pfad])
|
||||
return
|
||||
if regel.has("verweis"):
|
||||
for w in wert:
|
||||
_merke_verweis(str(regel["verweis"]), w, datei, pfad)
|
||||
if regel.has("enum"):
|
||||
for w in wert:
|
||||
if not _enum(regel["enum"]).has(w):
|
||||
fehler.append("%s: %s enthält %s (nicht in %s)" % [
|
||||
datei, pfad, w, regel["enum"]])
|
||||
if regel.get("effekte", false):
|
||||
for i in wert.size():
|
||||
_pruefe_effekt(datei, "%s[%d]" % [pfad, i], wert[i])
|
||||
if regel.has("element"):
|
||||
for i in wert.size():
|
||||
_pruefe_eintrag(datei, "%s[%d]" % [pfad, i], wert[i],
|
||||
regel["element"])
|
||||
"dict":
|
||||
if typeof(wert) != TYPE_DICTIONARY:
|
||||
if wert != null or not regel.get("nullable", false):
|
||||
fehler.append("%s: %s ist kein Objekt" % [datei, pfad])
|
||||
return
|
||||
if regel.has("schluessel"):
|
||||
for k in wert:
|
||||
if not _enum(regel["schluessel"]).has(k):
|
||||
fehler.append("%s: %s.%s ist nicht in %s" % [
|
||||
datei, pfad, k, regel["schluessel"]])
|
||||
|
||||
func _pruefe_effekt(datei: String, pfad: String, effekt: Variant) -> void:
|
||||
if typeof(effekt) != TYPE_DICTIONARY or not effekt.has("op"):
|
||||
fehler.append("%s: %s ist kein Effekt" % [datei, pfad])
|
||||
return
|
||||
var op := str(effekt["op"])
|
||||
var ops: Dictionary = schema.get("ops", {})
|
||||
if not ops.has(op):
|
||||
fehler.append("%s: %s unbekanntes op %s" % [datei, pfad, op])
|
||||
return
|
||||
for feld in ops[op].get("pflicht", []):
|
||||
if not effekt.has(feld):
|
||||
fehler.append("%s: %s.%s fehlt (op %s)" % [datei, pfad, feld, op])
|
||||
var eines: Array = ops[op].get("eines_von", [])
|
||||
if not eines.is_empty():
|
||||
var treffer := false
|
||||
for feld in eines:
|
||||
if effekt.has(feld):
|
||||
treffer = true
|
||||
if not treffer:
|
||||
fehler.append("%s: %s braucht eines von %s" % [datei, pfad, eines])
|
||||
for feld in ops[op].get("verweis", {}):
|
||||
if effekt.has(feld):
|
||||
_merke_verweis(str(ops[op]["verweis"][feld]), effekt[feld], datei,
|
||||
"%s.%s" % [pfad, feld])
|
||||
|
||||
var _verweise: Array = []
|
||||
|
||||
func _merke_verweis(typ: String, wert: Variant, datei: String, pfad: String) -> void:
|
||||
_verweise.append([typ, wert, datei, pfad])
|
||||
|
||||
func _pruefe_verweise() -> void:
|
||||
for v in _verweise:
|
||||
var typ: String = v[0]
|
||||
if not tables.has(typ):
|
||||
fehler.append("%s: %s verweist auf unbekannten Typ %s" % [v[2], v[3], typ])
|
||||
elif not tables[typ].has(v[1]):
|
||||
fehler.append("%s: %s = %s gibt es nicht in %s" % [v[2], v[3], v[1], typ])
|
||||
|
||||
func _enum(name: String) -> Array:
|
||||
return schema.get("enums", {}).get(name, [])
|
||||
|
||||
# ------------------------------------------------------------- Zugriff ------
|
||||
|
||||
func table(typ: String) -> Dictionary:
|
||||
return tables.get(typ, {})
|
||||
|
||||
func entry(typ: String, id: String) -> Dictionary:
|
||||
return tables.get(typ, {}).get(id, {})
|
||||
|
||||
func ids(typ: String) -> Array:
|
||||
return tables.get(typ, {}).keys()
|
||||
|
||||
## Kurzform für die häufigsten Zugriffe.
|
||||
func class_def(id: String) -> Dictionary:
|
||||
return entry("classes", id)
|
||||
|
||||
func spell(id: String) -> Dictionary:
|
||||
return entry("spells", id)
|
||||
|
||||
func monster(id: String) -> Dictionary:
|
||||
return entry("monsters", id)
|
||||
|
||||
func skill(id: String) -> Dictionary:
|
||||
return entry("skills", id)
|
||||
1
game/scripts/data/content_db.gd.uid
Normal file
1
game/scripts/data/content_db.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://coi18rypsqlol
|
||||
105
game/scripts/data/effect_runner.gd
Normal file
105
game/scripts/data/effect_runner.gd
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
extends Node
|
||||
## Rules (Autoload) — die Effekt-Vokabel aus docs/engine.md §5.
|
||||
##
|
||||
## Ein Effekt ist ein Wörterbuch mit `op` und Parametern; `apply()` löst ihn
|
||||
## gegen einen Kontext auf und liefert das Ergebnis zurück. Die Vokabel wird
|
||||
## hier EINMAL implementiert — neue Zauber, Klassen und Fähigkeiten sind neue
|
||||
## Kombinationen in game/data/, kein neuer Code.
|
||||
##
|
||||
## `ctx` (alles optional):
|
||||
## "target" : Dictionary einer Figur (saves, hp, tags …)
|
||||
## "targets" : Array solcher Dictionaries bei Flächeneffekten
|
||||
## "source" : Dictionary des Wirkenden (level, attributes …)
|
||||
## "dc" : Rettungswurf-SG, wenn der Effekt keinen eigenen mitbringt
|
||||
|
||||
## Ergebnis eines Effekts, z. B. {"op": "damage", "amount": 3, "saved": false}
|
||||
func apply(effects: Array, ctx: Dictionary = {}) -> Array:
|
||||
var out: Array = []
|
||||
for e in effects:
|
||||
var r := _run(e, ctx)
|
||||
if not r.is_empty():
|
||||
out.append(r)
|
||||
return out
|
||||
|
||||
func _run(e: Dictionary, ctx: Dictionary) -> Dictionary:
|
||||
match str(e.get("op", "")):
|
||||
"damage":
|
||||
var amount := Dice.roll(str(e.get("amount", "1d4")))
|
||||
var saved := _save(e, ctx)
|
||||
if saved and str(e.get("save_effect", "")) == "half":
|
||||
amount = int(amount / 2.0)
|
||||
return {"op": "damage", "amount": amount,
|
||||
"type": e.get("type", "wucht"), "saved": saved}
|
||||
|
||||
"heal":
|
||||
return {"op": "heal", "amount": Dice.roll(str(e.get("amount", "1d6"))),
|
||||
"affects": e.get("affects", "single")}
|
||||
|
||||
"condition":
|
||||
if e.has("add"):
|
||||
return {"op": "condition", "add": e["add"],
|
||||
"duration": e.get("duration", {}),
|
||||
"saved": _save(e, ctx)}
|
||||
return {"op": "condition", "remove": e["remove"]}
|
||||
|
||||
"bonus":
|
||||
var r := {"op": "bonus", "target": e.get("target"), "duration": {}}
|
||||
if e.has("value"):
|
||||
r["value"] = int(e["value"])
|
||||
if e.has("multiplier"):
|
||||
r["multiplier"] = int(e["multiplier"])
|
||||
for feld in ["save", "skill", "when", "per", "max", "affects"]:
|
||||
if e.has(feld):
|
||||
r[feld] = e[feld]
|
||||
return r
|
||||
|
||||
"move":
|
||||
return {"op": "move", "mode": e.get("mode", "walk"),
|
||||
"tiles": int(e.get("tiles", 0))}
|
||||
|
||||
"summon":
|
||||
var mon := Content.monster(str(e.get("monster", "")))
|
||||
return {"op": "summon", "monster": e.get("monster"),
|
||||
"count": int(e.get("count", 1)), "def": mon}
|
||||
|
||||
"light":
|
||||
return {"op": "light", "radius": int(e.get("radius", 0)),
|
||||
"duration": e.get("duration", {})}
|
||||
|
||||
"grant_spells":
|
||||
return {"op": "grant_spells", "school": e.get("school", "any")}
|
||||
|
||||
"extra_attack":
|
||||
return {"op": "extra_attack", "count": int(e.get("count", 1))}
|
||||
|
||||
"resource":
|
||||
return {"op": "resource", "pool": e.get("pool"),
|
||||
"delta": int(e.get("delta", 0))}
|
||||
|
||||
"message":
|
||||
return {"op": "message", "text_id": e.get("text_id", "")}
|
||||
|
||||
"turn_undead":
|
||||
return {"op": "turn_undead", "wurf": Dice.roll("2d6"),
|
||||
"duration": int(e.get("duration", 3)),
|
||||
"only": e.get("only", {})}
|
||||
|
||||
"immunity":
|
||||
return {"op": "immunity", "against": e.get("against", [])}
|
||||
|
||||
_:
|
||||
# Kein assert: ContentDB lehnt unbekannte ops schon beim Laden ab.
|
||||
# Hier ist es das Sicherheitsnetz für Effekte, die im Code entstehen.
|
||||
push_error("Rules: unbekanntes op '%s' — Vokabel in game/data/_schema.json "
|
||||
% str(e.get("op", "")) + "und effect_runner.gd ergänzen")
|
||||
return {}
|
||||
|
||||
## Rettungswurf: d20 + Bonus des Ziels gegen den SG des Effekts.
|
||||
func _save(e: Dictionary, ctx: Dictionary) -> bool:
|
||||
if not e.has("save"):
|
||||
return false
|
||||
var target: Dictionary = ctx.get("target", {})
|
||||
var bonuses: Dictionary = target.get("save_bonus", {})
|
||||
var bonus := int(bonuses.get(str(e["save"]), 0))
|
||||
var dc := int(e.get("dc", ctx.get("dc", 10)))
|
||||
return Dice.roll("1d20") + bonus >= dc
|
||||
1
game/scripts/data/effect_runner.gd.uid
Normal file
1
game/scripts/data/effect_runner.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dwkoqff7fc5jt
|
||||
88
game/scripts/main.gd
Normal file
88
game/scripts/main.gd
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
extends Node
|
||||
## Einstieg. Zwei Betriebsarten:
|
||||
##
|
||||
## godot --path game -> Kurzbericht (Phase 1: Titel folgt)
|
||||
## godot --path game -- --check -> Selbstprüfung, Exit 1 bei Fehler
|
||||
##
|
||||
## Die Selbstprüfung ist der Ersatz für "einmal durchspielen", solange es noch
|
||||
## keine Szene gibt: Daten geladen, Würfel rechnen, ein Effekt läuft, ein
|
||||
## Spielstand geht hin und zurück und ist danach identisch.
|
||||
|
||||
func _ready() -> void:
|
||||
var args := OS.get_cmdline_args() + OS.get_cmdline_user_args()
|
||||
if args.has("--check"):
|
||||
get_tree().quit(0 if _selbstpruefung() else 1)
|
||||
return
|
||||
_bericht()
|
||||
|
||||
func _bericht() -> void:
|
||||
print("Taloria — %d Klassen, %d Völker, %d Zauber, %d Gegner, %d Karten" % [
|
||||
Content.ids("classes").size(), Content.ids("races").size(),
|
||||
Content.ids("spells").size(), Content.ids("monsters").size(),
|
||||
Content.ids("maps").size()])
|
||||
for figur in Game.party:
|
||||
print(" %-6s %-8s %-9s TP %2d/%2d RK %2d Angriff +%d" % [
|
||||
figur["name"], figur["race"], figur["class"],
|
||||
int(figur["hp"]["current"]), int(figur["hp"]["max"]),
|
||||
Game.rk(figur), Game.angriffsbonus(figur)])
|
||||
|
||||
func _selbstpruefung() -> bool:
|
||||
var ok := true
|
||||
|
||||
ok = _pruefe("Daten geladen", Content.ids("classes").size() == 4
|
||||
and Content.ids("spells").size() >= 18) and ok
|
||||
|
||||
var w: int = Dice.roll("2d6+1")
|
||||
ok = _pruefe("Würfel 2d6+1", w >= 3 and w <= 13) and ok
|
||||
ok = _pruefe("Würfel-Modifikator 16 -> +2", Dice.modifier(16) == 2) and ok
|
||||
|
||||
# Font: die BMFont-Datei muss im Engine-Raster sitzen (Vorschub 8).
|
||||
var font: FontFile = load("res://assets/font/font8_10.fnt")
|
||||
var groesse: Vector2 = font.get_string_size("AA", HORIZONTAL_ALIGNMENT_LEFT, -1, 10)
|
||||
print(" Font: 2 Zeichen = %.1f px, Höhe %.1f, Ascent %.1f" % [
|
||||
groesse.x, font.get_height(10), font.get_ascent(10)])
|
||||
ok = _pruefe("Font Vorschub 8 px", is_equal_approx(groesse.x, 16.0)) and ok
|
||||
|
||||
var geschoss: Dictionary = Content.spell("magisches_geschoss")
|
||||
var ergebnis: Array = Rules.apply(geschoss.get("effects", []),
|
||||
{"target": {"save_bonus": {"ref": 0}}})
|
||||
ok = _pruefe("Effekt Magisches Geschoss", ergebnis.size() == 1
|
||||
and int(ergebnis[0].get("amount", 0)) >= 2) and ok
|
||||
|
||||
# Spielstand: schreiben, lesen, vergleichen.
|
||||
# JSON kennt nur "Zahl", Godot liest sie als float zurück; vor dem Vergleich
|
||||
# werden ganze Zahlen normalisiert (1.0 -> 1), sonst wäre der Test unehrlich
|
||||
# streng an einer Typfrage statt am Inhalt.
|
||||
var vorher := JSON.stringify(_normalisiere(Game.to_dict()))
|
||||
ok = _pruefe("Spielstand schreiben", Saves.write(9)) and ok
|
||||
var geladen: Dictionary = Saves.read(9)
|
||||
Game.from_dict(geladen)
|
||||
var nachher := JSON.stringify(_normalisiere(Game.to_dict()))
|
||||
ok = _pruefe("Spielstand identisch nach Neustart", vorher == nachher) and ok
|
||||
DirAccess.remove_absolute(Saves.pfad(9))
|
||||
|
||||
print("\nSelbstprüfung: %s" % ("bestanden" if ok else "FEHLGESCHLAGEN"))
|
||||
return ok
|
||||
|
||||
## Ganze Zahlen aus JSON wieder zu int machen, rekursiv.
|
||||
func _normalisiere(wert: Variant) -> Variant:
|
||||
match typeof(wert):
|
||||
TYPE_FLOAT:
|
||||
var f: float = wert
|
||||
return int(f) if f == floor(f) else f
|
||||
TYPE_DICTIONARY:
|
||||
var d := {}
|
||||
for k in wert:
|
||||
d[k] = _normalisiere(wert[k])
|
||||
return d
|
||||
TYPE_ARRAY:
|
||||
var a := []
|
||||
for v in wert:
|
||||
a.append(_normalisiere(v))
|
||||
return a
|
||||
_:
|
||||
return wert
|
||||
|
||||
func _pruefe(name: String, wahr: bool) -> bool:
|
||||
print(" %s %s" % [("ok " if wahr else "FEHL"), name])
|
||||
return wahr
|
||||
1
game/scripts/main.gd.uid
Normal file
1
game/scripts/main.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bnxiy0advd0ar
|
||||
108
game/scripts/systems/game_state.gd
Normal file
108
game/scripts/systems/game_state.gd
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
extends Node
|
||||
## Game (Autoload) — der Spielzustand: Party, Ort, Zeit, Flaggen.
|
||||
##
|
||||
## Gespeichert werden **Eingaben**, keine abgeleiteten Werte (docs/engine.md §7):
|
||||
## TP ja, RK nein. Wird eine Klasse nachbalanciert, korrigiert der nächste
|
||||
## Ladevorgang die Ableitung automatisch.
|
||||
|
||||
const START = "garana"
|
||||
|
||||
var party: Array = [] ## Array von Dictionaries (ids + Werte)
|
||||
var place: Dictionary = {"id": START, "x": 9, "y": 9}
|
||||
var time: Dictionary = {"day": 1, "slot": 0}
|
||||
var flags: Dictionary = {}
|
||||
var log_lines: Array[String] = []
|
||||
|
||||
func _ready() -> void:
|
||||
if party.is_empty():
|
||||
_neue_party()
|
||||
|
||||
## Vier Figuren, wie in docs/systeme.md §11 durchgerechnet.
|
||||
func _neue_party() -> void:
|
||||
var vorgabe := [
|
||||
{"name": "Aldric", "race": "human", "class": "fighter",
|
||||
"attributes": {"str": 16, "dex": 12, "con": 14, "int": 10, "wis": 9, "cha": 11}},
|
||||
{"name": "Bruna", "race": "dwarf", "class": "cleric",
|
||||
"attributes": {"str": 12, "dex": 9, "con": 15, "int": 10, "wis": 16, "cha": 11}},
|
||||
{"name": "Cael", "race": "elf", "class": "magier",
|
||||
"attributes": {"str": 8, "dex": 15, "con": 11, "int": 17, "wis": 12, "cha": 10}},
|
||||
{"name": "Dorn", "race": "halfling", "class": "thief",
|
||||
"attributes": {"str": 11, "dex": 17, "con": 12, "int": 12, "wis": 10, "cha": 13}},
|
||||
]
|
||||
party = []
|
||||
for i in vorgabe.size():
|
||||
party.append(neue_figur("pc_%d" % (i + 1), vorgabe[i]))
|
||||
|
||||
func neue_figur(id: String, vorgabe: Dictionary) -> Dictionary:
|
||||
var klasse: Dictionary = Content.class_def(str(vorgabe["class"]))
|
||||
var volk: Dictionary = Content.entry("races", str(vorgabe["race"]))
|
||||
var attrs: Dictionary = vorgabe["attributes"].duplicate()
|
||||
for attribut in volk.get("attribute_mods", {}):
|
||||
attrs[attribut] = int(attrs.get(attribut, 10)) + int(volk["attribute_mods"][attribut])
|
||||
var hp_max := _hp_stufe1(klasse, attrs)
|
||||
return {
|
||||
"id": id, "name": vorgabe["name"],
|
||||
"race": vorgabe["race"], "class": vorgabe["class"],
|
||||
"level": 1, "xp": 0,
|
||||
"attributes": attrs,
|
||||
"hp": {"current": hp_max, "max": hp_max},
|
||||
"skills": _startfertigkeiten(klasse),
|
||||
"spells": {"known": [], "prepared": [], "slots": {}},
|
||||
"inventory": [], "equipment": {},
|
||||
"conditions": [],
|
||||
}
|
||||
|
||||
func _hp_stufe1(klasse: Dictionary, attrs: Dictionary) -> int:
|
||||
var kon := Dice.modifier(int(attrs.get("con", 10)))
|
||||
return maxi(1, int(klasse.get("hit_die", 6)) + kon)
|
||||
|
||||
func _startfertigkeiten(klasse: Dictionary) -> Dictionary:
|
||||
var out := {}
|
||||
for id in klasse.get("trained_skills", []):
|
||||
var fertigkeit: Dictionary = Content.skill(str(id))
|
||||
out[str(id)] = int(fertigkeit.get("trained_bonus", 3))
|
||||
return out
|
||||
|
||||
## Abgeleitete Werte werden gerechnet, nie gespeichert.
|
||||
func rk(figur: Dictionary) -> int:
|
||||
var ac := 10 + Dice.modifier(int(figur["attributes"].get("dex", 10)))
|
||||
var ruestung: Dictionary = Content.entry("items", str(figur.get("equipment", {}).get("armor", "")))
|
||||
ac += int(ruestung.get("ac_bonus", 0))
|
||||
if figur.get("equipment", {}).get("shield", false):
|
||||
var schild: Dictionary = Content.entry("items", "schild")
|
||||
ac += int(schild.get("ac_bonus", 1))
|
||||
return ac
|
||||
|
||||
func angriffsbonus(figur: Dictionary) -> int:
|
||||
var klasse: Dictionary = Content.class_def(str(figur["class"]))
|
||||
var stufe := int(figur.get("level", 1))
|
||||
var leiter: Array = klasse.get("attack_per_level", [])
|
||||
if stufe - 1 < leiter.size():
|
||||
return int(leiter[stufe - 1])
|
||||
return int(leiter[leiter.size() - 1]) if not leiter.is_empty() else 0
|
||||
|
||||
func notiz(text: String) -> void:
|
||||
log_lines.append(text)
|
||||
if log_lines.size() > 200:
|
||||
log_lines.pop_front()
|
||||
|
||||
# ------------------------------------------------------------- speichern ----
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"save_version": Saves.VERSION,
|
||||
"place": place,
|
||||
"time": time,
|
||||
"party": party,
|
||||
"flags": flags,
|
||||
"log": log_lines,
|
||||
}
|
||||
|
||||
func from_dict(d: Dictionary) -> void:
|
||||
place = d.get("place", place)
|
||||
time = d.get("time", time)
|
||||
party = d.get("party", party)
|
||||
flags = d.get("flags", {})
|
||||
log_lines = []
|
||||
for zeile in d.get("log", []):
|
||||
log_lines.append(str(zeile))
|
||||
1
game/scripts/systems/game_state.gd.uid
Normal file
1
game/scripts/systems/game_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cs08vyu6o3j4c
|
||||
40
game/scripts/systems/save.gd
Normal file
40
game/scripts/systems/save.gd
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
extends Node
|
||||
## Saves (Autoload) — Spielstand schreiben und lesen (docs/engine.md §7).
|
||||
##
|
||||
## Format: JSON unter user://, mit `save_version`. Gespeichert werden nur
|
||||
## Eingaben; abgeleitete Werte (RK, Angriffsbonus) rechnet Game neu.
|
||||
## Eine unbekannte Version wird nicht stillschweigend geladen.
|
||||
|
||||
const VERSION := 1
|
||||
const ORDNER := "user://saves"
|
||||
|
||||
func pfad(slot: int = 0) -> String:
|
||||
return "%s/slot_%d.json" % [ORDNER, slot]
|
||||
|
||||
func write(slot: int = 0) -> bool:
|
||||
DirAccess.make_dir_recursive_absolute(ORDNER)
|
||||
var datei := FileAccess.open(pfad(slot), FileAccess.WRITE)
|
||||
if datei == null:
|
||||
push_error("Saves: kann %s nicht schreiben (%s)" % [pfad(slot), FileAccess.get_open_error()])
|
||||
return false
|
||||
datei.store_string(JSON.stringify(Game.to_dict(), "\t"))
|
||||
datei.close()
|
||||
return true
|
||||
|
||||
func read(slot: int = 0) -> Dictionary:
|
||||
if not FileAccess.file_exists(pfad(slot)):
|
||||
push_error("Saves: %s fehlt" % pfad(slot))
|
||||
return {}
|
||||
var wert: Variant = JSON.parse_string(FileAccess.get_file_as_string(pfad(slot)))
|
||||
if typeof(wert) != TYPE_DICTIONARY:
|
||||
push_error("Saves: %s ist kein gültiges JSON" % pfad(slot))
|
||||
return {}
|
||||
var d: Dictionary = wert
|
||||
var version := int(d.get("save_version", 0))
|
||||
if version != VERSION:
|
||||
push_error("Saves: Version %d, erwartet %d — Migration fehlt" % [version, VERSION])
|
||||
return {}
|
||||
return d
|
||||
|
||||
func exists(slot: int = 0) -> bool:
|
||||
return FileAccess.file_exists(pfad(slot))
|
||||
1
game/scripts/systems/save.gd.uid
Normal file
1
game/scripts/systems/save.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c1ilk2h82eajk
|
||||
19
game/scripts/ui/panel.gd
Normal file
19
game/scripts/ui/panel.gd
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class_name UiPanel
|
||||
extends NinePatchRect
|
||||
## Das 9-Slice-Panel aus art/final/UI (docs/ui.md §3).
|
||||
##
|
||||
## Rand 2 px, weil die Engine mit 1x-Assets im 640x360-Viewport arbeitet.
|
||||
## Damit ist jede Instanz pixelgleich zu `panel()` aus art/tools/ui.py —
|
||||
## geprüft von art/tools/ui_slice.py für 4x4 bis 400x56.
|
||||
|
||||
const TEXTUR := "res://assets/ui/ui_panel_9slice_12px.png"
|
||||
const RAND := 2
|
||||
|
||||
func _ready() -> void:
|
||||
if texture == null:
|
||||
texture = load(TEXTUR)
|
||||
patch_margin_left = RAND
|
||||
patch_margin_top = RAND
|
||||
patch_margin_right = RAND
|
||||
patch_margin_bottom = RAND
|
||||
texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
1
game/scripts/ui/panel.gd.uid
Normal file
1
game/scripts/ui/panel.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bxk547s8oftda
|
||||
Loading…
Add table
Add a link
Reference in a new issue