1
0
Fork 0
taleweave-ai/adventure/models/entity.py

114 lines
2.7 KiB
Python
Raw Normal View History

from typing import Callable, Dict, List, Literal
2024-05-02 11:56:57 +00:00
from pydantic import Field
from .base import BaseModel, dataclass, uuid
2024-05-02 11:56:57 +00:00
Actions = Dict[str, Callable]
AttributeValue = bool | float | int | str
2024-05-05 22:46:24 +00:00
Attributes = Dict[str, AttributeValue]
2024-05-02 11:56:57 +00:00
@dataclass
class StringAttributeEffect:
name: str
operation: Literal["set", "append", "prepend"]
value: str
@dataclass
class NumberAttributeEffect:
name: str
operation: Literal["set", "add", "subtract", "multiply", "divide"]
# TODO: make this a range
value: int | float
@dataclass
class BooleanAttributeEffect:
name: str
operation: Literal["set", "toggle"]
value: bool
AttributeEffect = StringAttributeEffect | NumberAttributeEffect | BooleanAttributeEffect
@dataclass
class Effect(BaseModel):
name: str
description: str
attributes: list[AttributeEffect] = Field(default_factory=list)
id: str = Field(default_factory=uuid)
type: Literal["effect"] = "effect"
2024-05-02 11:56:57 +00:00
@dataclass
class Item(BaseModel):
2024-05-02 11:56:57 +00:00
name: str
description: str
actions: Actions = Field(default_factory=dict)
2024-05-05 22:46:24 +00:00
attributes: Attributes = Field(default_factory=dict)
effects: List[Effect] = Field(default_factory=list)
items: List["Item"] = Field(default_factory=list)
id: str = Field(default_factory=uuid)
type: Literal["item"] = "item"
2024-05-02 11:56:57 +00:00
@dataclass
class Actor(BaseModel):
2024-05-02 11:56:57 +00:00
name: str
backstory: str
description: str
actions: Actions = Field(default_factory=dict)
2024-05-05 22:46:24 +00:00
attributes: Attributes = Field(default_factory=dict)
items: List[Item] = Field(default_factory=list)
id: str = Field(default_factory=uuid)
type: Literal["actor"] = "actor"
2024-05-02 11:56:57 +00:00
@dataclass
class Portal(BaseModel):
name: str
description: str
destination: str
actions: Actions = Field(default_factory=dict)
attributes: Attributes = Field(default_factory=dict)
id: str = Field(default_factory=uuid)
type: Literal["portal"] = "portal"
2024-05-02 11:56:57 +00:00
@dataclass
class Room(BaseModel):
2024-05-02 11:56:57 +00:00
name: str
description: str
actors: List[Actor] = Field(default_factory=list)
actions: Actions = Field(default_factory=dict)
2024-05-05 22:46:24 +00:00
attributes: Attributes = Field(default_factory=dict)
items: List[Item] = Field(default_factory=list)
portals: List[Portal] = Field(default_factory=list)
id: str = Field(default_factory=uuid)
type: Literal["room"] = "room"
2024-05-02 11:56:57 +00:00
@dataclass
class World(BaseModel):
name: str
2024-05-04 04:18:21 +00:00
order: List[str]
2024-05-02 11:56:57 +00:00
rooms: List[Room]
theme: str
id: str = Field(default_factory=uuid)
type: Literal["world"] = "world"
2024-05-02 11:56:57 +00:00
@dataclass
class WorldState(BaseModel):
2024-05-02 11:56:57 +00:00
memory: Dict[str, List[str | Dict[str, str]]]
step: int
2024-05-04 04:18:21 +00:00
world: World
id: str = Field(default_factory=uuid)
type: Literal["world_state"] = "world_state"
2024-05-09 02:11:16 +00:00
WorldEntity = Room | Actor | Item | Portal