2026-02-21 18:57:02 -05:00
|
|
|
# Item Type Template
|
|
|
|
|
|
2026-02-24 03:00:30 -05:00
|
|
|
This page is the practical template for the current plugin-driven item architecture.
|
2026-02-21 18:57:02 -05:00
|
|
|
|
|
|
|
|
## Plain-English Flow
|
|
|
|
|
|
2026-02-24 03:00:30 -05:00
|
|
|
When adding a new item type:
|
|
|
|
|
|
2026-02-24 03:08:30 -05:00
|
|
|
1. Server item package
|
|
|
|
|
- Add `server/app/items/types/<item_type>/` with:
|
|
|
|
|
- `definition.py` for metadata/constants
|
|
|
|
|
- `validator.py` for `validate_update(item, next_params)`
|
|
|
|
|
- `actions.py` for `use_item(item, nickname, clock_formatter)`
|
|
|
|
|
- `module.py` as thin exported surface
|
|
|
|
|
- `plugin.py` for registration
|
2026-02-21 22:04:17 -05:00
|
|
|
|
2026-02-24 03:00:30 -05:00
|
|
|
2. Server plugin file
|
|
|
|
|
- Add `server/app/items/types/<item_type>/plugin.py` exporting:
|
|
|
|
|
- `type`
|
|
|
|
|
- `order`
|
|
|
|
|
- `module`
|
2026-02-21 22:04:17 -05:00
|
|
|
|
2026-02-24 03:00:30 -05:00
|
|
|
3. Shared item-type unions
|
2026-02-21 22:04:17 -05:00
|
|
|
- Add the type in:
|
|
|
|
|
- `server/app/models.py`
|
|
|
|
|
- `client/src/network/protocol.ts`
|
|
|
|
|
- `client/src/state/gameState.ts`
|
|
|
|
|
|
2026-02-24 03:00:30 -05:00
|
|
|
4. Client runtime behavior (optional)
|
|
|
|
|
- Default: no item-specific client module needed.
|
|
|
|
|
- Add `client/src/items/types/<item_type>/behavior.ts` only if this item needs custom client runtime UX/audio logic (for example piano mode).
|
2026-02-21 18:57:02 -05:00
|
|
|
|
|
|
|
|
That is enough for a first working item type.
|
|
|
|
|
|
2026-02-24 03:08:30 -05:00
|
|
|
## Reference Sample Folder
|
2026-02-21 18:57:02 -05:00
|
|
|
|
2026-02-24 03:08:30 -05:00
|
|
|
See `docs/examples/item-type-sample/` for a complete copyable folder with all five files.
|
2026-02-21 18:57:02 -05:00
|
|
|
|
2026-02-24 03:08:30 -05:00
|
|
|
## Minimal `module.py` Example
|
2026-02-21 18:57:02 -05:00
|
|
|
|
2026-02-21 22:04:17 -05:00
|
|
|
```py
|
2026-02-24 03:08:30 -05:00
|
|
|
from .actions import use_item
|
|
|
|
|
from .definition import LABEL, TOOLTIP, EDITABLE_PROPERTIES, CAPABILITIES, USE_SOUND, EMIT_SOUND, USE_COOLDOWN_MS, EMIT_RANGE, DIRECTIONAL, DEFAULT_TITLE, DEFAULT_PARAMS, PROPERTY_METADATA
|
|
|
|
|
from .validator import validate_update
|
2026-02-21 18:57:02 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Checklist Before Commit
|
|
|
|
|
|
|
|
|
|
1. Add/adjust server tests for `use` and `update` validation.
|
|
|
|
|
2. Run `cd server && uv run --extra dev pytest`.
|
|
|
|
|
3. Run `cd client && npm run lint && npm run build`.
|
|
|
|
|
4. Update `docs/item-types.md` and `docs/item-schema.md` if behavior/defaults changed.
|