DWAutoLoad Node
DWAutoLoad Node
A Node that persists itself as a single row
Base node for global state that should round-trip through SQLite using the same schema metadata as DWRecord.
Ideal for inventories, progression flags, or analytics caches that live in Autoload singletons.
Automatically mirrors exported properties into a backing table using the node name as the key.
Supports manual `save_to_db(true)` calls when quitting or before scene transitions.
Usage patterns
Declare the state
Same rules as DWRecord, but the table holds one row. Add it as an autoload and it loads itself when the service connects.
class_name GameState extends DWAutoLoad
var table_name := "game_state"
var chapter: int = 1
var flags: Dictionary = {}
var unlocked: Array[String] = []
It saves itself
The node loads on ready (or when the service connects) and saves on `disconnecting`, so a normal shutdown persists it with no explicit call. Save by hand before anything risky.
func _on_chapter_complete() -> void:
chapter += 1
save_to_db(true) # wait for the commit before moving on
Key methods
- save_to_db(wait: bool = false) -> bool
Persists the node's state to its single row.
- load_from_db() -> bool
Loads the stored row back into this node.
Operational tips
- Add it as an autoload; it hooks the service's connect and disconnect signals itself.
- `table_type` is always AUTOLOAD for these, which is what makes the table single-row.