@awayjs/scene 0.13.324 → 0.13.325

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/.eslintrc +100 -100
  2. package/README.md +61 -61
  3. package/bundle/awayjs-scene.umd.js +1 -1
  4. package/bundle/awayjs-scene.umd.js.map +1 -1
  5. package/copyVersionToIndex.js +23 -23
  6. package/dist/index.d.ts +76 -76
  7. package/dist/index.js +67 -67
  8. package/dist/lib/Scene.d.ts +85 -85
  9. package/dist/lib/Scene.js +285 -285
  10. package/dist/lib/Settings.d.ts +16 -16
  11. package/dist/lib/Settings.js +60 -60
  12. package/dist/lib/adapters/IDisplayObjectAdapter.d.ts +13 -13
  13. package/dist/lib/adapters/IDisplayObjectAdapter.js +1 -1
  14. package/dist/lib/adapters/IFilter.d.ts +24 -24
  15. package/dist/lib/adapters/IFilter.js +1 -1
  16. package/dist/lib/adapters/IMovieClipAdapter.d.ts +15 -15
  17. package/dist/lib/adapters/IMovieClipAdapter.js +1 -1
  18. package/dist/lib/adapters/ITextfieldAdapter.d.ts +4 -4
  19. package/dist/lib/adapters/ITextfieldAdapter.js +1 -1
  20. package/dist/lib/base/IBitmapDrawable.d.ts +11 -11
  21. package/dist/lib/base/IBitmapDrawable.js +1 -1
  22. package/dist/lib/base/IFrameLabel.d.ts +4 -4
  23. package/dist/lib/base/IFrameLabel.js +1 -1
  24. package/dist/lib/base/IFrameScript.d.ts +5 -5
  25. package/dist/lib/base/IFrameScript.js +1 -1
  26. package/dist/lib/base/MouseButtons.d.ts +26 -26
  27. package/dist/lib/base/MouseButtons.js +1 -1
  28. package/dist/lib/base/Timeline.d.ts +147 -147
  29. package/dist/lib/base/Timeline.js +525 -525
  30. package/dist/lib/base/TimelineActionType.d.ts +18 -18
  31. package/dist/lib/base/TimelineActionType.js +1 -1
  32. package/dist/lib/controllers/ControllerBase.d.ts +14 -14
  33. package/dist/lib/controllers/ControllerBase.js +60 -60
  34. package/dist/lib/controllers/FirstPersonController.d.ts +78 -78
  35. package/dist/lib/controllers/FirstPersonController.js +228 -228
  36. package/dist/lib/controllers/FollowController.d.ts +12 -12
  37. package/dist/lib/controllers/FollowController.js +27 -27
  38. package/dist/lib/controllers/HoverController.d.ts +105 -105
  39. package/dist/lib/controllers/HoverController.js +302 -302
  40. package/dist/lib/controllers/LookAtController.d.ts +14 -14
  41. package/dist/lib/controllers/LookAtController.js +68 -68
  42. package/dist/lib/controllers/SpringController.d.ts +38 -38
  43. package/dist/lib/controllers/SpringController.js +59 -59
  44. package/dist/lib/display/Billboard.d.ts +132 -132
  45. package/dist/lib/display/Billboard.js +397 -397
  46. package/dist/lib/display/Camera.d.ts +31 -31
  47. package/dist/lib/display/Camera.js +72 -72
  48. package/dist/lib/display/DisplayObject.d.ts +921 -921
  49. package/dist/lib/display/DisplayObject.js +1595 -1595
  50. package/dist/lib/display/DisplayObjectContainer.d.ts +325 -325
  51. package/dist/lib/display/DisplayObjectContainer.js +486 -486
  52. package/dist/lib/display/LineSegment.d.ts +69 -69
  53. package/dist/lib/display/LineSegment.js +203 -203
  54. package/dist/lib/display/LoaderContainer.d.ts +504 -504
  55. package/dist/lib/display/LoaderContainer.js +603 -603
  56. package/dist/lib/display/MorphSprite.d.ts +20 -20
  57. package/dist/lib/display/MorphSprite.js +246 -246
  58. package/dist/lib/display/MovieClip.d.ts +149 -149
  59. package/dist/lib/display/MovieClip.js +733 -733
  60. package/dist/lib/display/SimpleButton.d.ts +158 -158
  61. package/dist/lib/display/SimpleButton.js +228 -228
  62. package/dist/lib/display/Skybox.d.ts +144 -144
  63. package/dist/lib/display/Skybox.js +288 -288
  64. package/dist/lib/display/Sprite.d.ts +65 -65
  65. package/dist/lib/display/Sprite.js +134 -134
  66. package/dist/lib/display/TextField.d.ts +1104 -1104
  67. package/dist/lib/display/TextField.d.ts.map +1 -1
  68. package/dist/lib/display/TextField.js +3019 -3018
  69. package/dist/lib/display/TextSprite.d.ts +16 -16
  70. package/dist/lib/display/TextSprite.js +36 -36
  71. package/dist/lib/elements/SkyboxElements.d.ts +29 -29
  72. package/dist/lib/elements/SkyboxElements.js +127 -127
  73. package/dist/lib/errors/CastError.d.ts +4 -4
  74. package/dist/lib/errors/CastError.js +10 -10
  75. package/dist/lib/events/CameraEvent.d.ts +16 -16
  76. package/dist/lib/events/CameraEvent.js +30 -30
  77. package/dist/lib/events/FocusEvent.d.ts +42 -42
  78. package/dist/lib/events/FocusEvent.js +43 -43
  79. package/dist/lib/events/KeyboardEvent.d.ts +21 -21
  80. package/dist/lib/events/KeyboardEvent.js +43 -43
  81. package/dist/lib/events/MouseEvent.d.ts +91 -91
  82. package/dist/lib/events/MouseEvent.js +122 -122
  83. package/dist/lib/events/PointerEvent.d.ts +93 -93
  84. package/dist/lib/events/PointerEvent.js +73 -73
  85. package/dist/lib/events/ResizeEvent.d.ts +15 -15
  86. package/dist/lib/events/ResizeEvent.js +38 -38
  87. package/dist/lib/events/TextfieldEvent.d.ts +19 -19
  88. package/dist/lib/events/TextfieldEvent.js +28 -28
  89. package/dist/lib/events/TouchEvent.d.ts +54 -54
  90. package/dist/lib/events/TouchEvent.js +89 -89
  91. package/dist/lib/factories/DefaultSceneGraphFactory.d.ts +27 -27
  92. package/dist/lib/factories/DefaultSceneGraphFactory.js +55 -55
  93. package/dist/lib/factories/ISceneGraphFactory.d.ts +20 -20
  94. package/dist/lib/factories/ISceneGraphFactory.js +1 -1
  95. package/dist/lib/image/SceneImage2D.d.ts +220 -220
  96. package/dist/lib/image/SceneImage2D.js +610 -610
  97. package/dist/lib/managers/DefaultFontManager.d.ts +14 -14
  98. package/dist/lib/managers/DefaultFontManager.js +101 -101
  99. package/dist/lib/managers/DeviceFontManager.d.ts +8 -8
  100. package/dist/lib/managers/DeviceFontManager.js +44 -44
  101. package/dist/lib/managers/FrameScriptManager.d.ts +37 -37
  102. package/dist/lib/managers/FrameScriptManager.js +386 -386
  103. package/dist/lib/managers/IInputRecorder.d.ts +3 -3
  104. package/dist/lib/managers/IInputRecorder.js +1 -1
  105. package/dist/lib/managers/MouseManager.d.ts +74 -74
  106. package/dist/lib/managers/MouseManager.js +803 -803
  107. package/dist/lib/prefabs/PrefabBase.d.ts +19 -19
  108. package/dist/lib/prefabs/PrefabBase.js +42 -42
  109. package/dist/lib/prefabs/PrimitiveCapsulePrefab.d.ts +56 -56
  110. package/dist/lib/prefabs/PrimitiveCapsulePrefab.js +269 -269
  111. package/dist/lib/prefabs/PrimitiveConePrefab.d.ts +21 -21
  112. package/dist/lib/prefabs/PrimitiveConePrefab.js +43 -43
  113. package/dist/lib/prefabs/PrimitiveCubePrefab.d.ts +74 -74
  114. package/dist/lib/prefabs/PrimitiveCubePrefab.js +545 -545
  115. package/dist/lib/prefabs/PrimitiveCylinderPrefab.d.ts +79 -79
  116. package/dist/lib/prefabs/PrimitiveCylinderPrefab.js +584 -584
  117. package/dist/lib/prefabs/PrimitivePlanePrefab.d.ts +65 -65
  118. package/dist/lib/prefabs/PrimitivePlanePrefab.js +300 -300
  119. package/dist/lib/prefabs/PrimitivePolygonPrefab.d.ts +29 -29
  120. package/dist/lib/prefabs/PrimitivePolygonPrefab.js +64 -64
  121. package/dist/lib/prefabs/PrimitivePrefabBase.d.ts +67 -67
  122. package/dist/lib/prefabs/PrimitivePrefabBase.js +158 -158
  123. package/dist/lib/prefabs/PrimitiveSpherePrefab.d.ts +48 -48
  124. package/dist/lib/prefabs/PrimitiveSpherePrefab.js +294 -294
  125. package/dist/lib/prefabs/PrimitiveTorusPrefab.d.ts +55 -55
  126. package/dist/lib/prefabs/PrimitiveTorusPrefab.js +260 -260
  127. package/dist/lib/text/AntiAliasType.d.ts +24 -24
  128. package/dist/lib/text/AntiAliasType.js +28 -28
  129. package/dist/lib/text/BitmapFontChar.d.ts +39 -39
  130. package/dist/lib/text/BitmapFontChar.js +42 -42
  131. package/dist/lib/text/BitmapFontTable.d.ts +73 -73
  132. package/dist/lib/text/BitmapFontTable.js +183 -183
  133. package/dist/lib/text/FNTGenerator.d.ts +10 -10
  134. package/dist/lib/text/FNTGenerator.js +74 -74
  135. package/dist/lib/text/FNTGeneratorCanvas.d.ts +22 -22
  136. package/dist/lib/text/FNTGeneratorCanvas.js +211 -211
  137. package/dist/lib/text/FNTGeneratrorBase.d.ts +7 -7
  138. package/dist/lib/text/FNTGeneratrorBase.js +7 -7
  139. package/dist/lib/text/Font.d.ts +38 -38
  140. package/dist/lib/text/Font.js +109 -109
  141. package/dist/lib/text/FontLookUpMode.d.ts +5 -5
  142. package/dist/lib/text/FontLookUpMode.js +7 -7
  143. package/dist/lib/text/FontStyleName.d.ts +6 -6
  144. package/dist/lib/text/FontStyleName.js +7 -7
  145. package/dist/lib/text/GridFitType.d.ts +31 -31
  146. package/dist/lib/text/GridFitType.js +35 -35
  147. package/dist/lib/text/HTMLTextProcessor.d.ts +8 -8
  148. package/dist/lib/text/HTMLTextProcessor.js +426 -426
  149. package/dist/lib/text/IFontTable.d.ts +16 -16
  150. package/dist/lib/text/IFontTable.js +1 -1
  151. package/dist/lib/text/TesselatedFontChar.d.ts +58 -58
  152. package/dist/lib/text/TesselatedFontChar.js +66 -66
  153. package/dist/lib/text/TesselatedFontTable.d.ts +88 -88
  154. package/dist/lib/text/TesselatedFontTable.js +963 -963
  155. package/dist/lib/text/TextFieldAutoSize.d.ts +28 -28
  156. package/dist/lib/text/TextFieldAutoSize.js +32 -32
  157. package/dist/lib/text/TextFieldType.d.ts +20 -20
  158. package/dist/lib/text/TextFieldType.js +24 -24
  159. package/dist/lib/text/TextFormat.d.ts +273 -273
  160. package/dist/lib/text/TextFormat.js +449 -449
  161. package/dist/lib/text/TextFormatAlign.d.ts +26 -26
  162. package/dist/lib/text/TextFormatAlign.js +30 -30
  163. package/dist/lib/text/TextInteractionMode.d.ts +21 -21
  164. package/dist/lib/text/TextInteractionMode.js +25 -25
  165. package/dist/lib/text/TextLineMetrics.d.ts +61 -61
  166. package/dist/lib/text/TextLineMetrics.js +42 -42
  167. package/dist/lib/text/TextShape.d.ts +22 -22
  168. package/dist/lib/text/TextShape.js +75 -75
  169. package/dist/lib/tools/Merge.d.ts +81 -81
  170. package/dist/lib/tools/Merge.js +266 -266
  171. package/dist/lib/utils/Cast.d.ts +20 -20
  172. package/dist/lib/utils/Cast.js +271 -271
  173. package/index.ts +92 -92
  174. package/lib/Scene.ts +339 -339
  175. package/lib/Settings.ts +83 -83
  176. package/lib/adapters/IDisplayObjectAdapter.ts +23 -23
  177. package/lib/adapters/IFilter.ts +25 -25
  178. package/lib/adapters/IMovieClipAdapter.ts +26 -26
  179. package/lib/adapters/ITextfieldAdapter.ts +6 -6
  180. package/lib/base/IBitmapDrawable.ts +13 -13
  181. package/lib/base/IFrameLabel.ts +3 -3
  182. package/lib/base/IFrameScript.ts +4 -4
  183. package/lib/base/MouseButtons.ts +31 -31
  184. package/lib/base/Timeline.ts +715 -715
  185. package/lib/base/TimelineActionType.ts +18 -18
  186. package/lib/controllers/ControllerBase.ts +66 -66
  187. package/lib/controllers/FirstPersonController.ts +241 -241
  188. package/lib/controllers/FollowController.ts +22 -22
  189. package/lib/controllers/HoverController.ts +304 -304
  190. package/lib/controllers/LookAtController.ts +75 -75
  191. package/lib/controllers/SpringController.ts +91 -91
  192. package/lib/display/Billboard.ts +468 -468
  193. package/lib/display/Camera.ts +75 -75
  194. package/lib/display/DisplayObject.ts +1829 -1829
  195. package/lib/display/DisplayObjectContainer.ts +546 -546
  196. package/lib/display/LineSegment.ts +229 -229
  197. package/lib/display/LoaderContainer.ts +651 -651
  198. package/lib/display/MorphSprite.ts +339 -339
  199. package/lib/display/MovieClip.ts +870 -870
  200. package/lib/display/SimpleButton.ts +224 -224
  201. package/lib/display/Skybox.ts +352 -352
  202. package/lib/display/Sprite.ts +154 -154
  203. package/lib/display/TextField.ts +3876 -3875
  204. package/lib/display/TextSprite.ts +34 -34
  205. package/lib/elements/SkyboxElements.ts +141 -141
  206. package/lib/errors/CastError.ts +6 -6
  207. package/lib/events/CameraEvent.ts +29 -29
  208. package/lib/events/FocusEvent.ts +69 -69
  209. package/lib/events/KeyboardEvent.ts +40 -40
  210. package/lib/events/MouseEvent.ts +144 -144
  211. package/lib/events/PointerEvent.ts +145 -145
  212. package/lib/events/ResizeEvent.ts +31 -31
  213. package/lib/events/TextfieldEvent.ts +28 -28
  214. package/lib/events/TouchEvent.ts +103 -103
  215. package/lib/factories/DefaultSceneGraphFactory.ts +58 -58
  216. package/lib/factories/ISceneGraphFactory.ts +28 -28
  217. package/lib/image/SceneImage2D.ts +912 -912
  218. package/lib/managers/DefaultFontManager.ts +124 -124
  219. package/lib/managers/DeviceFontManager.ts +55 -55
  220. package/lib/managers/FrameScriptManager.ts +440 -440
  221. package/lib/managers/IInputRecorder.ts +2 -2
  222. package/lib/managers/MouseManager.ts +942 -942
  223. package/lib/prefabs/PrefabBase.ts +47 -47
  224. package/lib/prefabs/PrimitiveCapsulePrefab.ts +286 -286
  225. package/lib/prefabs/PrimitiveConePrefab.ts +37 -37
  226. package/lib/prefabs/PrimitiveCubePrefab.ts +630 -630
  227. package/lib/prefabs/PrimitiveCylinderPrefab.ts +657 -657
  228. package/lib/prefabs/PrimitivePlanePrefab.ts +352 -352
  229. package/lib/prefabs/PrimitivePolygonPrefab.ts +53 -53
  230. package/lib/prefabs/PrimitivePrefabBase.ts +177 -177
  231. package/lib/prefabs/PrimitiveSpherePrefab.ts +336 -336
  232. package/lib/prefabs/PrimitiveTorusPrefab.ts +282 -282
  233. package/lib/text/AntiAliasType.ts +24 -24
  234. package/lib/text/BitmapFontChar.ts +53 -53
  235. package/lib/text/BitmapFontTable.ts +213 -213
  236. package/lib/text/FNTGenerator.ts +100 -100
  237. package/lib/text/FNTGeneratorCanvas.ts +292 -292
  238. package/lib/text/FNTGeneratrorBase.ts +10 -10
  239. package/lib/text/Font.ts +114 -114
  240. package/lib/text/FontLookUpMode.ts +5 -5
  241. package/lib/text/FontStyleName.ts +6 -6
  242. package/lib/text/GridFitType.ts +32 -32
  243. package/lib/text/HTMLTextProcessor.ts +421 -421
  244. package/lib/text/IFontTable.ts +17 -17
  245. package/lib/text/TesselatedFontChar.ts +80 -80
  246. package/lib/text/TesselatedFontTable.ts +1181 -1181
  247. package/lib/text/TextFieldAutoSize.ts +30 -30
  248. package/lib/text/TextFieldType.ts +21 -21
  249. package/lib/text/TextFormat.ts +603 -603
  250. package/lib/text/TextFormatAlign.ts +28 -28
  251. package/lib/text/TextInteractionMode.ts +21 -21
  252. package/lib/text/TextLineMetrics.ts +74 -74
  253. package/lib/text/TextShape.ts +91 -91
  254. package/lib/tools/Merge.ts +311 -311
  255. package/lib/utils/Cast.ts +304 -304
  256. package/package.json +74 -74
  257. package/rollup.config.js +33 -33
  258. package/scripts/build.sh +2 -2
  259. package/scripts/gendocs.sh +14 -14
  260. package/scripts/genexamples.sh +14 -14
  261. package/scripts/genfull.sh +14 -14
  262. package/system.config.js +51 -51
  263. package/tsconfig.json +18 -18
@@ -1,716 +1,716 @@
1
- import { WaveAudio, ColorTransform, IAsset, Matrix3D } from '@awayjs/core';
2
- import { BlendMode } from '@awayjs/stage';
3
- import { HierarchicalProperty } from '@awayjs/view';
4
- import { Graphics } from '@awayjs/graphics';
5
-
6
- import { IDisplayObjectAdapter } from '../adapters/IDisplayObjectAdapter';
7
- import { IFilter } from '../adapters/IFilter';
8
- import { IMovieClipAdapter } from '../adapters/IMovieClipAdapter';
9
- import { MovieClip } from '../display/MovieClip';
10
- import { Sprite } from '../display/Sprite';
11
- import { MorphSprite } from '../display/MorphSprite';
12
- import { DisplayObject } from '../display/DisplayObject';
13
- import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
14
- import { ISceneGraphFactory } from '../factories/ISceneGraphFactory';
15
- import { IFrameLabel } from './IFrameLabel';
16
- import { TimelineActionType as AType } from './TimelineActionType';
17
- import { IFrameScript } from './IFrameScript';
18
-
19
- const BLEND_MODES = [
20
- '', BlendMode.NORMAL, BlendMode.LAYER,
21
- BlendMode.MULTIPLY, BlendMode.SCREEN,
22
- BlendMode.LIGHTEN, BlendMode.DARKEN,
23
- BlendMode.DIFFERENCE, BlendMode.ADD,
24
- BlendMode.SUBTRACT, BlendMode.INVERT,
25
- BlendMode.ALPHA, BlendMode.ERASE, BlendMode.OVERLAY,
26
- BlendMode.HARDLIGHT
27
- ];
28
-
29
- function mapBlendIdToString(id: number = 1): string {
30
- return BLEND_MODES[id] || BLEND_MODES[1];
31
- }
32
-
33
- type TApplyFunction = (timeline: Timeline, child: DisplayObject, ratget: MovieClip, i: number) => void;
34
- export class Timeline {
35
- public static readonly applyFunctionMap: Record<AType, TApplyFunction > = {
36
- [AType.UPDATE_MTX]: Timeline.update_mtx_all,
37
- [AType.UPDATE_CMTX]: Timeline.update_colortransform,
38
- [AType.UPDATE_MASKS]: Timeline.update_masks,
39
- [AType.UPDATE_NAME]: Timeline.update_name,
40
- [AType.UPDATE_BUTTON_NAME]: Timeline.update_button_name,
41
- [AType.UPDATE_VISIBLE]: Timeline.update_visibility,
42
- [AType.UPDATE_BLENDMODE]: Timeline.update_blendmode,
43
- [AType.UPDATE_RENDERMODE]: Timeline.update_rendermode,
44
- [AType.UPDATE_FILTERS]: Timeline.update_filters,
45
- [AType.UPDATE_SCALE_ROT]: Timeline.update_mtx_scale_rot,
46
- [AType.UPDATE_POS]: Timeline.update_mtx_pos,
47
- [AType.ENABLE_MASKMODE]: Timeline.enable_maskmode,
48
- [AType.REMOVE_MASK]: Timeline.remove_masks,
49
- [AType.SWAP_GRAPHICS]: Timeline.swap_graphics,
50
- [AType.SET_RATIO]: Timeline.set_ratio,
51
- [AType.START_AUDIO]: Timeline.start_audio
52
- };
53
-
54
- private _blocked: boolean;
55
-
56
- public _update_indices: number[] = [];
57
- public _update_frames: number[] = [];
58
- public isButton: boolean = false;
59
- public _labels: StringMap<IFrameLabel>; // dictionary to store label => keyframeindex
60
-
61
- public avm1InitActions: Object; // dictionary to store keyframeindex => ExecuteScriptCommand
62
- public avm1ButtonActions: any[]; // dictionary to store keyframeindex => ExecuteScriptCommand
63
- public avm1Exports: Object; // dictionary to store keyframeindex => ExecuteScriptCommand
64
-
65
- // framescripts are not stored by keyframe-index, but by frameIdx
66
- // this makes it easy to get/set framescripts on the fly, even when no keyframe exists for that frame
67
- private _framescripts: StringMap<IFrameScript[]>;
68
- private _framescripts_translated: Object;
69
-
70
- public keyframe_to_frameidx: Object;
71
- public keyframe_indices: number[]; //stores 1 keyframeindex per frameindex
72
- public keyframe_firstframes: number[]; //stores the firstframe of each keyframe
73
- public keyframe_constructframes: number[]; //stores the previous fullConstruct keyframeindex
74
-
75
- public keyframe_durations: ArrayBufferView; //only needed to calulcate other arrays
76
-
77
- // synched:
78
- public frame_command_indices: ArrayBufferView;
79
- public frame_recipe: ArrayBufferView;
80
-
81
- // synched:
82
- public command_index_stream: ArrayBufferView;
83
- public command_length_stream: ArrayBufferView;
84
-
85
- public add_child_stream: ArrayBufferView;
86
- public add_sounds_stream: ArrayBufferView;
87
- public remove_child_stream: ArrayBufferView;
88
- public update_child_stream: ArrayBufferView;
89
-
90
- public update_child_props_length_stream: ArrayBufferView;
91
- public update_child_props_indices_stream: ArrayBufferView;
92
-
93
- public property_index_stream: ArrayBufferView;
94
- public property_type_stream: ArrayBufferView;
95
-
96
- public properties_stream_int: ArrayBufferView;
97
-
98
- // property_values_stream:
99
- public properties_stream_f32_mtx_all: ArrayBufferView; // list of floats
100
- public properties_stream_f32_mtx_scale_rot: ArrayBufferView; // list of floats
101
- public properties_stream_f32_mtx_pos: ArrayBufferView; // list of floats
102
- public properties_stream_f32_ct: ArrayBufferView; // list of floats
103
- public properties_stream_strings: string[];
104
-
105
- public properties_stream_filters: IFilter[];
106
-
107
- public placeObjectTagsForSessionIDs: NumberMap<any>;
108
- public graphicsPool: any;
109
-
110
- public audioPool: any;
111
-
112
- public numKeyFrames: number;
113
-
114
- /**
115
- * in AS3 framescript are getting added to mc by calling "mc.addFrameScript" from within the mc.constructor
116
- * because timelines are shared between all instances of a mc,
117
- * only the first instance of a mc should be allowd to add framescripts to the timeline
118
- * to check this, we track the id of mc-instance that adds the first framescript,
119
- * and only allow additional framescripts to be added from same instance
120
- **/
121
- private _initalMcID: number;
122
-
123
- constructor(readonly factory: ISceneGraphFactory) {
124
-
125
- this._initalMcID = -1;
126
- this.numKeyFrames = 0;
127
- this.keyframe_indices = [];
128
- this.avm1Exports = {};
129
- this.avm1InitActions = {};
130
- this.avm1ButtonActions = [];
131
- this.graphicsPool = {};
132
- this.audioPool = {};
133
- this.placeObjectTagsForSessionIDs = {};
134
- this._labels = {};
135
- this._framescripts = {};
136
- this._framescripts_translated = {};
137
- this.keyframe_to_frameidx = {};
138
- }
139
-
140
- public resetScripts() {
141
- this._framescripts = {};
142
- this._framescripts_translated = {};
143
- }
144
-
145
- /* should be called after timeline-streams have been set.
146
- prepares
147
- */
148
- public init(): void {
149
-
150
- if ((this.frame_command_indices == null) || (this.frame_recipe == null) || (this.keyframe_durations == null)) {
151
- return;
152
- }
153
-
154
- let frame_cnt = 0;
155
- let ic = 0;
156
- let ic2 = 0;
157
- let duration = 0;
158
- let keyframe_cnt = 0;
159
- let last_construct_frame = 0;
160
- this.keyframe_firstframes = [];
161
- this.keyframe_constructframes = [];
162
- this.keyframe_indices = [];
163
- this.keyframe_to_frameidx = {};
164
- this.keyframe_to_frameidx[0] = 0;
165
- let duration_all = 0;
166
- for (ic = 0; ic < this.numKeyFrames; ic++) {
167
-
168
- this.keyframe_to_frameidx[ic] = duration_all;
169
- duration = this.keyframe_durations[(ic)];
170
- duration_all += duration;
171
- if (this.frame_recipe[ic] & 1)
172
- last_construct_frame = keyframe_cnt;
173
-
174
- this.keyframe_firstframes[keyframe_cnt] = frame_cnt;
175
- this.keyframe_constructframes[keyframe_cnt++] = last_construct_frame;
176
-
177
- for (ic2 = 0; ic2 < duration; ic2++)
178
- this.keyframe_indices[frame_cnt++] = ic;
179
- }
180
- }
181
-
182
- /**
183
- * for AS3:
184
- * - called from constructor of MC
185
- * for AS2:
186
- * - called when decoding swf-tags to timeline-streams
187
- * @param script -
188
- * @param frame_idx - the index of the frame (not the keyframe-index)
189
- * @param target_mc - the mc-instance that is calling this function
190
- */
191
- public add_framescript(script: any, frame_idx: number, target_mc: MovieClip, isAVM1: boolean = false): void {
192
- if (this._initalMcID >= 0 && target_mc.id != this._initalMcID)
193
- return;
194
- this._initalMcID = target_mc.id;
195
- if (!this._framescripts[frame_idx]) {
196
- this._framescripts[frame_idx] = [];
197
- }
198
- if (Array.isArray(script)) {
199
- for (let i = 0; i < script.length; i++) {
200
- this._framescripts[frame_idx][this._framescripts[frame_idx].length] = script[i];
201
- }
202
- } else {
203
- this._framescripts[frame_idx].push(script);
204
- }
205
- this._framescripts_translated[frame_idx] = !isAVM1;
206
- }
207
-
208
- /**
209
- * get a array of framescripts for a specific frame
210
- * for AVM1 "checkForTranslation" should be true, so we get translated framescripts
211
- * @param target_mc
212
- * @param frame_idx
213
- * @param checkForTranslation
214
- */
215
- public get_script_for_frame(
216
- target_mc: MovieClip,
217
- frame_idx: number,
218
- checkForTranslation: boolean = false): IFrameScript[] {
219
-
220
- if (frame_idx >= 0 && this._framescripts[frame_idx]) {
221
- if (checkForTranslation && !this._framescripts_translated[frame_idx]) {
222
- // todo: cleanup so we can retrieve className of target_mc without hacks
223
- const name = (<any>target_mc).className ? (<any>target_mc).className : target_mc.name;
224
- this._framescripts[frame_idx] = this.factory.createFrameScripts(
225
- this._framescripts[frame_idx],
226
- frame_idx,
227
- name,
228
- target_mc.id);
229
- this._framescripts_translated[frame_idx] = true;
230
- }
231
- return this._framescripts[frame_idx];
232
- }
233
- return null;
234
- }
235
-
236
- public get numFrames(): number {
237
- return this.keyframe_indices.length;
238
- }
239
-
240
- public getKeyframeIndexForFrameIndex(frame_index: number): number {
241
- return this.keyframe_indices[frame_index];
242
- }
243
-
244
- public getChildInstance(symbolID: number, sessionID: number) {
245
- return this.factory.createChildInstanceForTimeline(this, symbolID, sessionID);
246
- }
247
-
248
- public extractHitArea(target_mc: MovieClip): DisplayObjectContainer {
249
- target_mc.reset(false);
250
- this.gotoFrame(target_mc, this.numFrames - 1, false);
251
- let i: number = target_mc.numChildren;
252
- const hitArea: DisplayObjectContainer = new DisplayObjectContainer();
253
- let child: DisplayObject;
254
- let originalChild: DisplayObject;
255
- while (i > 0) {
256
- i--;
257
- originalChild = target_mc.getChildAt(i);
258
- child = originalChild.clone();
259
- //child.reset();
260
-
261
- child.x = originalChild.x;
262
- child.scaleX = originalChild.scaleX;
263
- child.y = originalChild.y;
264
- child.scaleY = originalChild.scaleY;
265
- child.rotationZ = originalChild.rotationZ;
266
- hitArea.addChild(child);
267
- }
268
- hitArea.pickObjectFromTimeline = true;
269
- target_mc.pickObject = hitArea;
270
- target_mc.reset(false);
271
- return hitArea;
272
- }
273
-
274
- /**
275
- * Get the label at the current frame of the target_mc MovieClip instance.
276
- * If the current frame has no label, it returns null
277
- * @param target_mc
278
- */
279
- public getCurrentFrameLabel(target_mc: MovieClip): string {
280
- const firstFrameIdxOfCurKeyFrame = this.keyframe_to_frameidx[target_mc.constructedKeyFrameIndex];
281
- for (const key in this._labels) {
282
- if (this._labels[key].keyFrameIndex == target_mc.constructedKeyFrameIndex &&
283
- firstFrameIdxOfCurKeyFrame == target_mc.currentFrameIndex) {
284
- return this._labels[key].name;
285
- }
286
- }
287
- return null;
288
- }
289
-
290
- /**
291
- * Get the label at the current frame of the target_mc MovieClip instance.
292
- * If the current frame has no label it returns the name of the previous frame that includes a label.
293
- * If the current frame and previous frames do not include a label, it returns null
294
- * @param target_mc
295
- */
296
- public getCurrentLabel(target_mc: MovieClip): string {
297
- let label: string = null;
298
- let lastLabelframeIdx: number = -1;
299
- for (const key in this._labels) {
300
- const keyIndex = this._labels[key].keyFrameIndex;
301
- if (keyIndex > lastLabelframeIdx && keyIndex <= target_mc.constructedKeyFrameIndex) {
302
- lastLabelframeIdx = keyIndex;
303
- label = this._labels[key].name;
304
- }
305
- }
306
- return label;
307
- }
308
-
309
- public jumpToLabel(target_mc: MovieClip, label: string, offset: number = 0): void {
310
- if (!this._labels[label]) {
311
- console.warn('[TIMELINE] - jumpToLabel with invalid label', target_mc, label, offset);
312
- return;
313
- }
314
- const key_frame_index: number = this._labels[label].keyFrameIndex;
315
- if (key_frame_index >= 0)
316
- target_mc.currentFrameIndex = this.keyframe_firstframes[key_frame_index] + offset;
317
- }
318
-
319
- /**
320
- * Get scripts for a specific frame
321
- * atm this is only called from AVM1MovieClip._callFrame
322
- * @param target_mc
323
- * @param label
324
- * @param isAVM1
325
- */
326
- public getScriptForLabel(target_mc: MovieClip, label: string, isAVM1: boolean = false): IFrameScript[] {
327
- const key_frame_index: number = this._labels[label.toLowerCase()].keyFrameIndex;
328
- if (key_frame_index < 0)
329
- return null;
330
- const frameIdx: number = this.keyframe_firstframes[key_frame_index];
331
- if (frameIdx >= 0 && this._framescripts[frameIdx]) {
332
- return this.get_script_for_frame(target_mc, frameIdx, isAVM1);
333
- }
334
- return null;
335
- }
336
-
337
- /**
338
- * move the playhead of the timeline to a specific frame
339
- * @param target_mc
340
- * @param frame_idx
341
- * @param queue_script
342
- * @param queue_pass2
343
- * @param forceReconstruct
344
- */
345
- public gotoFrame(target_mc: MovieClip, frame_idx: number,
346
- queue_script: boolean = true,
347
- queue_pass2: boolean = false,
348
- forceReconstruct: boolean = false): void {
349
- const current_keyframe_idx: number = target_mc.constructedKeyFrameIndex;
350
- const target_keyframe_idx: number = this.keyframe_indices[frame_idx];
351
-
352
- if (current_keyframe_idx == target_keyframe_idx && !forceReconstruct) {
353
- (<IMovieClipAdapter>target_mc.adapter).queueFrameScripts(this, frame_idx, queue_script);
354
- return;
355
- } else if (current_keyframe_idx + 1 == target_keyframe_idx) {
356
- // target_keyframe_idx is the next keyframe. we can just use constructnext for this
357
- this.constructNextFrame(target_mc, queue_script, true);
358
- return;
359
- }
360
-
361
- // when constructing a frame we must start constructing
362
- // either at the beginning of the timeline, or at a frame where all object was removed
363
- // construct_keyframe_idx is the index of the first keyframe we must process
364
- const construct_keyframe_idx: number = this.keyframe_constructframes[target_keyframe_idx];
365
-
366
- // 3 keyframes:
367
- // - current_keyframe_idx
368
- // - target_keyframe_idx
369
- // - construct_keyframe_idx
370
-
371
- // normally construction must start at construct_keyframe_idx
372
- // if we jump forward, and target_keyframe_idx >
373
-
374
- let start_construct_idx: number = construct_keyframe_idx;
375
-
376
- const jump_forward: boolean = (target_keyframe_idx > current_keyframe_idx);
377
- if (jump_forward && current_keyframe_idx > construct_keyframe_idx)
378
- start_construct_idx = current_keyframe_idx + 1;
379
-
380
- (<IMovieClipAdapter>target_mc.adapter).constructFrame(this, start_construct_idx,
381
- target_keyframe_idx,
382
- jump_forward,
383
- frame_idx,
384
- queue_pass2,
385
- queue_script);
386
-
387
- // apply update commands for objects still on stage (only if they are not blocked by script)
388
- this.applyCollectedUpdateCommands(target_mc);
389
-
390
- target_mc.constructedKeyFrameIndex = target_keyframe_idx;
391
-
392
- }
393
-
394
- public applyCollectedUpdateCommands(target_mc: MovieClip): void {
395
- let k: number;
396
- const len: number = this._update_indices.length;
397
- for (k = 0; k < len; k++)
398
- this.update_childs(target_mc, this._update_indices[k], this._update_frames[k]);
399
- }
400
-
401
- /**
402
- * constructs the next frame of the timeline
403
- * expects the target_mc.currentFrameIndex to already be set to the next frame
404
- * @param target_mc
405
- * @param queueScript
406
- * @param scriptPass1
407
- */
408
- public constructNextFrame(target_mc: MovieClip, queueScript: boolean = true, scriptPass1: boolean = false): void {
409
- const frameIndex: number = target_mc.currentFrameIndex;
410
- const new_keyFrameIndex: number = this.keyframe_indices[frameIndex];
411
-
412
- if (queueScript)
413
- (<IMovieClipAdapter>target_mc.adapter).queueFrameScripts(this, frameIndex, scriptPass1);
414
-
415
- if (target_mc.constructedKeyFrameIndex != new_keyFrameIndex) {
416
- target_mc.constructedKeyFrameIndex = new_keyFrameIndex;
417
-
418
- let frame_command_idx = this.frame_command_indices[new_keyFrameIndex];
419
- const frame_recipe = this.frame_recipe[new_keyFrameIndex];
420
-
421
- if (frame_recipe & 1) {
422
- (<IMovieClipAdapter>target_mc.adapter).removeAllTimelineChilds();
423
- } else if (frame_recipe & 2) {
424
- this.remove_childs_continous(target_mc, frame_command_idx++);
425
- }
426
-
427
- if (frame_recipe & 4)
428
- this.add_childs_continous(target_mc, frame_command_idx++);
429
-
430
- if (frame_recipe & 8)
431
- this.update_childs(target_mc, frame_command_idx++);
432
-
433
- if (frame_recipe & 16)
434
- this.start_sounds(target_mc, frame_command_idx++);
435
-
436
- }
437
- }
438
-
439
- public remove_childs_continous(sourceMovieClip: MovieClip, frame_command_idx: number): void {
440
- const start_index: number = this.command_index_stream[frame_command_idx];
441
- const end_index: number = start_index + this.command_length_stream[frame_command_idx];
442
- for (let i: number = start_index; i < end_index; i++) {
443
- // in avm1 we remove by depth, in avm2 we remove by sessionID
444
- (<IMovieClipAdapter>sourceMovieClip.adapter).removeTimelineChildAt(this.remove_child_stream[i]);
445
- }
446
- }
447
-
448
- public add_childs_continous(target_mc: MovieClip, frame_command_idx: number): void {
449
- let idx: number;
450
- const start_index: number = this.command_index_stream[frame_command_idx];
451
- const end_index: number = start_index + this.command_length_stream[frame_command_idx];
452
- for (let i: number = start_index; i < end_index; i++) {
453
- idx = i * 3;
454
- if (typeof this.add_child_stream[idx] === 'undefined') {
455
- console.warn('[Timeline] - add_childs_continous - could not find child-id in child_stream for idx',
456
- idx, this.add_child_stream);
457
- continue;
458
- }
459
- const childAsset: IAsset = this.factory.createChildInstanceForTimeline(this,
460
- this.add_child_stream[idx + 2], this.add_child_stream[idx]);
461
- (<IMovieClipAdapter>target_mc.adapter).addTimelineChildAtDepth(<DisplayObject>childAsset,
462
- this.add_child_stream[idx + 1]);
463
- }
464
- }
465
-
466
- public start_sounds(target_mc: MovieClip, frame_command_idx: number): void {
467
- const start_index: number = this.command_index_stream[frame_command_idx];
468
- const end_index: number = start_index + this.command_length_stream[frame_command_idx];
469
- for (let i: number = start_index; i < end_index; i++) {
470
- const audioProps: any = this.audioPool[this.add_sounds_stream[i]];
471
- if (audioProps) {
472
- const sound: WaveAudio = audioProps.sound;
473
-
474
- if (!sound) {
475
- console.warn('[Timeline] Missing sound in audioProps!', audioProps);
476
- return;
477
- }
478
-
479
- if (audioProps.cmd == 15) {// start sound
480
- target_mc.startSound(sound, audioProps.props.loopCount || 0);
481
- } else if (audioProps.cmd == 16) {// stop sound
482
- target_mc.stopSound(sound);
483
- }
484
- //console.log("start sound:", child);
485
- }
486
- }
487
-
488
- }
489
-
490
- public update_childs(target_mc: MovieClip, frame_command_idx: number, frameIdx: number = -1): void {
491
-
492
- const start = this.command_index_stream[frame_command_idx];
493
- const end = start + this.command_length_stream[frame_command_idx];
494
-
495
- for (let i = start; i < end; i++) {
496
- const child = target_mc.getTimelineChildAtSessionID(this.update_child_stream[i]);
497
-
498
- if (!child) {
499
- continue;
500
- }
501
-
502
- // check if the child is blocked by script for transform
503
- this._blocked = !!(child._adapter && (<IDisplayObjectAdapter> child.adapter).isBlockedByScript());
504
-
505
- const propsStart = this.update_child_props_indices_stream[i];
506
- const propsEnd = propsStart + this.update_child_props_length_stream[i];
507
-
508
- for (let p = propsStart; p < propsEnd; p++) {
509
- Timeline.applyFunctionMap[this.property_type_stream[p]] (
510
- this,
511
- child,
512
- target_mc,
513
- this.property_index_stream[p]
514
- );
515
- }
516
- }
517
- }
518
-
519
- public static update_mtx_all(timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
520
- if (timeline._blocked || (<any>child).noTimelineUpdate)
521
- return;
522
-
523
- i *= 6;
524
-
525
- const new_matrix: Matrix3D = child.transform.matrix3D;
526
- const props_stream = timeline.properties_stream_f32_mtx_all;
527
-
528
- new_matrix._rawData[0] = props_stream[i++];
529
- new_matrix._rawData[1] = props_stream[i++];
530
- new_matrix._rawData[4] = props_stream[i++];
531
- new_matrix._rawData[5] = props_stream[i++];
532
- new_matrix._rawData[12] = props_stream[i++];
533
- new_matrix._rawData[13] = props_stream[i];
534
-
535
- child.transform.invalidateComponents();
536
- }
537
-
538
- public static update_colortransform(
539
- timeline: Timeline,child: DisplayObject, _target_mc: MovieClip, i: number
540
- ): void {
541
-
542
- if (child._adapter && (<IDisplayObjectAdapter> child.adapter).isColorTransformByScript())
543
- return;
544
-
545
- i *= 8;
546
- const props_stream = timeline.properties_stream_f32_ct;
547
- const new_ct = child.transform.colorTransform || (child.transform.colorTransform = new ColorTransform());
548
-
549
- new_ct._rawData[0] = props_stream[i++];
550
- new_ct._rawData[1] = props_stream[i++];
551
- new_ct._rawData[2] = props_stream[i++];
552
- new_ct._rawData[3] = props_stream[i++];
553
- new_ct._rawData[4] = props_stream[i++];
554
- new_ct._rawData[5] = props_stream[i++];
555
- new_ct._rawData[6] = props_stream[i++];
556
- new_ct._rawData[7] = props_stream[i];
557
-
558
- child.transform.invalidateColorTransform();
559
- }
560
-
561
- public static update_masks(timeline: Timeline, child: DisplayObject, target_mc: MovieClip, i: number): void {
562
- // an object could have a multiple groups of masks, in case a graphic clip was merged into the timeline
563
- // this is not implemented in the runtime yet
564
- // for now, a second mask-group would overwrite the first one
565
- const masks: Array<DisplayObject> = [];
566
- const numMasks = timeline.properties_stream_int[i++];
567
-
568
- if (numMasks === 0) {
569
- child.timelineMasks = undefined;
570
- return;
571
- }
572
-
573
- //mask may not exist if a goto command moves the playhead to a point in the timeline after
574
- //one of the masks in a mask array has already been removed. Therefore a check is needed.
575
- for (let m = 0; m < numMasks; m++) {
576
- masks.push(target_mc.getTimelineChildAtSessionID(timeline.properties_stream_int[i + m]));
577
- }
578
-
579
- child.timelineMasks = masks;
580
- }
581
-
582
- public static update_name(timeline: Timeline, child: DisplayObject, target_mc: MovieClip, i: number): void {
583
- if (timeline.properties_stream_strings[i].indexOf('instance') == 0) {
584
- return;
585
- }
586
-
587
- (<IMovieClipAdapter>target_mc.adapter).unregisterScriptObject(child);
588
- child.name = timeline.properties_stream_strings[i];
589
- (<IMovieClipAdapter> target_mc.adapter).registerScriptObject(child);
590
- }
591
-
592
- public static update_button_name(
593
- timeline: Timeline, target: DisplayObject, sourceMovieClip: MovieClip, i: number
594
- ): void {
595
-
596
- target.name = timeline.properties_stream_strings[i];
597
- (<MovieClip> target).addButtonListeners();
598
- (<IMovieClipAdapter> sourceMovieClip.adapter).registerScriptObject(target);
599
- }
600
-
601
- public static update_visibility(_timeline: Timeline, child: DisplayObject, target_mc: MovieClip, i: number): void {
602
- if (!child._adapter || !(<IDisplayObjectAdapter> child.adapter).isVisibilityByScript()) {
603
- child.visible = !!i;
604
- }
605
- }
606
-
607
- public static update_mtx_scale_rot(
608
- timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number
609
- ): void {
610
-
611
- if (timeline._blocked || (<any>child).noTimelineUpdate) {
612
- return;
613
- }
614
-
615
- i *= 4;
616
-
617
- const new_matrix: Matrix3D = child.transform.matrix3D;
618
- const props_stream = timeline.properties_stream_f32_mtx_scale_rot;
619
-
620
- new_matrix._rawData[0] = props_stream[i++];
621
- new_matrix._rawData[1] = props_stream[i++];
622
- new_matrix._rawData[4] = props_stream[i++];
623
- new_matrix._rawData[5] = props_stream[i];
624
-
625
- child.transform.invalidateComponents();
626
-
627
- child._invalidateHierarchicalProperty(HierarchicalProperty.SCENE_TRANSFORM);
628
- }
629
-
630
- public static update_mtx_pos(timeline: Timeline, child: DisplayObject, target_mc: MovieClip, i: number): void {
631
- if (timeline._blocked || (<any>child).noTimelineUpdate)
632
- return;
633
-
634
- i *= 2;
635
-
636
- const new_matrix = child.transform.matrix3D;
637
-
638
- new_matrix._rawData[12] = timeline.properties_stream_f32_mtx_pos[i++];
639
- new_matrix._rawData[13] = timeline.properties_stream_f32_mtx_pos[i];
640
-
641
- child.transform.invalidatePosition();
642
- }
643
-
644
- public static enable_maskmode(_timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, _i: number): void {
645
- child.maskMode = true;
646
- }
647
-
648
- public static remove_masks(_timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, _i: number): void {
649
- child.timelineMasks = undefined;
650
- }
651
-
652
- public static update_filters(timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
653
- const startFilter: number = timeline.properties_stream_int[i++];
654
- const numFilter: number = timeline.properties_stream_int[i++];
655
- const adapter = <IDisplayObjectAdapter>child.adapter;
656
-
657
- if (numFilter === 0) {
658
- adapter.updateFilters(null);
659
- return;
660
- }
661
-
662
- adapter.updateFilters(
663
- timeline.properties_stream_filters.slice(startFilter, startFilter + numFilter)
664
- );
665
- }
666
-
667
- public static swap_graphics(timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
668
- if (!child.isAsset(Sprite)) {
669
- console.warn('[Timeline] - swap_graphics - child is not a Sprite');
670
- return;
671
- }
672
-
673
- const sprite = <Sprite>child;
674
- const target = <Graphics> timeline.graphicsPool[timeline.properties_stream_int[i]];
675
-
676
- if (target.id === sprite.graphics.id) {
677
- // already the same graphics
678
- return;
679
- }
680
-
681
- sprite.graphics = target;
682
- }
683
-
684
- public static start_audio(_timeline: Timeline, _child: DisplayObject, _target_mc: MovieClip, _i: number): void {}
685
-
686
- public static set_ratio(_timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
687
- if (!child.isAsset(MorphSprite)) {
688
- console.warn('[Timeline] - set_ratio - child is not a MorphSprite');
689
- return;
690
- }
691
-
692
- (<MorphSprite>child).setRatio(_timeline.properties_stream_int[i] / 0xffff);
693
- }
694
-
695
- public static update_blendmode(_timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
696
- child.blendMode = mapBlendIdToString(i);
697
- }
698
-
699
- public static update_rendermode(
700
- _timeline: Timeline, _child: DisplayObject, _target_mc: MovieClip, i: number): void {
701
- console.log('update rendermode ' + i);
702
- }
703
-
704
- public dispose() {
705
- this.keyframe_indices = [];
706
- this.avm1Exports = {};
707
- this.avm1InitActions = {};
708
- this.avm1ButtonActions = [];
709
- this.graphicsPool = {};
710
- this.audioPool = {};
711
- this.placeObjectTagsForSessionIDs = {};
712
- this._labels = {};
713
- this._framescripts = {};
714
- this._framescripts_translated = {};
715
- }
1
+ import { WaveAudio, ColorTransform, IAsset, Matrix3D } from '@awayjs/core';
2
+ import { BlendMode } from '@awayjs/stage';
3
+ import { HierarchicalProperty } from '@awayjs/view';
4
+ import { Graphics } from '@awayjs/graphics';
5
+
6
+ import { IDisplayObjectAdapter } from '../adapters/IDisplayObjectAdapter';
7
+ import { IFilter } from '../adapters/IFilter';
8
+ import { IMovieClipAdapter } from '../adapters/IMovieClipAdapter';
9
+ import { MovieClip } from '../display/MovieClip';
10
+ import { Sprite } from '../display/Sprite';
11
+ import { MorphSprite } from '../display/MorphSprite';
12
+ import { DisplayObject } from '../display/DisplayObject';
13
+ import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
14
+ import { ISceneGraphFactory } from '../factories/ISceneGraphFactory';
15
+ import { IFrameLabel } from './IFrameLabel';
16
+ import { TimelineActionType as AType } from './TimelineActionType';
17
+ import { IFrameScript } from './IFrameScript';
18
+
19
+ const BLEND_MODES = [
20
+ '', BlendMode.NORMAL, BlendMode.LAYER,
21
+ BlendMode.MULTIPLY, BlendMode.SCREEN,
22
+ BlendMode.LIGHTEN, BlendMode.DARKEN,
23
+ BlendMode.DIFFERENCE, BlendMode.ADD,
24
+ BlendMode.SUBTRACT, BlendMode.INVERT,
25
+ BlendMode.ALPHA, BlendMode.ERASE, BlendMode.OVERLAY,
26
+ BlendMode.HARDLIGHT
27
+ ];
28
+
29
+ function mapBlendIdToString(id: number = 1): string {
30
+ return BLEND_MODES[id] || BLEND_MODES[1];
31
+ }
32
+
33
+ type TApplyFunction = (timeline: Timeline, child: DisplayObject, ratget: MovieClip, i: number) => void;
34
+ export class Timeline {
35
+ public static readonly applyFunctionMap: Record<AType, TApplyFunction > = {
36
+ [AType.UPDATE_MTX]: Timeline.update_mtx_all,
37
+ [AType.UPDATE_CMTX]: Timeline.update_colortransform,
38
+ [AType.UPDATE_MASKS]: Timeline.update_masks,
39
+ [AType.UPDATE_NAME]: Timeline.update_name,
40
+ [AType.UPDATE_BUTTON_NAME]: Timeline.update_button_name,
41
+ [AType.UPDATE_VISIBLE]: Timeline.update_visibility,
42
+ [AType.UPDATE_BLENDMODE]: Timeline.update_blendmode,
43
+ [AType.UPDATE_RENDERMODE]: Timeline.update_rendermode,
44
+ [AType.UPDATE_FILTERS]: Timeline.update_filters,
45
+ [AType.UPDATE_SCALE_ROT]: Timeline.update_mtx_scale_rot,
46
+ [AType.UPDATE_POS]: Timeline.update_mtx_pos,
47
+ [AType.ENABLE_MASKMODE]: Timeline.enable_maskmode,
48
+ [AType.REMOVE_MASK]: Timeline.remove_masks,
49
+ [AType.SWAP_GRAPHICS]: Timeline.swap_graphics,
50
+ [AType.SET_RATIO]: Timeline.set_ratio,
51
+ [AType.START_AUDIO]: Timeline.start_audio
52
+ };
53
+
54
+ private _blocked: boolean;
55
+
56
+ public _update_indices: number[] = [];
57
+ public _update_frames: number[] = [];
58
+ public isButton: boolean = false;
59
+ public _labels: StringMap<IFrameLabel>; // dictionary to store label => keyframeindex
60
+
61
+ public avm1InitActions: Object; // dictionary to store keyframeindex => ExecuteScriptCommand
62
+ public avm1ButtonActions: any[]; // dictionary to store keyframeindex => ExecuteScriptCommand
63
+ public avm1Exports: Object; // dictionary to store keyframeindex => ExecuteScriptCommand
64
+
65
+ // framescripts are not stored by keyframe-index, but by frameIdx
66
+ // this makes it easy to get/set framescripts on the fly, even when no keyframe exists for that frame
67
+ private _framescripts: StringMap<IFrameScript[]>;
68
+ private _framescripts_translated: Object;
69
+
70
+ public keyframe_to_frameidx: Object;
71
+ public keyframe_indices: number[]; //stores 1 keyframeindex per frameindex
72
+ public keyframe_firstframes: number[]; //stores the firstframe of each keyframe
73
+ public keyframe_constructframes: number[]; //stores the previous fullConstruct keyframeindex
74
+
75
+ public keyframe_durations: ArrayBufferView; //only needed to calulcate other arrays
76
+
77
+ // synched:
78
+ public frame_command_indices: ArrayBufferView;
79
+ public frame_recipe: ArrayBufferView;
80
+
81
+ // synched:
82
+ public command_index_stream: ArrayBufferView;
83
+ public command_length_stream: ArrayBufferView;
84
+
85
+ public add_child_stream: ArrayBufferView;
86
+ public add_sounds_stream: ArrayBufferView;
87
+ public remove_child_stream: ArrayBufferView;
88
+ public update_child_stream: ArrayBufferView;
89
+
90
+ public update_child_props_length_stream: ArrayBufferView;
91
+ public update_child_props_indices_stream: ArrayBufferView;
92
+
93
+ public property_index_stream: ArrayBufferView;
94
+ public property_type_stream: ArrayBufferView;
95
+
96
+ public properties_stream_int: ArrayBufferView;
97
+
98
+ // property_values_stream:
99
+ public properties_stream_f32_mtx_all: ArrayBufferView; // list of floats
100
+ public properties_stream_f32_mtx_scale_rot: ArrayBufferView; // list of floats
101
+ public properties_stream_f32_mtx_pos: ArrayBufferView; // list of floats
102
+ public properties_stream_f32_ct: ArrayBufferView; // list of floats
103
+ public properties_stream_strings: string[];
104
+
105
+ public properties_stream_filters: IFilter[];
106
+
107
+ public placeObjectTagsForSessionIDs: NumberMap<any>;
108
+ public graphicsPool: any;
109
+
110
+ public audioPool: any;
111
+
112
+ public numKeyFrames: number;
113
+
114
+ /**
115
+ * in AS3 framescript are getting added to mc by calling "mc.addFrameScript" from within the mc.constructor
116
+ * because timelines are shared between all instances of a mc,
117
+ * only the first instance of a mc should be allowd to add framescripts to the timeline
118
+ * to check this, we track the id of mc-instance that adds the first framescript,
119
+ * and only allow additional framescripts to be added from same instance
120
+ **/
121
+ private _initalMcID: number;
122
+
123
+ constructor(readonly factory: ISceneGraphFactory) {
124
+
125
+ this._initalMcID = -1;
126
+ this.numKeyFrames = 0;
127
+ this.keyframe_indices = [];
128
+ this.avm1Exports = {};
129
+ this.avm1InitActions = {};
130
+ this.avm1ButtonActions = [];
131
+ this.graphicsPool = {};
132
+ this.audioPool = {};
133
+ this.placeObjectTagsForSessionIDs = {};
134
+ this._labels = {};
135
+ this._framescripts = {};
136
+ this._framescripts_translated = {};
137
+ this.keyframe_to_frameidx = {};
138
+ }
139
+
140
+ public resetScripts() {
141
+ this._framescripts = {};
142
+ this._framescripts_translated = {};
143
+ }
144
+
145
+ /* should be called after timeline-streams have been set.
146
+ prepares
147
+ */
148
+ public init(): void {
149
+
150
+ if ((this.frame_command_indices == null) || (this.frame_recipe == null) || (this.keyframe_durations == null)) {
151
+ return;
152
+ }
153
+
154
+ let frame_cnt = 0;
155
+ let ic = 0;
156
+ let ic2 = 0;
157
+ let duration = 0;
158
+ let keyframe_cnt = 0;
159
+ let last_construct_frame = 0;
160
+ this.keyframe_firstframes = [];
161
+ this.keyframe_constructframes = [];
162
+ this.keyframe_indices = [];
163
+ this.keyframe_to_frameidx = {};
164
+ this.keyframe_to_frameidx[0] = 0;
165
+ let duration_all = 0;
166
+ for (ic = 0; ic < this.numKeyFrames; ic++) {
167
+
168
+ this.keyframe_to_frameidx[ic] = duration_all;
169
+ duration = this.keyframe_durations[(ic)];
170
+ duration_all += duration;
171
+ if (this.frame_recipe[ic] & 1)
172
+ last_construct_frame = keyframe_cnt;
173
+
174
+ this.keyframe_firstframes[keyframe_cnt] = frame_cnt;
175
+ this.keyframe_constructframes[keyframe_cnt++] = last_construct_frame;
176
+
177
+ for (ic2 = 0; ic2 < duration; ic2++)
178
+ this.keyframe_indices[frame_cnt++] = ic;
179
+ }
180
+ }
181
+
182
+ /**
183
+ * for AS3:
184
+ * - called from constructor of MC
185
+ * for AS2:
186
+ * - called when decoding swf-tags to timeline-streams
187
+ * @param script -
188
+ * @param frame_idx - the index of the frame (not the keyframe-index)
189
+ * @param target_mc - the mc-instance that is calling this function
190
+ */
191
+ public add_framescript(script: any, frame_idx: number, target_mc: MovieClip, isAVM1: boolean = false): void {
192
+ if (this._initalMcID >= 0 && target_mc.id != this._initalMcID)
193
+ return;
194
+ this._initalMcID = target_mc.id;
195
+ if (!this._framescripts[frame_idx]) {
196
+ this._framescripts[frame_idx] = [];
197
+ }
198
+ if (Array.isArray(script)) {
199
+ for (let i = 0; i < script.length; i++) {
200
+ this._framescripts[frame_idx][this._framescripts[frame_idx].length] = script[i];
201
+ }
202
+ } else {
203
+ this._framescripts[frame_idx].push(script);
204
+ }
205
+ this._framescripts_translated[frame_idx] = !isAVM1;
206
+ }
207
+
208
+ /**
209
+ * get a array of framescripts for a specific frame
210
+ * for AVM1 "checkForTranslation" should be true, so we get translated framescripts
211
+ * @param target_mc
212
+ * @param frame_idx
213
+ * @param checkForTranslation
214
+ */
215
+ public get_script_for_frame(
216
+ target_mc: MovieClip,
217
+ frame_idx: number,
218
+ checkForTranslation: boolean = false): IFrameScript[] {
219
+
220
+ if (frame_idx >= 0 && this._framescripts[frame_idx]) {
221
+ if (checkForTranslation && !this._framescripts_translated[frame_idx]) {
222
+ // todo: cleanup so we can retrieve className of target_mc without hacks
223
+ const name = (<any>target_mc).className ? (<any>target_mc).className : target_mc.name;
224
+ this._framescripts[frame_idx] = this.factory.createFrameScripts(
225
+ this._framescripts[frame_idx],
226
+ frame_idx,
227
+ name,
228
+ target_mc.id);
229
+ this._framescripts_translated[frame_idx] = true;
230
+ }
231
+ return this._framescripts[frame_idx];
232
+ }
233
+ return null;
234
+ }
235
+
236
+ public get numFrames(): number {
237
+ return this.keyframe_indices.length;
238
+ }
239
+
240
+ public getKeyframeIndexForFrameIndex(frame_index: number): number {
241
+ return this.keyframe_indices[frame_index];
242
+ }
243
+
244
+ public getChildInstance(symbolID: number, sessionID: number) {
245
+ return this.factory.createChildInstanceForTimeline(this, symbolID, sessionID);
246
+ }
247
+
248
+ public extractHitArea(target_mc: MovieClip): DisplayObjectContainer {
249
+ target_mc.reset(false);
250
+ this.gotoFrame(target_mc, this.numFrames - 1, false);
251
+ let i: number = target_mc.numChildren;
252
+ const hitArea: DisplayObjectContainer = new DisplayObjectContainer();
253
+ let child: DisplayObject;
254
+ let originalChild: DisplayObject;
255
+ while (i > 0) {
256
+ i--;
257
+ originalChild = target_mc.getChildAt(i);
258
+ child = originalChild.clone();
259
+ //child.reset();
260
+
261
+ child.x = originalChild.x;
262
+ child.scaleX = originalChild.scaleX;
263
+ child.y = originalChild.y;
264
+ child.scaleY = originalChild.scaleY;
265
+ child.rotationZ = originalChild.rotationZ;
266
+ hitArea.addChild(child);
267
+ }
268
+ hitArea.pickObjectFromTimeline = true;
269
+ target_mc.pickObject = hitArea;
270
+ target_mc.reset(false);
271
+ return hitArea;
272
+ }
273
+
274
+ /**
275
+ * Get the label at the current frame of the target_mc MovieClip instance.
276
+ * If the current frame has no label, it returns null
277
+ * @param target_mc
278
+ */
279
+ public getCurrentFrameLabel(target_mc: MovieClip): string {
280
+ const firstFrameIdxOfCurKeyFrame = this.keyframe_to_frameidx[target_mc.constructedKeyFrameIndex];
281
+ for (const key in this._labels) {
282
+ if (this._labels[key].keyFrameIndex == target_mc.constructedKeyFrameIndex &&
283
+ firstFrameIdxOfCurKeyFrame == target_mc.currentFrameIndex) {
284
+ return this._labels[key].name;
285
+ }
286
+ }
287
+ return null;
288
+ }
289
+
290
+ /**
291
+ * Get the label at the current frame of the target_mc MovieClip instance.
292
+ * If the current frame has no label it returns the name of the previous frame that includes a label.
293
+ * If the current frame and previous frames do not include a label, it returns null
294
+ * @param target_mc
295
+ */
296
+ public getCurrentLabel(target_mc: MovieClip): string {
297
+ let label: string = null;
298
+ let lastLabelframeIdx: number = -1;
299
+ for (const key in this._labels) {
300
+ const keyIndex = this._labels[key].keyFrameIndex;
301
+ if (keyIndex > lastLabelframeIdx && keyIndex <= target_mc.constructedKeyFrameIndex) {
302
+ lastLabelframeIdx = keyIndex;
303
+ label = this._labels[key].name;
304
+ }
305
+ }
306
+ return label;
307
+ }
308
+
309
+ public jumpToLabel(target_mc: MovieClip, label: string, offset: number = 0): void {
310
+ if (!this._labels[label]) {
311
+ console.warn('[TIMELINE] - jumpToLabel with invalid label', target_mc, label, offset);
312
+ return;
313
+ }
314
+ const key_frame_index: number = this._labels[label].keyFrameIndex;
315
+ if (key_frame_index >= 0)
316
+ target_mc.currentFrameIndex = this.keyframe_firstframes[key_frame_index] + offset;
317
+ }
318
+
319
+ /**
320
+ * Get scripts for a specific frame
321
+ * atm this is only called from AVM1MovieClip._callFrame
322
+ * @param target_mc
323
+ * @param label
324
+ * @param isAVM1
325
+ */
326
+ public getScriptForLabel(target_mc: MovieClip, label: string, isAVM1: boolean = false): IFrameScript[] {
327
+ const key_frame_index: number = this._labels[label.toLowerCase()].keyFrameIndex;
328
+ if (key_frame_index < 0)
329
+ return null;
330
+ const frameIdx: number = this.keyframe_firstframes[key_frame_index];
331
+ if (frameIdx >= 0 && this._framescripts[frameIdx]) {
332
+ return this.get_script_for_frame(target_mc, frameIdx, isAVM1);
333
+ }
334
+ return null;
335
+ }
336
+
337
+ /**
338
+ * move the playhead of the timeline to a specific frame
339
+ * @param target_mc
340
+ * @param frame_idx
341
+ * @param queue_script
342
+ * @param queue_pass2
343
+ * @param forceReconstruct
344
+ */
345
+ public gotoFrame(target_mc: MovieClip, frame_idx: number,
346
+ queue_script: boolean = true,
347
+ queue_pass2: boolean = false,
348
+ forceReconstruct: boolean = false): void {
349
+ const current_keyframe_idx: number = target_mc.constructedKeyFrameIndex;
350
+ const target_keyframe_idx: number = this.keyframe_indices[frame_idx];
351
+
352
+ if (current_keyframe_idx == target_keyframe_idx && !forceReconstruct) {
353
+ (<IMovieClipAdapter>target_mc.adapter).queueFrameScripts(this, frame_idx, queue_script);
354
+ return;
355
+ } else if (current_keyframe_idx + 1 == target_keyframe_idx) {
356
+ // target_keyframe_idx is the next keyframe. we can just use constructnext for this
357
+ this.constructNextFrame(target_mc, queue_script, true);
358
+ return;
359
+ }
360
+
361
+ // when constructing a frame we must start constructing
362
+ // either at the beginning of the timeline, or at a frame where all object was removed
363
+ // construct_keyframe_idx is the index of the first keyframe we must process
364
+ const construct_keyframe_idx: number = this.keyframe_constructframes[target_keyframe_idx];
365
+
366
+ // 3 keyframes:
367
+ // - current_keyframe_idx
368
+ // - target_keyframe_idx
369
+ // - construct_keyframe_idx
370
+
371
+ // normally construction must start at construct_keyframe_idx
372
+ // if we jump forward, and target_keyframe_idx >
373
+
374
+ let start_construct_idx: number = construct_keyframe_idx;
375
+
376
+ const jump_forward: boolean = (target_keyframe_idx > current_keyframe_idx);
377
+ if (jump_forward && current_keyframe_idx > construct_keyframe_idx)
378
+ start_construct_idx = current_keyframe_idx + 1;
379
+
380
+ (<IMovieClipAdapter>target_mc.adapter).constructFrame(this, start_construct_idx,
381
+ target_keyframe_idx,
382
+ jump_forward,
383
+ frame_idx,
384
+ queue_pass2,
385
+ queue_script);
386
+
387
+ // apply update commands for objects still on stage (only if they are not blocked by script)
388
+ this.applyCollectedUpdateCommands(target_mc);
389
+
390
+ target_mc.constructedKeyFrameIndex = target_keyframe_idx;
391
+
392
+ }
393
+
394
+ public applyCollectedUpdateCommands(target_mc: MovieClip): void {
395
+ let k: number;
396
+ const len: number = this._update_indices.length;
397
+ for (k = 0; k < len; k++)
398
+ this.update_childs(target_mc, this._update_indices[k], this._update_frames[k]);
399
+ }
400
+
401
+ /**
402
+ * constructs the next frame of the timeline
403
+ * expects the target_mc.currentFrameIndex to already be set to the next frame
404
+ * @param target_mc
405
+ * @param queueScript
406
+ * @param scriptPass1
407
+ */
408
+ public constructNextFrame(target_mc: MovieClip, queueScript: boolean = true, scriptPass1: boolean = false): void {
409
+ const frameIndex: number = target_mc.currentFrameIndex;
410
+ const new_keyFrameIndex: number = this.keyframe_indices[frameIndex];
411
+
412
+ if (queueScript)
413
+ (<IMovieClipAdapter>target_mc.adapter).queueFrameScripts(this, frameIndex, scriptPass1);
414
+
415
+ if (target_mc.constructedKeyFrameIndex != new_keyFrameIndex) {
416
+ target_mc.constructedKeyFrameIndex = new_keyFrameIndex;
417
+
418
+ let frame_command_idx = this.frame_command_indices[new_keyFrameIndex];
419
+ const frame_recipe = this.frame_recipe[new_keyFrameIndex];
420
+
421
+ if (frame_recipe & 1) {
422
+ (<IMovieClipAdapter>target_mc.adapter).removeAllTimelineChilds();
423
+ } else if (frame_recipe & 2) {
424
+ this.remove_childs_continous(target_mc, frame_command_idx++);
425
+ }
426
+
427
+ if (frame_recipe & 4)
428
+ this.add_childs_continous(target_mc, frame_command_idx++);
429
+
430
+ if (frame_recipe & 8)
431
+ this.update_childs(target_mc, frame_command_idx++);
432
+
433
+ if (frame_recipe & 16)
434
+ this.start_sounds(target_mc, frame_command_idx++);
435
+
436
+ }
437
+ }
438
+
439
+ public remove_childs_continous(sourceMovieClip: MovieClip, frame_command_idx: number): void {
440
+ const start_index: number = this.command_index_stream[frame_command_idx];
441
+ const end_index: number = start_index + this.command_length_stream[frame_command_idx];
442
+ for (let i: number = start_index; i < end_index; i++) {
443
+ // in avm1 we remove by depth, in avm2 we remove by sessionID
444
+ (<IMovieClipAdapter>sourceMovieClip.adapter).removeTimelineChildAt(this.remove_child_stream[i]);
445
+ }
446
+ }
447
+
448
+ public add_childs_continous(target_mc: MovieClip, frame_command_idx: number): void {
449
+ let idx: number;
450
+ const start_index: number = this.command_index_stream[frame_command_idx];
451
+ const end_index: number = start_index + this.command_length_stream[frame_command_idx];
452
+ for (let i: number = start_index; i < end_index; i++) {
453
+ idx = i * 3;
454
+ if (typeof this.add_child_stream[idx] === 'undefined') {
455
+ console.warn('[Timeline] - add_childs_continous - could not find child-id in child_stream for idx',
456
+ idx, this.add_child_stream);
457
+ continue;
458
+ }
459
+ const childAsset: IAsset = this.factory.createChildInstanceForTimeline(this,
460
+ this.add_child_stream[idx + 2], this.add_child_stream[idx]);
461
+ (<IMovieClipAdapter>target_mc.adapter).addTimelineChildAtDepth(<DisplayObject>childAsset,
462
+ this.add_child_stream[idx + 1]);
463
+ }
464
+ }
465
+
466
+ public start_sounds(target_mc: MovieClip, frame_command_idx: number): void {
467
+ const start_index: number = this.command_index_stream[frame_command_idx];
468
+ const end_index: number = start_index + this.command_length_stream[frame_command_idx];
469
+ for (let i: number = start_index; i < end_index; i++) {
470
+ const audioProps: any = this.audioPool[this.add_sounds_stream[i]];
471
+ if (audioProps) {
472
+ const sound: WaveAudio = audioProps.sound;
473
+
474
+ if (!sound) {
475
+ console.warn('[Timeline] Missing sound in audioProps!', audioProps);
476
+ return;
477
+ }
478
+
479
+ if (audioProps.cmd == 15) {// start sound
480
+ target_mc.startSound(sound, audioProps.props.loopCount || 0);
481
+ } else if (audioProps.cmd == 16) {// stop sound
482
+ target_mc.stopSound(sound);
483
+ }
484
+ //console.log("start sound:", child);
485
+ }
486
+ }
487
+
488
+ }
489
+
490
+ public update_childs(target_mc: MovieClip, frame_command_idx: number, frameIdx: number = -1): void {
491
+
492
+ const start = this.command_index_stream[frame_command_idx];
493
+ const end = start + this.command_length_stream[frame_command_idx];
494
+
495
+ for (let i = start; i < end; i++) {
496
+ const child = target_mc.getTimelineChildAtSessionID(this.update_child_stream[i]);
497
+
498
+ if (!child) {
499
+ continue;
500
+ }
501
+
502
+ // check if the child is blocked by script for transform
503
+ this._blocked = !!(child._adapter && (<IDisplayObjectAdapter> child.adapter).isBlockedByScript());
504
+
505
+ const propsStart = this.update_child_props_indices_stream[i];
506
+ const propsEnd = propsStart + this.update_child_props_length_stream[i];
507
+
508
+ for (let p = propsStart; p < propsEnd; p++) {
509
+ Timeline.applyFunctionMap[this.property_type_stream[p]] (
510
+ this,
511
+ child,
512
+ target_mc,
513
+ this.property_index_stream[p]
514
+ );
515
+ }
516
+ }
517
+ }
518
+
519
+ public static update_mtx_all(timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
520
+ if (timeline._blocked || (<any>child).noTimelineUpdate)
521
+ return;
522
+
523
+ i *= 6;
524
+
525
+ const new_matrix: Matrix3D = child.transform.matrix3D;
526
+ const props_stream = timeline.properties_stream_f32_mtx_all;
527
+
528
+ new_matrix._rawData[0] = props_stream[i++];
529
+ new_matrix._rawData[1] = props_stream[i++];
530
+ new_matrix._rawData[4] = props_stream[i++];
531
+ new_matrix._rawData[5] = props_stream[i++];
532
+ new_matrix._rawData[12] = props_stream[i++];
533
+ new_matrix._rawData[13] = props_stream[i];
534
+
535
+ child.transform.invalidateComponents();
536
+ }
537
+
538
+ public static update_colortransform(
539
+ timeline: Timeline,child: DisplayObject, _target_mc: MovieClip, i: number
540
+ ): void {
541
+
542
+ if (child._adapter && (<IDisplayObjectAdapter> child.adapter).isColorTransformByScript())
543
+ return;
544
+
545
+ i *= 8;
546
+ const props_stream = timeline.properties_stream_f32_ct;
547
+ const new_ct = child.transform.colorTransform || (child.transform.colorTransform = new ColorTransform());
548
+
549
+ new_ct._rawData[0] = props_stream[i++];
550
+ new_ct._rawData[1] = props_stream[i++];
551
+ new_ct._rawData[2] = props_stream[i++];
552
+ new_ct._rawData[3] = props_stream[i++];
553
+ new_ct._rawData[4] = props_stream[i++];
554
+ new_ct._rawData[5] = props_stream[i++];
555
+ new_ct._rawData[6] = props_stream[i++];
556
+ new_ct._rawData[7] = props_stream[i];
557
+
558
+ child.transform.invalidateColorTransform();
559
+ }
560
+
561
+ public static update_masks(timeline: Timeline, child: DisplayObject, target_mc: MovieClip, i: number): void {
562
+ // an object could have a multiple groups of masks, in case a graphic clip was merged into the timeline
563
+ // this is not implemented in the runtime yet
564
+ // for now, a second mask-group would overwrite the first one
565
+ const masks: Array<DisplayObject> = [];
566
+ const numMasks = timeline.properties_stream_int[i++];
567
+
568
+ if (numMasks === 0) {
569
+ child.timelineMasks = undefined;
570
+ return;
571
+ }
572
+
573
+ //mask may not exist if a goto command moves the playhead to a point in the timeline after
574
+ //one of the masks in a mask array has already been removed. Therefore a check is needed.
575
+ for (let m = 0; m < numMasks; m++) {
576
+ masks.push(target_mc.getTimelineChildAtSessionID(timeline.properties_stream_int[i + m]));
577
+ }
578
+
579
+ child.timelineMasks = masks;
580
+ }
581
+
582
+ public static update_name(timeline: Timeline, child: DisplayObject, target_mc: MovieClip, i: number): void {
583
+ if (timeline.properties_stream_strings[i].indexOf('instance') == 0) {
584
+ return;
585
+ }
586
+
587
+ (<IMovieClipAdapter>target_mc.adapter).unregisterScriptObject(child);
588
+ child.name = timeline.properties_stream_strings[i];
589
+ (<IMovieClipAdapter> target_mc.adapter).registerScriptObject(child);
590
+ }
591
+
592
+ public static update_button_name(
593
+ timeline: Timeline, target: DisplayObject, sourceMovieClip: MovieClip, i: number
594
+ ): void {
595
+
596
+ target.name = timeline.properties_stream_strings[i];
597
+ (<MovieClip> target).addButtonListeners();
598
+ (<IMovieClipAdapter> sourceMovieClip.adapter).registerScriptObject(target);
599
+ }
600
+
601
+ public static update_visibility(_timeline: Timeline, child: DisplayObject, target_mc: MovieClip, i: number): void {
602
+ if (!child._adapter || !(<IDisplayObjectAdapter> child.adapter).isVisibilityByScript()) {
603
+ child.visible = !!i;
604
+ }
605
+ }
606
+
607
+ public static update_mtx_scale_rot(
608
+ timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number
609
+ ): void {
610
+
611
+ if (timeline._blocked || (<any>child).noTimelineUpdate) {
612
+ return;
613
+ }
614
+
615
+ i *= 4;
616
+
617
+ const new_matrix: Matrix3D = child.transform.matrix3D;
618
+ const props_stream = timeline.properties_stream_f32_mtx_scale_rot;
619
+
620
+ new_matrix._rawData[0] = props_stream[i++];
621
+ new_matrix._rawData[1] = props_stream[i++];
622
+ new_matrix._rawData[4] = props_stream[i++];
623
+ new_matrix._rawData[5] = props_stream[i];
624
+
625
+ child.transform.invalidateComponents();
626
+
627
+ child._invalidateHierarchicalProperty(HierarchicalProperty.SCENE_TRANSFORM);
628
+ }
629
+
630
+ public static update_mtx_pos(timeline: Timeline, child: DisplayObject, target_mc: MovieClip, i: number): void {
631
+ if (timeline._blocked || (<any>child).noTimelineUpdate)
632
+ return;
633
+
634
+ i *= 2;
635
+
636
+ const new_matrix = child.transform.matrix3D;
637
+
638
+ new_matrix._rawData[12] = timeline.properties_stream_f32_mtx_pos[i++];
639
+ new_matrix._rawData[13] = timeline.properties_stream_f32_mtx_pos[i];
640
+
641
+ child.transform.invalidatePosition();
642
+ }
643
+
644
+ public static enable_maskmode(_timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, _i: number): void {
645
+ child.maskMode = true;
646
+ }
647
+
648
+ public static remove_masks(_timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, _i: number): void {
649
+ child.timelineMasks = undefined;
650
+ }
651
+
652
+ public static update_filters(timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
653
+ const startFilter: number = timeline.properties_stream_int[i++];
654
+ const numFilter: number = timeline.properties_stream_int[i++];
655
+ const adapter = <IDisplayObjectAdapter>child.adapter;
656
+
657
+ if (numFilter === 0) {
658
+ adapter.updateFilters(null);
659
+ return;
660
+ }
661
+
662
+ adapter.updateFilters(
663
+ timeline.properties_stream_filters.slice(startFilter, startFilter + numFilter)
664
+ );
665
+ }
666
+
667
+ public static swap_graphics(timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
668
+ if (!child.isAsset(Sprite)) {
669
+ console.warn('[Timeline] - swap_graphics - child is not a Sprite');
670
+ return;
671
+ }
672
+
673
+ const sprite = <Sprite>child;
674
+ const target = <Graphics> timeline.graphicsPool[timeline.properties_stream_int[i]];
675
+
676
+ if (target.id === sprite.graphics.id) {
677
+ // already the same graphics
678
+ return;
679
+ }
680
+
681
+ sprite.graphics = target;
682
+ }
683
+
684
+ public static start_audio(_timeline: Timeline, _child: DisplayObject, _target_mc: MovieClip, _i: number): void {}
685
+
686
+ public static set_ratio(_timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
687
+ if (!child.isAsset(MorphSprite)) {
688
+ console.warn('[Timeline] - set_ratio - child is not a MorphSprite');
689
+ return;
690
+ }
691
+
692
+ (<MorphSprite>child).setRatio(_timeline.properties_stream_int[i] / 0xffff);
693
+ }
694
+
695
+ public static update_blendmode(_timeline: Timeline, child: DisplayObject, _target_mc: MovieClip, i: number): void {
696
+ child.blendMode = mapBlendIdToString(i);
697
+ }
698
+
699
+ public static update_rendermode(
700
+ _timeline: Timeline, _child: DisplayObject, _target_mc: MovieClip, i: number): void {
701
+ console.log('update rendermode ' + i);
702
+ }
703
+
704
+ public dispose() {
705
+ this.keyframe_indices = [];
706
+ this.avm1Exports = {};
707
+ this.avm1InitActions = {};
708
+ this.avm1ButtonActions = [];
709
+ this.graphicsPool = {};
710
+ this.audioPool = {};
711
+ this.placeObjectTagsForSessionIDs = {};
712
+ this._labels = {};
713
+ this._framescripts = {};
714
+ this._framescripts_translated = {};
715
+ }
716
716
  }