Add simple whiteboard

This commit is contained in:
2026-03-12 14:49:41 +01:00
parent f000b4423d
commit 5a458d7fca
9 changed files with 398 additions and 2 deletions

View File

@@ -0,0 +1 @@
"""Whiteboard item type package."""

View File

@@ -0,0 +1,23 @@
"""Whiteboard item use actions."""
from __future__ import annotations
from typing import Callable
from ....item_types import ItemUseResult
from ....models import WorldItem
def use_item(item: WorldItem, nickname: str, _clock_formatter: Callable[[dict], str]) -> ItemUseResult:
"""Report whiteboard contents to the user who used it."""
lines = item.params.get("lines", [])
if not isinstance(lines, list):
lines = []
n = len(lines)
line_text = f"{n} line{'s' if n != 1 else ''}"
return ItemUseResult(
self_message=f"You open {item.title}. {line_text}.",
others_message=f"{nickname} opens {item.title}.",
)

View File

@@ -0,0 +1,19 @@
"""Whiteboard item static metadata and defaults."""
from __future__ import annotations
LABEL = "whiteboard"
TOOLTIP = "A shared text board. Use to read and edit lines."
EDITABLE_PROPERTIES: tuple[str, ...] = ("title",)
CAPABILITIES: tuple[str, ...] = ("editable", "carryable", "deletable", "usable")
USE_SOUND: str | None = None
EMIT_SOUND: str | None = None
USE_COOLDOWN_MS = 500
EMIT_RANGE = 15
DIRECTIONAL = False
DEFAULT_TITLE = "whiteboard"
DEFAULT_PARAMS: dict = {"lines": []}
PARAM_KEYS: tuple[str, ...] = ("lines",)
PROPERTY_METADATA: dict[str, dict[str, object]] = {
"title": {"valueType": "text", "tooltip": "Display name.", "maxLength": 80},
}

View File

@@ -0,0 +1,16 @@
"""Plugin registration for whiteboard item type."""
from __future__ import annotations
from ..plugin_helpers import build_item_module
from . import actions, definition, validator
ITEM_TYPE_PLUGIN = {
"type": "whiteboard",
"order": 70,
"module": build_item_module(
definition,
validate_update=validator.validate_update,
use_item=actions.use_item,
),
}

View File

@@ -0,0 +1,32 @@
"""Whiteboard item validation/normalization."""
from __future__ import annotations
from ....models import WorldItem
from ...helpers import keep_only_known_params
from .definition import PARAM_KEYS
_MAX_LINES = 20
_MAX_LINE_LENGTH = 200
def validate_update(_item: WorldItem, next_params: dict) -> dict:
"""Validate and normalize whiteboard params."""
lines = next_params.get("lines", [])
if not isinstance(lines, list):
raise ValueError("lines must be a list.")
if len(lines) > _MAX_LINES:
raise ValueError(f"A whiteboard can have at most {_MAX_LINES} lines.")
cleaned: list[str] = []
for line in lines:
if not isinstance(line, str):
raise ValueError("Each line must be a string.")
stripped = line.strip()
if len(stripped) > _MAX_LINE_LENGTH:
raise ValueError(f"Each line must be at most {_MAX_LINE_LENGTH} characters.")
cleaned.append(stripped)
next_params["lines"] = cleaned
return keep_only_known_params(next_params, PARAM_KEYS)