Server & Game refactor basics

This commit is contained in:
KuMiShi
2026-01-29 16:55:45 +01:00
parent 50d2b16224
commit e655de8f54
23 changed files with 189 additions and 121 deletions

View File

@@ -11,7 +11,7 @@ from serializable import Serializable
import json
import os
mcp = FastMCP("wyvern-castle")
game = Game()
game: Game = None
logging.basicConfig(
level=logging.INFO,
@@ -21,8 +21,53 @@ logging.basicConfig(
]
)
# History file path
# Constants
HISTORY_FILE = "game_history.json"
SAVE_PATH = "save_"
@mcp.tool()
async def load_game(slot:int):
"""Loads an already existing game.
Args:
slot: Integer id of the save slot.
"""
global game
path = SAVE_PATH + str(slot) + ".json"
try:
with open(path, "r", encoding="utf-8") as f:
game.deserialize(f.read())
return {
"success": True,
"msg": f"{path} as been successfully loaded!"
}
except OSError as e:
return {
"success": False,
"error": str(e)
}
@mcp.tool()
async def save_game(slot:int):
"""Saves the current game to the given slot.
Args:
slot: Integer id of the save slot.
"""
global game
path = SAVE_PATH + str(slot) + ".json"
try:
with open(path, "w", encoding="utf-8") as f:
f.write(game.serialize())
return {
"success": True,
"msg": f"{path} as been successfully saved!"
}
except OSError as e:
return {
"success": False,
"error": str(e)
}
def append_to_history(event: Dict[str, Any]):
"""Append a game event to the history file."""