Context Menu System
Hyperscape features OSRS-accurate right-click context menus for inventory items, world entities, NPCs, and players with colored entity names and manifest-driven action ordering.Context menu code lives in
packages/client/src/game/systems/InventoryActionDispatcher.ts and packages/shared/src/utils/item-helpers.ts.Overview
Context menus provide:- Manifest-driven actions - Actions defined in item/entity manifests
- OSRS-accurate ordering - Primary action first, then secondary actions
- Colored entity names - Yellow NPCs, cyan scenery, orange items
- Cancel option - Always last in the menu
- Left-click primary action - First action in the list
Inventory Context Menus
Item Actions
Right-click items in your inventory to see available actions:Action Ordering
Actions are ordered by priority (lower = higher priority):Manifest-Driven Actions
Items define their actions initems.json:
Heuristic Detection
IfinventoryActions is not specified, the system detects actions based on item properties:
Tools like hatchets and pickaxes can be equipped as weapons. The system checks
equipSlot first before falling back to type-based detection.Action Handlers
TheInventoryActionDispatcher provides centralized handling for all inventory actions:
- eat: Sends
useItemnetwork packet → server validates eat delay → consumes food → heals player - drink: Sends
useItemnetwork packet → server validates → applies potion effects - bury: Sends
buryBonesnetwork message - wield: Sends
equipItemnetwork message (weapons/shields) - wear: Sends
equipItemnetwork message (armor) - drop: Calls
world.network.dropItem() - examine: Shows examine text in chat and toast
- use: Enters targeting mode for item-on-item/item-on-object interactions
- cancel: No-op, menu already closed
Food Consumption: The eat action is server-authoritative with 3-tick (1.8s) eat delay and combat attack delay integration. See Inventory System for details.
Entity Context Menus
Colored Entity Names
Entity names are colored by type (OSRS-accurate):Entity Actions
Entities define actions in their manifests:Context Menu Example
Right-clicking a goblin shows:InventoryActionDispatcher
TheInventoryActionDispatcher is the single source of truth for handling inventory actions. Both context menu selections and left-click primary actions route through this dispatcher.
Dispatcher Flow
Primary Action Detection
Manifest-First Approach
The system uses a manifest-first approach with heuristic fallback:Item Type Detection
Helper functions determine item types:Cancel Option
All context menus include a Cancel option at the bottom (OSRS-accurate):Context Menu Colors
Color Constants
Detection Logic
ThegetPrimaryAction function uses a manifest-first approach:
- Noted items: Always return “use” (cannot eat/equip notes)
- Manifest actions: Check
item.inventoryActions[0]if defined - Heuristic fallback: Detect based on item properties
- Food:
type === "consumable"+healAmount > 0+ not potion - Potions:
type === "consumable"+id.includes("potion") - Bones:
id === "bones"orid.endsWith("_bones") - Weapons/Shields:
usesWield()checksequipSlotandweaponType - Armor:
usesWear()checksequipableandequipSlot
- Food:
- Final fallback: Return “use”
Adding Custom Actions
Testing
Context menus have unit test coverage:Related Documentation
- Inventory System - Item storage
- Item Manifests - Defining item actions
- Eating System - Food consumption
- Equipment System - Wield/Wear actions