loopier / animatron

Animatron for Godot 4.x <
MIT License
16 stars 1 forks source link

Relative commands - syntax #9

Open loopier opened 1 year ago

loopier commented 1 year ago

I've started implementing /relative commands (https://github.com/loopier/animatron/commit/434598dba303ad847b4ac5b5611736d7fbb52c74), and I'm not sure about the approach. The syntax so far is: /relative /command actor value[s], for example: /relative /position x 0.1 0.1.

A pro of this syntax is that we only need one entry in the commands Dictionary:

commands = {
  "/relative": setRelativeProperty,
  ...
}

But it's problematic if we want to use aliases:

nodeCommands = {
  "/position": setProperty,
  "/move": ???, # how do we tell it to use a relative value of '/position'?
...
}

One solution is using "/relative/<property>": setRelativeProperty, and extract the property name from the command address in setRelativeProperty(key, args):

nodeCommands = {
  "/position": setProperty,
  "/relative/position": setRelativeProperty,
  "/move": "/relative/position",

This demands of one extra entry for aliases but I think I prefer it, not sure.

What do you think?

totalgee commented 1 year ago

One problem with relative commands might be that what "relative" means might be different for different properties. For example, for position or 2D rotation, the relative would be done additively. For something like scaling, it might make more sense to be multiplicative (e.g. 10% bigger or 50% smaller, factors of 1.1x or 0.5x). Adding -0.5 to scaling isn't really useful in general.

But that's a different topic from what you're asking here. One thing that occurred to me is you could maybe use lambdas to define some of those functions, like the simple "glue" that binds the right things to call the appropriate "relative position" command for /move.

On Sat, Sep 2, 2023, 09:00 Roger Pibernat @.***> wrote:

I've started implementing /relative commands (434598d https://github.com/loopier/animatron/commit/434598dba303ad847b4ac5b5611736d7fbb52c74), and I'm not sure about the approach. The syntax so far is: /relative /command actor value[s], for example: /relative /position x 0.1 0.1.

A pro of this syntax is that we only need one entry in the commands Dictionary:

commands = { "/relative": setRelativeProperty, ... }

But it's problematic if we want to use aliases:

nodeCommands = { "/position": setProperty, "/move": ???, # how do we tell it to use a relative value of '/position'? ... }

One solution is using "/relative/": setRelativeProperty, and extract the property name from the command address in setRelativeProperty(key, args):

nodeCommands = { "/position": setProperty, "/relative/position": setRelativeProperty, "/move": "/relative/position",

This demands of one extra entry for aliases but I think I prefer it, not sure.

What do you think?

— Reply to this email directly, view it on GitHub https://github.com/loopier/animatron/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKXIUNDP3NW3F5LE3SONDXYMUV3ANCNFSM6AAAAAA4ISYMHQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

loopier commented 1 year ago

That's one of the things I was wondering about.

The lambdas sound like a good solution. What would be the syntax?

Some more ideas:

/<property> <target> <operator> <amount>

Usage:

/size target /mult 0.5
/angle target /add 30

or

/size target /= 0.5 # setter
/size target /* 0.5
/angle target /+ 30 

or

/size target = 0.5
/size target * 0.5
/angle target + 30 

A variant of the same idea

/multiply <target> <property> <amount>
/add <target> <property> <amount>
/multiply target /size 2
/add target /angle -30

or, to be consistent with other commands with subcommands:

/multiply /size target 2
/add /angle target -30