Closed loopier closed 8 months ago
I'd put it in the coreCommands
with the mapped value probably being the callable to your colorActor
method.
There are different command map dictionaries depending on how messages should be handled:
coreCommands
calls the method passing the command arguments as individual and separate parameters. For example: the entry coreCommands{ "/create": createActor }
is mapping /create actor anim
to createActor(actor, anim)
.arrayCommands
calls the method passing the command arguments as an array. For example arrayCommands{ "/def": setDef }
maps /def /bla arg1 , /create $arg1 bla
to setDef(["/bla", "arg1", ",", "/create", "$args1", "bla"])
.nodeCommands
use the command address as method call, so you can just add entries with existing GDScript node methods replacing underscores with /
. For example: nodeCommands = { "/rotation/degrees": setActorProperty }
would map /rotation/degrees target 45
to something like getActor("target").set_rotation_degrees(45)
. There are different callables depending on what we need to do with the arguments: set a node property, set an animation property, if the property setter accepts a value or a vector, etc... If you look at the values in this dictionary you'll see that they repeat a lot. They are generic methods to call different stuff of the actors.Does it make sense? I know its a bit confusing, but I think it makes it easier to implement new stuff. The hardest part may be knowing in what dictionary it must be added. Naming of the dictionaries might not be very helpful in this regard and should probably change? Can you think of a better way? All dictionaries are parsed in the same function, which I think is the most confusing of all. But passed this point, everything is very intuitive and I don't think we'll need too change much in this function (just if we need any other kind of dictionary).
In your case I'd probably add it to coreCommands
:
var coreCommands: Dictionary = {
// ...
"/color": colorActor,
}
# the sender is handled by the parser before calling this method so we don't need to add it as argument
func colorActor(actor: String, red: float, green: float, blue: float) -> Status:
var result = getActor(actorName)
if result.isError(): return result
var node = result.value
var rgb = Vector3(red, green, blue)
setShaderUniform(node, "uAddColor", rgb)
return result
func setShaderUniform(node, uname, uValue):
# the code to change the color
I think arrayCommands
is unnecessary. We could use a common callable for commands that need arguments to be passed as an array, like we do in nodeCommands
with methods callActorMethodWithVector
and the like. Maybe name it callMethodWithArray
?
I'm not sure we can unify nodeCommands
and coreCommands
because the former passes the command address (the dictionary key) as first argument and that is parsed in parseCommand
.
In your case I'd probably add it to coreCommands:
Thanks, I did that in 326d475. The support for /color
is now there, as it was with the Godot 3.x version, using a very simple shader for now. BTW, what happened to the docs
directory we used to have, with the Markdown documentation? Where should I document this new OSC command?
what happened to the
docs
directory we used to have, with the Markdown documentation? Where should I document this new OSC command?
I created a new issue to discuss the help system.
This issue has been resolved at some point (not sure when, though...)
@totalgee wrote:
Not sure I totally understand yet how your generic command handling works. If I want to add "set color" for Actors, I would add a new entry in nodeCommands, and then somehow it dispatches the correct thiing... But in this case I need to get some sub-objects (e.g. a ShaderMaterial) and then set some arbitary value on it. Nothing so far seems to be written in a "special case" like this, but how would you do it?
In the old days, it was: