arcadia-unity / ArcadiaGodot

Other
174 stars 14 forks source link

Implement automatic hook attachment through function metadata #25

Closed kwrooijen closed 3 years ago

kwrooijen commented 3 years ago

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

This PR implements a method of automatically attaching hooks to scenes. It does it in the follow way:

  1. Add metadata to your function is the form:

    (defn ^:{:hook/ready ["res://Scene/Main.tscn"]} ready [self _] ,,,)
  2. During startup we search for all clj files in :source-paths and process these in arcadia/internal/hook.clj.

  3. Load these files, get all their functions + metadata and filter any :hook/* keys.

  4. Generate a new ArcadiaHook node (through ArcadiaHook.tscn) and attach any hook to keys this.

  5. Attach the new ArcadiaHook node to the scene specified in the metadata, if the hooks did not change, skip this step.

  6. Do these steps for each file separately when the specific file changes (with the ArcadiaWatcher)

What do you think of this strategy? Being able to attach hooks through clojure code is a much better experience IMHO rather than manually adding the node + hooks. This is also an opt-in method so you could also choose the manual route if you want to.

selfsame commented 3 years ago

functions declaring the node file path they attach to is an interesting and ergonomic idea, but I think ultimately attaching a script to a game object is the familiar pattern here.