Animatron/player — pull request #29 by shamansir (2012-07-17 14:45:12+00:00)
Title: From 0.23 bugfixes: Fix Issue in children cloning

Relates to [`another_cloning_problem`][1] tag in [Nek.Chain-Reaction][2] game:

Colors of the circles were not cloned and click/contains tests failed to check point correctly when called `var newLevel = b(level)` (see [L227][3]). It was a complicate one, despite the fix looks tiny.

The reasons/fixes:

* When cloned, every child (circle thing) of the level kept the `parent` pointer pointing to the source level, which was never drawn and so had no state/matrix -> coordinates were converted to global space incorrectly, so contains failed to work. Now `parent` link is updated to point to new clone when cloning, for children (not for the cloned element, because cloning means detaching from the tree).
* Circle drawing problem. A painter of a circle uses `builder.f` (fill) and `builder.s` (stroke) properties to draw an arc with current color, and it saved a pointer to source builder to update them if they were changed. These properties are stored only in Builder instance in case of circle (for other shapes they are stored as as `xdata.path` properties). However:
* The 'template' circle was cloned to produce other circles with different random fill, so builder pointer from a closure became invalid in each case. Now I store a link to builder in the element itself.
* Then, they were cloned as a children of a level. When a cloning like this happens, only elements' instances are appended to the clone as children, not the builders that wrapped them (however, if there were no previous case, closure pointer to builder should be saved anyway, physically builders were not lost). It was also solved with keeping a link (and copying it with the clone operation) to builder instance, in the element and using it in painter.

[1]: https://github.com/Nek/Chain-Reaction/tree/another_cloning_problem
[2]: https://github.com/Nek/Chain-Reaction
[3]: https://github.com/Nek/Chain-Reaction/blob/another_cloning_problem/index.html#L227