Files
the-island/backend/app/schemas.py
empty cf1739b7f8 feat: pivot to island survival simulation with SQLite persistence
Phase 3 - "The Island" transformation:
- Add SQLAlchemy + SQLite for data persistence (database.py)
- Rewrite models.py with User, Agent, WorldState ORM models
- Refactor engine.py for survival mechanics (energy decay, starvation)
- Implement feed command (10 gold -> +20 energy)
- Auto-seed 3 NPCs on startup (Jack/Luna/Bob)
- Update frontend with agent card view and Chinese UI
- Remove old Boss/Player RPG mechanics
- Add .gitignore for database and cache files
- Fix SQLAlchemy session detachment issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 17:15:35 +08:00

60 lines
1.9 KiB
Python

"""
Pydantic models for the JSON protocol.
Defines standardized structures for game events and messages.
"""
from enum import Enum
from typing import Any
from pydantic import BaseModel, Field
import time
class EventType(str, Enum):
"""Enumeration of all possible game event types."""
COMMENT = "comment"
TICK = "tick"
SYSTEM = "system"
ERROR = "error"
# Island survival events
AGENTS_UPDATE = "agents_update" # All agents status broadcast
AGENT_DIED = "agent_died" # An agent has died
FEED = "feed" # User fed an agent
USER_UPDATE = "user_update" # User gold/status update
WORLD_UPDATE = "world_update" # World state update
CHECK = "check" # Status check response
class GameEvent(BaseModel):
"""
Standardized game event structure for WebSocket communication.
Attributes:
event_type: The type of event (comment, agent_response, tick, etc.)
timestamp: Unix timestamp when the event was created
data: Arbitrary payload data for the event
"""
event_type: str = Field(..., description="Type of the game event")
timestamp: float = Field(default_factory=time.time, description="Unix timestamp")
data: dict[str, Any] = Field(default_factory=dict, description="Event payload")
class Config:
json_schema_extra = {
"example": {
"event_type": "comment",
"timestamp": 1704067200.0,
"data": {"user": "User123", "message": "Attack!"}
}
}
class ClientMessage(BaseModel):
"""
Message structure for client-to-server communication.
Attributes:
action: The action the client wants to perform
payload: Data associated with the action
"""
action: str = Field(..., description="Action to perform")
payload: dict[str, Any] = Field(default_factory=dict, description="Action payload")