Skip to main content

Context Menu API

The context menu system provides OSRS-accurate right-click menus with colored entity names, manifest-driven actions, and centralized dispatching.

InventoryActionDispatcher

Centralized inventory action dispatching. Location: packages/client/src/game/systems/InventoryActionDispatcher.ts

dispatchInventoryAction()

Dispatch an inventory action to the appropriate handler.
Parameters:
  • action - The action ID (e.g., “eat”, “wield”, “drop”)
  • ctx - Context containing world, itemId, slot, and optional quantity
Returns: ActionResult indicating success/failure Example:

Supported Actions


Item Helpers

Type detection utilities for inventory actions. Location: packages/shared/src/utils/item-helpers.ts

Type Detection Functions

isFood()

Check if item is food (can be eaten).
Detection: type === "consumable" + healAmount > 0 + not a potion Example:

isPotion()

Check if item is a potion (can be drunk).
Detection: type === "consumable" + id.includes("potion")

isBone()

Check if item is bones (can be buried).
Detection: id === "bones" or id.endsWith("_bones")

isWeapon()

Check if item is a weapon.
Detection: equipSlot === "weapon" or equipSlot === "2h" or is2h === true or weaponType != null

isShield()

Check if item is a shield.
Detection: equipSlot === "shield"

usesWield()

Check if item uses “Wield” action (weapons + shields).
Returns: isWeapon(item) || isShield(item)

usesWear()

Check if item uses “Wear” action (armor, not weapons/shields).
Detection: equipable === true and not a weapon/shield

isNotedItem()

Check if item is a bank note.
Detection: isNoted === true or id.endsWith("_noted")

Primary Action Detection

getPrimaryAction()

Get primary action using manifest-first approach with heuristic fallback.
Parameters:
  • item - Item to check
  • isNoted - Whether item is a bank note
Returns: "eat" | "drink" | "bury" | "wield" | "wear" | "use" Logic:
  1. If noted → return “use”
  2. Check item.inventoryActions[0] if defined
  3. Heuristic fallback based on item properties
  4. Final fallback → “use”
Example:

getPrimaryActionFromManifest()

Get primary action from manifest’s inventoryActions only.
Returns: First action from inventoryActions array, or null if not defined Example:

Context Menu Colors

Location: packages/shared/src/constants/GameConstants.ts

CONTEXT_MENU_COLORS

OSRS-accurate color constants for context menu entity names.
Usage:

Context Menu Action Structure

ContextMenuAction Interface

Example:

Interaction Handlers

Base class for all interaction handlers. Location: packages/shared/src/systems/client/interaction/handlers/BaseInteractionHandler.ts

BaseInteractionHandler

All handlers extend this base class:

Handler Registry


Manifest Integration

Item Manifest

Items can define explicit inventoryActions:
Rules:
  • First action becomes left-click default
  • Actions are case-insensitive when dispatched
  • If not specified, system uses heuristic detection
  • Noted items always use [“Use”, “Drop”, “Examine”]

Supported Manifest Actions


Testing

InventoryActionDispatcher Tests

File: packages/client/src/game/systems/__tests__/InventoryActionDispatcher.test.ts Coverage: 333 lines, 100% of all actions Example:

Item Helpers Tests

File: packages/shared/src/utils/__tests__/item-helpers.test.ts Coverage: 510 lines, all edge cases Example: