This Lua module for Defold ensures selected "game.project" settings keep their expected values by reading from inside the bundle, inhibiting the extraordinary tampering Defold allows if players edit "game.projectc".
Called as a function, it constructs a new .projectc-formatted file from the developer's desired constants and the user's desired configuration, then reboots the game using the merged config. The file exposes the same settings as before ("look"), but in an unassuming & suitably-named hidden file called ".session" that has no effect on the game if edited ("don't touch").
Setup:
- Include this module & "inifile" with your project, and add "look_dont_touch" to a script at game start with "require()"
- Create a ".lua" file that returns an empty table for saving project constants; if the project has been bundled before, Look Don't Touch fills the table in debug
- A table in "look_dont_touch.lua" named "lookup" defines configurable settings; it includes common game options, maybe missing some troubleshooting/compatibility
- Call the module as a function; it returns
true
if successful
look_dont_touch(consts_path, consts_table, passkey)
-- consts_path = path string to save the constants module
-- consts_table = the constants module
-- passkey
5C4D
= the body of a "--config=" argument, like "bootstrap.rebooted=true"
The constants table only picks up changes when running the project in debug, after bundling the project at least one time with the correct settings.
The "game.projectc" file may be tidied up by deleting unwanted categories or keys. Note: Defold still requires file paths if it cannot resolve an alternative. For example, if the "main_collection" key is omitted, Defold looks for it at the engine default value: "/logic/main.collectionc"