-
Notifications
You must be signed in to change notification settings - Fork 0
Data class
- Overview of the Data System
- Data Properties
- Interacting with Properties
- Listening to Properties
- Registering Elements
- Parsing YAML files to Add or Update Upgrades and Properties
The Data system is a pivotal part of Dome Keeper. Acting as a core data handler, the Data singleton manages a myriad of game properties. It oversees the loading of various elements, parsing YAML files, applying upgrades, managing gadgets, listeners, and more.
The Data system primarily serves as a variable storage and notification service. Any script can add to and listen for changes in any property stored in Data, with notifications issued upon changes to properties. This configuration facilitates the easy interconnection of various game systems in a decoupled manner.
Simply put, properties in Data are variables stored in the values dictionary within Data. Data acts as a layer between these variables and other systems, providing additional functionality and utility.
Properties follow a straightforward naming pattern:
elementId.propertyName
❗ Examples:
dome.health, laser.dps or keeper1.drillStrength
It's highly recommended to read more about properties here to get a deeper understanding about the naming scheme.
💡 Tip: Even though some properties are written in camelCase, adhere to using lower case property names when writing code.
In the following sections, we will explore some of the most significant methods of interacting with properties.
To retrieve the current value of a property in Data, use the Data.of(property:String) method.
❗ Example:
Data.of("dome.health")In case you're uncertain if a property exists, you can use Data.ofOr(property:String, default). This will return the default parameter you set if the property isn't yet in Data.
❗ Example:
Data.ofOr("multiplayer.releasedate", "soon")To add properties to Data, employ the Data.apply(property:String, value) method.
❗ Examples:
Data.apply("hydraLauncher.projectileDamage", 10)Data.apply("domeKeeper.isAwesome", true)To change numerical property values, use Data.changeByInt(property:String, change).
❗ Example:
# dome.health: 100
Data.changeByInt("dome.health", -20)
# dome.health: 80💡 Tip: This method also works with float values.
Alternatively, properties can be altered using Data.apply(property:String, value).
❗ Example:
# dome.health: 100
Data.apply("dome.health", Data.of("dome.health")-20)
# dome.health: 80The property listeners are what truly set Data apart. These listeners notify any listening script about property changes.
To listen to a property from a script, use Data.listen(listener, property:String).
❗ Example:
func _ready():
Data.listen(self, "dome.health")As part of this interaction, a new propertyChanged function should be added to the script that listens to Data property changes. This function's boilerplate code can be found above the listen() function in Data.
❗ Example:
func propertyChanged(property:String, oldValue, newValue):
match property:
# ONLY LOWERCASE HERE
"dome.health":
# do things
if newValue <= 0:
print("GitGud")To stop listening to a particular property change, you can invoke Data.unlisten(listener, property:String).
Data provides several functions to "register" new elements to the game:
registerDome(domeId:String)registerKeeper(keeperId:String)registerGameMode(gameModeId:String)registerGadget(gadgetId:String)registerRunModifier(runModifierId:String)registerPet(petId:String)registerSkin(keeperId:String, skinId:String)
These functions are particularly handy for adding mod content to the game.
❗ Example:
Data.registerGameMode("Deathmatch")Data includes two functions that parse YAML files and either add or update the game's gadgets/upgrades. These are the same functions that Dome Keeper uses initially to add all the upgrades and properties to the game.
You can leverage these functions to modify properties via a YAML file or to add your own elements to the game.
The parseUpgradesYaml function is most commonly used by mods.
By using Data.parseUpgradesYaml(upgradesPath:String), you can parse a .yaml file that has a similar format to the original upgrades.yaml.
🚨 Important: These yaml parsing functions do NOT support the complete yaml syntax! Ensure you examine the original upgrades.yaml file to understand what can and cannot be used.
❗ Example:
Review the upgrades.yaml file in the Hydra Launcher mod to comprehend how new properties and upgrades are defined.
This file is parsed in the mod's modInit() function as follows:
Data.parseUpgradesYaml("path/to/upgrades.yaml")
Data then parses the new gadget, its upgrades, and the properties, setting everything up accordingly.

