@awayjs/scene 0.13.322 → 0.13.323

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