Closed ilya-klindukhov closed 3 years ago
Hi. I made some changes.
<X>Strategy
- I think - it is bad idea because if pattern strategy will using in another place than will not clear which strategy where using. Prefix Spawn<X>Strategy
say that this strategy about spawn particles.Ah, I missed that spawn strategies were global, and was thinking that they were one per emitter. In that case, I would suggest that parseConfig()
on each strategy returns an object containing the parsed data, and the emitter saves that object and gives it back during spawn()
. That way, the Emitter and its properties don't need to know about any of the strategy specifics, only that the strategy exists.
With release 5.0.0, the emitter now uses configurable behaviors for everything, including spawn strategies, which should cover the use cases here.
Hi again.
I made a little bit refactoring)
What was made:
1) create spawnFactory with registered spawn strategies for each spawnType. Spawn funcions and parsing spawn config moved from Emitter to strategies. SpawnFactory supporting add new strategies and override exists by extend from it. The Emitter has become easier.
2) removed _spawnFunc() from Emitter. Insteand using strategy.spawn(). At the start of refactoring I don't remove it and mark as deprecated and set _spawnFunc = strategy.spawn for legacy. But this solution has some limitation i.e. if strategy has other function which using in spawn than this functions not available because to _spawnFunc set link to function and strategy context(this) will be missing. Also was additional code for decide which function use _spawnFunc or strategy.spawn(). I decided to remove _spawnFunc() and using only strategy.spawn().
3) add public getter for rotation property and rename to _rotation protected property. Using in spawn functions on strategies.
I tried to do as less as possible breaking changes on this refactoring. Potential BC: 1) using _spawnFunc in extended classes. Early this function was private ( I made this function protected 3 days ago and think than no one had time to use it). Using hack emitter["_spawnFunc"] not in count. 2) rotation -> _rotation. Can affect if try to set value to 'rotation' property in extended from Emitter class. But to set rotation has rotate() function so this case must be quite rare.
Some examples how it help to customize emitter: I will use previos example with spawn rect with normal
1) register new spawn strategy 'rectNormal'
Emitter
Factory
Strategy
2. Change already exists strategy
Emitter
Factory
Strategy
Config