One of my many lofty goals for StupidRPG is the idea that it could be successfully completed using only the mouse (or touch, on mobile). This presents a number of challenges because I don’t want to compromise the textual nature of the output (i.e. I don’t want to clutter the output with a ton of available actions). Context menus are my first attempt at solving this problem. Text-input players can ignore them entirely (treat them as non-interactive text just like the rest).
It’s a little dropdown thingy that opens from clickable command tags (highlighted bits of text that perform an action when clicked). Generally speaking, clicking on a compass direction will move the player in that direction, and clicking an object or NPC will LOOK AT
the object or NPC. Context menus allow for more actions to be available for each tag.
How do they work?
On the technical side, not every tag has context actions. Context actions are globally registered with the Entity prototype, which runs a bit of code each time a tag is generated to see which actions are suitable. Right now I have four actions defined:
LOOK
: Always available (if an object is being mentioned in a description, the player can obviously see it).
TAKE
: Available if the Entity can be taken (there’s already a flag for that).
EAT
: Available if the Entity has the ‘Edible’ component.
TALK TO
: Available if the Entity has the ‘Living’ component and has a Conversation object.
New actions can be added to the Entity prototype from anywhere (so modules can add new context actions).
What’s next? What’s missing?
Next up I’d like to add the ability for Entities to specify unique, arbitrary context actions (not shared with other Entities). This is a pretty easy task and will let me vary up the dropdowns (and expose some unique interactions and features the player might not be aware of).
The mobile problem: the context menu opens on hover. Hover is not well supported on mobile (some newer phones and tablets optionally support it). Switching to click will make behavior inconsistent because it’s not visually obvious which tags are simple click tags and which also have a menu. Could switch to tap on mobile and make all tags have a context menu (some with only 1 option). Requires an extra click but the behavior is more predictable.