RevFramework – Sample Scene: 02_Currency_Exchange¶
Namespace: RevGaming.RevFramework.Runtime.Currency.Samples.Scenes
🎯 Purpose¶
Learn how to convert one currency into another using a Currency Exchange Table — including rates, fees, and rounding behaviour.
This scene demonstrates how to define, preview, and execute conversions safely using the ICurrencyExchange interface.
🧩 What This Scene Teaches¶
- How to set up and use a
CurrencyExchangeTableasset. - How to define conversion rates, fees, and limits between currencies.
- The relationship between
TryQuote()(preview) andTryExchange()(execution). - How live wallet balances update automatically after conversion.
- How exchange operations work with decorated services (Audit, Caps, Authority).
🕹️ How to Use¶
- Enter Play Mode.
- Open the CurrencyExchangePanel (
F8). - Choose a source and destination currency.
- Enter an amount in the From field.
- Press Quote to preview the converted amount, fees, and limits.
- Press Exchange to perform the conversion and update both wallets.
- Adjust rates, fees, or rounding mode live in the
CurrencyExchangeTableasset and observe the effect immediately.
🔐 Authority (Important)¶
This sample scene includes a CurrencyAuthorityBinder configured for single-player use:
CurrencyAuthorityBinderalwaysTrue = true
This allows all currency mutations so the demo works out of the box.
Why this exists¶
RevFramework currency mutations are authority-gated by default.
- If no authority is present, all mutations are blocked.
- This is intentional and required for multiplayer safety.
Multiplayer note¶
For multiplayer or server-authoritative games:
- Do not use
CurrencyAuthorityBinder - Implement your own
ICurrencyAuthority - Validate all currency mutations on the server/host
This scene uses the permissive binder only to demonstrate behaviour in a local, single-player context.
💡 Key Takeaways¶
- Exchange rates are data-driven through the
CurrencyExchangeTable. - Each rate entry defines:
rate— base conversion multiplier.feePct— transaction fee (%).minSrc/maxSrc— valid input bounds.roundDown— rounding mode (floor vs. round).- Use
TryQuote()to preview and validate before callingTryExchange(). - The
ICurrencyExchangeinterface keeps your economy modular and stack-agnostic. - The system integrates seamlessly with Audit, Caps, and Authority decorators.
⚙️ Stack Composition¶
Bootstrap: CurrencyServiceBootstrap
Service Stack:
SceneCurrencyService → CappedCurrencyService → AuditedCurrencyService → AuthorityCurrencyService
(Authority provided by CurrencyAuthorityBinder for single-player demos; idempotency and batch events omitted for clarity.)
Teaching Panel: CurrencyExchangePanel
Supporting Assets:
- CurrencyExchangeTable (ScriptableObject defining rates)
- CurrencySet (for readable currency labels)
Scene Path:
Assets/RevFramework/Runtime/Systems/Currency/Samples/Scenes/02_Currency_Exchange/
⚠️ Gotchas¶
- The fee applies after conversion, deducted from the destination amount.
TryQuote()returnsfalseif no valid rate or bounds exist — check before executing.- The system does not automatically replicate results in multiplayer; use your own authority/replication layer.
minSrcandmaxSrcare evaluated against the source amount — not the converted result.- Fees, limits, and rounding apply consistently in both directions (
A→BandB→A) only if both entries are defined.
📚 Related¶
- 01_Currency_PolicyCaps — Cap enforcement and rule modes.
- Core —
CurrencyTxn,CurrencyPurchase, andCurrencyFactories. - Exchange — Underlying exchange implementation.
- Decorators — Decorator layers used in stack composition.
- 04_Currency_UIBars — UI updates during currency changes.