RevFramework – Sample Scene: 03_Currency_Persistence_Audit¶
Goal¶
Teach the currency save/restore loop:
StableId owners → WalletSnapshot → JSON SaveBlob → load → restore through ICurrencyService → optional audit inspection.
What This Scene Demonstrates¶
This scene shows how wallet state can be captured, serialized, restored, and audited.
The flow is:
StableId owner → selected CurrencyId scope → WalletSnapshot → SaveBlob → JSON file → restore by StableId → CurOpResult
- Wallets are identified by
StableId, not scene object references - Capture creates
WalletSnapshotdata for selected currencies - JSON is only the transport format
- Restore maps saved owner ids back to scene objects
- Restore applies balances through the real
ICurrencyService - Audit is optional and depends on the composed service stack
Restore is not a silent field overwrite.
The service result is truth.
What To Look For¶
Use the CurrencyPersistenceAuditPanel to follow save, load, restore, and audit verification.
-
Setup tab
-
Shows the resolved
ICurrencyService - Shows whether audit reading is available
- Shows discovered
StableIdowner count - Shows valid captured currency count
- Shows the JSON file name
-
Provides Reason / SourceId metadata for restore operations
-
Persistence tab
-
File field controls the save file name under
Application.persistentDataPath - Save Now captures wallets and writes JSON to disk
- Load Now reads JSON and restores wallets through the service
- Show JSON (live) builds JSON from current wallet state without saving
-
Clear JSON Buffer only clears the visible text area
-
JSON area
-
Shows the exact JSON written or loaded
- Can be edited manually before loading
-
Negative balances are normalized to zero by the demo wrapper
-
Audit tab
-
Selects a discovered
StableIdowner - Filters recent entries by kind and currency
- Shows restore, set, credit, debit, or transfer entries when audit is available
Sample Scope¶
This scene covers:
- Discovering wallet owners by
StableId - Capturing selected currency balances into
WalletSnapshotdata - Wrapping snapshot dictionaries in a JsonUtility-friendly
SaveBlob - Saving and loading JSON under
Application.persistentDataPath - Restoring balances through
CurrencyPersistence.Restore - Applying Reason / SourceId metadata during restore
- Inspecting audit entries when
ICurrencyAuditReaderis available
This scene does NOT cover:
- Cloud saves
- Async file IO
- Encryption or save tamper protection
- Versioned migration pipelines
- Multiplayer replication or networking
- Full production save-slot management
Those are project-level concerns or dedicated integration work.
Authority Note¶
This scene may include a permissive sample authority setup so it runs without additional configuration.
Networking Reminder¶
RevFramework does not include networking.
For multiplayer projects, currency restore and mutation flows must be validated and executed through your own authority and networking layer.
How To Use¶
- Enter Play Mode.
- Toggle the
CurrencyPersistenceAuditPanelwithF8. -
In Setup:
-
Confirm
ICurrencyServiceis resolved - Confirm valid currencies are available
- Check whether audit is available
- Set Reason / SourceId for restore operations if desired
- Use another panel or gameplay to create wallet balances.
-
In Persistence:
-
Press Show JSON (live) to inspect current captured wallet state
- Press Save Now to write wallet JSON to disk
- Change balances so restore is visible
- Press Load Now to restore from the saved JSON
-
In Audit:
-
Select an owner
- Choose Last N
- Filter by kind or currency if needed
- Confirm restore entries appear when audit is available
Failure Behaviour¶
Failures are shown through dependency messages, save/load results, restore counts, or audit availability messages.
Common causes:
-
Play Mode required
-
The panel scans scene
StableIdobjects and reads live wallet state -
Fix: enter Play Mode
-
Service missing
-
No
ICurrencyServicewas resolved -
Fix: add
SceneCurrencyService, addCurrencyServiceBootstrap, or publish a custom service -
Audit not available
-
The active service does not expose
ICurrencyAuditReader - Fix: compose audit support into the service stack if this scene is meant to show audit
-
Persistence still works without audit
-
No capture currencies available
-
No valid currencies were found from
CurrencySetor boundCurrencyDefinitionassets -
Fix: assign a CurrencySet or valid CurrencyDefinitions before saving or building JSON
-
Save error
-
File writing failed
-
Fix: check file name, path permissions, and valid capture currencies
-
Load file missing
-
The named JSON file does not exist
-
Fix: press Save Now first or enter an existing save file name
-
Load parse error
-
JSON does not match the expected
SaveBlobformat -
Fix: correct the JSON structure and owner/currency ids
-
Missing owners during restore
-
Saved owner ids do not match any current scene
StableId -
Fix: check StableId values in the scene against
ownerIdvalues in the JSON -
Restore failed for an owner
-
The service rejected one or more restored balances
- Fix: inspect service rules, authority, caps, and the selected currency data
Behind The Scenes¶
The panel uses real Currency persistence and audit APIs:
-
CurrencyResolve.ServiceFrom -
resolves the active
ICurrencyService -
StableId -
provides persistent owner identity
-
CurrencyPersistence.Capture -
captures selected currency balances into a
WalletSnapshot -
CurrencyPersistence.Restore -
restores a snapshot through the resolved
ICurrencyService -
WalletSnapshot -
stores captured currency lines
-
SaveBlob -
wraps owner snapshot data so
JsonUtilitycan serialize it -
JsonUtility.ToJson -
serializes the save data
-
JsonUtility.FromJson -
parses loaded save data
-
Application.persistentDataPath -
stores the demo save file
-
ICurrencyAuditReader -
enables audit display when composed into the service stack
-
CurrencyAudit.Get -
reads recent audit entries for the selected owner
JSON stores data.
StableId maps that data back to scene owners.
ICurrencyService decides what actually restores.
Key Takeaway¶
Persistence saves wallet state by stable owner identity, not scene references.
Restore goes back through the real currency service.
Audit, when available, proves what changed and why.