@awayjs/scene 0.13.264 → 0.13.266

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