29 lines
753 B
Python
29 lines
753 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from src.engine import StoryEngine
|
|
from src.parser import parse_story
|
|
from src.storage import load_game
|
|
|
|
|
|
def test_save_and_load_roundtrip(tmp_path: Path) -> None:
|
|
parsed = parse_story("data/main_story.yaml")
|
|
engine = StoryEngine(parsed.story)
|
|
|
|
# intro -> gate
|
|
engine.choose(0)
|
|
assert engine.current_node_id == "gate"
|
|
|
|
save_path = tmp_path / "save.json"
|
|
engine.save(save_path)
|
|
|
|
payload = load_game(save_path)
|
|
assert payload.story_id == parsed.story.story_id
|
|
assert payload.current_node == "gate"
|
|
|
|
engine2 = StoryEngine(parsed.story)
|
|
engine2.load(save_path)
|
|
assert engine2.current_node_id == "gate"
|
|
assert engine2.state == engine.state
|