ShapeModifiers.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {
  2. extendPrototype,
  3. } from '../functionExtensions';
  4. import DynamicPropertyContainer from '../helpers/dynamicProperties';
  5. import {
  6. initialDefaultFrame,
  7. } from '../../main';
  8. import shapeCollectionPool from '../pooling/shapeCollection_pool';
  9. const ShapeModifiers = (function () {
  10. var ob = {};
  11. var modifiers = {};
  12. ob.registerModifier = registerModifier;
  13. ob.getModifier = getModifier;
  14. function registerModifier(nm, factory) {
  15. if (!modifiers[nm]) {
  16. modifiers[nm] = factory;
  17. }
  18. }
  19. function getModifier(nm, elem, data) {
  20. return new modifiers[nm](elem, data);
  21. }
  22. return ob;
  23. }());
  24. function ShapeModifier() {}
  25. ShapeModifier.prototype.initModifierProperties = function () {};
  26. ShapeModifier.prototype.addShapeToModifier = function () {};
  27. ShapeModifier.prototype.addShape = function (data) {
  28. if (!this.closed) {
  29. // Adding shape to dynamic properties. It covers the case where a shape has no effects applied, to reset it's _mdf state on every tick.
  30. data.sh.container.addDynamicProperty(data.sh);
  31. var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() };
  32. this.shapes.push(shapeData);
  33. this.addShapeToModifier(shapeData);
  34. if (this._isAnimated) {
  35. data.setAsAnimated();
  36. }
  37. }
  38. };
  39. ShapeModifier.prototype.init = function (elem, data) {
  40. this.shapes = [];
  41. this.elem = elem;
  42. this.initDynamicPropertyContainer(elem);
  43. this.initModifierProperties(elem, data);
  44. this.frameId = initialDefaultFrame;
  45. this.closed = false;
  46. this.k = false;
  47. if (this.dynamicProperties.length) {
  48. this.k = true;
  49. } else {
  50. this.getValue(true);
  51. }
  52. };
  53. ShapeModifier.prototype.processKeys = function () {
  54. if (this.elem.globalData.frameId === this.frameId) {
  55. return;
  56. }
  57. this.frameId = this.elem.globalData.frameId;
  58. this.iterateDynamicProperties();
  59. };
  60. extendPrototype([DynamicPropertyContainer], ShapeModifier);
  61. export {
  62. ShapeModifiers,
  63. ShapeModifier,
  64. };