Add PlayerData TypedDict to fix type errors

This commit is contained in:
Jared Miller 2026-02-07 22:10:30 -05:00
parent 565690cef2
commit 4f9999efa5
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 16 additions and 2 deletions

View file

@ -21,6 +21,7 @@ from mudlib.content import load_commands
from mudlib.effects import clear_expired from mudlib.effects import clear_expired
from mudlib.player import Player, players from mudlib.player import Player, players
from mudlib.store import ( from mudlib.store import (
PlayerData,
account_exists, account_exists,
authenticate, authenticate,
create_account, create_account,
@ -229,7 +230,7 @@ async def shell(
update_last_login(player_name) update_last_login(player_name)
# Load player data from database or use defaults for new player # Load player data from database or use defaults for new player
player_data = login_result["player_data"] player_data: PlayerData | None = login_result["player_data"]
if player_data is None: if player_data is None:
# New player - find a passable starting position # New player - find a passable starting position
center_x = _world.width // 2 center_x = _world.width // 2

View file

@ -5,9 +5,22 @@ import hmac
import os import os
import sqlite3 import sqlite3
from pathlib import Path from pathlib import Path
from typing import TypedDict
from mudlib.player import Player from mudlib.player import Player
class PlayerData(TypedDict):
"""Shape of persisted player data from the database."""
x: int
y: int
pl: float
stamina: float
max_stamina: float
flying: bool
# Module-level database path # Module-level database path
_db_path: str | None = None _db_path: str | None = None
@ -188,7 +201,7 @@ def save_player(player: Player) -> None:
conn.close() conn.close()
def load_player_data(name: str) -> dict | None: def load_player_data(name: str) -> PlayerData | None:
"""Load player data from the database. """Load player data from the database.
Args: Args: