arcadia-unity / ArcadiaGodot

Other
174 stars 14 forks source link

Implement EDN defined variables #26

Closed kwrooijen closed 3 years ago

kwrooijen commented 3 years ago

This PR allows users to defined export variables (https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_exports.html) with Clojure's EDN syntax.

The basic idea is that you have a variables.edn file in your project's root directory where you define a map. The keys of the map are the paths to the scenes (using the res:// syntax) and the values are maps with keys + types. The types are written just like you would in GDScript (see the gdscript_exports link mentioned above). All the example on the docs page are supported except for the enum keyword. Here's an example on a variables.edn file:

{"res://Scenes/Main.tscn"
 {:mob PackedScene}

 "res://Scenes/Player.tscn"
 {:speed int
  :job (String "Warrior" "Magician" "Thief")}

 "res://Scenes/Mob.tscn"
 {:min-speed int
  :max-speed int}}

When the game launches (in debug mode), the variables.edn file is read and generates GDScripts for each key value pair. These scripts are then attached to their respective scenes. Afterwards when these variables are read and set in the node's state when a node's callback is called (e.g. ready, process). This way the programmer doesn't have to use .Get and can refer to their own specified keyword.

Currently the watcher doesn't listen to variables.edn. Once the watcher PR is merged I can implement that as well.

Fixes: https://github.com/arcadia-unity/ArcadiaGodot/issues/24

kwrooijen commented 3 years ago

I'm not sure why, but for some reason when I change an export variable in the editor, the new value doesn't get applied in the current runtime. You have to close and re-open the game to actually get the new value. This isn't the case when using pure C#.

Edit: Nevermind, this only happens when I try to create a new Instance of a scene. Maybe this is default Godot behavior. Existing nodes don't reset their state when variables are changed though. So you still don't have variable live reload (Unless you use .Get).

Edit2: Another problem is that we'd need compile the variables.edn file with the release build, since this is used to populate the Node's state (being able to know which variables belong to which nodes with which keyword). With all of these problems (and myself not seeing an immediate solution) we might want to opt for just using the .Get method rather than populating the state.

selfsame commented 3 years ago

I understand the idea here, but I'd like to avoid code generation, and manually creating a gdscript or C# class to hold export properties probably serves most needs.