Overview
dill pixel provides a robust data management system through its DataAdapter
class. This system allows you to:
- Store and retrieve game data
- Persist data to localStorage
- Listen for data changes
- Selectively backup specific data keys
Basic Configuration
Configure data management in your dill-pixel.config.ts
:
Data Manipulation Methods
The DataAdapter provides several methods for managing game data. Each has specific use cases and behaviors.
save() Method
The save()
method updates a single key and triggers localStorage backup if configured:
set() Method
The set()
method allows updating multiple values at once, with optional deep merging:
get() and load() Methods
Two methods are available for retrieving data:
Key differences:
get()
: Returns the entire data object
load()
: Returns a specific field value with type safety
clear() Method
The clear()
method removes data both from memory and localStorage:
Deep Merging Behavior
When using set()
with merge: true
(default), the DataAdapter performs a deep merge:
In src/dill-pixel.config.ts
:
In src/MyApplication.ts
In src/scenes/MyScene.ts
Change Events
All data modifications emit change events that you can listen to: