swf2js 0.1.2 → 0.4.0
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.
- package/README.md +81 -14
- package/package.json +11 -7
- package/studio/actionscript-roundtrip.test.js +54 -0
- package/studio/actionscript-scripts.test.js +169 -0
- package/studio/animated-image.test.js +137 -0
- package/studio/arithmetic.test.js +16 -0
- package/studio/as3-import.test.js +110 -0
- package/studio/audio-info.test.js +44 -0
- package/studio/components.test.js +152 -0
- package/studio/document-editing.test.js +92 -0
- package/studio/examples/01-space-mission.json +1628 -0
- package/studio/examples/02-clockwork-vault.json +1079 -0
- package/studio/examples/03-neon-synth.json +1364 -0
- package/studio/examples/04-kinetic-poster.json +923 -0
- package/studio/examples/05-signal-relay.json +1131 -0
- package/studio/examples/06-calculator.json +564 -0
- package/studio/frame-editing.test.js +129 -0
- package/studio/frame-events.test.js +117 -0
- package/studio/groups.test.js +88 -0
- package/studio/index.html +962 -0
- package/studio/interaction-triggers.test.js +37 -0
- package/studio/linked-actions.test.js +48 -0
- package/studio/lottie.test.js +208 -0
- package/studio/masks.test.js +43 -0
- package/studio/media-assets.test.js +62 -0
- package/studio/paint-tools.test.js +60 -0
- package/studio/playback.test.js +17 -0
- package/studio/project-io.test.js +405 -0
- package/studio/project-preview.test.js +475 -0
- package/studio/scene-transition.test.js +32 -0
- package/studio/server/archive-companions.js +27 -0
- package/studio/server/as3-library.js +91 -0
- package/studio/server/assets.js +162 -0
- package/studio/server/audio-info.js +82 -0
- package/studio/server/font-files.js +332 -0
- package/studio/server/http.js +135 -0
- package/studio/server/linked-actions.js +93 -0
- package/studio/server/png-decode.js +1 -0
- package/studio/server/project-movie.js +1164 -0
- package/studio/server/project-preview.js +152 -0
- package/studio/server/projects.js +370 -0
- package/studio/server/report.js +29 -0
- package/studio/server/routes.js +93 -0
- package/studio/server/swf-authoring.js +90 -0
- package/studio/server/swf-control-runtime.as +513 -0
- package/studio/server/swf-controls.js +119 -0
- package/studio/server/swf-export.js +293 -0
- package/studio/server/swf-import.js +1675 -0
- package/studio/server/swf-morphs.js +64 -0
- package/studio/server/swf-routes.js +42 -0
- package/studio/server/swf-streams.js +80 -0
- package/studio/server/swf-transition-runtime.as +52 -0
- package/studio/server/tween-recovery.js +106 -0
- package/studio/server-api.test.js +283 -0
- package/studio/server.js +320 -0
- package/studio/src/animated-image.js +423 -0
- package/studio/src/appearance-inspector.js +63 -0
- package/studio/src/arithmetic.js +50 -0
- package/studio/src/authored-controls.js +42 -0
- package/studio/src/busy.js +41 -0
- package/studio/src/canvas.js +430 -0
- package/studio/src/clipper-browser.js +2 -0
- package/studio/src/color-transform.js +38 -0
- package/studio/src/component-inspector.js +126 -0
- package/studio/src/components.js +268 -0
- package/studio/src/display-frame.js +262 -0
- package/studio/src/document-editing.js +69 -0
- package/studio/src/event-editor.js +150 -0
- package/studio/src/frame-editing.js +150 -0
- package/studio/src/frame-events.js +128 -0
- package/studio/src/frame-image.js +28 -0
- package/studio/src/groups.js +125 -0
- package/studio/src/handler-editor.js +122 -0
- package/studio/src/history.js +83 -0
- package/studio/src/imported-paths.js +99 -0
- package/studio/src/index.js +3582 -0
- package/studio/src/interaction-triggers.js +42 -0
- package/studio/src/json-patch.js +77 -0
- package/studio/src/layer-icons.js +25 -0
- package/studio/src/lottie-export.js +948 -0
- package/studio/src/lottie-import.js +1138 -0
- package/studio/src/masks.js +69 -0
- package/studio/src/media-assets.js +188 -0
- package/studio/src/media-library.js +193 -0
- package/studio/src/model.js +431 -0
- package/studio/src/numeric-fields.js +46 -0
- package/studio/src/object-list.js +57 -0
- package/studio/src/paint-tools.js +76 -0
- package/studio/src/placement-effects.js +74 -0
- package/studio/src/playback.js +10 -0
- package/studio/src/preview-audio.js +64 -0
- package/studio/src/preview-interactions.js +106 -0
- package/studio/src/preview-recorder.js +335 -0
- package/studio/src/preview-surface.js +338 -0
- package/studio/src/project-io.js +905 -0
- package/studio/src/project-session.js +375 -0
- package/studio/src/projects-dialog.js +319 -0
- package/studio/src/scene-transition.js +129 -0
- package/studio/src/script-editor.js +175 -0
- package/studio/src/script-references.js +74 -0
- package/studio/src/scripted-controls.js +146 -0
- package/studio/src/scripts.js +185 -0
- package/studio/src/stage-guides.js +101 -0
- package/studio/src/svg-animation.js +416 -0
- package/studio/src/svg-context.js +522 -0
- package/studio/src/svg-frame.js +413 -0
- package/studio/src/svg-import.js +1208 -0
- package/studio/src/swf-recording.js +104 -0
- package/studio/src/symbol-library.js +39 -0
- package/studio/src/symbols.js +62 -0
- package/studio/src/text-fields.js +58 -0
- package/studio/src/theme.js +43 -0
- package/studio/src/timeline.js +321 -0
- package/studio/src/vector-cut.js +103 -0
- package/studio/src/vector-geometry.js +254 -0
- package/studio/src/vector-style.js +146 -0
- package/studio/src/video-encode.js +84 -0
- package/studio/src/video-export.js +331 -0
- package/studio/src/video-mux.js +339 -0
- package/studio/src/video-playback.js +281 -0
- package/studio/src/workspace.js +344 -0
- package/studio/stroke-style.test.js +119 -0
- package/studio/styles.css +1547 -0
- package/studio/svg-export.test.js +162 -0
- package/studio/svg-import.test.js +318 -0
- package/studio/swf-authoring.test.js +140 -0
- package/studio/swf-export.test.js +324 -0
- package/studio/swf-import.test.js +489 -0
- package/studio/symbols.test.js +68 -0
- package/studio/tests/accessibility-interactions.mjs +138 -0
- package/studio/tests/appearance-interactions.mjs +103 -0
- package/studio/tests/control-interactions.mjs +60 -0
- package/studio/tests/event-interactions.mjs +117 -0
- package/studio/tests/external-resources.mjs +174 -0
- package/studio/tests/frame-image.mjs +71 -0
- package/studio/tests/html-export.mjs +68 -0
- package/studio/tests/import-files.mjs +131 -0
- package/studio/tests/lottie.mjs +125 -0
- package/studio/tests/mask-interactions.mjs +148 -0
- package/studio/tests/media-interactions.mjs +109 -0
- package/studio/tests/paint-interactions.mjs +64 -0
- package/studio/tests/project-interactions.mjs +244 -0
- package/studio/tests/script-interactions.mjs +178 -0
- package/studio/tests/scripted-control-interactions.mjs +107 -0
- package/studio/tests/svg-export.mjs +149 -0
- package/studio/tests/text-field-interactions.mjs +64 -0
- package/studio/tests/theme-interactions.mjs +53 -0
- package/studio/tests/timeline-browser.mjs +507 -0
- package/studio/tests/transition-interactions.mjs +94 -0
- package/studio/tests/trigger-interactions.mjs +93 -0
- package/studio/tests/video-export.mjs +243 -0
- package/studio/tests/workspace-interactions.mjs +226 -0
- package/studio/tween-recovery.test.js +31 -0
- package/studio/vector-style.test.js +56 -0
- package/studio/video-export.test.js +326 -0
- package/studiospec/actionscript.md +88 -0
- package/studiospec/architecture.md +378 -0
- package/studiospec/controls.md +100 -0
- package/studiospec/file-support.md +268 -0
- package/studiospec/lottie.md +69 -0
- package/studiospec/requirements.md +135 -0
- package/studiospec/stroke-style.md +95 -0
- package/studiospec/svg-export.md +83 -0
- package/studiospec/svg-import.md +139 -0
- package/studiospec/swooflib-integration.md +115 -0
- package/studiospec/tasks.md +573 -0
- package/studiospec/video-export.md +127 -0
- package/swf2js/__tests__/actionscript.test.js +1609 -0
- package/swf2js/__tests__/adpcm-audio.test.js +43 -0
- package/swf2js/__tests__/as2-compiler.test.js +153 -0
- package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
- package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
- package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
- package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
- package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
- package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
- package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
- package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
- package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
- package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
- package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
- package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
- package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
- package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
- package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
- package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
- package/swf2js/__tests__/avm1-key-events.test.js +52 -0
- package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
- package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
- package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
- package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
- package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
- package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
- package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
- package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
- package/swf2js/__tests__/avm1-super.test.js +70 -0
- package/swf2js/__tests__/avm1-target-path.test.js +325 -0
- package/swf2js/__tests__/avm1-try.test.js +229 -0
- package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
- package/swf2js/__tests__/avm2-applytype.test.js +180 -0
- package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
- package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
- package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
- package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
- package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
- package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
- package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
- package/swf2js/__tests__/avm2-e4x.test.js +326 -0
- package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
- package/swf2js/__tests__/avm2-findprop.test.js +110 -0
- package/swf2js/__tests__/avm2-getlex.test.js +166 -0
- package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
- package/swf2js/__tests__/avm2-interface.test.js +95 -0
- package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
- package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
- package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
- package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
- package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
- package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
- package/swf2js/__tests__/avm2-protected.test.js +214 -0
- package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
- package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
- package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
- package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
- package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
- package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
- package/swf2js/__tests__/bevel-filter.test.js +116 -0
- package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
- package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
- package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
- package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
- package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
- package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
- package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
- package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
- package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
- package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
- package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
- package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
- package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
- package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
- package/swf2js/__tests__/blur-filter.test.js +48 -0
- package/swf2js/__tests__/bundle-emitter.test.js +394 -0
- package/swf2js/__tests__/button-actions.test.js +370 -0
- package/swf2js/__tests__/button-color-transform.test.js +48 -0
- package/swf2js/__tests__/button-decoder.test.js +106 -0
- package/swf2js/__tests__/button-hit-test.test.js +825 -0
- package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
- package/swf2js/__tests__/button-sound.test.js +105 -0
- package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
- package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
- package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
- package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
- package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
- package/swf2js/__tests__/companion-swf.test.js +638 -0
- package/swf2js/__tests__/context-menu.test.js +149 -0
- package/swf2js/__tests__/convolution-filter.test.js +74 -0
- package/swf2js/__tests__/definefont4.test.js +280 -0
- package/swf2js/__tests__/display-displacement.test.js +161 -0
- package/swf2js/__tests__/display-list.test.js +80 -0
- package/swf2js/__tests__/display-mask-render.test.js +656 -0
- package/swf2js/__tests__/displayobject-stage.test.js +320 -0
- package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
- package/swf2js/__tests__/embedded-swf.test.js +202 -0
- package/swf2js/__tests__/embedded-textfield.test.js +107 -0
- package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
- package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
- package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
- package/swf2js/__tests__/event-priority-order.test.js +125 -0
- package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
- package/swf2js/__tests__/event-will-trigger.test.js +43 -0
- package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
- package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
- package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
- package/swf2js/__tests__/font-encoder.test.js +95 -0
- package/swf2js/__tests__/font-outline-text.test.js +659 -0
- package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
- package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
- package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
- package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
- package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
- package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
- package/swf2js/__tests__/input-events.test.js +714 -0
- package/swf2js/__tests__/integration/corpus.test.js +41 -0
- package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
- package/swf2js/__tests__/loader-info.test.js +81 -0
- package/swf2js/__tests__/local-connection.test.js +122 -0
- package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
- package/swf2js/__tests__/morph-topology.test.js +267 -0
- package/swf2js/__tests__/movie-data-codec.test.js +128 -0
- package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
- package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
- package/swf2js/__tests__/path-stream.test.js +81 -0
- package/swf2js/__tests__/place-object-filters.test.js +88 -0
- package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
- package/swf2js/__tests__/place-object3-image.test.js +85 -0
- package/swf2js/__tests__/player-version.test.js +46 -0
- package/swf2js/__tests__/root-textfield.test.js +287 -0
- package/swf2js/__tests__/scaling-grid.test.js +183 -0
- package/swf2js/__tests__/shape-decoder.test.js +361 -0
- package/swf2js/__tests__/shape-line-style2.test.js +138 -0
- package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
- package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
- package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
- package/swf2js/__tests__/socket-offline.test.js +67 -0
- package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
- package/swf2js/__tests__/sound-envelope.test.js +110 -0
- package/swf2js/__tests__/sound-extract.test.js +168 -0
- package/swf2js/__tests__/sound-id3.test.js +283 -0
- package/swf2js/__tests__/sound-load.test.js +259 -0
- package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
- package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
- package/swf2js/__tests__/sound-transform.test.js +104 -0
- package/swf2js/__tests__/speex-audio.test.js +77 -0
- package/swf2js/__tests__/stage-noscale.test.js +45 -0
- package/swf2js/__tests__/swf-encoder.test.js +134 -0
- package/swf2js/__tests__/swflib-assemble.test.js +20 -0
- package/swf2js/__tests__/textfield-html-text.test.js +368 -0
- package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
- package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
- package/swf2js/__tests__/textfield-scroll.test.js +79 -0
- package/swf2js/__tests__/textfield-selection.test.js +383 -0
- package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
- package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
- package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
- package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
- package/{src → swf2js}/cli.js +43 -11
- package/swf2js/compiler/as2-classes.js +156 -0
- package/swf2js/compiler/as2-parser.js +598 -0
- package/swf2js/compiler/avm1-codegen.js +897 -0
- package/swf2js/compiler/index.js +28 -0
- package/{src → swf2js}/decoder/button-decoder.js +3 -1
- package/swf2js/decoder/png.js +114 -0
- package/{src → swf2js}/decoder/shape-decoder.js +20 -10
- package/{src → swf2js}/decoder/tag-decoder.js +5 -3
- package/{src → swf2js}/decoder/tag-types.js +4 -0
- package/swf2js/decompiler/avm1-decompiler.js +1138 -0
- package/{src → swf2js}/emitter/asset-encoder.js +66 -113
- package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
- package/swf2js/emitter/external-resources.js +39 -0
- package/swf2js/emitter/movie-data-codec.js +91 -0
- package/swf2js/encoder/bit-writer.js +182 -0
- package/swf2js/encoder/shape-encoder.js +310 -0
- package/swf2js/encoder/swf-builder.js +639 -0
- package/swf2js/encoder/swf-writer.js +55 -0
- package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
- package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
- package/{src → swf2js}/runtime/index.js +1 -1
- package/{src → swf2js}/runtime/movie-runtime.js +28 -2
- package/{src → swf2js}/transpiler/actionscript.js +82 -19
- package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
- package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
- package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
- package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
- package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
- package/swooflib/README.md +569 -0
- package/swooflib/adpcm.js +147 -0
- package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
- package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
- package/swooflib/control-definitions.js +42 -0
- package/swooflib/control-widget.js +763 -0
- package/swooflib/controls.js +300 -0
- package/{src/runtime/swflib → swooflib}/display.js +16 -10
- package/{src/runtime/swflib → swooflib}/events.js +11 -0
- package/{src/runtime/swflib → swooflib}/flash.js +6 -5
- package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
- package/{src/runtime/swflib → swooflib}/input.js +12 -14
- package/{src/runtime/swflib → swooflib}/loader.js +52 -22
- package/swooflib/movie-network.js +86 -0
- package/swooflib/path-stream.js +169 -0
- package/{src/runtime/swflib → swooflib}/render.js +3 -13
- package/{src/runtime/swflib → swooflib}/sound.js +25 -2
- package/{src/runtime/swflib → swooflib}/stage.js +3 -3
- package/swooflib/stream-time.js +21 -0
- package/{src/runtime/swflib → swooflib}/system.js +88 -37
- package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
- package/{src/runtime/swflib → swooflib}/text.js +8 -0
- package/swooflib/xml-node.js +53 -0
- package/src/emitter/timeline-data-codec.js +0 -58
- /package/{src → swf2js}/decoder/symbol-table.js +0 -0
- /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
- /package/{src → swf2js}/emitter/font-encoder.js +0 -0
- /package/{src → swf2js}/model/swf-document.js +0 -0
- /package/{src → swf2js}/model/transpile-result.js +0 -0
- /package/{src → swf2js}/parser/bit-reader.js +0 -0
- /package/{src → swf2js}/parser/decompressor.js +0 -0
- /package/{src → swf2js}/parser/swf-parser.js +0 -0
- /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
- /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
- /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
- /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
- /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
- /package/{src → swf2js}/util/diagnostics.js +0 -0
- /package/{src → swf2js}/util/logger.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
- /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
- /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
- /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
- /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
- /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
- /package/{src/runtime/swflib → swooflib}/host.js +0 -0
- /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
- /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
- /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
- /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
- /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
- /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
- /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
- /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
- /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
|
@@ -0,0 +1,1723 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import * as acorn from 'acorn';
|
|
4
|
+
import { parse } from '../parser/swf-parser.js';
|
|
5
|
+
import { decode, decodeTag } from '../decoder/tag-decoder.js';
|
|
6
|
+
import { TAG } from '../decoder/tag-types.js';
|
|
7
|
+
import { buildDisplayList, buildFramesFromTags } from '../transpiler/timeline/display-list.js';
|
|
8
|
+
import { generateTimelineEngine, hitTestButtonGeometry, normalizeSceneGotoArguments, resolveTimelineFrame, sceneNavigationFrame, timelineEngineFactorySource, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
|
|
9
|
+
import { AVM1_RUNTIME_STUB, transpileAvm1 } from '../transpiler/avm1/avm1-transpiler.js';
|
|
10
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
11
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
12
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
13
|
+
import { runInNewContext } from 'node:vm';
|
|
14
|
+
|
|
15
|
+
const scenes = [
|
|
16
|
+
{ name: 'Intro', offset: 0, numFrames: 3 },
|
|
17
|
+
{ name: 'Game', offset: 3, numFrames: 4 },
|
|
18
|
+
];
|
|
19
|
+
const frames = [
|
|
20
|
+
{}, {}, {}, { label: 'start' }, {}, {}, {},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
function makeTimeline(fixtureFrames = frames, characters = {}, fixtureScript = '') {
|
|
24
|
+
const engine = generateTimelineEngine({ frames: fixtureFrames, characters, scenes }, {
|
|
25
|
+
frameRate: 24, frameCount: fixtureFrames.length, stageW: 320, stageH: 240, backgroundColor: '#000',
|
|
26
|
+
});
|
|
27
|
+
const context = {
|
|
28
|
+
console: { warn() {} },
|
|
29
|
+
requestAnimationFrame: () => 1,
|
|
30
|
+
loaded: {},
|
|
31
|
+
FRAME_RATE: 24,
|
|
32
|
+
};
|
|
33
|
+
context.window = context;
|
|
34
|
+
return runInNewContext(`
|
|
35
|
+
${SWFLIB_SOURCE}
|
|
36
|
+
${engine}
|
|
37
|
+
var root = {};
|
|
38
|
+
var main = new MovieClip();
|
|
39
|
+
main._swoofHostTimeline = true;
|
|
40
|
+
window.__swoof = { timeline: timeline, main: main, root: root };
|
|
41
|
+
main.root = main;
|
|
42
|
+
__swoof_swflib.stage.addChild(main);
|
|
43
|
+
${fixtureScript}
|
|
44
|
+
timeline.render = function () {};
|
|
45
|
+
({ timeline, main, root, FRAME_SCRIPTS, SPRITE_FRAME_SCRIPTS, displayList, instanceDrawState });
|
|
46
|
+
`, context);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('root timeline scenes', () => {
|
|
50
|
+
it('honors a final-frame stop during normal looping playback and wraps after Play', () => {
|
|
51
|
+
const { main, timeline } = makeTimeline([{}, {}]);
|
|
52
|
+
main.addFrameScript(1, function () { this.stop(); });
|
|
53
|
+
timeline.enter();
|
|
54
|
+
timeline.tick();
|
|
55
|
+
timeline.tick();
|
|
56
|
+
expect([timeline.frame, timeline.playing]).toEqual([1, false]);
|
|
57
|
+
timeline.play();
|
|
58
|
+
timeline.tick();
|
|
59
|
+
expect([timeline.frame, timeline.playing]).toEqual([0, true]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('keeps looping across a final stop when the player explicitly enables the Loop command', () => {
|
|
63
|
+
const { main, timeline } = makeTimeline([{}, {}]);
|
|
64
|
+
timeline.overrideFinalStop = true;
|
|
65
|
+
main.addFrameScript(1, function () { this.stop(); });
|
|
66
|
+
timeline.enter();
|
|
67
|
+
|
|
68
|
+
timeline.tick();
|
|
69
|
+
expect(timeline.frame).toBe(1);
|
|
70
|
+
expect(timeline.playing).toBe(true);
|
|
71
|
+
|
|
72
|
+
timeline.tick();
|
|
73
|
+
expect(timeline.frame).toBe(0);
|
|
74
|
+
expect(timeline.playing).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('stops at the final root frame when looping is disabled', () => {
|
|
78
|
+
const { main, timeline } = makeTimeline([{}, {}]);
|
|
79
|
+
main.addFrameScript(1, function () { this.stop(); });
|
|
80
|
+
timeline.loop = false;
|
|
81
|
+
timeline.enter();
|
|
82
|
+
|
|
83
|
+
timeline.tick();
|
|
84
|
+
expect(timeline.frame).toBe(1);
|
|
85
|
+
expect(timeline.playing).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('uses live Stage frame rates while keeping catch-up paints bounded', () => {
|
|
89
|
+
const { timeline, main } = makeTimeline([{ places: [] }], {}, `
|
|
90
|
+
main.animationFrames = [];
|
|
91
|
+
requestAnimationFrame = callback => main.animationFrames.push(callback);
|
|
92
|
+
`);
|
|
93
|
+
const paints = [];
|
|
94
|
+
timeline.render = () => paints.push(timeline._ticks);
|
|
95
|
+
main.stage.frameRate = 50;
|
|
96
|
+
timeline.start();
|
|
97
|
+
function pump(time) {
|
|
98
|
+
main.animationFrames.shift()(time);
|
|
99
|
+
return timeline._ticks;
|
|
100
|
+
}
|
|
101
|
+
expect([pump(0), pump(20)]).toEqual([0, 1]);
|
|
102
|
+
main.stage.frameRate = 25;
|
|
103
|
+
expect([pump(40), pump(60), pump(1060)]).toEqual([1, 2, 5]);
|
|
104
|
+
expect(paints).toEqual([1, 2, 5]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('keeps movie playheads and scene callbacks independent in the shared factory', () => {
|
|
108
|
+
const factory = runInNewContext(`
|
|
109
|
+
var __swoof_swflib = { timelineHelpers: ${timelineHelpersSource()} };
|
|
110
|
+
${timelineEngineFactorySource()};
|
|
111
|
+
`);
|
|
112
|
+
const data = { frames, characters: {}, scenes, frameCount: frames.length };
|
|
113
|
+
const config = { stageWidth: 320, stageHeight: 240, frameRate: 24, assets: [], symbolClasses: [] };
|
|
114
|
+
function makeMovie() {
|
|
115
|
+
const root = {};
|
|
116
|
+
const movieGlobal = {};
|
|
117
|
+
const movieWindow = { __swoof: { root } };
|
|
118
|
+
const visits = [];
|
|
119
|
+
const engine = factory(data, config, {
|
|
120
|
+
global: movieGlobal, window: movieWindow, root, loaded: {},
|
|
121
|
+
requestAnimationFrame: () => 1,
|
|
122
|
+
runClipScript: (clip, script) => script.call(clip),
|
|
123
|
+
_enterFrameAll: () => visits.push('enter'),
|
|
124
|
+
}, {});
|
|
125
|
+
engine.FRAME_SCRIPTS[0] = [function () { visits.push(this.currentScene.name); }];
|
|
126
|
+
engine.FRAME_SCRIPTS[3] = [function () { visits.push(this.currentScene.name); }];
|
|
127
|
+
return { ...engine, root, movieGlobal, visits };
|
|
128
|
+
}
|
|
129
|
+
const first = makeMovie();
|
|
130
|
+
const second = makeMovie();
|
|
131
|
+
first.timeline.enter();
|
|
132
|
+
second.timeline.enter();
|
|
133
|
+
first.timeline.gotoAndStop('start', 'Game');
|
|
134
|
+
first.ensureSpritePlay(7, 2).frame = 1;
|
|
135
|
+
|
|
136
|
+
expect(first.visits).toEqual(['Intro', 'enter', 'Game']);
|
|
137
|
+
expect(second.visits).toEqual(['Intro', 'enter']);
|
|
138
|
+
expect(first.timeline.frame).toBe(3);
|
|
139
|
+
expect(second.timeline.frame).toBe(0);
|
|
140
|
+
expect(first.root.currentScene.name).toBe('Game');
|
|
141
|
+
expect(second.root.currentScene.name).toBe('Intro');
|
|
142
|
+
expect(first.displayList).not.toBe(second.displayList);
|
|
143
|
+
expect(second.spritePlay[7]).toBeUndefined();
|
|
144
|
+
expect(first.movieGlobal.__swoof_bindAs3SymbolInstance).not.toBe(second.movieGlobal.__swoof_bindAs3SymbolInstance);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('steps an imported Age of War 2 unit with its own symbol data under the host clock', async () => {
|
|
148
|
+
const { doc } = await parse(readFileSync('archive/Swf/age-of-war-2.swf'));
|
|
149
|
+
const payload = doc.tags.find(tag => tag.code === TAG.DefineBinaryData && (tag.data[0] | (tag.data[1] << 8)) === 80);
|
|
150
|
+
const { doc: units, diagnostics } = await parse(payload.data.subarray(6));
|
|
151
|
+
const unit = units.tags.find(tag => tag.code === TAG.DefineSprite && (tag.data[0] | (tag.data[1] << 8)) === 133);
|
|
152
|
+
const symbols = new SymbolTable();
|
|
153
|
+
symbols.set(133, decodeTag(unit, units, diagnostics));
|
|
154
|
+
const { characters } = buildDisplayList([], symbols, diagnostics, { swfVersion: units.header.version });
|
|
155
|
+
const state = runInNewContext(`
|
|
156
|
+
${SWFLIB_SOURCE}
|
|
157
|
+
__swoof_swflib.timelineHelpers = ${timelineHelpersSource()};
|
|
158
|
+
var factory = ${timelineEngineFactorySource()};
|
|
159
|
+
function makeOwner(characters, symbolClasses) {
|
|
160
|
+
const main = __swoof_swflib.stage.addChild(new MovieClip());
|
|
161
|
+
const namespace = { __swoof: { main } };
|
|
162
|
+
const engine = factory({
|
|
163
|
+
characters, frames: [{ places: [] }], frameCount: 1,
|
|
164
|
+
scenes: [{ name: 'Scene 1', offset: 0, numFrames: 1 }],
|
|
165
|
+
}, { symbolClasses, frameRate: 30, assets: [] }, {
|
|
166
|
+
global: namespace, window: namespace, runtime: __swoof_swflib, loaded: {},
|
|
167
|
+
}, {});
|
|
168
|
+
main._swoofHostTimeline = true;
|
|
169
|
+
main._swoofTimeline = engine.timeline;
|
|
170
|
+
engine.timeline.render = function () {};
|
|
171
|
+
engine.timeline.enter();
|
|
172
|
+
return { main, namespace, timeline: engine.timeline };
|
|
173
|
+
}
|
|
174
|
+
const host = makeOwner({}, []);
|
|
175
|
+
const assets = makeOwner(${JSON.stringify(characters)}, [{ id: 133, name: 'UnitFixture' }]);
|
|
176
|
+
host.main.addChild(assets.main);
|
|
177
|
+
class UnitFixture extends MovieClip {
|
|
178
|
+
constructor() {
|
|
179
|
+
super();
|
|
180
|
+
assets.namespace.__swoof_bindAs3SymbolInstance(this);
|
|
181
|
+
this.visit = [];
|
|
182
|
+
this.addFrameScript(210, function () { this.visit.push(this.currentFrame); });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
UnitFixture.__swoofQualifiedName = 'UnitFixture';
|
|
186
|
+
const units = [host.main, host.main, assets.main].map(owner => {
|
|
187
|
+
const clip = owner.addChild(new UnitFixture());
|
|
188
|
+
clip.gotoAndPlay('walkCycle');
|
|
189
|
+
return clip;
|
|
190
|
+
});
|
|
191
|
+
host.timeline.tick();
|
|
192
|
+
const afterHost = units.map(clip => [clip.currentFrame, clip.visit.slice()]);
|
|
193
|
+
assets.timeline.tick();
|
|
194
|
+
({ afterHost, afterChild: units.map(clip => [clip.currentFrame, clip.visit]) });
|
|
195
|
+
`);
|
|
196
|
+
expect(state.afterHost).toEqual([[211, [211]], [211, [211]], [210, []]]);
|
|
197
|
+
expect(state.afterChild).toEqual([[211, [211]], [211, [211]], [211, [211]]]);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('resolves scene-local numbers, qualified labels, and AVM1 scene bias distinctly', () => {
|
|
201
|
+
expect(resolveTimelineFrame(2, 'Game', null, scenes, 7, 0, frames)).toBe(4);
|
|
202
|
+
expect(resolveTimelineFrame('Game:start', null, null, scenes, 7, 0, frames)).toBe(3);
|
|
203
|
+
expect(resolveTimelineFrame('start', 'Game', null, scenes, 7, 0, frames)).toBe(3);
|
|
204
|
+
expect(resolveTimelineFrame(2, null, 3, scenes, 7, 0, frames)).toBe(4);
|
|
205
|
+
expect(resolveTimelineFrame('missing', null, null, scenes, 7, 5, frames)).toBe(5);
|
|
206
|
+
expect(resolveTimelineFrame(2, 'missing', null, scenes, 7, 5, frames)).toBe(5);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('accepts an AVM1 case mismatch only when the destination is unambiguous', () => {
|
|
210
|
+
const labelled = [...frames];
|
|
211
|
+
labelled[0] = { label: 'Start' };
|
|
212
|
+
labelled[4] = { label: 'dialogue', labels: ['dialogue', 'Talk'] };
|
|
213
|
+
const seek = (label, allowCaseFallback) =>
|
|
214
|
+
resolveTimelineFrame(label, null, null, scenes, 7, 5, labelled, allowCaseFallback);
|
|
215
|
+
expect(seek('START', true)).toBe(5);
|
|
216
|
+
expect(seek('start', true)).toBe(3);
|
|
217
|
+
expect(seek('Game:START', true)).toBe(3);
|
|
218
|
+
expect(seek('TALK', true)).toBe(4);
|
|
219
|
+
expect(seek('TALK', false)).toBe(5);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('supports AS2 scene-first and AS3 frame-first goto argument orders', () => {
|
|
223
|
+
expect(normalizeSceneGotoArguments('Game', 2, null, scenes)).toEqual({ frame: 2, scene: 'Game', sceneBias: null });
|
|
224
|
+
expect(normalizeSceneGotoArguments(2, 'Game', null, scenes)).toEqual({ frame: 2, scene: 'Game', sceneBias: null });
|
|
225
|
+
expect(normalizeSceneGotoArguments('Game', 'start', null, scenes)).toEqual({ frame: 'start', scene: 'Game', sceneBias: null });
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('moves nextScene/prevScene to scene starts and holds at table edges', () => {
|
|
229
|
+
expect(sceneNavigationFrame(1, 1, scenes)).toBe(3);
|
|
230
|
+
expect(sceneNavigationFrame(4, -1, scenes)).toBe(0);
|
|
231
|
+
expect(sceneNavigationFrame(0, -1, scenes)).toBe(0);
|
|
232
|
+
expect(sceneNavigationFrame(6, 1, scenes)).toBe(3);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('transpiles ActionGotoFrame2 scene-bias flags into a root navigation argument', () => {
|
|
236
|
+
// Push integer 2, then GotoFrame2(Play=1, SceneBiasFlag=1, SceneBias=3).
|
|
237
|
+
const bytecode = Uint8Array.from([0x96, 5, 0, 7, 2, 0, 0, 0, 0x9f, 3, 0, 3, 3, 0]);
|
|
238
|
+
const source = transpileAvm1(bytecode, new DiagnosticsCollector());
|
|
239
|
+
expect(source).toContain('this.gotoAndPlay(2, null, 3);');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('keeps ActionGotoFrame absolute in a movie with scenes', () => {
|
|
243
|
+
// GotoFrame 4 (0-based) is the Game scene's second frame wherever it runs: Flash adds the
|
|
244
|
+
// scene offset when it compiles gotoAndPlay inside a scene.
|
|
245
|
+
const source = transpileAvm1(new Uint8Array([0x81, 2, 0, 4, 0, 0x06, 0]), new DiagnosticsCollector());
|
|
246
|
+
expect(source).toContain('gotoAndPlay(5, null, 0);');
|
|
247
|
+
expect(resolveTimelineFrame(5, null, 0, scenes, frames.length, 3, frames)).toBe(4);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('retains decoded scene labels and offsets in the display list', () => {
|
|
251
|
+
const tags = [
|
|
252
|
+
{ type: 'SceneAndFrameLabels', scenes: [{ name: 'Intro', offset: 0 }, { name: 'Game', offset: 3 }], labels: [{ frame: 3, name: 'start' }] },
|
|
253
|
+
...Array.from({ length: 7 }, () => ({ type: 'ShowFrame' })),
|
|
254
|
+
];
|
|
255
|
+
const displayList = buildDisplayList(tags, new SymbolTable());
|
|
256
|
+
expect(displayList.scenes).toEqual(scenes);
|
|
257
|
+
expect(displayList.frames[3].label).toBe('start');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('resolves earlier root FrameLabel records alongside a scene-table label', () => {
|
|
261
|
+
const tags = [
|
|
262
|
+
{ type: 'ShowFrame' },
|
|
263
|
+
{ type: 'FrameLabel', name: 'ready' },
|
|
264
|
+
{ type: 'FrameLabel', name: 'start' },
|
|
265
|
+
{ type: 'ShowFrame' },
|
|
266
|
+
{ type: 'SceneAndFrameLabels', labels: [{ frame: 1, name: 'play' }] },
|
|
267
|
+
];
|
|
268
|
+
const { frames: rootFrames, scenes: rootScenes } = buildDisplayList(tags, new SymbolTable());
|
|
269
|
+
for (const name of ['ready', 'start', 'play']) {
|
|
270
|
+
expect(resolveTimelineFrame(name, null, null, rootScenes, 2, 0, rootFrames)).toBe(1);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('resolves the original Knightmare Tower scene by its UTF-8 name', async () => {
|
|
275
|
+
const { doc } = await parse(readFileSync('archive/Swf/knightmare-tower.swf'));
|
|
276
|
+
const tags = doc.tags.filter(raw => raw.code === TAG.DefineSceneAndFrameLabelData || raw.code === TAG.ShowFrame)
|
|
277
|
+
.map(raw => decodeTag(raw, doc));
|
|
278
|
+
const { frames, scenes } = buildDisplayList(tags, new SymbolTable());
|
|
279
|
+
expect(scenes[0].name).toBe('Séquence 1');
|
|
280
|
+
expect(resolveTimelineFrame(2, 'Séquence 1', null, scenes, frames.length, 0, frames)).toBe(1);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('exposes typed root and nested frame labels before authored scripts read them', async () => {
|
|
284
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/knightmare-tower.swf'));
|
|
285
|
+
const raw = doc.tags.find(raw => raw.code === TAG.DefineSprite && (raw.data[0] | (raw.data[1] << 8)) === 46);
|
|
286
|
+
const symbols = new SymbolTable();
|
|
287
|
+
symbols.set(46, decodeTag(raw, doc, diagnostics));
|
|
288
|
+
const { characters } = buildDisplayList([], symbols, diagnostics, { swfVersion: doc.header.version });
|
|
289
|
+
const { timeline, main } = makeTimeline([{ label: 'intro', labels: ['intro', 'opening'] }], characters, `
|
|
290
|
+
var SYMBOL_CLASSES = [{ id: 46, name: 'CreditsFixture' }];
|
|
291
|
+
class CreditsFixture extends MovieClip {
|
|
292
|
+
constructor() {
|
|
293
|
+
super();
|
|
294
|
+
bindAs3SymbolInstance(this);
|
|
295
|
+
this.constructedLabels = this.currentLabels;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
CreditsFixture.__swoofQualifiedName = 'CreditsFixture';
|
|
299
|
+
main.credits = new CreditsFixture();
|
|
300
|
+
main.frameLabelType = __swoof_swflib.packages.display.FrameLabel;
|
|
301
|
+
main.sceneType = __swoof_swflib.packages.display.Scene;
|
|
302
|
+
`);
|
|
303
|
+
const pairs = labels => Array.from(labels, label => [label.name, label.frame]);
|
|
304
|
+
const typed = labels => labels.every(label => label instanceof main.frameLabelType);
|
|
305
|
+
const { credits } = main;
|
|
306
|
+
expect(pairs(credits.constructedLabels)).toEqual([['rollover', 2], ['rollout', 11]]);
|
|
307
|
+
expect(typed(credits.constructedLabels)).toBe(true);
|
|
308
|
+
credits.gotoAndStop('rollover');
|
|
309
|
+
expect(credits.currentFrameLabel).toBe('rollover');
|
|
310
|
+
expect(pairs(credits.currentLabels)).toEqual([['rollover', 2], ['rollout', 11]]);
|
|
311
|
+
timeline.enter();
|
|
312
|
+
expect(pairs(main.currentLabels)).toEqual([['intro', 1], ['opening', 1]]);
|
|
313
|
+
expect(typed(main.currentLabels)).toBe(true);
|
|
314
|
+
expect(main.currentScene).toBeInstanceOf(main.sceneType);
|
|
315
|
+
expect(main.currentScene.labels).toBe(main.currentLabels);
|
|
316
|
+
expect(main.currentScene.numFrames).toBe(main.totalFrames);
|
|
317
|
+
expect(() => { main.currentLabels = []; }).toThrow(/#1074/);
|
|
318
|
+
expect(() => { main.scenes = []; }).toThrow(/#1074/);
|
|
319
|
+
expect(() => { main.currentScene = null; }).toThrow(/#1074/);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('publishes scene state to a document subclass through the MovieClip getters', () => {
|
|
323
|
+
const { timeline, main } = makeTimeline(frames, {}, `
|
|
324
|
+
class MainTimeline extends MovieClip {}
|
|
325
|
+
var documentMain = new MainTimeline();
|
|
326
|
+
documentMain._swoofHostTimeline = true;
|
|
327
|
+
documentMain.root = documentMain;
|
|
328
|
+
main = documentMain;
|
|
329
|
+
window.__swoof.main = documentMain;
|
|
330
|
+
__swoof_swflib.stage.addChild(documentMain);
|
|
331
|
+
`);
|
|
332
|
+
expect(() => timeline.enter()).not.toThrow();
|
|
333
|
+
expect(main.scenes.map(scene => scene.name)).toEqual(['Intro', 'Game']);
|
|
334
|
+
expect(main.currentScene.name).toBe('Intro');
|
|
335
|
+
expect(main.currentLabels).toBe(main.currentScene.labels);
|
|
336
|
+
expect(Object.prototype.hasOwnProperty.call(main, 'scenes')).toBe(false);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('plays linked sprite StartSound cues on an explicit offstage seek', () => {
|
|
340
|
+
const characters = {
|
|
341
|
+
7: {
|
|
342
|
+
type: 'sprite',
|
|
343
|
+
frames: [
|
|
344
|
+
{ places: [] },
|
|
345
|
+
{ places: [], sounds: [{ soundId: 11, soundInfo: { loopCount: 1 } }] },
|
|
346
|
+
],
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
const engine = generateTimelineEngine({ frames: [{ places: [] }], characters }, {
|
|
350
|
+
frameRate: 24, frameCount: 1, stageW: 320, stageH: 240, backgroundColor: '#000',
|
|
351
|
+
});
|
|
352
|
+
const sandbox = {
|
|
353
|
+
console: { warn() {} },
|
|
354
|
+
requestAnimationFrame: () => 1,
|
|
355
|
+
loaded: {},
|
|
356
|
+
FRAME_RATE: 24,
|
|
357
|
+
};
|
|
358
|
+
sandbox.window = sandbox;
|
|
359
|
+
const { clip, cues } = runInNewContext(`
|
|
360
|
+
${SWFLIB_SOURCE}
|
|
361
|
+
var cues = [];
|
|
362
|
+
__swoof_swflib.playSound = function (id, loops, info) {
|
|
363
|
+
cues.push([id, loops, info && info.loopCount]);
|
|
364
|
+
return {};
|
|
365
|
+
};
|
|
366
|
+
${engine}
|
|
367
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'SoundFixture' }];
|
|
368
|
+
class SoundFixture extends MovieClip {
|
|
369
|
+
constructor() {
|
|
370
|
+
super();
|
|
371
|
+
bindAs3SymbolInstance(this);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
SoundFixture.__swoofQualifiedName = 'SoundFixture';
|
|
375
|
+
var holder = new Sprite();
|
|
376
|
+
var clip = holder.addChild(new SoundFixture());
|
|
377
|
+
timeline.render = function () {};
|
|
378
|
+
timeline.enter();
|
|
379
|
+
({ clip, cues });
|
|
380
|
+
`, sandbox);
|
|
381
|
+
expect(clip.stage).toBeNull();
|
|
382
|
+
expect(cues).toEqual([]);
|
|
383
|
+
clip.gotoAndStop(2);
|
|
384
|
+
expect(clip.currentFrame).toBe(2);
|
|
385
|
+
expect(cues).toEqual([[11, 1, 1]]);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('constructs original Strike Force Heroes settings controls before an offstage frame script', async () => {
|
|
389
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/strike-force-heroes-1.swf'));
|
|
390
|
+
const raw = doc.tags.find(tag => tag.code === TAG.DefineSprite && (tag.data[0] | (tag.data[1] << 8)) === 1132);
|
|
391
|
+
const symbols = new SymbolTable();
|
|
392
|
+
symbols.set(1132, decodeTag(raw, doc, diagnostics));
|
|
393
|
+
const { characters } = buildDisplayList([], symbols, diagnostics, { swfVersion: doc.header.version });
|
|
394
|
+
const { main, timeline } = makeTimeline([{ places: [] }], characters, `
|
|
395
|
+
var SYMBOL_CLASSES = [{ id: 1132, name: 'SettingsFixture' }];
|
|
396
|
+
class SettingsFixture extends MovieClip {
|
|
397
|
+
constructor() {
|
|
398
|
+
super();
|
|
399
|
+
bindAs3SymbolInstance(this);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
SettingsFixture.__swoofQualifiedName = 'SettingsFixture';
|
|
403
|
+
main.menu = new Sprite();
|
|
404
|
+
main.settings = main.menu.addChild(new SettingsFixture());
|
|
405
|
+
main.visits = [];
|
|
406
|
+
main.menu.addEventListener(Event.FRAME_CONSTRUCTED, () => main.visits.push(['capture']), true);
|
|
407
|
+
main.settings.addEventListener(Event.FRAME_CONSTRUCTED, function (event) {
|
|
408
|
+
main.visits.push(['frameConstructed', this.currentFrame, event.target === this]);
|
|
409
|
+
if (this.rd_qualH) this.rd_qualH.groupName = 'qualGroup';
|
|
410
|
+
});
|
|
411
|
+
main.settings.addEventListener(Event.EXIT_FRAME, () => main.visits.push(['exitFrame']));
|
|
412
|
+
main.settings.addFrameScript(39, function () {
|
|
413
|
+
main.visits.push(['script', this.currentFrame, this.rd_qualH.groupName]);
|
|
414
|
+
});
|
|
415
|
+
`);
|
|
416
|
+
timeline.enter();
|
|
417
|
+
expect(main.settings.stage).toBeNull();
|
|
418
|
+
main.settings.gotoAndStop(40);
|
|
419
|
+
expect(main.settings.rd_qualH.parent).toBe(main.settings);
|
|
420
|
+
expect(main.visits).toEqual([['frameConstructed', 40, true], ['script', 40, 'qualGroup']]);
|
|
421
|
+
expect(main.visits).toHaveLength(2);
|
|
422
|
+
timeline.tick(true);
|
|
423
|
+
expect(main.settings.stage).toBeNull();
|
|
424
|
+
expect(main.visits.filter(visit => visit[0] === 'frameConstructed')).toEqual([
|
|
425
|
+
['frameConstructed', 40, true], ['frameConstructed', 40, true],
|
|
426
|
+
]);
|
|
427
|
+
expect(main.visits.filter(visit => visit[0] === 'exitFrame')).toEqual([['exitFrame']]);
|
|
428
|
+
expect(main.visits.some(visit => visit[0] === 'capture')).toBe(false);
|
|
429
|
+
main.addChild(main.menu);
|
|
430
|
+
timeline.tick(true);
|
|
431
|
+
expect(main.settings.stage).toBe(main.stage);
|
|
432
|
+
expect(main.visits.filter(visit => visit[0] === 'frameConstructed')).toHaveLength(3);
|
|
433
|
+
expect(main.visits.filter(visit => visit[0] === 'exitFrame')).toHaveLength(2);
|
|
434
|
+
expect(main.visits.filter(visit => visit[0] === 'script')).toHaveLength(1);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
it('seeks to the original UTF-8 frame label in Grow Tower sprite 1382', async () => {
|
|
438
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/grow-tower.swf'));
|
|
439
|
+
const raw = doc.tags.find(raw => raw.code === TAG.DefineSprite && (raw.data[0] | (raw.data[1] << 8)) === 1382);
|
|
440
|
+
const symbols = new SymbolTable();
|
|
441
|
+
symbols.set(1382, decodeTag(raw, doc, diagnostics));
|
|
442
|
+
const { characters } = buildDisplayList([], symbols, diagnostics, { swfVersion: doc.header.version });
|
|
443
|
+
expect(characters[1382].frames[45].label).toBe('lvl2');
|
|
444
|
+
|
|
445
|
+
const engine = generateTimelineEngine({
|
|
446
|
+
characters, frames: [{ places: [{ depth: 1, characterId: 1382, name: 'tower' }] }],
|
|
447
|
+
}, { frameCount: 1 });
|
|
448
|
+
const context = { ctx: null, loaded: {}, requestAnimationFrame: () => 1, SWF_VERSION: doc.header.version };
|
|
449
|
+
context.window = context;
|
|
450
|
+
const tower = runInNewContext(`
|
|
451
|
+
${SWFLIB_SOURCE}
|
|
452
|
+
${engine}
|
|
453
|
+
${AVM1_RUNTIME_STUB}
|
|
454
|
+
var __swoof_root = timeline;
|
|
455
|
+
window.__swoof = { root, timeline };
|
|
456
|
+
timeline.enter();
|
|
457
|
+
root.tower;
|
|
458
|
+
`, context);
|
|
459
|
+
expect(tower.currentFrame).toBe(1);
|
|
460
|
+
tower.gotoAndStop('lvl2');
|
|
461
|
+
expect(tower.currentFrame).toBe(46);
|
|
462
|
+
tower.gotoAndStop(1);
|
|
463
|
+
tower.gotoAndStop('LVL2');
|
|
464
|
+
expect(tower.currentFrame).toBe(46);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it('honors both authored labels when the Rubiks Cube controller positions its pieces', async () => {
|
|
468
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Rubiks Cube.swf'));
|
|
469
|
+
const symbols = new SymbolTable();
|
|
470
|
+
for (const raw of doc.tags) {
|
|
471
|
+
const id = raw.data[0] | (raw.data[1] << 8);
|
|
472
|
+
if (raw.code === TAG.DefineSprite && [984, 1951].includes(id)) symbols.set(id, decodeTag(raw, doc, diagnostics));
|
|
473
|
+
}
|
|
474
|
+
const { characters } = buildDisplayList([], symbols, diagnostics, { swfVersion: doc.header.version });
|
|
475
|
+
const controller = symbols.get(1951).tags.find(raw => raw.code === TAG.DoAction);
|
|
476
|
+
const actions = transpileAvm1(controller.data, diagnostics);
|
|
477
|
+
const engine = generateTimelineEngine({
|
|
478
|
+
characters, frames: [{ places: [{ depth: 4, characterId: 1951, name: 'qb3' }] }],
|
|
479
|
+
}, { frameCount: 1 });
|
|
480
|
+
const context = { ctx: null, loaded: {}, requestAnimationFrame: () => 1, SWF_VERSION: doc.header.version };
|
|
481
|
+
context.window = context;
|
|
482
|
+
const cube = runInNewContext(`
|
|
483
|
+
${SWFLIB_SOURCE}
|
|
484
|
+
${engine}
|
|
485
|
+
${AVM1_RUNTIME_STUB}
|
|
486
|
+
var __swoof_root = timeline;
|
|
487
|
+
window.__swoof = { root, timeline };
|
|
488
|
+
timeline.enter();
|
|
489
|
+
(function () { ${actions} }).call(root.qb3);
|
|
490
|
+
root.qb3;
|
|
491
|
+
`, context);
|
|
492
|
+
expect([cube['59'].currentFrame, cube['49'].currentFrame, cube['23'].currentFrame]).toEqual([7, 20, 33]);
|
|
493
|
+
cube['59'].gotoAndStop(200);
|
|
494
|
+
cube['59'].gotoAndStop('59to11');
|
|
495
|
+
expect(cube['59'].currentFrame).toBe(7);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it('keeps repeated anonymous Blocks placements and their named children independent', async () => {
|
|
499
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/blocks.swf'));
|
|
500
|
+
const symbols = new SymbolTable();
|
|
501
|
+
for (const raw of doc.tags) {
|
|
502
|
+
const id = raw.data[0] | (raw.data[1] << 8);
|
|
503
|
+
if (raw.code === TAG.DefineSprite && [67, 11, 10, 20, 19].includes(id)) symbols.set(id, decodeTag(raw, doc, diagnostics));
|
|
504
|
+
}
|
|
505
|
+
const { characters } = buildDisplayList([], symbols, diagnostics);
|
|
506
|
+
const engine = generateTimelineEngine({
|
|
507
|
+
characters, frames: [{ places: [{ depth: 1, characterId: 67, name: 'board' }] }],
|
|
508
|
+
}, { frameCount: 1 });
|
|
509
|
+
const context = { ctx: null, loaded: {}, requestAnimationFrame: () => 1 };
|
|
510
|
+
context.window = context;
|
|
511
|
+
const board = runInNewContext(`
|
|
512
|
+
${SWFLIB_SOURCE}
|
|
513
|
+
${engine}
|
|
514
|
+
var root = __swoof_swflib.stage.addChild(new MovieClip());
|
|
515
|
+
root._swoofHostTimeline = true;
|
|
516
|
+
window.__swoof = { root, main: root, timeline };
|
|
517
|
+
timeline.enter();
|
|
518
|
+
root.board;
|
|
519
|
+
`, context);
|
|
520
|
+
const repeated = board._children.filter(clip => clip._swoofCharacterId === 11);
|
|
521
|
+
expect(repeated).toHaveLength(2);
|
|
522
|
+
const [left, right] = repeated;
|
|
523
|
+
expect(left.name).toBe('');
|
|
524
|
+
expect(right.name).toBe('');
|
|
525
|
+
expect(board.glaza).toBeUndefined();
|
|
526
|
+
expect(left.glaza.parent).toBe(left);
|
|
527
|
+
expect(right.glaza.parent).toBe(right);
|
|
528
|
+
expect(left.glaza).not.toBe(right.glaza);
|
|
529
|
+
expect(left.glaza.localToGlobal({ x: 0, y: 0 })).toMatchObject({ x: -224.975, y: 272.375 });
|
|
530
|
+
expect(right.glaza.localToGlobal({ x: 0, y: 0 })).toMatchObject({ x: 26.025, y: 272.375 });
|
|
531
|
+
|
|
532
|
+
const events = [];
|
|
533
|
+
left.glaza.addEventListener('removedFromStage', () => events.push('left eyes'));
|
|
534
|
+
right.glaza.addEventListener('removedFromStage', () => events.push('right eyes'));
|
|
535
|
+
board.gotoAndStop(11);
|
|
536
|
+
expect(events).toEqual(['left eyes']);
|
|
537
|
+
expect(left.parent).toBeNull();
|
|
538
|
+
expect(left.glaza.stage).toBeNull();
|
|
539
|
+
expect(right.parent).toBe(board);
|
|
540
|
+
expect(right.glaza.stage).toBe(board.stage);
|
|
541
|
+
expect(board._children.filter(clip => clip._swoofCharacterId === 11)).toEqual([right]);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it('paints new visual-only Raze 3 sprite placements from their own first frame', async () => {
|
|
545
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/raze-3.swf'));
|
|
546
|
+
const symbols = new SymbolTable();
|
|
547
|
+
for (const raw of doc.tags) {
|
|
548
|
+
const id = raw.data[0] | (raw.data[1] << 8);
|
|
549
|
+
if ((raw.code === TAG.DefineSprite && [1330, 1306].includes(id)) ||
|
|
550
|
+
([TAG.DefineShape, TAG.DefineShape2, TAG.DefineShape3, TAG.DefineShape4].includes(raw.code) && [1304, 1305].includes(id))) {
|
|
551
|
+
symbols.set(id, decodeTag(raw, doc, diagnostics));
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
const { characters } = buildDisplayList([], symbols, diagnostics);
|
|
555
|
+
const engine = generateTimelineEngine({
|
|
556
|
+
characters, frames: [{ places: [{ depth: 1, characterId: 1330, name: 'sequence' }] }],
|
|
557
|
+
}, { frameCount: 1 });
|
|
558
|
+
const fills = [];
|
|
559
|
+
let translation;
|
|
560
|
+
const ctx = new Proxy({
|
|
561
|
+
canvas: { width: 800, height: 600 }, globalAlpha: 1,
|
|
562
|
+
setTransform(_a, _b, _c, _d, x, y) { translation = [x, y]; },
|
|
563
|
+
fill(path) { fills.push({ translation, start: path.start }); },
|
|
564
|
+
}, { get: (target, key) => target[key] ?? (() => {}) });
|
|
565
|
+
class Path2D {
|
|
566
|
+
moveTo(x, y) { this.start ??= [x, y]; }
|
|
567
|
+
lineTo() {} quadraticCurveTo() {} closePath() {}
|
|
568
|
+
}
|
|
569
|
+
const context = { ctx, Path2D, loaded: {}, STAGE_WIDTH: 800, STAGE_HEIGHT: 600, BACKGROUND: '#fff', requestAnimationFrame: () => 1 };
|
|
570
|
+
context.window = context;
|
|
571
|
+
const { sequence, timeline } = runInNewContext(`
|
|
572
|
+
${SWFLIB_SOURCE}
|
|
573
|
+
${engine}
|
|
574
|
+
var root = __swoof_swflib.stage.addChild(new MovieClip());
|
|
575
|
+
root._swoofHostTimeline = true;
|
|
576
|
+
window.__swoof = { root, main: root, timeline };
|
|
577
|
+
timeline.enter();
|
|
578
|
+
({ sequence: root.sequence, timeline });
|
|
579
|
+
`, context);
|
|
580
|
+
sequence.gotoAndStop(54);
|
|
581
|
+
timeline.render();
|
|
582
|
+
timeline.tick();
|
|
583
|
+
sequence.gotoAndPlay(62);
|
|
584
|
+
fills.length = 0;
|
|
585
|
+
timeline.tick();
|
|
586
|
+
|
|
587
|
+
expect(sequence.currentFrame).toBe(63);
|
|
588
|
+
const firstPaintAt = (x, y) => fills.find(fill => fill.translation[0] === x && fill.translation[1] === y)?.start;
|
|
589
|
+
expect(firstPaintAt(542 / 20, 97 / 20)).toEqual([1.45, 0.6]); // older depth 3 uses shape 1305
|
|
590
|
+
expect(firstPaintAt(241 / 20, 156 / 20)).toEqual([-3.65, 0.65]); // fresh depth 1 uses shape 1304
|
|
591
|
+
const older = sequence._swoofSpriteChildren['1330:3'];
|
|
592
|
+
const fresh = sequence._swoofSpriteChildren['1330:1'];
|
|
593
|
+
expect([older.currentFrame, fresh.currentFrame]).toEqual([3, 1]);
|
|
594
|
+
expect(sequence.getChildIndex(fresh)).toBeLessThan(sequence.getChildIndex(older));
|
|
595
|
+
timeline.tick();
|
|
596
|
+
expect([older.currentFrame, fresh.currentFrame]).toEqual([4, 2]);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
it('inserts a newly placed lower depth beneath the existing root children before added fires', () => {
|
|
600
|
+
const { timeline, main } = makeTimeline([
|
|
601
|
+
{ places: [{ depth: 3, characterId: 7, name: 'upper' }] },
|
|
602
|
+
{ places: [{ depth: 1, characterId: 7, name: 'lower' }] },
|
|
603
|
+
], { 7: { type: 'sprite', frames: [{ places: [] }] } });
|
|
604
|
+
timeline.enter();
|
|
605
|
+
const overlay = main.addChild(new main.constructor());
|
|
606
|
+
const added = [];
|
|
607
|
+
main.addEventListener('added', event => {
|
|
608
|
+
if (event.target === main.lower) added.push(main.getChildIndex(main.lower));
|
|
609
|
+
});
|
|
610
|
+
main.gotoAndStop(2);
|
|
611
|
+
|
|
612
|
+
expect(main.getChildAt(0)).toBe(main.lower);
|
|
613
|
+
expect(main.getChildAt(1)).toBe(main.upper);
|
|
614
|
+
expect(main.getChildAt(2)).toBe(overlay);
|
|
615
|
+
expect(added).toEqual([0]);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it('exposes direct unnamed root sprites to indexed access and later frame mutations', () => {
|
|
619
|
+
const { timeline, main } = makeTimeline([
|
|
620
|
+
{ places: [
|
|
621
|
+
{ depth: 1, characterId: 7, name: 'first' },
|
|
622
|
+
{ depth: 2, characterId: 8 },
|
|
623
|
+
{ depth: 4, characterId: 9, name: 'last' },
|
|
624
|
+
] },
|
|
625
|
+
{ removes: [2], places: [{ depth: 3, characterId: 8 }] },
|
|
626
|
+
], {
|
|
627
|
+
7: { type: 'sprite', frames: [{ places: [] }] },
|
|
628
|
+
8: { type: 'sprite', frames: [{ places: [] }] },
|
|
629
|
+
9: { type: 'sprite', frames: [{ places: [] }] },
|
|
630
|
+
});
|
|
631
|
+
timeline.enter();
|
|
632
|
+
const overlay = main.addChild(new main.constructor());
|
|
633
|
+
const { first, last } = main;
|
|
634
|
+
expect([...main._children]).toEqual([first, last, overlay]);
|
|
635
|
+
const additions = [];
|
|
636
|
+
main.addEventListener('added', event => additions.push(event.target));
|
|
637
|
+
|
|
638
|
+
expect(main.getChildIndex(last)).toBe(2);
|
|
639
|
+
const indexed = main.getChildAt(1);
|
|
640
|
+
expect(indexed?._swoofCharacterId).toBe(8);
|
|
641
|
+
expect(main.numChildren).toBe(4);
|
|
642
|
+
expect([...main._children]).toEqual([first, indexed, last, overlay]);
|
|
643
|
+
expect(additions).toEqual([]);
|
|
644
|
+
expect(main.removeChildAt(1)).toBe(indexed);
|
|
645
|
+
|
|
646
|
+
main.gotoAndStop(2);
|
|
647
|
+
const replacement = main.getChildAt(1);
|
|
648
|
+
expect(indexed.parent).toBeNull();
|
|
649
|
+
expect(replacement?._swoofCharacterId).toBe(8);
|
|
650
|
+
expect(replacement).not.toBe(indexed);
|
|
651
|
+
expect([...main._children]).toEqual([first, replacement, last, overlay]);
|
|
652
|
+
expect(additions).toEqual([replacement]);
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
it.each(['setChildIndex', 'swapChildrenAt', 'swapChildren'])('uses the authored indices for %s before any indexed read', method => {
|
|
656
|
+
const { timeline, main } = makeTimeline([{ places: [
|
|
657
|
+
{ depth: 1, characterId: 7, name: 'first' },
|
|
658
|
+
{ depth: 2, characterId: 8 },
|
|
659
|
+
{ depth: 3, characterId: 7, name: 'third' },
|
|
660
|
+
] }], {
|
|
661
|
+
7: { type: 'sprite', frames: [{ places: [] }] },
|
|
662
|
+
8: { type: 'sprite', frames: [{ places: [] }] },
|
|
663
|
+
});
|
|
664
|
+
timeline.enter();
|
|
665
|
+
const { first, third } = main;
|
|
666
|
+
expect([...main._children]).toEqual([first, third]);
|
|
667
|
+
const added = [];
|
|
668
|
+
main.addEventListener('added', event => added.push(event.target));
|
|
669
|
+
|
|
670
|
+
if (method === 'setChildIndex') {
|
|
671
|
+
main.setChildIndex(first, 2);
|
|
672
|
+
expect(main.getChildAt(0)._swoofCharacterId).toBe(8);
|
|
673
|
+
expect([main.getChildAt(1), main.getChildAt(2)]).toEqual([third, first]);
|
|
674
|
+
} else {
|
|
675
|
+
if (method === 'swapChildrenAt') main.swapChildrenAt(0, 2);
|
|
676
|
+
else main.swapChildren(first, third);
|
|
677
|
+
expect(main.getChildAt(1)._swoofCharacterId).toBe(8);
|
|
678
|
+
expect([main.getChildAt(0), main.getChildAt(2)]).toEqual([third, first]);
|
|
679
|
+
}
|
|
680
|
+
expect(added).toEqual([]);
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
it('inserts specified indices among unnamed authored sprites before added fires', () => {
|
|
684
|
+
const { timeline, main } = makeTimeline([{ places: [
|
|
685
|
+
{ depth: 1, characterId: 7, name: 'first' },
|
|
686
|
+
{ depth: 2, characterId: 8 },
|
|
687
|
+
{ depth: 3, characterId: 7, name: 'third' },
|
|
688
|
+
] }], {
|
|
689
|
+
7: { type: 'sprite', frames: [{ places: [] }] },
|
|
690
|
+
8: { type: 'sprite', frames: [{ places: [] }] },
|
|
691
|
+
});
|
|
692
|
+
timeline.enter();
|
|
693
|
+
const { first, third } = main;
|
|
694
|
+
expect([...main._children]).toEqual([first, third]);
|
|
695
|
+
const inserted = new main.constructor();
|
|
696
|
+
const added = [];
|
|
697
|
+
main.addEventListener('added', event => added.push([event.target, main.getChildIndex(event.target)]));
|
|
698
|
+
|
|
699
|
+
expect(main.addChildAt(inserted, 2)).toBe(inserted);
|
|
700
|
+
expect(main.getChildAt(1)._swoofCharacterId).toBe(8);
|
|
701
|
+
expect([main.getChildAt(0), main.getChildAt(2), main.getChildAt(3)]).toEqual([first, inserted, third]);
|
|
702
|
+
expect(added).toEqual([[inserted, 2]]);
|
|
703
|
+
expect(main.addChildAt(first, 3)).toBe(first);
|
|
704
|
+
expect(main.getChildAt(3)).toBe(first);
|
|
705
|
+
expect(added).toEqual([[inserted, 2]]);
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
it('indexes unnamed sprites nested inside an unnamed sprite', () => {
|
|
709
|
+
const { timeline, main } = makeTimeline(
|
|
710
|
+
[{ places: [{ depth: 1, characterId: 7, name: 'holder' }] }],
|
|
711
|
+
{
|
|
712
|
+
7: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 8 }] }] },
|
|
713
|
+
8: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 9 }] }] },
|
|
714
|
+
9: { type: 'sprite', frames: [{}] },
|
|
715
|
+
},
|
|
716
|
+
);
|
|
717
|
+
timeline.enter();
|
|
718
|
+
const added = [];
|
|
719
|
+
const holder = main.holder;
|
|
720
|
+
holder.addEventListener('added', event => added.push(event.target));
|
|
721
|
+
expect(holder.numChildren).toBe(1);
|
|
722
|
+
const wrapper = holder.getChildAt(0);
|
|
723
|
+
expect(wrapper._swoofCharacterId).toBe(8);
|
|
724
|
+
wrapper.addEventListener('added', event => added.push(event.target));
|
|
725
|
+
expect(wrapper.numChildren).toBe(1);
|
|
726
|
+
expect(wrapper.getChildAt(0)._swoofCharacterId).toBe(9);
|
|
727
|
+
expect(added).toEqual([]);
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
it('indexes unnamed shape and bitmap leaves between authored sprites', () => {
|
|
731
|
+
const shape = { type: 'shape', bounds: { x: 0, y: 0, w: 10, h: 10 }, draws: [{
|
|
732
|
+
fill: { type: 'solid', color: 0xff0000 },
|
|
733
|
+
path: [['M', 0, 0], ['L', 10, 0], ['L', 10, 10], ['Z']],
|
|
734
|
+
}] };
|
|
735
|
+
const bitmap = { type: 'bitmap', width: 2, height: 2 };
|
|
736
|
+
const sprite = { type: 'sprite', frames: [{}] };
|
|
737
|
+
const { timeline, main } = makeTimeline(
|
|
738
|
+
[{ places: [
|
|
739
|
+
{ depth: 1, characterId: 8, name: 'before' },
|
|
740
|
+
{ depth: 2, characterId: 9 },
|
|
741
|
+
{ depth: 3, characterId: 10 },
|
|
742
|
+
{ depth: 4, characterId: 8, name: 'after' },
|
|
743
|
+
] }],
|
|
744
|
+
{ 8: sprite, 9: shape, 10: bitmap },
|
|
745
|
+
);
|
|
746
|
+
timeline.enter();
|
|
747
|
+
const added = [];
|
|
748
|
+
main.addEventListener('added', event => added.push(event.target));
|
|
749
|
+
expect(main.numChildren).toBe(4);
|
|
750
|
+
const graphic = main.getChildAt(1);
|
|
751
|
+
const image = main.getChildAt(2);
|
|
752
|
+
expect(graphic.constructor.name).toBe('Shape');
|
|
753
|
+
expect(graphic.graphics._cmds.map(command => command.op)).toEqual(['fill', 'M', 'L', 'L', 'Z', 'endFill']);
|
|
754
|
+
expect(image.constructor.name).toBe('Bitmap');
|
|
755
|
+
expect(image.bitmapData.width).toBe(2);
|
|
756
|
+
expect(image.bitmapData.height).toBe(2);
|
|
757
|
+
expect([main.getChildAt(0), main.getChildAt(3)]).toEqual([main.before, main.after]);
|
|
758
|
+
expect(added).toEqual([]);
|
|
759
|
+
expect(main.removeChildAt(1)).toBe(graphic);
|
|
760
|
+
expect(graphic.parent).toBeNull();
|
|
761
|
+
expect(main.getChildAt(1)).toBe(image);
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
it('copies gradient, bitmap, and morph fills onto indexed shape wrappers', () => {
|
|
765
|
+
const path = [['M', 0, 0], ['L', 10, 0], ['L', 10, 10], ['Z']];
|
|
766
|
+
const endPath = [['M', 0, 0], ['L', 20, 0], ['L', 20, 10], ['Z']];
|
|
767
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
768
|
+
const { timeline, main } = makeTimeline(
|
|
769
|
+
[{ places: [{ depth: 1, characterId: 8, name: 'holder' }] }],
|
|
770
|
+
{
|
|
771
|
+
8: { type: 'sprite', frames: [
|
|
772
|
+
{ places: [
|
|
773
|
+
{ depth: 1, characterId: 9 },
|
|
774
|
+
{ depth: 2, characterId: 11 },
|
|
775
|
+
{ depth: 3, characterId: 12, ratio: 0 },
|
|
776
|
+
] },
|
|
777
|
+
{ places: [{ depth: 3, move: true, ratio: 65535 }] },
|
|
778
|
+
] },
|
|
779
|
+
9: { type: 'shape', draws: [{ path, fill: {
|
|
780
|
+
type: 'linear', spreadMode: 2, interpolationMode: 1, matrix,
|
|
781
|
+
stops: [{ ratio: 0, color: '#ff0000' }, { ratio: 255, color: '#0000ff' }],
|
|
782
|
+
} }] },
|
|
783
|
+
10: { type: 'bitmap', width: 4, height: 4 },
|
|
784
|
+
11: { type: 'shape', draws: [{ path, fill: {
|
|
785
|
+
type: 'bitmap', bitmapId: 10, repeat: false, smoothed: true, matrix,
|
|
786
|
+
} }] },
|
|
787
|
+
12: { type: 'shape', morph: {
|
|
788
|
+
startDraws: [{ path, fill: { type: 'solid', color: 0xff0000 } }],
|
|
789
|
+
endDraws: [{ path: endPath, fill: { type: 'solid', color: 0x0000ff } }],
|
|
790
|
+
} },
|
|
791
|
+
},
|
|
792
|
+
);
|
|
793
|
+
timeline.enter();
|
|
794
|
+
const holder = main.holder;
|
|
795
|
+
expect(holder.numChildren).toBe(3);
|
|
796
|
+
const gradient = holder.getChildAt(0).graphics._cmds[0].fill;
|
|
797
|
+
const bitmap = holder.getChildAt(1).graphics._cmds[0].fill;
|
|
798
|
+
const morph = holder.getChildAt(2);
|
|
799
|
+
expect(gradient.gradientType).toBe('linear');
|
|
800
|
+
expect(gradient.colors).toEqual([0xff0000, 0x0000ff]);
|
|
801
|
+
expect(gradient.spreadMethod).toBe('repeat');
|
|
802
|
+
expect(gradient.interpolationMethod).toBe('linearRGB');
|
|
803
|
+
expect(bitmap.bitmap.width).toBe(4);
|
|
804
|
+
expect(bitmap.repeat).toBe(false);
|
|
805
|
+
expect(bitmap.smooth).toBe(true);
|
|
806
|
+
expect(morph.graphics._cmds.find(command => command.op === 'L').x).toBe(10);
|
|
807
|
+
holder.gotoAndStop(2);
|
|
808
|
+
expect(holder.getChildAt(2)).toBe(morph);
|
|
809
|
+
expect(morph.graphics._cmds.find(command => command.op === 'L').x).toBe(20);
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
it('keeps a gradient stroke and an unsized bitmap fill on indexed shape wrappers', () => {
|
|
813
|
+
const path = [['M', 0, 0], ['L', 8, 0], ['L', 8, 8], ['Z']];
|
|
814
|
+
const { timeline, main } = makeTimeline(
|
|
815
|
+
[{ places: [{ depth: 1, characterId: 8, name: 'holder' }] }],
|
|
816
|
+
{
|
|
817
|
+
8: { type: 'sprite', frames: [{ places: [
|
|
818
|
+
{ depth: 1, characterId: 9 },
|
|
819
|
+
{ depth: 2, characterId: 11 },
|
|
820
|
+
] }] },
|
|
821
|
+
9: { type: 'shape', draws: [{ path, stroke: { width: 2, fill: {
|
|
822
|
+
type: 'linear',
|
|
823
|
+
stops: [{ ratio: 0, color: '#00ff00' }, { ratio: 255, color: '#000000' }],
|
|
824
|
+
} } }] },
|
|
825
|
+
10: { type: 'bitmap' },
|
|
826
|
+
11: { type: 'shape', draws: [{ path, fill: {
|
|
827
|
+
type: 'bitmap', bitmapId: 10, repeat: true, smoothed: false,
|
|
828
|
+
} }] },
|
|
829
|
+
},
|
|
830
|
+
);
|
|
831
|
+
timeline.enter();
|
|
832
|
+
const holder = main.holder;
|
|
833
|
+
const stroke = holder.getChildAt(0).graphics._cmds.find(command => command.op === 'lineStyle').line.fill;
|
|
834
|
+
const bitmap = holder.getChildAt(1).graphics._cmds[0].fill;
|
|
835
|
+
expect(stroke.gradientType).toBe('linear');
|
|
836
|
+
expect(stroke.colors).toEqual([0x00ff00, 0x000000]);
|
|
837
|
+
expect(bitmap.bitmapId).toBe(10);
|
|
838
|
+
expect(bitmap.bitmap).toBeNull();
|
|
839
|
+
expect(bitmap.repeat).toBe(true);
|
|
840
|
+
expect(holder.getChildAt(1).graphics._cmds.map(command => command.op)).toContain('M');
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
it('includes an unnamed shape in point queries and target bounds before an index read', () => {
|
|
844
|
+
const path = [['M', 0, 0], ['L', 10, 0], ['L', 10, 10], ['Z']];
|
|
845
|
+
const characters = { 9: { type: 'shape', bounds: { x: 0, y: 0, w: 10, h: 10 }, draws: [{
|
|
846
|
+
path, fill: { type: 'solid', color: 0xff0000 },
|
|
847
|
+
}] } };
|
|
848
|
+
const places = [{ places: [{ depth: 1, characterId: 9 }] }];
|
|
849
|
+
const queried = makeTimeline(places, characters);
|
|
850
|
+
queried.timeline.enter();
|
|
851
|
+
const added = [];
|
|
852
|
+
queried.main.addEventListener('added', event => added.push(event.target));
|
|
853
|
+
expect(queried.main.hitTestPoint(5, 5, true)).toBe(true);
|
|
854
|
+
const found = queried.main.getObjectsUnderPoint({ x: 5, y: 5 });
|
|
855
|
+
expect(found.map(child => child.constructor.name)).toEqual(['Shape']);
|
|
856
|
+
expect(queried.main.getObjectsUnderPoint({ x: 40, y: 40 })).toEqual([]);
|
|
857
|
+
const measured = makeTimeline(places, characters);
|
|
858
|
+
measured.timeline.enter();
|
|
859
|
+
const bounds = measured.main.getBounds(measured.main.stage);
|
|
860
|
+
expect(bounds.width).toBe(10);
|
|
861
|
+
expect(bounds.height).toBe(10);
|
|
862
|
+
expect(added).toEqual([]);
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
it('inserts an explicit index between unnamed shape leaves', () => {
|
|
866
|
+
const path = [['M', 0, 0], ['L', 4, 0], ['L', 4, 4], ['Z']];
|
|
867
|
+
const shape = color => ({ type: 'shape', bounds: { x: 0, y: 0, w: 4, h: 4 }, draws: [{
|
|
868
|
+
path, fill: { type: 'solid', color },
|
|
869
|
+
}] });
|
|
870
|
+
const { timeline, main } = makeTimeline(
|
|
871
|
+
[{ places: [
|
|
872
|
+
{ depth: 1, characterId: 9 },
|
|
873
|
+
{ depth: 2, characterId: 10 },
|
|
874
|
+
] }],
|
|
875
|
+
{ 9: shape(0xff0000), 10: shape(0x00ff00) },
|
|
876
|
+
);
|
|
877
|
+
timeline.enter();
|
|
878
|
+
const inserted = new main.constructor();
|
|
879
|
+
const added = [];
|
|
880
|
+
main.addEventListener('added', event => added.push([event.target, main.getChildIndex(event.target)]));
|
|
881
|
+
expect(main.addChildAt(inserted, 1)).toBe(inserted);
|
|
882
|
+
expect(main.getChildAt(0)._swoofCharacterId).toBe(9);
|
|
883
|
+
expect(main.getChildAt(1)).toBe(inserted);
|
|
884
|
+
expect(main.getChildAt(2)._swoofCharacterId).toBe(10);
|
|
885
|
+
expect(added).toEqual([[inserted, 1]]);
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
it('keeps repeated root placements separate and rebinds their alias on removal', () => {
|
|
889
|
+
const { timeline, main } = makeTimeline([
|
|
890
|
+
{ places: [
|
|
891
|
+
{ depth: 4, characterId: 7, name: 'errtxt', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 640, ty: 1100 } },
|
|
892
|
+
{ depth: 162, characterId: 8, name: 'errtxt', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 640, ty: 3520 } },
|
|
893
|
+
] },
|
|
894
|
+
{ places: [], removes: [162] },
|
|
895
|
+
{ places: [], removes: [4] },
|
|
896
|
+
], {
|
|
897
|
+
7: { type: 'sprite', frames: [{ places: [] }] },
|
|
898
|
+
8: { type: 'sprite', frames: [{ places: [] }] },
|
|
899
|
+
});
|
|
900
|
+
timeline.enter();
|
|
901
|
+
|
|
902
|
+
const children = [main.getChildAt(0), main.getChildAt(1)];
|
|
903
|
+
expect(children.map(child => [child?.name, child?._swoofCharacterId, child?.y]))
|
|
904
|
+
.toEqual([['errtxt', 7, 55], ['errtxt', 8, 176]]);
|
|
905
|
+
expect(main.getChildByName('errtxt')).toBe(children[0]);
|
|
906
|
+
expect(main.errtxt).toBe(children[1]);
|
|
907
|
+
|
|
908
|
+
const frameAliases = [];
|
|
909
|
+
main.addFrameScript(1, function () { frameAliases.push(this.errtxt); });
|
|
910
|
+
main.addFrameScript(2, function () { frameAliases.push(this.errtxt); });
|
|
911
|
+
main.gotoAndStop(2);
|
|
912
|
+
expect(children[1].parent).toBeNull();
|
|
913
|
+
expect(main.getChildAt(0)).toBe(children[0]);
|
|
914
|
+
expect(main.errtxt).toBe(children[0]);
|
|
915
|
+
main.gotoAndStop(3);
|
|
916
|
+
expect(children[0].parent).toBeNull();
|
|
917
|
+
expect(main.errtxt).toBeNull();
|
|
918
|
+
expect(frameAliases).toEqual([children[0], null]);
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
it('rebinds retained gun-menu children after the original higher copies are removed', async () => {
|
|
922
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/strike-force-heroes-2.swf'));
|
|
923
|
+
const symbols = new SymbolTable();
|
|
924
|
+
for (const raw of doc.tags) {
|
|
925
|
+
const id = raw.data[0] | (raw.data[1] << 8);
|
|
926
|
+
if (raw.code === TAG.DefineSprite && [491, 1577].includes(id)) symbols.set(id, decodeTag(raw, doc, diagnostics));
|
|
927
|
+
}
|
|
928
|
+
const { characters } = buildDisplayList([], symbols, diagnostics, { swfVersion: doc.header.version });
|
|
929
|
+
const { timeline, main } = makeTimeline([{ places: [{ depth: 1, characterId: 1577, name: 'guns' }] }], characters);
|
|
930
|
+
timeline.enter();
|
|
931
|
+
const { guns } = main;
|
|
932
|
+
guns.gotoAndStop(34);
|
|
933
|
+
const side = guns.getChildByName('side');
|
|
934
|
+
const top = guns.getChildByName('top');
|
|
935
|
+
expect([side?._swoofDepth, guns.side?._swoofDepth, top?._swoofDepth, guns.top?._swoofDepth])
|
|
936
|
+
.toEqual([39, 69, 30, 60]);
|
|
937
|
+
const aliasesOnFrame42 = [];
|
|
938
|
+
guns.addFrameScript(41, function () { aliasesOnFrame42.push(this.side, this.top); });
|
|
939
|
+
guns.gotoAndStop(42);
|
|
940
|
+
expect([guns.side, guns.top].map(child => child?._swoofDepth)).toEqual([39, 30]);
|
|
941
|
+
expect(guns.side).toBe(side);
|
|
942
|
+
expect(guns.top).toBe(top);
|
|
943
|
+
expect(aliasesOnFrame42).toEqual([side, top]);
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
it('emits distinct scene navigation and ordinary frame resolution into valid engine code', () => {
|
|
947
|
+
const engine = generateTimelineEngine({ frames, characters: {}, scenes }, {
|
|
948
|
+
frameRate: 24, frameCount: 7, stageW: 320, stageH: 240, backgroundColor: '#000',
|
|
949
|
+
});
|
|
950
|
+
expect(engine).toContain('resolveTimelineFrameOperand(f, sceneName, sceneBias');
|
|
951
|
+
expect(engine).toContain('sceneNavigationFrame(timeline.frame, delta, SCENES)');
|
|
952
|
+
expect(engine).toContain('timeline.gotoAndStop(sceneNavigationFrame(timeline.frame, delta, SCENES) + 1)');
|
|
953
|
+
expect(engine).toContain('landRootFrame(resolveFrame(f, scene, sceneBias), playing, false)');
|
|
954
|
+
expect(() => acorn.parse(engine, { ecmaVersion: 2020 })).not.toThrow();
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
it('finishes a root frame script before running the last requested destination', () => {
|
|
958
|
+
const { main, timeline } = makeTimeline();
|
|
959
|
+
const visits = [];
|
|
960
|
+
main.addFrameScript(0, function () {
|
|
961
|
+
this.gotoAndPlay(2);
|
|
962
|
+
this.gotoAndPlay('start', 'Game');
|
|
963
|
+
visits.push(['after goto', this.currentFrame, this.currentScene.name]);
|
|
964
|
+
}, 1, () => visits.push(['overridden destination']), 3, function () {
|
|
965
|
+
visits.push(['destination', this.currentFrame, this.currentScene.name]);
|
|
966
|
+
this.stop();
|
|
967
|
+
});
|
|
968
|
+
timeline.enter();
|
|
969
|
+
timeline.tick();
|
|
970
|
+
expect(visits).toEqual([['after goto', 1, 'Intro'], ['destination', 1, 'Game']]);
|
|
971
|
+
expect(timeline.frame).toBe(3);
|
|
972
|
+
expect(timeline.playing).toBe(false);
|
|
973
|
+
expect(main._playing).toBe(false);
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
it('applies play or stop issued after a queued root goto at its destination', () => {
|
|
977
|
+
const { main, timeline } = makeTimeline();
|
|
978
|
+
const visits = [];
|
|
979
|
+
main.addFrameScript(0, function () {
|
|
980
|
+
this.gotoAndStop(2);
|
|
981
|
+
this.play();
|
|
982
|
+
}, 1, function () {
|
|
983
|
+
visits.push(timeline.playing);
|
|
984
|
+
}, 2, function () {
|
|
985
|
+
this.gotoAndPlay('start', 'Game');
|
|
986
|
+
this.stop();
|
|
987
|
+
}, 3, function () {
|
|
988
|
+
visits.push(timeline.playing);
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
timeline.enter();
|
|
992
|
+
expect(timeline.frame).toBe(1);
|
|
993
|
+
expect(timeline.playing).toBe(true);
|
|
994
|
+
timeline.tick();
|
|
995
|
+
expect(timeline.frame).toBe(3);
|
|
996
|
+
expect(timeline.playing).toBe(false);
|
|
997
|
+
expect(visits).toEqual([true, false]);
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
it('stops a sprite on its first frame when that sprite changes scene', () => {
|
|
1001
|
+
const characters = { 7: { type: 'sprite', frames: [{}, { label: 'later' }, {}] } };
|
|
1002
|
+
const { main, timeline } = makeTimeline(
|
|
1003
|
+
[{ places: [{ depth: 1, characterId: 7, name: 'unit' }] }],
|
|
1004
|
+
characters,
|
|
1005
|
+
`
|
|
1006
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'UnitFixture' }];
|
|
1007
|
+
class UnitFixture extends MovieClip {
|
|
1008
|
+
constructor() { super(); bindAs3SymbolInstance(this); }
|
|
1009
|
+
}
|
|
1010
|
+
UnitFixture.__swoofQualifiedName = 'UnitFixture';
|
|
1011
|
+
`,
|
|
1012
|
+
);
|
|
1013
|
+
timeline.enter();
|
|
1014
|
+
const unit = main.unit;
|
|
1015
|
+
unit.gotoAndPlay(3);
|
|
1016
|
+
expect(unit.currentFrame).toBe(3);
|
|
1017
|
+
expect(unit._playing).toBe(true);
|
|
1018
|
+
unit.nextScene();
|
|
1019
|
+
expect(unit.currentFrame).toBe(1);
|
|
1020
|
+
expect(unit._playing).toBe(false);
|
|
1021
|
+
unit.gotoAndPlay(2);
|
|
1022
|
+
unit.prevScene();
|
|
1023
|
+
expect(unit.currentFrame).toBe(1);
|
|
1024
|
+
expect(unit._playing).toBe(false);
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
it('constructs an on-stage sprite frame before its script without repeating that event in the same pulse', () => {
|
|
1028
|
+
const characters = { 7: { type: 'sprite', frames: [{}, {}, {}] } };
|
|
1029
|
+
const { main, timeline } = makeTimeline(
|
|
1030
|
+
[{ places: [{ depth: 1, characterId: 7, name: 'unit' }] }],
|
|
1031
|
+
characters,
|
|
1032
|
+
`
|
|
1033
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'UnitFixture' }];
|
|
1034
|
+
class UnitFixture extends MovieClip {
|
|
1035
|
+
constructor() { super(); bindAs3SymbolInstance(this); }
|
|
1036
|
+
}
|
|
1037
|
+
UnitFixture.__swoofQualifiedName = 'UnitFixture';
|
|
1038
|
+
`,
|
|
1039
|
+
);
|
|
1040
|
+
timeline.enter();
|
|
1041
|
+
const unit = main.unit;
|
|
1042
|
+
const visits = [];
|
|
1043
|
+
unit.addEventListener('frameConstructed', () => visits.push('constructed'));
|
|
1044
|
+
unit.addEventListener('exitFrame', () => visits.push('exit'));
|
|
1045
|
+
unit.addFrameScript(1, () => visits.push(['script', unit.currentFrame]));
|
|
1046
|
+
unit.addFrameScript(2, () => visits.push(['script', unit.currentFrame]));
|
|
1047
|
+
unit.gotoAndStop(2);
|
|
1048
|
+
expect(visits).toEqual(['constructed', ['script', 2]]);
|
|
1049
|
+
visits.length = 0;
|
|
1050
|
+
unit.play();
|
|
1051
|
+
timeline.tick(true);
|
|
1052
|
+
expect(visits).toEqual(['constructed', ['script', 3], 'exit']);
|
|
1053
|
+
});
|
|
1054
|
+
|
|
1055
|
+
it('replaces sprite children one depth at a time before the frame script', () => {
|
|
1056
|
+
const characters = {
|
|
1057
|
+
7: { type: 'sprite', frames: [
|
|
1058
|
+
{ places: [
|
|
1059
|
+
{ depth: 1, characterId: 8, name: 'low' },
|
|
1060
|
+
{ depth: 3, characterId: 8, name: 'high' },
|
|
1061
|
+
] },
|
|
1062
|
+
{ removes: [3], places: [
|
|
1063
|
+
{ depth: 1, characterId: 9, name: 'next' },
|
|
1064
|
+
{ depth: 4, characterId: 9, name: 'later' },
|
|
1065
|
+
] },
|
|
1066
|
+
] },
|
|
1067
|
+
8: { type: 'sprite', frames: [{}] },
|
|
1068
|
+
9: { type: 'sprite', frames: [{}] },
|
|
1069
|
+
};
|
|
1070
|
+
const { main, timeline } = makeTimeline(
|
|
1071
|
+
[{ places: [{ depth: 1, characterId: 7, name: 'unit' }] }],
|
|
1072
|
+
characters,
|
|
1073
|
+
`
|
|
1074
|
+
var SYMBOL_CLASSES = [
|
|
1075
|
+
{ id: 7, name: 'UnitFixture' },
|
|
1076
|
+
{ id: 8, name: 'OldPiece' },
|
|
1077
|
+
{ id: 9, name: 'NewPiece' },
|
|
1078
|
+
];
|
|
1079
|
+
main.order = [];
|
|
1080
|
+
class OldPiece extends MovieClip {
|
|
1081
|
+
constructor() {
|
|
1082
|
+
super();
|
|
1083
|
+
bindAs3SymbolInstance(this);
|
|
1084
|
+
this.addEventListener('removedFromStage', () => main.order.push(['removedFromStage', this.name]));
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
class NewPiece extends MovieClip {
|
|
1088
|
+
constructor() {
|
|
1089
|
+
super();
|
|
1090
|
+
bindAs3SymbolInstance(this);
|
|
1091
|
+
this.addEventListener('addedToStage', () => main.order.push(['addedToStage', this.name]));
|
|
1092
|
+
this.addFrameScript(0, () => main.order.push(['child', this.name]));
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
class UnitFixture extends MovieClip {
|
|
1096
|
+
constructor() { super(); bindAs3SymbolInstance(this); }
|
|
1097
|
+
}
|
|
1098
|
+
OldPiece.__swoofQualifiedName = 'OldPiece';
|
|
1099
|
+
NewPiece.__swoofQualifiedName = 'NewPiece';
|
|
1100
|
+
UnitFixture.__swoofQualifiedName = 'UnitFixture';
|
|
1101
|
+
function resolveLinkedClass(name) {
|
|
1102
|
+
if (name === 'OldPiece') return OldPiece;
|
|
1103
|
+
if (name === 'NewPiece') return NewPiece;
|
|
1104
|
+
if (name === 'UnitFixture') return UnitFixture;
|
|
1105
|
+
}
|
|
1106
|
+
`,
|
|
1107
|
+
);
|
|
1108
|
+
timeline.enter();
|
|
1109
|
+
const unit = main.unit;
|
|
1110
|
+
main.order.length = 0;
|
|
1111
|
+
unit.addEventListener('removed', event => {
|
|
1112
|
+
if (event.target !== unit) main.order.push(['removed', event.target.name]);
|
|
1113
|
+
});
|
|
1114
|
+
unit.addEventListener('added', event => {
|
|
1115
|
+
if (event.target !== unit) main.order.push(['added', event.target.name]);
|
|
1116
|
+
});
|
|
1117
|
+
unit.addFrameScript(1, function () {
|
|
1118
|
+
main.order.push(['script', this.getChildByName('low'), this.getChildByName('next').name, this.getChildByName('later').name]);
|
|
1119
|
+
});
|
|
1120
|
+
unit.gotoAndStop(2);
|
|
1121
|
+
expect(main.order).toEqual([
|
|
1122
|
+
['removed', 'low'], ['removedFromStage', 'low'],
|
|
1123
|
+
['added', 'next'], ['addedToStage', 'next'],
|
|
1124
|
+
['removed', 'high'], ['removedFromStage', 'high'],
|
|
1125
|
+
['added', 'later'], ['addedToStage', 'later'],
|
|
1126
|
+
['script', null, 'next', 'later'],
|
|
1127
|
+
['child', 'next'], ['child', 'later'],
|
|
1128
|
+
]);
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
it('runs a root frame script before the scripts of sprites placed on that frame', () => {
|
|
1132
|
+
const characters = { 7: { type: 'sprite', frames: [{}] } };
|
|
1133
|
+
const { main, timeline } = makeTimeline(
|
|
1134
|
+
[{ places: [{ depth: 1, characterId: 7, name: 'unit' }] }],
|
|
1135
|
+
characters,
|
|
1136
|
+
`
|
|
1137
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'UnitFixture' }];
|
|
1138
|
+
main.order = [];
|
|
1139
|
+
class UnitFixture extends MovieClip {
|
|
1140
|
+
constructor() {
|
|
1141
|
+
super();
|
|
1142
|
+
bindAs3SymbolInstance(this);
|
|
1143
|
+
this.ready = false;
|
|
1144
|
+
this.addFrameScript(0, function () {
|
|
1145
|
+
this.ready = true;
|
|
1146
|
+
main.order.push('child');
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
UnitFixture.__swoofQualifiedName = 'UnitFixture';
|
|
1151
|
+
function resolveLinkedClass(name) {
|
|
1152
|
+
if (name === 'UnitFixture') return UnitFixture;
|
|
1153
|
+
}
|
|
1154
|
+
main.addFrameScript(0, function () {
|
|
1155
|
+
main.order.push(['root', this.unit.ready]);
|
|
1156
|
+
});
|
|
1157
|
+
`,
|
|
1158
|
+
);
|
|
1159
|
+
timeline.enter();
|
|
1160
|
+
expect(main.order).toEqual([['root', false], 'child']);
|
|
1161
|
+
expect(main.unit.ready).toBe(true);
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1164
|
+
it('broadcasts frameConstructed through a sprite and its children before either frame script', () => {
|
|
1165
|
+
const characters = {
|
|
1166
|
+
7: { type: 'sprite', frames: [{}, { places: [{ depth: 1, characterId: 8, name: 'nested' }] }] },
|
|
1167
|
+
8: { type: 'sprite', frames: [{}] },
|
|
1168
|
+
};
|
|
1169
|
+
const { main, timeline } = makeTimeline(
|
|
1170
|
+
[{ places: [{ depth: 1, characterId: 7, name: 'unit' }] }],
|
|
1171
|
+
characters,
|
|
1172
|
+
`
|
|
1173
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'UnitFixture' }, { id: 8, name: 'NestedFixture' }];
|
|
1174
|
+
main.order = [];
|
|
1175
|
+
class NestedFixture extends MovieClip {
|
|
1176
|
+
constructor() {
|
|
1177
|
+
super();
|
|
1178
|
+
bindAs3SymbolInstance(this);
|
|
1179
|
+
this.addEventListener('frameConstructed', () => main.order.push('child-constructed'));
|
|
1180
|
+
this.addFrameScript(0, () => main.order.push('child-script'));
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
class UnitFixture extends MovieClip {
|
|
1184
|
+
constructor() { super(); bindAs3SymbolInstance(this); }
|
|
1185
|
+
}
|
|
1186
|
+
NestedFixture.__swoofQualifiedName = 'NestedFixture';
|
|
1187
|
+
UnitFixture.__swoofQualifiedName = 'UnitFixture';
|
|
1188
|
+
function resolveLinkedClass(name) {
|
|
1189
|
+
if (name === 'NestedFixture') return NestedFixture;
|
|
1190
|
+
if (name === 'UnitFixture') return UnitFixture;
|
|
1191
|
+
}
|
|
1192
|
+
`,
|
|
1193
|
+
);
|
|
1194
|
+
timeline.enter();
|
|
1195
|
+
const unit = main.unit;
|
|
1196
|
+
unit.addEventListener('frameConstructed', () => main.order.push('parent-constructed'));
|
|
1197
|
+
unit.addFrameScript(1, () => main.order.push('parent-script'));
|
|
1198
|
+
unit.gotoAndStop(2);
|
|
1199
|
+
expect(main.order).toEqual(['parent-constructed', 'child-constructed', 'parent-script', 'child-script']);
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
it('lands a sprite seek on the destination frame without running the frames it skips', () => {
|
|
1203
|
+
const characters = { 7: { type: 'sprite', frames: [{}, {}, {}, {}] } };
|
|
1204
|
+
const { main, timeline } = makeTimeline(
|
|
1205
|
+
[{ places: [{ depth: 1, characterId: 7, name: 'unit' }] }],
|
|
1206
|
+
characters,
|
|
1207
|
+
`
|
|
1208
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'UnitFixture' }];
|
|
1209
|
+
class UnitFixture extends MovieClip {
|
|
1210
|
+
constructor() {
|
|
1211
|
+
super();
|
|
1212
|
+
bindAs3SymbolInstance(this);
|
|
1213
|
+
this.visits = [];
|
|
1214
|
+
this.addFrameScript(
|
|
1215
|
+
0, () => this.visits.push(1),
|
|
1216
|
+
1, () => this.visits.push(2),
|
|
1217
|
+
2, () => this.visits.push(3),
|
|
1218
|
+
3, () => this.visits.push(4),
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
UnitFixture.__swoofQualifiedName = 'UnitFixture';
|
|
1223
|
+
function resolveLinkedClass(name) {
|
|
1224
|
+
if (name === 'UnitFixture') return UnitFixture;
|
|
1225
|
+
}
|
|
1226
|
+
`,
|
|
1227
|
+
);
|
|
1228
|
+
timeline.enter();
|
|
1229
|
+
const unit = main.unit;
|
|
1230
|
+
expect(unit.visits).toEqual([1]);
|
|
1231
|
+
unit.gotoAndStop(4);
|
|
1232
|
+
expect(unit.visits).toEqual([1, 4]);
|
|
1233
|
+
expect(unit.currentFrame).toBe(4);
|
|
1234
|
+
unit.gotoAndStop(4);
|
|
1235
|
+
expect(unit.visits).toEqual([1, 4]);
|
|
1236
|
+
unit.gotoAndStop(2);
|
|
1237
|
+
expect(unit.visits).toEqual([1, 4, 2]);
|
|
1238
|
+
unit.gotoAndStop('missing');
|
|
1239
|
+
expect(unit.currentFrame).toBe(2);
|
|
1240
|
+
expect(unit.visits).toEqual([1, 4, 2]);
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
it('routes AS3 frame stepping and same-frame stops through the root playhead', () => {
|
|
1244
|
+
const { main, timeline } = makeTimeline();
|
|
1245
|
+
const visits = [];
|
|
1246
|
+
main.addFrameScript(3, () => visits.push('start'), 4, () => visits.push('step'));
|
|
1247
|
+
timeline.enter();
|
|
1248
|
+
main.nextScene();
|
|
1249
|
+
main.gotoAndStop(1);
|
|
1250
|
+
main.nextFrame();
|
|
1251
|
+
expect(main.currentFrame).toBe(2);
|
|
1252
|
+
expect(timeline.frame).toBe(4);
|
|
1253
|
+
main.prevFrame();
|
|
1254
|
+
expect(timeline.frame).toBe(3);
|
|
1255
|
+
expect(visits).toEqual(['start', 'step', 'start']);
|
|
1256
|
+
});
|
|
1257
|
+
|
|
1258
|
+
it('runs newly registered frame-zero sprite actions after placements are primed', () => {
|
|
1259
|
+
const sprite = { type: 'sprite', frames: [{}] };
|
|
1260
|
+
const firstFrame = { places: [{ depth: 1, characterId: 7 }] };
|
|
1261
|
+
const { timeline, SPRITE_FRAME_SCRIPTS } = makeTimeline([firstFrame, ...frames.slice(1)], { 7: sprite });
|
|
1262
|
+
let boots = 0;
|
|
1263
|
+
SPRITE_FRAME_SCRIPTS[7] = [[() => { boots++; }]];
|
|
1264
|
+
timeline.enter();
|
|
1265
|
+
timeline.tick();
|
|
1266
|
+
expect(boots).toBe(1);
|
|
1267
|
+
});
|
|
1268
|
+
|
|
1269
|
+
it('binds linked sprites before their constructor code and exposes later authored children', () => {
|
|
1270
|
+
const rootFrame = { places: [{
|
|
1271
|
+
depth: 1, characterId: 7, name: 'preloader',
|
|
1272
|
+
matrix: { a: 0.5, b: 0, c: 0, d: -0.5, tx: 20, ty: 40 },
|
|
1273
|
+
}] };
|
|
1274
|
+
const characters = {
|
|
1275
|
+
7: { type: 'sprite', frames: [
|
|
1276
|
+
{ places: [{ depth: 1, characterId: 8, name: 'mask' }] },
|
|
1277
|
+
{ label: 'finish', places: [{ depth: 2, characterId: 8, name: 'start' }] },
|
|
1278
|
+
] },
|
|
1279
|
+
8: { type: 'sprite', frames: [{}] },
|
|
1280
|
+
};
|
|
1281
|
+
const { main, timeline } = makeTimeline([rootFrame, ...frames.slice(1)], characters, `
|
|
1282
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'FixturePreloader' }];
|
|
1283
|
+
class FixturePreloader extends MovieClip {
|
|
1284
|
+
constructor() {
|
|
1285
|
+
super();
|
|
1286
|
+
bindAs3SymbolInstance(this);
|
|
1287
|
+
this.constructedWithStage = !!this.stage;
|
|
1288
|
+
this.constructedWithMask = !!this.getChildByName('mask');
|
|
1289
|
+
this.addFrameScript(1, function () {
|
|
1290
|
+
this.enteredFinishWithStart = !!this.getChildByName('start');
|
|
1291
|
+
});
|
|
1292
|
+
super.stop();
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
FixturePreloader.__swoofQualifiedName = 'FixturePreloader';
|
|
1296
|
+
function resolveLinkedClass(name) {
|
|
1297
|
+
if (name === 'FixturePreloader') return FixturePreloader;
|
|
1298
|
+
}
|
|
1299
|
+
`);
|
|
1300
|
+
timeline.enter();
|
|
1301
|
+
const preloader = main.getChildByName('preloader');
|
|
1302
|
+
expect(preloader.constructedWithStage).toBe(true);
|
|
1303
|
+
expect(preloader.constructedWithMask).toBe(true);
|
|
1304
|
+
expect([preloader.scaleX, preloader.scaleY]).toEqual([0.5, 0.5]);
|
|
1305
|
+
expect(preloader.transform.matrix.d).toBe(-0.5);
|
|
1306
|
+
timeline.tick();
|
|
1307
|
+
expect(preloader.currentFrame).toBe(1);
|
|
1308
|
+
preloader.nextFrame();
|
|
1309
|
+
expect(preloader.currentFrameLabel).toBe('finish');
|
|
1310
|
+
expect(preloader.enteredFinishWithStart).toBe(true);
|
|
1311
|
+
});
|
|
1312
|
+
|
|
1313
|
+
it('supplies timeline names to AS3 constructors and preserves scripted names across moves', () => {
|
|
1314
|
+
const move = { depth: 1, move: true, matrix: { a: 1, b: 0, c: 0, d: 1, tx: 40, ty: 0 } };
|
|
1315
|
+
const replacementName = { depth: 1, move: true, name: 'renamed' };
|
|
1316
|
+
const { main, timeline } = makeTimeline([
|
|
1317
|
+
{ places: [{ depth: 1, characterId: 8, name: 'outer_node' }, { depth: 2, characterId: 7, name: 'holder' }] },
|
|
1318
|
+
{ places: [move] },
|
|
1319
|
+
{ places: [replacementName] },
|
|
1320
|
+
{ removes: [1] },
|
|
1321
|
+
], {
|
|
1322
|
+
7: { type: 'sprite', frames: [
|
|
1323
|
+
{ places: [{ depth: 1, characterId: 8, name: 'inner_node' }] },
|
|
1324
|
+
{ places: [move] },
|
|
1325
|
+
{ places: [replacementName] },
|
|
1326
|
+
{ removes: [1] },
|
|
1327
|
+
] },
|
|
1328
|
+
8: { type: 'sprite', frames: [{}] },
|
|
1329
|
+
}, `
|
|
1330
|
+
var SYMBOL_CLASSES = [{ id: 8, name: 'FixtureNode' }];
|
|
1331
|
+
class FixtureNode extends MovieClip {
|
|
1332
|
+
constructor() {
|
|
1333
|
+
super();
|
|
1334
|
+
bindAs3SymbolInstance(this);
|
|
1335
|
+
this.nameAtConstruction = this.name;
|
|
1336
|
+
if (this.name) this.name = 'scripted_' + this.name;
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
FixtureNode.__swoofQualifiedName = 'FixtureNode';
|
|
1340
|
+
function resolveLinkedClass() { return FixtureNode; }
|
|
1341
|
+
main.standalone = new FixtureNode();
|
|
1342
|
+
`);
|
|
1343
|
+
|
|
1344
|
+
timeline.enter();
|
|
1345
|
+
const { outer_node: outer, holder } = main;
|
|
1346
|
+
const inner = holder.inner_node;
|
|
1347
|
+
expect([outer.nameAtConstruction, inner.nameAtConstruction]).toEqual(['outer_node', 'inner_node']);
|
|
1348
|
+
expect([outer.name, inner.name]).toEqual(['scripted_outer_node', 'scripted_inner_node']);
|
|
1349
|
+
expect(main.standalone.nameAtConstruction).toBe('');
|
|
1350
|
+
|
|
1351
|
+
outer.name = 'later_outer';
|
|
1352
|
+
inner.name = 'later_inner';
|
|
1353
|
+
const seek = frame => {
|
|
1354
|
+
timeline.gotoAndStop(frame);
|
|
1355
|
+
holder.gotoAndStop(frame);
|
|
1356
|
+
};
|
|
1357
|
+
seek(2);
|
|
1358
|
+
expect([outer.name, inner.name]).toEqual(['later_outer', 'later_inner']);
|
|
1359
|
+
expect([outer.x, inner.x]).toEqual([2, 2]);
|
|
1360
|
+
seek(3);
|
|
1361
|
+
expect([main.renamed, holder.renamed]).toEqual([outer, inner]);
|
|
1362
|
+
expect([main.outer_node, holder.inner_node]).toEqual([null, null]);
|
|
1363
|
+
outer.name = 'retired_outer';
|
|
1364
|
+
inner.name = 'retired_inner';
|
|
1365
|
+
seek(4);
|
|
1366
|
+
expect([main.renamed, holder.renamed]).toEqual([null, null]);
|
|
1367
|
+
expect([outer.parent, inner.parent]).toEqual([null, null]);
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1370
|
+
it('binds the nearest AS3 symbol across an unlinked subclass constructor chain', () => {
|
|
1371
|
+
const spriteWithChild = name => ({
|
|
1372
|
+
type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 10, name }] }],
|
|
1373
|
+
});
|
|
1374
|
+
const { main } = makeTimeline([{}], {
|
|
1375
|
+
7: spriteWithChild('baseChild'),
|
|
1376
|
+
8: spriteWithChild('nearestChild'),
|
|
1377
|
+
9: spriteWithChild('explicitChild'),
|
|
1378
|
+
10: { type: 'sprite', frames: [{}] },
|
|
1379
|
+
}, `
|
|
1380
|
+
var SYMBOL_CLASSES = [
|
|
1381
|
+
{ id: 7, name: 'FixtureBase' },
|
|
1382
|
+
{ id: 8, name: 'FixtureMiddle' },
|
|
1383
|
+
{ id: 9, name: 'FixtureExplicit' },
|
|
1384
|
+
];
|
|
1385
|
+
class FixtureBase extends MovieClip {
|
|
1386
|
+
constructor() {
|
|
1387
|
+
super();
|
|
1388
|
+
bindAs3SymbolInstance(this);
|
|
1389
|
+
this.visits = [['base', this.getChildAt(0)]];
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
class FixtureMiddle extends FixtureBase {
|
|
1393
|
+
constructor() {
|
|
1394
|
+
super();
|
|
1395
|
+
bindAs3SymbolInstance(this);
|
|
1396
|
+
this.visits.push(['middle', this.getChildAt(0)]);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
class FixtureLeaf extends FixtureMiddle {
|
|
1400
|
+
constructor() {
|
|
1401
|
+
super();
|
|
1402
|
+
bindAs3SymbolInstance(this);
|
|
1403
|
+
this.visits.push(['leaf', this.getChildAt(0)]);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
class FixtureExplicit extends FixtureLeaf {
|
|
1407
|
+
constructor() {
|
|
1408
|
+
super();
|
|
1409
|
+
bindAs3SymbolInstance(this);
|
|
1410
|
+
this.visits.push(['explicit', this.getChildAt(0)]);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
for (const type of [FixtureBase, FixtureMiddle, FixtureLeaf, FixtureExplicit]) {
|
|
1414
|
+
type.__swoofQualifiedName = type.name;
|
|
1415
|
+
}
|
|
1416
|
+
main.inherited = new FixtureLeaf();
|
|
1417
|
+
main.explicit = new FixtureExplicit();
|
|
1418
|
+
`);
|
|
1419
|
+
const { inherited, explicit } = main;
|
|
1420
|
+
expect(inherited.constructor.name).toBe('FixtureLeaf');
|
|
1421
|
+
expect(inherited._swoofCharacterId).toBe(8);
|
|
1422
|
+
expect(inherited.numChildren).toBe(1);
|
|
1423
|
+
expect(inherited.visits).toEqual(['base', 'middle', 'leaf'].map(name => [name, inherited.nearestChild]));
|
|
1424
|
+
expect(explicit.constructor.name).toBe('FixtureExplicit');
|
|
1425
|
+
expect(explicit._swoofCharacterId).toBe(9);
|
|
1426
|
+
expect(explicit.numChildren).toBe(1);
|
|
1427
|
+
expect(explicit.visits).toEqual(['base', 'middle', 'leaf', 'explicit'].map(name => [name, explicit.explicitChild]));
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
it('reports the transformed dimensions of the Strike Force Heroes 3 arena box', async () => {
|
|
1431
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/strike-force-heroes-3.swf'));
|
|
1432
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1433
|
+
const boxPlace = symbolTable.get(3128).tags
|
|
1434
|
+
.map(tag => decodeTag(tag, diagnostics))
|
|
1435
|
+
.find(tag => tag?.name === 'box');
|
|
1436
|
+
expect(boxPlace.characterId).toBe(2038);
|
|
1437
|
+
const selected = new SymbolTable();
|
|
1438
|
+
for (const id of [26, 2038]) selected.set(id, symbolTable.get(id));
|
|
1439
|
+
const { characters } = buildDisplayList([], selected, diagnostics);
|
|
1440
|
+
const wall = 3128;
|
|
1441
|
+
characters[wall] = { type: 'sprite', frames: [{ places: [boxPlace] }] };
|
|
1442
|
+
const { main, timeline } = makeTimeline([
|
|
1443
|
+
{ places: [{ depth: 1, characterId: wall, name: 'wallMC' }] },
|
|
1444
|
+
], characters, `
|
|
1445
|
+
main.collisionBitmap = function () {
|
|
1446
|
+
return new BitmapData(this.wallMC.box.width, this.wallMC.box.height, true, 0);
|
|
1447
|
+
};
|
|
1448
|
+
main.programmatic = new MovieClip();
|
|
1449
|
+
main.programmatic.width = 50;
|
|
1450
|
+
main.programmatic.height = 60;
|
|
1451
|
+
`);
|
|
1452
|
+
timeline.enter();
|
|
1453
|
+
const { wallMC, programmatic } = main;
|
|
1454
|
+
const box = wallMC.box;
|
|
1455
|
+
const bounds = box.getBounds(wallMC);
|
|
1456
|
+
expect([box.width, box.height]).toEqual([bounds.width, bounds.height]);
|
|
1457
|
+
const bitmap = main.collisionBitmap();
|
|
1458
|
+
expect([bitmap.width, bitmap.height]).toEqual([2872, 1148]);
|
|
1459
|
+
|
|
1460
|
+
box.width = 200;
|
|
1461
|
+
box.height = 50;
|
|
1462
|
+
expect(box.getBounds(wallMC).width).toBeCloseTo(200);
|
|
1463
|
+
expect(box.getBounds(wallMC).height).toBeCloseTo(50);
|
|
1464
|
+
expect([programmatic.width, programmatic.height, programmatic.scaleX, programmatic.scaleY]).toEqual([50, 60, 1, 1]);
|
|
1465
|
+
});
|
|
1466
|
+
|
|
1467
|
+
it('reconciles named children on sprite seeks and starts each linked instance at frame one', () => {
|
|
1468
|
+
const button = { depth: 1, characterId: 8, name: 'playButton' };
|
|
1469
|
+
const characters = {
|
|
1470
|
+
7: { type: 'sprite', frames: [
|
|
1471
|
+
{ places: [button] },
|
|
1472
|
+
{ places: [{ depth: 1, move: true, matrix: { a: 1, b: 0, c: 0, d: 1, tx: 400, ty: 0 } }] },
|
|
1473
|
+
{ removes: [1] },
|
|
1474
|
+
{ places: [button] },
|
|
1475
|
+
] },
|
|
1476
|
+
8: { type: 'sprite', frames: [{}] },
|
|
1477
|
+
};
|
|
1478
|
+
const { main, timeline } = makeTimeline([
|
|
1479
|
+
{ places: [{ depth: 1, characterId: 7, name: 'first' }] },
|
|
1480
|
+
{ places: [{ depth: 2, characterId: 7, name: 'second' }] },
|
|
1481
|
+
...frames.slice(2),
|
|
1482
|
+
], characters, `
|
|
1483
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'FixtureMenu' }];
|
|
1484
|
+
class FixtureMenu extends MovieClip {
|
|
1485
|
+
constructor() {
|
|
1486
|
+
super();
|
|
1487
|
+
this.playButton = null;
|
|
1488
|
+
bindAs3SymbolInstance(this);
|
|
1489
|
+
this.addFrameScript(1, function () { this.frameTwoButton = this.playButton; });
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
FixtureMenu.__swoofQualifiedName = 'FixtureMenu';
|
|
1493
|
+
function resolveLinkedClass() { return FixtureMenu; }
|
|
1494
|
+
`);
|
|
1495
|
+
timeline.enter();
|
|
1496
|
+
const first = main.first;
|
|
1497
|
+
const initial = first.playButton;
|
|
1498
|
+
first.gotoAndStop(2);
|
|
1499
|
+
expect(first.frameTwoButton).toBe(initial);
|
|
1500
|
+
expect(first.playButton.x).toBe(20);
|
|
1501
|
+
|
|
1502
|
+
main.gotoAndStop(2);
|
|
1503
|
+
const second = main.second;
|
|
1504
|
+
expect(second.currentFrame).toBe(1);
|
|
1505
|
+
expect(second.playButton).not.toBe(initial);
|
|
1506
|
+
expect(second.playButton.x).toBe(0);
|
|
1507
|
+
expect(first.currentFrame).toBe(2);
|
|
1508
|
+
timeline.tick();
|
|
1509
|
+
expect(second.currentFrame).toBe(2);
|
|
1510
|
+
expect(second.frameTwoButton).toBe(second.playButton);
|
|
1511
|
+
|
|
1512
|
+
first.gotoAndStop(4); // The timeline removed and recreated the same character and name.
|
|
1513
|
+
expect(first.playButton).not.toBe(initial);
|
|
1514
|
+
expect(initial.parent).toBeNull();
|
|
1515
|
+
first.gotoAndStop(3);
|
|
1516
|
+
expect(first.playButton).toBeNull();
|
|
1517
|
+
first.gotoAndStop(2); // The button must be reconstructed even though frame two is move-only.
|
|
1518
|
+
expect(first.frameTwoButton).toBe(first.playButton);
|
|
1519
|
+
expect(first.playButton.x).toBe(20);
|
|
1520
|
+
expect(second.playButton.parent).toBe(second);
|
|
1521
|
+
});
|
|
1522
|
+
|
|
1523
|
+
it('constructs and runs a linked sprite’s seek destination while the sprite is off stage', () => {
|
|
1524
|
+
const characters = {
|
|
1525
|
+
7: { type: 'sprite', frames: [
|
|
1526
|
+
{ label: 'intro', places: [{ depth: 1, characterId: 8, name: 'introClip' }] },
|
|
1527
|
+
{ label: 'local', removes: [1], places: [{ depth: 1, characterId: 8, name: 'localPanel' }] },
|
|
1528
|
+
] },
|
|
1529
|
+
8: { type: 'sprite', frames: [{}] },
|
|
1530
|
+
};
|
|
1531
|
+
const { main, timeline } = makeTimeline([{}], characters, `
|
|
1532
|
+
var SYMBOL_CLASSES = [{ id: 7, name: 'FixturePanel' }];
|
|
1533
|
+
class FixturePanel extends MovieClip {
|
|
1534
|
+
constructor() {
|
|
1535
|
+
super();
|
|
1536
|
+
this.localPanel = null;
|
|
1537
|
+
bindAs3SymbolInstance(this);
|
|
1538
|
+
this.addFrameScript(1, function () {
|
|
1539
|
+
this.enteredPanel = this.localPanel;
|
|
1540
|
+
this.entries = (this.entries || 0) + 1;
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
FixturePanel.__swoofQualifiedName = 'FixturePanel';
|
|
1545
|
+
var holder = main.testHolder = new Sprite();
|
|
1546
|
+
holder.addChild(new FixturePanel());
|
|
1547
|
+
`);
|
|
1548
|
+
const holder = main.testHolder;
|
|
1549
|
+
const clip = holder.getChildAt(0);
|
|
1550
|
+
const intro = clip.introClip;
|
|
1551
|
+
clip.gotoAndStop('local');
|
|
1552
|
+
const panel = clip.localPanel;
|
|
1553
|
+
expect(clip.stage).toBeNull();
|
|
1554
|
+
expect(clip.currentFrameLabel).toBe('local');
|
|
1555
|
+
expect(panel?.parent).toBe(clip);
|
|
1556
|
+
expect(clip.getChildByName('localPanel')).toBe(panel);
|
|
1557
|
+
expect(intro.parent).toBeNull();
|
|
1558
|
+
expect(clip.enteredPanel).toBe(panel);
|
|
1559
|
+
expect(clip.entries).toBe(1);
|
|
1560
|
+
clip.gotoAndStop('local');
|
|
1561
|
+
expect(clip.entries).toBe(1);
|
|
1562
|
+
|
|
1563
|
+
main.addChild(holder);
|
|
1564
|
+
timeline.enter();
|
|
1565
|
+
timeline.tick();
|
|
1566
|
+
expect(clip.enteredPanel).toBe(panel);
|
|
1567
|
+
expect(clip.entries).toBe(1);
|
|
1568
|
+
|
|
1569
|
+
main.removeChild(holder);
|
|
1570
|
+
clip.gotoAndStop('intro');
|
|
1571
|
+
expect(clip.localPanel).toBeNull();
|
|
1572
|
+
clip.gotoAndStop('local');
|
|
1573
|
+
expect(clip.localPanel?.parent).toBe(clip);
|
|
1574
|
+
expect(clip.localPanel).not.toBe(panel);
|
|
1575
|
+
expect(clip.enteredPanel).toBe(clip.localPanel);
|
|
1576
|
+
expect(clip.entries).toBe(2);
|
|
1577
|
+
main.addChild(holder);
|
|
1578
|
+
timeline.tick();
|
|
1579
|
+
expect(clip.enteredPanel).toBe(clip.localPanel);
|
|
1580
|
+
expect(clip.entries).toBe(2);
|
|
1581
|
+
});
|
|
1582
|
+
|
|
1583
|
+
it('rebinds AS3 root and nested names without detaching the placed objects', () => {
|
|
1584
|
+
const child = { depth: 1, characterId: 8, name: 'original' };
|
|
1585
|
+
const rename = { depth: 1, move: true, name: 'renamed' };
|
|
1586
|
+
const clear = { depth: 1, move: true, name: '' };
|
|
1587
|
+
const { main, timeline } = makeTimeline([
|
|
1588
|
+
{ places: [child, { depth: 2, characterId: 7, name: 'holder' }] },
|
|
1589
|
+
{ places: [rename] },
|
|
1590
|
+
{ places: [clear] },
|
|
1591
|
+
], {
|
|
1592
|
+
7: { type: 'sprite', frames: [{ places: [child] }, { places: [rename] }, { places: [clear] }] },
|
|
1593
|
+
8: { type: 'sprite', frames: [{}] },
|
|
1594
|
+
});
|
|
1595
|
+
timeline.enter();
|
|
1596
|
+
const { holder, original: outer } = main;
|
|
1597
|
+
const inner = holder.original;
|
|
1598
|
+
|
|
1599
|
+
timeline.gotoAndStop(2);
|
|
1600
|
+
holder.gotoAndStop(2);
|
|
1601
|
+
expect(main.renamed).toBe(outer);
|
|
1602
|
+
expect(holder.renamed).toBe(inner);
|
|
1603
|
+
expect(main.getChildByName('renamed')).toBe(outer);
|
|
1604
|
+
expect(holder.getChildByName('renamed')).toBe(inner);
|
|
1605
|
+
expect([main.original, holder.original]).toEqual([null, null]);
|
|
1606
|
+
|
|
1607
|
+
timeline.gotoAndStop(3);
|
|
1608
|
+
holder.gotoAndStop(3);
|
|
1609
|
+
expect([outer.name, inner.name]).toEqual(['', '']);
|
|
1610
|
+
expect([main.renamed, holder.renamed]).toEqual([null, null]);
|
|
1611
|
+
expect(outer.parent).toBe(main);
|
|
1612
|
+
expect(inner.parent).toBe(holder);
|
|
1613
|
+
});
|
|
1614
|
+
|
|
1615
|
+
it('exposes the authored visual bounds and hit state of a named AS3 timeline button', () => {
|
|
1616
|
+
const matrix = (x, y) => ({ a: 1, b: 0, c: 0, d: 1, tx: x * 20, ty: y * 20 });
|
|
1617
|
+
const { main, timeline } = makeTimeline([
|
|
1618
|
+
{ places: [{ depth: 1, characterId: 2, name: 'button', matrix: matrix(5, 4) }] },
|
|
1619
|
+
], {
|
|
1620
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 10, h: 10 }, draws: [{
|
|
1621
|
+
fill: { type: 'solid' },
|
|
1622
|
+
path: [['M', 0, 0], ['L', 10, 0], ['L', 0, 10], ['Z']],
|
|
1623
|
+
}] },
|
|
1624
|
+
2: { type: 'button', buttonStates: { up: [{ characterId: 1, matrix: matrix(0, 0) }] },
|
|
1625
|
+
buttonHitStates: [{ characterId: 1, matrix: matrix(40, 0) }] },
|
|
1626
|
+
});
|
|
1627
|
+
timeline.enter();
|
|
1628
|
+
const { button } = main;
|
|
1629
|
+
const bounds = button.getBounds(main);
|
|
1630
|
+
expect([bounds.x, bounds.y, bounds.width, bounds.height]).toEqual([5, 4, 10, 10]);
|
|
1631
|
+
expect(button.hitTestPoint(46, 5)).toBe(true);
|
|
1632
|
+
expect(button.hitTestPoint(46, 5, true)).toBe(true);
|
|
1633
|
+
expect(button.hitTestPoint(54, 13)).toBe(true);
|
|
1634
|
+
expect(button.hitTestPoint(54, 13, true)).toBe(false);
|
|
1635
|
+
expect(button.hitTestPoint(7, 5)).toBe(false);
|
|
1636
|
+
});
|
|
1637
|
+
|
|
1638
|
+
it.each(['AS3', 'AVM1'])('hides and reveals root and nested %s placements without replacing them', mode => {
|
|
1639
|
+
const show = { type: 'ShowFrame' };
|
|
1640
|
+
const place = (depth, characterId, name, visible) => ({ type: 'PlaceObject3', depth, characterId, name, visible });
|
|
1641
|
+
const move = visible => ({ type: 'PlaceObject3', depth: 1, move: true, visible });
|
|
1642
|
+
const visibilityFrames = (name, siblings = []) => buildFramesFromTags([
|
|
1643
|
+
place(1, 8, name), ...siblings, show,
|
|
1644
|
+
move(false), show,
|
|
1645
|
+
move(), show,
|
|
1646
|
+
move(true), show,
|
|
1647
|
+
]);
|
|
1648
|
+
const characters = {
|
|
1649
|
+
7: { type: 'sprite', frames: visibilityFrames('inner') },
|
|
1650
|
+
8: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 9 }] }, {}] },
|
|
1651
|
+
9: { type: 'shape', draws: [{ fill: { type: 'solid' },
|
|
1652
|
+
path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']] }] },
|
|
1653
|
+
};
|
|
1654
|
+
const fixtureFrames = visibilityFrames('outer', [
|
|
1655
|
+
place(2, 7, 'holder'), place(3, 8, 'initiallyHidden', false), place(4, 9, undefined, false),
|
|
1656
|
+
]);
|
|
1657
|
+
const avm1 = mode === 'AVM1';
|
|
1658
|
+
const fixtureScript = avm1 ? `
|
|
1659
|
+
var __swoof_root = timeline;
|
|
1660
|
+
${AVM1_RUNTIME_STUB}
|
|
1661
|
+
main = root;
|
|
1662
|
+
window.__swoof = { root, timeline };
|
|
1663
|
+
` : '';
|
|
1664
|
+
const { main, timeline, displayList, instanceDrawState } = makeTimeline(fixtureFrames, characters, fixtureScript);
|
|
1665
|
+
timeline.enter();
|
|
1666
|
+
const { outer, holder, initiallyHidden } = main;
|
|
1667
|
+
const inner = holder.inner;
|
|
1668
|
+
expect(initiallyHidden?.parent === main).toBe(true);
|
|
1669
|
+
expect(initiallyHidden.visible).toBe(false);
|
|
1670
|
+
expect(instanceDrawState(displayList[4]).visible).toBe(false);
|
|
1671
|
+
outer.gotoAndStop(2);
|
|
1672
|
+
inner.gotoAndStop(2);
|
|
1673
|
+
outer.scriptState = inner.scriptState = 42;
|
|
1674
|
+
const removed = [];
|
|
1675
|
+
for (const clip of [outer, inner]) {
|
|
1676
|
+
if (avm1) clip.onUnload = () => removed.push(clip);
|
|
1677
|
+
else clip.addEventListener('removed', () => removed.push(clip));
|
|
1678
|
+
}
|
|
1679
|
+
const seek = frame => {
|
|
1680
|
+
timeline.gotoAndStop(frame);
|
|
1681
|
+
holder.gotoAndStop(frame);
|
|
1682
|
+
};
|
|
1683
|
+
const nestedHit = () => hitTestButtonGeometry(characters, 7, null, 4, 4, null, 0, holder);
|
|
1684
|
+
|
|
1685
|
+
seek(2);
|
|
1686
|
+
expect(main.outer).toBe(outer);
|
|
1687
|
+
expect(holder.inner).toBe(inner);
|
|
1688
|
+
expect([outer.visible, inner.visible]).toEqual([false, false]);
|
|
1689
|
+
expect(instanceDrawState(displayList[1]).visible).toBe(false);
|
|
1690
|
+
expect(nestedHit()).toBe(false);
|
|
1691
|
+
|
|
1692
|
+
outer.visible = inner.visible = true;
|
|
1693
|
+
seek(3);
|
|
1694
|
+
expect(instanceDrawState(displayList[1]).visible).toBe(true);
|
|
1695
|
+
expect(nestedHit()).toBe(true);
|
|
1696
|
+
outer.visible = inner.visible = false;
|
|
1697
|
+
seek(4);
|
|
1698
|
+
expect([outer.visible, inner.visible]).toEqual([true, true]);
|
|
1699
|
+
expect([outer.scriptState, inner.scriptState]).toEqual([42, 42]);
|
|
1700
|
+
expect([outer.currentFrame, inner.currentFrame]).toEqual([2, 2]);
|
|
1701
|
+
timeline.tick();
|
|
1702
|
+
expect(removed).toEqual([]);
|
|
1703
|
+
});
|
|
1704
|
+
|
|
1705
|
+
it('stops an alternating frame-script redirect cycle without recursive stack growth', () => {
|
|
1706
|
+
const { timeline, main } = makeTimeline();
|
|
1707
|
+
let visits = 0;
|
|
1708
|
+
main.addFrameScript(0, function () { visits++; this.gotoAndPlay(2); },
|
|
1709
|
+
1, function () { visits++; this.gotoAndPlay(1); });
|
|
1710
|
+
timeline.enter();
|
|
1711
|
+
expect(visits).toBe(100);
|
|
1712
|
+
expect(timeline.playing).toBe(false);
|
|
1713
|
+
});
|
|
1714
|
+
|
|
1715
|
+
it('handles real root timelines without an explicit scene table as one scene', async () => {
|
|
1716
|
+
const bytes = new Uint8Array(readFileSync('archive/Swf/bubble-tanks-2.swf'));
|
|
1717
|
+
const { doc } = await parse(bytes);
|
|
1718
|
+
const { tags, symbolTable } = decode(doc);
|
|
1719
|
+
const displayList = buildDisplayList(tags, symbolTable);
|
|
1720
|
+
expect(displayList.scenes).toHaveLength(1);
|
|
1721
|
+
expect(sceneNavigationFrame(displayList.frames.length - 1, 1, displayList.scenes)).toBe(0);
|
|
1722
|
+
});
|
|
1723
|
+
});
|