Skip to main content

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 in items.json:
The first action becomes the left-click default.

Heuristic Detection

If inventoryActions 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

The InventoryActionDispatcher provides centralized handling for all inventory actions:
Supported actions:
  • eat: Sends useItem network packet → server validates eat delay → consumes food → heals player
  • drink: Sends useItem network packet → server validates → applies potion effects
  • bury: Sends buryBones network message
  • wield: Sends equipItem network message (weapons/shields)
  • wear: Sends equipItem network 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:
The name “Goblin” is colored red (#ff0000) because it’s a mob.

InventoryActionDispatcher

The InventoryActionDispatcher 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):
The Cancel action is a silent no-op - it just closes the menu:

Context Menu Colors

Color Constants

Detection Logic

The getPrimaryAction function uses a manifest-first approach:
  1. Noted items: Always return “use” (cannot eat/equip notes)
  2. Manifest actions: Check item.inventoryActions[0] if defined
  3. Heuristic fallback: Detect based on item properties
    • Food: type === "consumable" + healAmount > 0 + not potion
    • Potions: type === "consumable" + id.includes("potion")
    • Bones: id === "bones" or id.endsWith("_bones")
    • Weapons/Shields: usesWield() checks equipSlot and weaponType
    • Armor: usesWear() checks equipable and equipSlot
  4. Final fallback: Return “use”

Adding Custom Actions


Testing

Context menus have unit test coverage:
Integration tests verify the full dispatcher flow: