Initial commit: DOOM x MATRIX System Failure text adventure
Modulares Python-Textadventure mit Kampfsystem (Stagger, Bullet Time, Glory Kills, Hacking-Skill-Checks), Hub-Raum-Navigation, prozeduralen Encountern, 3 Charakterklassen, mehreren Enden und Story-Elementen (weißer Hase, Orakel, schwarze-Katze-Deja-vu-Glitch).
This commit is contained in:
commit
46116f7f4b
25 files changed
+2594
No files matched your search
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Speichersystem (JSON-Savegames) und persistente Meta-Statistiken fuer den
|
||||
Loop-Twist: das Spiel 'erinnert' sich, wie oft es schon gespielt wurde."""
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
from doom_matrix.entities.player import Player
|
||||
|
||||
_SAVE_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "saves")
|
||||
_META_PATH = os.path.join(_SAVE_DIR, "meta.json")
|
||||
|
||||
_DEFAULT_META = {"run_count": 0, "completed_runs": 0, "endings_seen": []}
|
||||
|
||||
|
||||
def _ensure_dir():
|
||||
os.makedirs(_SAVE_DIR, exist_ok=True)
|
||||
|
||||
|
||||
def save_game(player, slot="autosave"):
|
||||
_ensure_dir()
|
||||
path = os.path.join(_SAVE_DIR, f"{slot}.json")
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(player.to_dict(), f, ensure_ascii=False, indent=2)
|
||||
return path
|
||||
|
||||
|
||||
def load_game(slot="autosave"):
|
||||
path = os.path.join(_SAVE_DIR, f"{slot}.json")
|
||||
if not os.path.exists(path):
|
||||
return None
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
return Player.from_dict(data)
|
||||
|
||||
|
||||
def save_exists(slot="autosave"):
|
||||
return os.path.exists(os.path.join(_SAVE_DIR, f"{slot}.json"))
|
||||
|
||||
|
||||
def load_meta():
|
||||
if not os.path.exists(_META_PATH):
|
||||
return dict(_DEFAULT_META)
|
||||
try:
|
||||
with open(_META_PATH, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
merged = dict(_DEFAULT_META)
|
||||
merged.update(data)
|
||||
return merged
|
||||
except (json.JSONDecodeError, OSError):
|
||||
return dict(_DEFAULT_META)
|
||||
|
||||
|
||||
def save_meta(meta):
|
||||
_ensure_dir()
|
||||
with open(_META_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(meta, f, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
def register_new_run():
|
||||
meta = load_meta()
|
||||
meta["run_count"] += 1
|
||||
save_meta(meta)
|
||||
return meta["run_count"]
|
||||
|
||||
|
||||
def register_ending(ending_key):
|
||||
meta = load_meta()
|
||||
meta["completed_runs"] += 1
|
||||
if ending_key not in meta["endings_seen"]:
|
||||
meta["endings_seen"].append(ending_key)
|
||||
save_meta(meta)
|
||||
return meta
|
||||
|
||||
|
||||
def loop_twist_line(run_count):
|
||||
"""Gibt einen Dialogzeile zurueck, falls das Spiel schon oefter gelaufen ist -- oder None."""
|
||||
if run_count <= 1:
|
||||
return None
|
||||
if run_count == 2:
|
||||
return "Morpheus Hayden: 'Habe ich das hier nicht schon einmal gesagt?'"
|
||||
if run_count < 5:
|
||||
return f"Morpheus Hayden: 'Lauf Nummer {run_count}. Du wirst besser. Oder ich erinnere mich besser.'"
|
||||
return f"Morpheus Hayden: 'Lauf Nummer {run_count}. Ehrlich gesagt -- ich weiss nicht mehr, welcher von uns beiden real ist.'"
|
||||
Reference in new issue
Block a user