Hey there,
I’m looking for a way to dynamically change the proto argument of an existing Event for Object Prototyping purposes. Do you have any tips?
// Create A Proto-Object for ALL Objects
~proto = (rectSize: {|ev| ev.rect.bounds });
~templates = IdentityDictionary[]; // Templates-Lib
~templates[\classA] = (rect: { Rect(200, 200, 105, 20)}).proto_(~proto);
~templates[\classB] = (rect: { Rect(200, 200, 115, 27)}).proto_(~proto);
// create some Objects
~objA = (someFunc: {|ev| "hello A bounds: %".format(ev.rectSize).postln}).proto_(~templates[\classA])
~objB = (someFunc: {|ev| "hello B bounds: %".format(ev.rectSize).postln}).proto_(~templates[\classB])
// Inheritance works:
~objB.someFunc
~objA.rectSize
What I would like to do is the following:
// 1. change the template in the Dictionary
~templates[\classA] = (rect: { Rect(200, 200, 105, 2000)}).proto_(~proto);
// 2. Call mehthods in the Objects
~objA.someFunc // this would now return Size(105,2000) after swapping out the Template
Unfortunately, just passing in a function doesn’t seem to work.
~objA = (someFunc: {|ev| "hello A bounds: %".format(ev.rectSize).postln}).proto_({~templates[\classA]}) // doesn't work
Of course I could keep track of all created Event-“Objects” by using a makeObject-Function, but this doesn’t seem very convenient at the moment.
Thanks for reading!
Moritz