@awayjs/scene 0.13.265 → 0.13.267

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 +55 -0
  93. package/dist/lib/events/TouchEvent.d.ts.map +1 -0
  94. package/dist/lib/events/TouchEvent.js +89 -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 +812 -761
  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 +107 -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 +948 -884
  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,535 +1,535 @@
1
- var _a;
2
- import { ColorTransform } from '@awayjs/core';
3
- import { BlendMode } from '@awayjs/stage';
4
- import { HierarchicalProperty } from '@awayjs/view';
5
- import { Sprite } from '../display/Sprite';
6
- import { MorphSprite } from '../display/MorphSprite';
7
- import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
8
- var BLEND_MODES = [
9
- '', BlendMode.NORMAL, BlendMode.LAYER,
10
- BlendMode.MULTIPLY, BlendMode.SCREEN,
11
- BlendMode.LIGHTEN, BlendMode.DARKEN,
12
- BlendMode.DIFFERENCE, BlendMode.ADD,
13
- BlendMode.SUBTRACT, BlendMode.INVERT,
14
- BlendMode.ALPHA, BlendMode.ERASE, BlendMode.OVERLAY,
15
- BlendMode.HARDLIGHT
16
- ];
17
- function mapBlendIdToString(id) {
18
- if (id === void 0) { id = 1; }
19
- return BLEND_MODES[id] || BLEND_MODES[1];
20
- }
21
- var Timeline = /** @class */ (function () {
22
- function Timeline(factory) {
23
- this.factory = factory;
24
- this._update_indices = [];
25
- this._update_frames = [];
26
- this.isButton = false;
27
- this._initalMcID = -1;
28
- this.numKeyFrames = 0;
29
- this.keyframe_indices = [];
30
- this.avm1Exports = {};
31
- this.avm1InitActions = {};
32
- this.avm1ButtonActions = [];
33
- this.graphicsPool = {};
34
- this.audioPool = {};
35
- this.placeObjectTagsForSessionIDs = {};
36
- this._labels = {};
37
- this._framescripts = {};
38
- this._framescripts_translated = {};
39
- this.keyframe_to_frameidx = {};
40
- }
41
- Timeline.prototype.resetScripts = function () {
42
- this._framescripts = {};
43
- this._framescripts_translated = {};
44
- };
45
- /* should be called after timeline-streams have been set.
46
- prepares
47
- */
48
- Timeline.prototype.init = function () {
49
- if ((this.frame_command_indices == null) || (this.frame_recipe == null) || (this.keyframe_durations == null)) {
50
- return;
51
- }
52
- var frame_cnt = 0;
53
- var ic = 0;
54
- var ic2 = 0;
55
- var duration = 0;
56
- var keyframe_cnt = 0;
57
- var last_construct_frame = 0;
58
- this.keyframe_firstframes = [];
59
- this.keyframe_constructframes = [];
60
- this.keyframe_indices = [];
61
- this.keyframe_to_frameidx = {};
62
- this.keyframe_to_frameidx[0] = 0;
63
- var duration_all = 0;
64
- for (ic = 0; ic < this.numKeyFrames; ic++) {
65
- this.keyframe_to_frameidx[ic] = duration_all;
66
- duration = this.keyframe_durations[(ic)];
67
- duration_all += duration;
68
- if (this.frame_recipe[ic] & 1)
69
- last_construct_frame = keyframe_cnt;
70
- this.keyframe_firstframes[keyframe_cnt] = frame_cnt;
71
- this.keyframe_constructframes[keyframe_cnt++] = last_construct_frame;
72
- for (ic2 = 0; ic2 < duration; ic2++)
73
- this.keyframe_indices[frame_cnt++] = ic;
74
- }
75
- };
76
- // legacy code. no longer used
77
- Timeline.prototype.get_framescript = function (frame_index) {
78
- if (this._framescripts[frame_index] == null)
79
- return '';
80
- if (typeof this._framescripts[frame_index] == 'string')
81
- return this._framescripts[frame_index];
82
- else {
83
- throw new Error('Framescript is already translated to Function!!!');
84
- }
85
- };
86
- /**
87
- * for AS3:
88
- * - called from constructor of MC
89
- * for AS2:
90
- * - called when decoding swf-tags to timeline-streams
91
- * @param script -
92
- * @param frame_idx - the index of the frame (not the keyframe-index)
93
- * @param target_mc - the mc-instance that is calling this function
94
- */
95
- Timeline.prototype.add_framescript = function (script, frame_idx, target_mc, isAVM1) {
96
- if (isAVM1 === void 0) { isAVM1 = false; }
97
- if (this._initalMcID >= 0 && target_mc.id != this._initalMcID)
98
- return;
99
- this._initalMcID = target_mc.id;
100
- if (!this._framescripts[frame_idx]) {
101
- this._framescripts[frame_idx] = [];
102
- }
103
- if (Array.isArray(script)) {
104
- for (var i = 0; i < script.length; i++) {
105
- this._framescripts[frame_idx][this._framescripts[frame_idx].length] = script[i];
106
- }
107
- }
108
- else {
109
- this._framescripts[frame_idx].push(script);
110
- }
111
- this._framescripts_translated[frame_idx] = !isAVM1;
112
- };
113
- /**
114
- * get a array of framescripts for a specific frame
115
- * for AVM1 "checkForTranslation" should be true, so we get translated framescripts
116
- * @param target_mc
117
- * @param frame_idx
118
- * @param checkForTranslation
119
- */
120
- Timeline.prototype.get_script_for_frame = function (target_mc, frame_idx, checkForTranslation) {
121
- if (checkForTranslation === void 0) { checkForTranslation = false; }
122
- if (frame_idx >= 0 && this._framescripts[frame_idx]) {
123
- if (checkForTranslation && !this._framescripts_translated[frame_idx]) {
124
- // todo: cleanup so we can retrieve className of target_mc without hacks
125
- var name_1 = target_mc.className ? target_mc.className : target_mc.name;
126
- this._framescripts[frame_idx] = this.factory.createFrameScripts(this._framescripts[frame_idx], frame_idx, name_1, target_mc.id);
127
- this._framescripts_translated[frame_idx] = true;
128
- }
129
- return this._framescripts[frame_idx];
130
- }
131
- return null;
132
- };
133
- Object.defineProperty(Timeline.prototype, "numFrames", {
134
- get: function () {
135
- return this.keyframe_indices.length;
136
- },
137
- enumerable: false,
138
- configurable: true
139
- });
140
- Timeline.prototype.getKeyframeIndexForFrameIndex = function (frame_index) {
141
- return this.keyframe_indices[frame_index];
142
- };
143
- Timeline.prototype.getChildInstance = function (symbolID, sessionID) {
144
- return this.factory.createChildInstanceForTimeline(this, symbolID, sessionID);
145
- };
146
- Timeline.prototype.extractHitArea = function (target_mc) {
147
- target_mc.reset(false);
148
- this.gotoFrame(target_mc, this.numFrames - 1, false);
149
- var i = target_mc.numChildren;
150
- var hitArea = new DisplayObjectContainer();
151
- var child;
152
- var originalChild;
153
- while (i > 0) {
154
- i--;
155
- originalChild = target_mc.getChildAt(i);
156
- child = originalChild.clone();
157
- //child.reset();
158
- child.x = originalChild.x;
159
- child.scaleX = originalChild.scaleX;
160
- child.y = originalChild.y;
161
- child.scaleY = originalChild.scaleY;
162
- child.rotationZ = originalChild.rotationZ;
163
- hitArea.addChild(child);
164
- }
165
- hitArea.pickObjectFromTimeline = true;
166
- target_mc.pickObject = hitArea;
167
- target_mc.reset(false);
168
- return hitArea;
169
- };
170
- /**
171
- * Get the label at the current frame of the target_mc MovieClip instance.
172
- * If the current frame has no label, it returns null
173
- * @param target_mc
174
- */
175
- Timeline.prototype.getCurrentFrameLabel = function (target_mc) {
176
- var firstFrameIdxOfCurKeyFrame = this.keyframe_to_frameidx[target_mc.constructedKeyFrameIndex];
177
- for (var key in this._labels) {
178
- if (this._labels[key].keyFrameIndex == target_mc.constructedKeyFrameIndex &&
179
- firstFrameIdxOfCurKeyFrame == target_mc.currentFrameIndex) {
180
- return this._labels[key].name;
181
- }
182
- }
183
- return null;
184
- };
185
- /**
186
- * Get the label at the current frame of the target_mc MovieClip instance.
187
- * If the current frame has no label it returns the name of the previous frame that includes a label.
188
- * If the current frame and previous frames do not include a label, it returns null
189
- * @param target_mc
190
- */
191
- Timeline.prototype.getCurrentLabel = function (target_mc) {
192
- var label = null;
193
- var lastLabelframeIdx = -1;
194
- for (var key in this._labels) {
195
- var keyIndex = this._labels[key].keyFrameIndex;
196
- if (keyIndex > lastLabelframeIdx && keyIndex <= target_mc.constructedKeyFrameIndex) {
197
- lastLabelframeIdx = keyIndex;
198
- label = this._labels[key].name;
199
- }
200
- }
201
- return label;
202
- };
203
- Timeline.prototype.jumpToLabel = function (target_mc, label, offset) {
204
- if (offset === void 0) { offset = 0; }
205
- if (!this._labels[label]) {
206
- console.warn('[TIMELINE] - jumpToLabel with invalid label', target_mc, label, offset);
207
- return;
208
- }
209
- var key_frame_index = this._labels[label].keyFrameIndex;
210
- if (key_frame_index >= 0)
211
- target_mc.currentFrameIndex = this.keyframe_firstframes[key_frame_index] + offset;
212
- };
213
- /**
214
- * Get scripts for a specific frame
215
- * atm this is only called from AVM1MovieClip._callFrame
216
- * @param target_mc
217
- * @param label
218
- * @param isAVM1
219
- */
220
- Timeline.prototype.getScriptForLabel = function (target_mc, label, isAVM1) {
221
- if (isAVM1 === void 0) { isAVM1 = false; }
222
- var key_frame_index = this._labels[label.toLowerCase()].keyFrameIndex;
223
- if (key_frame_index < 0)
224
- return null;
225
- var frameIdx = this.keyframe_firstframes[key_frame_index];
226
- if (frameIdx >= 0 && this._framescripts[frameIdx]) {
227
- return this.get_script_for_frame(target_mc, frameIdx, isAVM1);
228
- }
229
- return null;
230
- };
231
- /**
232
- * move the playhead of the timeline to a specific frame
233
- * @param target_mc
234
- * @param frame_idx
235
- * @param queue_script
236
- * @param queue_pass2
237
- * @param forceReconstruct
238
- */
239
- Timeline.prototype.gotoFrame = function (target_mc, frame_idx, queue_script, queue_pass2, forceReconstruct) {
240
- if (queue_script === void 0) { queue_script = true; }
241
- if (queue_pass2 === void 0) { queue_pass2 = false; }
242
- if (forceReconstruct === void 0) { forceReconstruct = false; }
243
- var current_keyframe_idx = target_mc.constructedKeyFrameIndex;
244
- var target_keyframe_idx = this.keyframe_indices[frame_idx];
245
- if (current_keyframe_idx == target_keyframe_idx && !forceReconstruct) {
246
- target_mc.adapter.queueFrameScripts(this, frame_idx, queue_script);
247
- return;
248
- }
249
- else if (current_keyframe_idx + 1 == target_keyframe_idx) {
250
- // target_keyframe_idx is the next keyframe. we can just use constructnext for this
251
- this.constructNextFrame(target_mc, queue_script, true);
252
- return;
253
- }
254
- // when constructing a frame we must start constructing
255
- // either at the beginning of the timeline, or at a frame where all object was removed
256
- // construct_keyframe_idx is the index of the first keyframe we must process
257
- var construct_keyframe_idx = this.keyframe_constructframes[target_keyframe_idx];
258
- // 3 keyframes:
259
- // - current_keyframe_idx
260
- // - target_keyframe_idx
261
- // - construct_keyframe_idx
262
- // normally construction must start at construct_keyframe_idx
263
- // if we jump forward, and target_keyframe_idx >
264
- var start_construct_idx = construct_keyframe_idx;
265
- var jump_forward = (target_keyframe_idx > current_keyframe_idx);
266
- if (jump_forward && current_keyframe_idx > construct_keyframe_idx)
267
- start_construct_idx = current_keyframe_idx + 1;
268
- target_mc.adapter.constructFrame(this, start_construct_idx, target_keyframe_idx, jump_forward, frame_idx, queue_pass2, queue_script);
269
- // apply update commands for objects still on stage (only if they are not blocked by script)
270
- this.applyCollectedUpdateCommands(target_mc);
271
- target_mc.constructedKeyFrameIndex = target_keyframe_idx;
272
- };
273
- Timeline.prototype.applyCollectedUpdateCommands = function (target_mc) {
274
- var k;
275
- var len = this._update_indices.length;
276
- for (k = 0; k < len; k++)
277
- this.update_childs(target_mc, this._update_indices[k], this._update_frames[k]);
278
- };
279
- /**
280
- * constructs the next frame of the timeline
281
- * expects the target_mc.currentFrameIndex to already be set to the next frame
282
- * @param target_mc
283
- * @param queueScript
284
- * @param scriptPass1
285
- */
286
- Timeline.prototype.constructNextFrame = function (target_mc, queueScript, scriptPass1) {
287
- if (queueScript === void 0) { queueScript = true; }
288
- if (scriptPass1 === void 0) { scriptPass1 = false; }
289
- var frameIndex = target_mc.currentFrameIndex;
290
- var new_keyFrameIndex = this.keyframe_indices[frameIndex];
291
- if (queueScript)
292
- target_mc.adapter.queueFrameScripts(this, frameIndex, scriptPass1);
293
- if (target_mc.constructedKeyFrameIndex != new_keyFrameIndex) {
294
- target_mc.constructedKeyFrameIndex = new_keyFrameIndex;
295
- var frame_command_idx = this.frame_command_indices[new_keyFrameIndex];
296
- var frame_recipe = this.frame_recipe[new_keyFrameIndex];
297
- if (frame_recipe & 1) {
298
- target_mc.adapter.removeAllTimelineChilds();
299
- }
300
- else if (frame_recipe & 2) {
301
- this.remove_childs_continous(target_mc, frame_command_idx++);
302
- }
303
- if (frame_recipe & 4)
304
- this.add_childs_continous(target_mc, frame_command_idx++);
305
- if (frame_recipe & 8)
306
- this.update_childs(target_mc, frame_command_idx++);
307
- if (frame_recipe & 16)
308
- this.start_sounds(target_mc, frame_command_idx++);
309
- }
310
- };
311
- Timeline.prototype.remove_childs_continous = function (sourceMovieClip, frame_command_idx) {
312
- var start_index = this.command_index_stream[frame_command_idx];
313
- var end_index = start_index + this.command_length_stream[frame_command_idx];
314
- for (var i = start_index; i < end_index; i++) {
315
- // in avm1 we remove by depth, in avm2 we remove by sessionID
316
- sourceMovieClip.adapter.removeTimelineChildAt(this.remove_child_stream[i]);
317
- }
318
- };
319
- Timeline.prototype.add_childs_continous = function (target_mc, frame_command_idx) {
320
- var idx;
321
- var start_index = this.command_index_stream[frame_command_idx];
322
- var end_index = start_index + this.command_length_stream[frame_command_idx];
323
- for (var i = start_index; i < end_index; i++) {
324
- idx = i * 3;
325
- if (typeof this.add_child_stream[idx] === 'undefined') {
326
- console.warn('[Timeline] - add_childs_continous - could not find child-id in child_stream for idx', idx, this.add_child_stream);
327
- continue;
328
- }
329
- var childAsset = this.factory.createChildInstanceForTimeline(this, this.add_child_stream[idx + 2], this.add_child_stream[idx]);
330
- target_mc.adapter.addTimelineChildAtDepth(childAsset, this.add_child_stream[idx + 1]);
331
- }
332
- };
333
- Timeline.prototype.start_sounds = function (target_mc, frame_command_idx) {
334
- var start_index = this.command_index_stream[frame_command_idx];
335
- var end_index = start_index + this.command_length_stream[frame_command_idx];
336
- for (var i = start_index; i < end_index; i++) {
337
- var audioProps = this.audioPool[this.add_sounds_stream[i]];
338
- if (audioProps) {
339
- var sound = audioProps.sound;
340
- if (!sound) {
341
- console.warn('[Timeline] Missing sound in audioProps!', audioProps);
342
- return;
343
- }
344
- if (audioProps.cmd == 15) { // start sound
345
- target_mc.startSound(sound, audioProps.props.loopCount || 0);
346
- }
347
- else if (audioProps.cmd == 16) { // stop sound
348
- target_mc.stopSound(sound);
349
- }
350
- //console.log("start sound:", child);
351
- }
352
- }
353
- };
354
- Timeline.prototype.update_childs = function (target_mc, frame_command_idx, frameIdx) {
355
- if (frameIdx === void 0) { frameIdx = -1; }
356
- var start = this.command_index_stream[frame_command_idx];
357
- var end = start + this.command_length_stream[frame_command_idx];
358
- for (var i = start; i < end; i++) {
359
- var child = target_mc.getTimelineChildAtSessionID(this.update_child_stream[i]);
360
- if (!child) {
361
- continue;
362
- }
363
- // check if the child is blocked by script for transform
364
- this._blocked = !!(child._adapter && child.adapter.isBlockedByScript());
365
- var propsStart = this.update_child_props_indices_stream[i];
366
- var propsEnd = propsStart + this.update_child_props_length_stream[i];
367
- for (var p = propsStart; p < propsEnd; p++) {
368
- Timeline.applyFunctionMap[this.property_type_stream[p]](this, child, target_mc, this.property_index_stream[p]);
369
- }
370
- }
371
- };
372
- Timeline.update_mtx_all = function (timeline, child, _target_mc, i) {
373
- if (timeline._blocked || child.noTimelineUpdate)
374
- return;
375
- i *= 6;
376
- var new_matrix = child.transform.matrix3D;
377
- var props_stream = timeline.properties_stream_f32_mtx_all;
378
- new_matrix._rawData[0] = props_stream[i++];
379
- new_matrix._rawData[1] = props_stream[i++];
380
- new_matrix._rawData[4] = props_stream[i++];
381
- new_matrix._rawData[5] = props_stream[i++];
382
- new_matrix._rawData[12] = props_stream[i++];
383
- new_matrix._rawData[13] = props_stream[i];
384
- child.transform.invalidateComponents();
385
- };
386
- Timeline.update_colortransform = function (timeline, child, _target_mc, i) {
387
- if (child._adapter && child.adapter.isColorTransformByScript())
388
- return;
389
- i *= 8;
390
- var props_stream = timeline.properties_stream_f32_ct;
391
- var new_ct = child.transform.colorTransform || (child.transform.colorTransform = new ColorTransform());
392
- new_ct._rawData[0] = props_stream[i++];
393
- new_ct._rawData[1] = props_stream[i++];
394
- new_ct._rawData[2] = props_stream[i++];
395
- new_ct._rawData[3] = props_stream[i++];
396
- new_ct._rawData[4] = props_stream[i++];
397
- new_ct._rawData[5] = props_stream[i++];
398
- new_ct._rawData[6] = props_stream[i++];
399
- new_ct._rawData[7] = props_stream[i];
400
- child.transform.invalidateColorTransform();
401
- };
402
- Timeline.update_masks = function (timeline, child, target_mc, i) {
403
- // an object could have a multiple groups of masks, in case a graphic clip was merged into the timeline
404
- // this is not implemented in the runtime yet
405
- // for now, a second mask-group would overwrite the first one
406
- var masks = [];
407
- var numMasks = timeline.properties_stream_int[i++];
408
- if (numMasks === 0) {
409
- child.updateTimelineMask(null);
410
- return;
411
- }
412
- //mask may not exist if a goto command moves the playhead to a point in the timeline after
413
- //one of the masks in a mask array has already been removed. Therefore a check is needed.
414
- for (var m = 0; m < numMasks; m++) {
415
- masks.push(target_mc.getTimelineChildAtSessionID(timeline.properties_stream_int[i + m]));
416
- }
417
- child.updateTimelineMask(masks);
418
- };
419
- Timeline.update_name = function (timeline, child, target_mc, i) {
420
- if (timeline.properties_stream_strings[i].indexOf('instance') == 0) {
421
- return;
422
- }
423
- target_mc.adapter.unregisterScriptObject(child);
424
- child.name = timeline.properties_stream_strings[i];
425
- target_mc.adapter.registerScriptObject(child);
426
- };
427
- Timeline.update_button_name = function (timeline, target, sourceMovieClip, i) {
428
- target.name = timeline.properties_stream_strings[i];
429
- target.addButtonListeners();
430
- sourceMovieClip.adapter.registerScriptObject(target);
431
- };
432
- Timeline.update_visibility = function (_timeline, child, target_mc, i) {
433
- if (!child._adapter || !child.adapter.isVisibilityByScript()) {
434
- child.visible = !!i;
435
- }
436
- };
437
- Timeline.update_mtx_scale_rot = function (timeline, child, _target_mc, i) {
438
- if (timeline._blocked || child.noTimelineUpdate) {
439
- return;
440
- }
441
- i *= 4;
442
- var new_matrix = child.transform.matrix3D;
443
- var props_stream = timeline.properties_stream_f32_mtx_scale_rot;
444
- new_matrix._rawData[0] = props_stream[i++];
445
- new_matrix._rawData[1] = props_stream[i++];
446
- new_matrix._rawData[4] = props_stream[i++];
447
- new_matrix._rawData[5] = props_stream[i];
448
- child.transform.invalidateComponents();
449
- child._invalidateHierarchicalProperty(HierarchicalProperty.SCENE_TRANSFORM);
450
- };
451
- Timeline.update_mtx_pos = function (timeline, child, target_mc, i) {
452
- if (timeline._blocked || child.noTimelineUpdate)
453
- return;
454
- i *= 2;
455
- var new_matrix = child.transform.matrix3D;
456
- new_matrix._rawData[12] = timeline.properties_stream_f32_mtx_pos[i++];
457
- new_matrix._rawData[13] = timeline.properties_stream_f32_mtx_pos[i];
458
- child.transform.invalidatePosition();
459
- };
460
- Timeline.enable_maskmode = function (_timeline, child, _target_mc, _i) {
461
- child.maskMode = true;
462
- };
463
- Timeline.remove_masks = function (_timeline, child, _target_mc, _i) {
464
- child.updateTimelineMask(null);
465
- };
466
- Timeline.update_filters = function (timeline, child, _target_mc, i) {
467
- var startFilter = timeline.properties_stream_int[i++];
468
- var numFilter = timeline.properties_stream_int[i++];
469
- var adapter = child.adapter;
470
- if (numFilter === 0) {
471
- adapter.updateFilters(null);
472
- return;
473
- }
474
- adapter.updateFilters(timeline.properties_stream_filters.slice(startFilter, startFilter + numFilter));
475
- };
476
- Timeline.swap_graphics = function (timeline, child, _target_mc, i) {
477
- if (!child.isAsset(Sprite)) {
478
- console.warn('[Timeline] - swap_graphics - child is not a Sprite');
479
- return;
480
- }
481
- var sprite = child;
482
- var target = timeline.graphicsPool[timeline.properties_stream_int[i]];
483
- if (target.id === sprite.graphics.id) {
484
- // already the same graphics
485
- return;
486
- }
487
- sprite.graphics = target;
488
- };
489
- Timeline.start_audio = function (_timeline, _child, _target_mc, _i) { };
490
- Timeline.set_ratio = function (_timeline, child, _target_mc, i) {
491
- if (!child.isAsset(MorphSprite)) {
492
- console.warn('[Timeline] - set_ratio - child is not a MorphSprite');
493
- return;
494
- }
495
- child.setRatio(_timeline.properties_stream_int[i] / 0xffff);
496
- };
497
- Timeline.update_blendmode = function (_timeline, child, _target_mc, i) {
498
- child.blendMode = mapBlendIdToString(i);
499
- };
500
- Timeline.update_rendermode = function (_timeline, _child, _target_mc, i) {
501
- console.log('update rendermode ' + i);
502
- };
503
- Timeline.prototype.dispose = function () {
504
- this.keyframe_indices = [];
505
- this.avm1Exports = {};
506
- this.avm1InitActions = {};
507
- this.avm1ButtonActions = [];
508
- this.graphicsPool = {};
509
- this.audioPool = {};
510
- this.placeObjectTagsForSessionIDs = {};
511
- this._labels = {};
512
- this._framescripts = {};
513
- this._framescripts_translated = {};
514
- };
515
- Timeline.applyFunctionMap = (_a = {},
516
- _a[1 /* AType.UPDATE_MTX */] = Timeline.update_mtx_all,
517
- _a[2 /* AType.UPDATE_CMTX */] = Timeline.update_colortransform,
518
- _a[3 /* AType.UPDATE_MASKS */] = Timeline.update_masks,
519
- _a[4 /* AType.UPDATE_NAME */] = Timeline.update_name,
520
- _a[5 /* AType.UPDATE_BUTTON_NAME */] = Timeline.update_button_name,
521
- _a[6 /* AType.UPDATE_VISIBLE */] = Timeline.update_visibility,
522
- _a[7 /* AType.UPDATE_BLENDMODE */] = Timeline.update_blendmode,
523
- _a[8 /* AType.UPDATE_RENDERMODE */] = Timeline.update_rendermode,
524
- _a[9 /* AType.UPDATE_FILTERS */] = Timeline.update_filters,
525
- _a[11 /* AType.UPDATE_SCALE_ROT */] = Timeline.update_mtx_scale_rot,
526
- _a[12 /* AType.UPDATE_POS */] = Timeline.update_mtx_pos,
527
- _a[200 /* AType.ENABLE_MASKMODE */] = Timeline.enable_maskmode,
528
- _a[201 /* AType.REMOVE_MASK */] = Timeline.remove_masks,
529
- _a[202 /* AType.SWAP_GRAPHICS */] = Timeline.swap_graphics,
530
- _a[203 /* AType.SET_RATIO */] = Timeline.set_ratio,
531
- _a[204 /* AType.START_AUDIO */] = Timeline.start_audio,
532
- _a);
533
- return Timeline;
534
- }());
535
- export { Timeline };
1
+ var _a;
2
+ import { ColorTransform } from '@awayjs/core';
3
+ import { BlendMode } from '@awayjs/stage';
4
+ import { HierarchicalProperty } from '@awayjs/view';
5
+ import { Sprite } from '../display/Sprite';
6
+ import { MorphSprite } from '../display/MorphSprite';
7
+ import { DisplayObjectContainer } from '../display/DisplayObjectContainer';
8
+ var BLEND_MODES = [
9
+ '', BlendMode.NORMAL, BlendMode.LAYER,
10
+ BlendMode.MULTIPLY, BlendMode.SCREEN,
11
+ BlendMode.LIGHTEN, BlendMode.DARKEN,
12
+ BlendMode.DIFFERENCE, BlendMode.ADD,
13
+ BlendMode.SUBTRACT, BlendMode.INVERT,
14
+ BlendMode.ALPHA, BlendMode.ERASE, BlendMode.OVERLAY,
15
+ BlendMode.HARDLIGHT
16
+ ];
17
+ function mapBlendIdToString(id) {
18
+ if (id === void 0) { id = 1; }
19
+ return BLEND_MODES[id] || BLEND_MODES[1];
20
+ }
21
+ var Timeline = /** @class */ (function () {
22
+ function Timeline(factory) {
23
+ this.factory = factory;
24
+ this._update_indices = [];
25
+ this._update_frames = [];
26
+ this.isButton = false;
27
+ this._initalMcID = -1;
28
+ this.numKeyFrames = 0;
29
+ this.keyframe_indices = [];
30
+ this.avm1Exports = {};
31
+ this.avm1InitActions = {};
32
+ this.avm1ButtonActions = [];
33
+ this.graphicsPool = {};
34
+ this.audioPool = {};
35
+ this.placeObjectTagsForSessionIDs = {};
36
+ this._labels = {};
37
+ this._framescripts = {};
38
+ this._framescripts_translated = {};
39
+ this.keyframe_to_frameidx = {};
40
+ }
41
+ Timeline.prototype.resetScripts = function () {
42
+ this._framescripts = {};
43
+ this._framescripts_translated = {};
44
+ };
45
+ /* should be called after timeline-streams have been set.
46
+ prepares
47
+ */
48
+ Timeline.prototype.init = function () {
49
+ if ((this.frame_command_indices == null) || (this.frame_recipe == null) || (this.keyframe_durations == null)) {
50
+ return;
51
+ }
52
+ var frame_cnt = 0;
53
+ var ic = 0;
54
+ var ic2 = 0;
55
+ var duration = 0;
56
+ var keyframe_cnt = 0;
57
+ var last_construct_frame = 0;
58
+ this.keyframe_firstframes = [];
59
+ this.keyframe_constructframes = [];
60
+ this.keyframe_indices = [];
61
+ this.keyframe_to_frameidx = {};
62
+ this.keyframe_to_frameidx[0] = 0;
63
+ var duration_all = 0;
64
+ for (ic = 0; ic < this.numKeyFrames; ic++) {
65
+ this.keyframe_to_frameidx[ic] = duration_all;
66
+ duration = this.keyframe_durations[(ic)];
67
+ duration_all += duration;
68
+ if (this.frame_recipe[ic] & 1)
69
+ last_construct_frame = keyframe_cnt;
70
+ this.keyframe_firstframes[keyframe_cnt] = frame_cnt;
71
+ this.keyframe_constructframes[keyframe_cnt++] = last_construct_frame;
72
+ for (ic2 = 0; ic2 < duration; ic2++)
73
+ this.keyframe_indices[frame_cnt++] = ic;
74
+ }
75
+ };
76
+ // legacy code. no longer used
77
+ Timeline.prototype.get_framescript = function (frame_index) {
78
+ if (this._framescripts[frame_index] == null)
79
+ return '';
80
+ if (typeof this._framescripts[frame_index] == 'string')
81
+ return this._framescripts[frame_index];
82
+ else {
83
+ throw new Error('Framescript is already translated to Function!!!');
84
+ }
85
+ };
86
+ /**
87
+ * for AS3:
88
+ * - called from constructor of MC
89
+ * for AS2:
90
+ * - called when decoding swf-tags to timeline-streams
91
+ * @param script -
92
+ * @param frame_idx - the index of the frame (not the keyframe-index)
93
+ * @param target_mc - the mc-instance that is calling this function
94
+ */
95
+ Timeline.prototype.add_framescript = function (script, frame_idx, target_mc, isAVM1) {
96
+ if (isAVM1 === void 0) { isAVM1 = false; }
97
+ if (this._initalMcID >= 0 && target_mc.id != this._initalMcID)
98
+ return;
99
+ this._initalMcID = target_mc.id;
100
+ if (!this._framescripts[frame_idx]) {
101
+ this._framescripts[frame_idx] = [];
102
+ }
103
+ if (Array.isArray(script)) {
104
+ for (var i = 0; i < script.length; i++) {
105
+ this._framescripts[frame_idx][this._framescripts[frame_idx].length] = script[i];
106
+ }
107
+ }
108
+ else {
109
+ this._framescripts[frame_idx].push(script);
110
+ }
111
+ this._framescripts_translated[frame_idx] = !isAVM1;
112
+ };
113
+ /**
114
+ * get a array of framescripts for a specific frame
115
+ * for AVM1 "checkForTranslation" should be true, so we get translated framescripts
116
+ * @param target_mc
117
+ * @param frame_idx
118
+ * @param checkForTranslation
119
+ */
120
+ Timeline.prototype.get_script_for_frame = function (target_mc, frame_idx, checkForTranslation) {
121
+ if (checkForTranslation === void 0) { checkForTranslation = false; }
122
+ if (frame_idx >= 0 && this._framescripts[frame_idx]) {
123
+ if (checkForTranslation && !this._framescripts_translated[frame_idx]) {
124
+ // todo: cleanup so we can retrieve className of target_mc without hacks
125
+ var name_1 = target_mc.className ? target_mc.className : target_mc.name;
126
+ this._framescripts[frame_idx] = this.factory.createFrameScripts(this._framescripts[frame_idx], frame_idx, name_1, target_mc.id);
127
+ this._framescripts_translated[frame_idx] = true;
128
+ }
129
+ return this._framescripts[frame_idx];
130
+ }
131
+ return null;
132
+ };
133
+ Object.defineProperty(Timeline.prototype, "numFrames", {
134
+ get: function () {
135
+ return this.keyframe_indices.length;
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ Timeline.prototype.getKeyframeIndexForFrameIndex = function (frame_index) {
141
+ return this.keyframe_indices[frame_index];
142
+ };
143
+ Timeline.prototype.getChildInstance = function (symbolID, sessionID) {
144
+ return this.factory.createChildInstanceForTimeline(this, symbolID, sessionID);
145
+ };
146
+ Timeline.prototype.extractHitArea = function (target_mc) {
147
+ target_mc.reset(false);
148
+ this.gotoFrame(target_mc, this.numFrames - 1, false);
149
+ var i = target_mc.numChildren;
150
+ var hitArea = new DisplayObjectContainer();
151
+ var child;
152
+ var originalChild;
153
+ while (i > 0) {
154
+ i--;
155
+ originalChild = target_mc.getChildAt(i);
156
+ child = originalChild.clone();
157
+ //child.reset();
158
+ child.x = originalChild.x;
159
+ child.scaleX = originalChild.scaleX;
160
+ child.y = originalChild.y;
161
+ child.scaleY = originalChild.scaleY;
162
+ child.rotationZ = originalChild.rotationZ;
163
+ hitArea.addChild(child);
164
+ }
165
+ hitArea.pickObjectFromTimeline = true;
166
+ target_mc.pickObject = hitArea;
167
+ target_mc.reset(false);
168
+ return hitArea;
169
+ };
170
+ /**
171
+ * Get the label at the current frame of the target_mc MovieClip instance.
172
+ * If the current frame has no label, it returns null
173
+ * @param target_mc
174
+ */
175
+ Timeline.prototype.getCurrentFrameLabel = function (target_mc) {
176
+ var firstFrameIdxOfCurKeyFrame = this.keyframe_to_frameidx[target_mc.constructedKeyFrameIndex];
177
+ for (var key in this._labels) {
178
+ if (this._labels[key].keyFrameIndex == target_mc.constructedKeyFrameIndex &&
179
+ firstFrameIdxOfCurKeyFrame == target_mc.currentFrameIndex) {
180
+ return this._labels[key].name;
181
+ }
182
+ }
183
+ return null;
184
+ };
185
+ /**
186
+ * Get the label at the current frame of the target_mc MovieClip instance.
187
+ * If the current frame has no label it returns the name of the previous frame that includes a label.
188
+ * If the current frame and previous frames do not include a label, it returns null
189
+ * @param target_mc
190
+ */
191
+ Timeline.prototype.getCurrentLabel = function (target_mc) {
192
+ var label = null;
193
+ var lastLabelframeIdx = -1;
194
+ for (var key in this._labels) {
195
+ var keyIndex = this._labels[key].keyFrameIndex;
196
+ if (keyIndex > lastLabelframeIdx && keyIndex <= target_mc.constructedKeyFrameIndex) {
197
+ lastLabelframeIdx = keyIndex;
198
+ label = this._labels[key].name;
199
+ }
200
+ }
201
+ return label;
202
+ };
203
+ Timeline.prototype.jumpToLabel = function (target_mc, label, offset) {
204
+ if (offset === void 0) { offset = 0; }
205
+ if (!this._labels[label]) {
206
+ console.warn('[TIMELINE] - jumpToLabel with invalid label', target_mc, label, offset);
207
+ return;
208
+ }
209
+ var key_frame_index = this._labels[label].keyFrameIndex;
210
+ if (key_frame_index >= 0)
211
+ target_mc.currentFrameIndex = this.keyframe_firstframes[key_frame_index] + offset;
212
+ };
213
+ /**
214
+ * Get scripts for a specific frame
215
+ * atm this is only called from AVM1MovieClip._callFrame
216
+ * @param target_mc
217
+ * @param label
218
+ * @param isAVM1
219
+ */
220
+ Timeline.prototype.getScriptForLabel = function (target_mc, label, isAVM1) {
221
+ if (isAVM1 === void 0) { isAVM1 = false; }
222
+ var key_frame_index = this._labels[label.toLowerCase()].keyFrameIndex;
223
+ if (key_frame_index < 0)
224
+ return null;
225
+ var frameIdx = this.keyframe_firstframes[key_frame_index];
226
+ if (frameIdx >= 0 && this._framescripts[frameIdx]) {
227
+ return this.get_script_for_frame(target_mc, frameIdx, isAVM1);
228
+ }
229
+ return null;
230
+ };
231
+ /**
232
+ * move the playhead of the timeline to a specific frame
233
+ * @param target_mc
234
+ * @param frame_idx
235
+ * @param queue_script
236
+ * @param queue_pass2
237
+ * @param forceReconstruct
238
+ */
239
+ Timeline.prototype.gotoFrame = function (target_mc, frame_idx, queue_script, queue_pass2, forceReconstruct) {
240
+ if (queue_script === void 0) { queue_script = true; }
241
+ if (queue_pass2 === void 0) { queue_pass2 = false; }
242
+ if (forceReconstruct === void 0) { forceReconstruct = false; }
243
+ var current_keyframe_idx = target_mc.constructedKeyFrameIndex;
244
+ var target_keyframe_idx = this.keyframe_indices[frame_idx];
245
+ if (current_keyframe_idx == target_keyframe_idx && !forceReconstruct) {
246
+ target_mc.adapter.queueFrameScripts(this, frame_idx, queue_script);
247
+ return;
248
+ }
249
+ else if (current_keyframe_idx + 1 == target_keyframe_idx) {
250
+ // target_keyframe_idx is the next keyframe. we can just use constructnext for this
251
+ this.constructNextFrame(target_mc, queue_script, true);
252
+ return;
253
+ }
254
+ // when constructing a frame we must start constructing
255
+ // either at the beginning of the timeline, or at a frame where all object was removed
256
+ // construct_keyframe_idx is the index of the first keyframe we must process
257
+ var construct_keyframe_idx = this.keyframe_constructframes[target_keyframe_idx];
258
+ // 3 keyframes:
259
+ // - current_keyframe_idx
260
+ // - target_keyframe_idx
261
+ // - construct_keyframe_idx
262
+ // normally construction must start at construct_keyframe_idx
263
+ // if we jump forward, and target_keyframe_idx >
264
+ var start_construct_idx = construct_keyframe_idx;
265
+ var jump_forward = (target_keyframe_idx > current_keyframe_idx);
266
+ if (jump_forward && current_keyframe_idx > construct_keyframe_idx)
267
+ start_construct_idx = current_keyframe_idx + 1;
268
+ target_mc.adapter.constructFrame(this, start_construct_idx, target_keyframe_idx, jump_forward, frame_idx, queue_pass2, queue_script);
269
+ // apply update commands for objects still on stage (only if they are not blocked by script)
270
+ this.applyCollectedUpdateCommands(target_mc);
271
+ target_mc.constructedKeyFrameIndex = target_keyframe_idx;
272
+ };
273
+ Timeline.prototype.applyCollectedUpdateCommands = function (target_mc) {
274
+ var k;
275
+ var len = this._update_indices.length;
276
+ for (k = 0; k < len; k++)
277
+ this.update_childs(target_mc, this._update_indices[k], this._update_frames[k]);
278
+ };
279
+ /**
280
+ * constructs the next frame of the timeline
281
+ * expects the target_mc.currentFrameIndex to already be set to the next frame
282
+ * @param target_mc
283
+ * @param queueScript
284
+ * @param scriptPass1
285
+ */
286
+ Timeline.prototype.constructNextFrame = function (target_mc, queueScript, scriptPass1) {
287
+ if (queueScript === void 0) { queueScript = true; }
288
+ if (scriptPass1 === void 0) { scriptPass1 = false; }
289
+ var frameIndex = target_mc.currentFrameIndex;
290
+ var new_keyFrameIndex = this.keyframe_indices[frameIndex];
291
+ if (queueScript)
292
+ target_mc.adapter.queueFrameScripts(this, frameIndex, scriptPass1);
293
+ if (target_mc.constructedKeyFrameIndex != new_keyFrameIndex) {
294
+ target_mc.constructedKeyFrameIndex = new_keyFrameIndex;
295
+ var frame_command_idx = this.frame_command_indices[new_keyFrameIndex];
296
+ var frame_recipe = this.frame_recipe[new_keyFrameIndex];
297
+ if (frame_recipe & 1) {
298
+ target_mc.adapter.removeAllTimelineChilds();
299
+ }
300
+ else if (frame_recipe & 2) {
301
+ this.remove_childs_continous(target_mc, frame_command_idx++);
302
+ }
303
+ if (frame_recipe & 4)
304
+ this.add_childs_continous(target_mc, frame_command_idx++);
305
+ if (frame_recipe & 8)
306
+ this.update_childs(target_mc, frame_command_idx++);
307
+ if (frame_recipe & 16)
308
+ this.start_sounds(target_mc, frame_command_idx++);
309
+ }
310
+ };
311
+ Timeline.prototype.remove_childs_continous = function (sourceMovieClip, frame_command_idx) {
312
+ var start_index = this.command_index_stream[frame_command_idx];
313
+ var end_index = start_index + this.command_length_stream[frame_command_idx];
314
+ for (var i = start_index; i < end_index; i++) {
315
+ // in avm1 we remove by depth, in avm2 we remove by sessionID
316
+ sourceMovieClip.adapter.removeTimelineChildAt(this.remove_child_stream[i]);
317
+ }
318
+ };
319
+ Timeline.prototype.add_childs_continous = function (target_mc, frame_command_idx) {
320
+ var idx;
321
+ var start_index = this.command_index_stream[frame_command_idx];
322
+ var end_index = start_index + this.command_length_stream[frame_command_idx];
323
+ for (var i = start_index; i < end_index; i++) {
324
+ idx = i * 3;
325
+ if (typeof this.add_child_stream[idx] === 'undefined') {
326
+ console.warn('[Timeline] - add_childs_continous - could not find child-id in child_stream for idx', idx, this.add_child_stream);
327
+ continue;
328
+ }
329
+ var childAsset = this.factory.createChildInstanceForTimeline(this, this.add_child_stream[idx + 2], this.add_child_stream[idx]);
330
+ target_mc.adapter.addTimelineChildAtDepth(childAsset, this.add_child_stream[idx + 1]);
331
+ }
332
+ };
333
+ Timeline.prototype.start_sounds = function (target_mc, frame_command_idx) {
334
+ var start_index = this.command_index_stream[frame_command_idx];
335
+ var end_index = start_index + this.command_length_stream[frame_command_idx];
336
+ for (var i = start_index; i < end_index; i++) {
337
+ var audioProps = this.audioPool[this.add_sounds_stream[i]];
338
+ if (audioProps) {
339
+ var sound = audioProps.sound;
340
+ if (!sound) {
341
+ console.warn('[Timeline] Missing sound in audioProps!', audioProps);
342
+ return;
343
+ }
344
+ if (audioProps.cmd == 15) { // start sound
345
+ target_mc.startSound(sound, audioProps.props.loopCount || 0);
346
+ }
347
+ else if (audioProps.cmd == 16) { // stop sound
348
+ target_mc.stopSound(sound);
349
+ }
350
+ //console.log("start sound:", child);
351
+ }
352
+ }
353
+ };
354
+ Timeline.prototype.update_childs = function (target_mc, frame_command_idx, frameIdx) {
355
+ if (frameIdx === void 0) { frameIdx = -1; }
356
+ var start = this.command_index_stream[frame_command_idx];
357
+ var end = start + this.command_length_stream[frame_command_idx];
358
+ for (var i = start; i < end; i++) {
359
+ var child = target_mc.getTimelineChildAtSessionID(this.update_child_stream[i]);
360
+ if (!child) {
361
+ continue;
362
+ }
363
+ // check if the child is blocked by script for transform
364
+ this._blocked = !!(child._adapter && child.adapter.isBlockedByScript());
365
+ var propsStart = this.update_child_props_indices_stream[i];
366
+ var propsEnd = propsStart + this.update_child_props_length_stream[i];
367
+ for (var p = propsStart; p < propsEnd; p++) {
368
+ Timeline.applyFunctionMap[this.property_type_stream[p]](this, child, target_mc, this.property_index_stream[p]);
369
+ }
370
+ }
371
+ };
372
+ Timeline.update_mtx_all = function (timeline, child, _target_mc, i) {
373
+ if (timeline._blocked || child.noTimelineUpdate)
374
+ return;
375
+ i *= 6;
376
+ var new_matrix = child.transform.matrix3D;
377
+ var props_stream = timeline.properties_stream_f32_mtx_all;
378
+ new_matrix._rawData[0] = props_stream[i++];
379
+ new_matrix._rawData[1] = props_stream[i++];
380
+ new_matrix._rawData[4] = props_stream[i++];
381
+ new_matrix._rawData[5] = props_stream[i++];
382
+ new_matrix._rawData[12] = props_stream[i++];
383
+ new_matrix._rawData[13] = props_stream[i];
384
+ child.transform.invalidateComponents();
385
+ };
386
+ Timeline.update_colortransform = function (timeline, child, _target_mc, i) {
387
+ if (child._adapter && child.adapter.isColorTransformByScript())
388
+ return;
389
+ i *= 8;
390
+ var props_stream = timeline.properties_stream_f32_ct;
391
+ var new_ct = child.transform.colorTransform || (child.transform.colorTransform = new ColorTransform());
392
+ new_ct._rawData[0] = props_stream[i++];
393
+ new_ct._rawData[1] = props_stream[i++];
394
+ new_ct._rawData[2] = props_stream[i++];
395
+ new_ct._rawData[3] = props_stream[i++];
396
+ new_ct._rawData[4] = props_stream[i++];
397
+ new_ct._rawData[5] = props_stream[i++];
398
+ new_ct._rawData[6] = props_stream[i++];
399
+ new_ct._rawData[7] = props_stream[i];
400
+ child.transform.invalidateColorTransform();
401
+ };
402
+ Timeline.update_masks = function (timeline, child, target_mc, i) {
403
+ // an object could have a multiple groups of masks, in case a graphic clip was merged into the timeline
404
+ // this is not implemented in the runtime yet
405
+ // for now, a second mask-group would overwrite the first one
406
+ var masks = [];
407
+ var numMasks = timeline.properties_stream_int[i++];
408
+ if (numMasks === 0) {
409
+ child.updateTimelineMask(null);
410
+ return;
411
+ }
412
+ //mask may not exist if a goto command moves the playhead to a point in the timeline after
413
+ //one of the masks in a mask array has already been removed. Therefore a check is needed.
414
+ for (var m = 0; m < numMasks; m++) {
415
+ masks.push(target_mc.getTimelineChildAtSessionID(timeline.properties_stream_int[i + m]));
416
+ }
417
+ child.updateTimelineMask(masks);
418
+ };
419
+ Timeline.update_name = function (timeline, child, target_mc, i) {
420
+ if (timeline.properties_stream_strings[i].indexOf('instance') == 0) {
421
+ return;
422
+ }
423
+ target_mc.adapter.unregisterScriptObject(child);
424
+ child.name = timeline.properties_stream_strings[i];
425
+ target_mc.adapter.registerScriptObject(child);
426
+ };
427
+ Timeline.update_button_name = function (timeline, target, sourceMovieClip, i) {
428
+ target.name = timeline.properties_stream_strings[i];
429
+ target.addButtonListeners();
430
+ sourceMovieClip.adapter.registerScriptObject(target);
431
+ };
432
+ Timeline.update_visibility = function (_timeline, child, target_mc, i) {
433
+ if (!child._adapter || !child.adapter.isVisibilityByScript()) {
434
+ child.visible = !!i;
435
+ }
436
+ };
437
+ Timeline.update_mtx_scale_rot = function (timeline, child, _target_mc, i) {
438
+ if (timeline._blocked || child.noTimelineUpdate) {
439
+ return;
440
+ }
441
+ i *= 4;
442
+ var new_matrix = child.transform.matrix3D;
443
+ var props_stream = timeline.properties_stream_f32_mtx_scale_rot;
444
+ new_matrix._rawData[0] = props_stream[i++];
445
+ new_matrix._rawData[1] = props_stream[i++];
446
+ new_matrix._rawData[4] = props_stream[i++];
447
+ new_matrix._rawData[5] = props_stream[i];
448
+ child.transform.invalidateComponents();
449
+ child._invalidateHierarchicalProperty(HierarchicalProperty.SCENE_TRANSFORM);
450
+ };
451
+ Timeline.update_mtx_pos = function (timeline, child, target_mc, i) {
452
+ if (timeline._blocked || child.noTimelineUpdate)
453
+ return;
454
+ i *= 2;
455
+ var new_matrix = child.transform.matrix3D;
456
+ new_matrix._rawData[12] = timeline.properties_stream_f32_mtx_pos[i++];
457
+ new_matrix._rawData[13] = timeline.properties_stream_f32_mtx_pos[i];
458
+ child.transform.invalidatePosition();
459
+ };
460
+ Timeline.enable_maskmode = function (_timeline, child, _target_mc, _i) {
461
+ child.maskMode = true;
462
+ };
463
+ Timeline.remove_masks = function (_timeline, child, _target_mc, _i) {
464
+ child.updateTimelineMask(null);
465
+ };
466
+ Timeline.update_filters = function (timeline, child, _target_mc, i) {
467
+ var startFilter = timeline.properties_stream_int[i++];
468
+ var numFilter = timeline.properties_stream_int[i++];
469
+ var adapter = child.adapter;
470
+ if (numFilter === 0) {
471
+ adapter.updateFilters(null);
472
+ return;
473
+ }
474
+ adapter.updateFilters(timeline.properties_stream_filters.slice(startFilter, startFilter + numFilter));
475
+ };
476
+ Timeline.swap_graphics = function (timeline, child, _target_mc, i) {
477
+ if (!child.isAsset(Sprite)) {
478
+ console.warn('[Timeline] - swap_graphics - child is not a Sprite');
479
+ return;
480
+ }
481
+ var sprite = child;
482
+ var target = timeline.graphicsPool[timeline.properties_stream_int[i]];
483
+ if (target.id === sprite.graphics.id) {
484
+ // already the same graphics
485
+ return;
486
+ }
487
+ sprite.graphics = target;
488
+ };
489
+ Timeline.start_audio = function (_timeline, _child, _target_mc, _i) { };
490
+ Timeline.set_ratio = function (_timeline, child, _target_mc, i) {
491
+ if (!child.isAsset(MorphSprite)) {
492
+ console.warn('[Timeline] - set_ratio - child is not a MorphSprite');
493
+ return;
494
+ }
495
+ child.setRatio(_timeline.properties_stream_int[i] / 0xffff);
496
+ };
497
+ Timeline.update_blendmode = function (_timeline, child, _target_mc, i) {
498
+ child.blendMode = mapBlendIdToString(i);
499
+ };
500
+ Timeline.update_rendermode = function (_timeline, _child, _target_mc, i) {
501
+ console.log('update rendermode ' + i);
502
+ };
503
+ Timeline.prototype.dispose = function () {
504
+ this.keyframe_indices = [];
505
+ this.avm1Exports = {};
506
+ this.avm1InitActions = {};
507
+ this.avm1ButtonActions = [];
508
+ this.graphicsPool = {};
509
+ this.audioPool = {};
510
+ this.placeObjectTagsForSessionIDs = {};
511
+ this._labels = {};
512
+ this._framescripts = {};
513
+ this._framescripts_translated = {};
514
+ };
515
+ Timeline.applyFunctionMap = (_a = {},
516
+ _a[1 /* AType.UPDATE_MTX */] = Timeline.update_mtx_all,
517
+ _a[2 /* AType.UPDATE_CMTX */] = Timeline.update_colortransform,
518
+ _a[3 /* AType.UPDATE_MASKS */] = Timeline.update_masks,
519
+ _a[4 /* AType.UPDATE_NAME */] = Timeline.update_name,
520
+ _a[5 /* AType.UPDATE_BUTTON_NAME */] = Timeline.update_button_name,
521
+ _a[6 /* AType.UPDATE_VISIBLE */] = Timeline.update_visibility,
522
+ _a[7 /* AType.UPDATE_BLENDMODE */] = Timeline.update_blendmode,
523
+ _a[8 /* AType.UPDATE_RENDERMODE */] = Timeline.update_rendermode,
524
+ _a[9 /* AType.UPDATE_FILTERS */] = Timeline.update_filters,
525
+ _a[11 /* AType.UPDATE_SCALE_ROT */] = Timeline.update_mtx_scale_rot,
526
+ _a[12 /* AType.UPDATE_POS */] = Timeline.update_mtx_pos,
527
+ _a[200 /* AType.ENABLE_MASKMODE */] = Timeline.enable_maskmode,
528
+ _a[201 /* AType.REMOVE_MASK */] = Timeline.remove_masks,
529
+ _a[202 /* AType.SWAP_GRAPHICS */] = Timeline.swap_graphics,
530
+ _a[203 /* AType.SET_RATIO */] = Timeline.set_ratio,
531
+ _a[204 /* AType.START_AUDIO */] = Timeline.start_audio,
532
+ _a);
533
+ return Timeline;
534
+ }());
535
+ export { Timeline };