Optimistic GUI Actions
This architecture makes GUI actions feel instant on the client, while still reconciling with server state. It is designed to be generic (items, skills, shop, future GUIs) and to work with existinggui.open flows.
Goals
- UI updates immediately after user input (no waiting for round-trip).
- Server remains authoritative.
- Client reconciles when server sends updated data.
How It Works
1) Client action pipeline
When a GUI component callsonInteraction(name, data), the client:
- Generates a
clientActionId. - Applies an optimistic reducer (if registered for the GUI).
- Sends the action to the server via
gui.interactionwithclientActionId.
2) Server reconcile
On the server, after processing an action, the GUI sends a snapshot update:- Replaces GUI data with the server snapshot.
- Removes the matching pending action (if
clientActionIdexists). - Replays remaining pending actions to keep the UI responsive.
Client API (RpgGui)
Register optimistic reducers per GUI:Server API (Gui)
Useupdate() to reconcile from the server:
Built-In Example
The Main Menu already uses optimistic updates for:useItemequipItem
gui.update snapshot after each action to reconcile the local state.
Extending the System
To add a new optimistic action:- Register a reducer for the GUI id.
- Update GUI data immutably in the reducer.
- Call
gui.update()on the server after processing.