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,2002 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { runInNewContext } from 'node:vm';
|
|
3
|
+
import { expect, it } from 'vitest';
|
|
4
|
+
import { decode, decodeTag } from '../decoder/tag-decoder.js';
|
|
5
|
+
import { parse } from '../parser/swf-parser.js';
|
|
6
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
7
|
+
import { TAG } from '../decoder/tag-types.js';
|
|
8
|
+
import { AVM1_RUNTIME_FACTORY_SOURCE, AVM1_RUNTIME_STUB, SWFLIB_SOURCE } from '../runtime/index.js';
|
|
9
|
+
import { transpileActionScript } from '../transpiler/actionscript.js';
|
|
10
|
+
import { OP } from '../transpiler/avm1/avm1-opcodes.js';
|
|
11
|
+
import { buildDisplayList, buildFramesFromTags } from '../transpiler/timeline/display-list.js';
|
|
12
|
+
import { generateTimelineEngine, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
|
|
13
|
+
|
|
14
|
+
function mountAvm1Fixture(displayList, fullJs, frameRate = 24, {
|
|
15
|
+
pointerEvents = true, width = 240, height = 400, viewport,
|
|
16
|
+
} = {}) {
|
|
17
|
+
const engine = generateTimelineEngine(displayList, {
|
|
18
|
+
stageW: width, stageH: height, frameRate, frameCount: displayList.frames.length,
|
|
19
|
+
});
|
|
20
|
+
const handlers = new Map(), windowHandlers = { keydown: [], keyup: [] };
|
|
21
|
+
const canvas = { width, height, style: {}, focus() { document.activeElement = this; }, setPointerCapture() {},
|
|
22
|
+
getBoundingClientRect() {
|
|
23
|
+
return { width: parseFloat(this.style.width) || width, height: parseFloat(this.style.height) || height, left: 0, top: 0 };
|
|
24
|
+
},
|
|
25
|
+
addEventListener(type, handler) {
|
|
26
|
+
const listeners = handlers.get(type) ?? [];
|
|
27
|
+
listeners.push(handler);
|
|
28
|
+
handlers.set(type, listeners);
|
|
29
|
+
} };
|
|
30
|
+
const focusOutlines = [];
|
|
31
|
+
const ctx = new Proxy({ canvas, globalAlpha: 1, measureText: value => ({ width: String(value).length * 6 }),
|
|
32
|
+
strokeRect(...rect) { focusOutlines.push(rect); } },
|
|
33
|
+
{ get: (target, key) => target[key] ?? (() => {}) });
|
|
34
|
+
const stageWrap = viewport ? { style: {} } : null;
|
|
35
|
+
const document = {
|
|
36
|
+
getElementById: id => id === 'stage' ? canvas : id === 'stage-wrap' ? stageWrap : null,
|
|
37
|
+
createElement: () => ({ getContext: () => null }),
|
|
38
|
+
};
|
|
39
|
+
const sandbox = { STAGE_WIDTH: width, STAGE_HEIGHT: height, FRAME_RATE: frameRate,
|
|
40
|
+
BACKGROUND: '#fff', loaded: {}, document, ctx, PointerEvent: pointerEvents ? function () {} : undefined,
|
|
41
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
42
|
+
requestAnimationFrame: () => 1, addEventListener(type, handler) { (windowHandlers[type] ??= []).push(handler); }, console };
|
|
43
|
+
if (viewport) [sandbox.innerWidth, sandbox.innerHeight] = viewport;
|
|
44
|
+
sandbox.window = sandbox;
|
|
45
|
+
const { root, timeline, selection } = runInNewContext(`
|
|
46
|
+
${SWFLIB_SOURCE}
|
|
47
|
+
${engine}
|
|
48
|
+
var __swoof_root = timeline;
|
|
49
|
+
${fullJs}
|
|
50
|
+
window.__swoof = { root, timeline };
|
|
51
|
+
timeline.enter();
|
|
52
|
+
({ root, timeline, selection: Selection });
|
|
53
|
+
`, sandbox);
|
|
54
|
+
|
|
55
|
+
function dispatchKey(type, key, shiftKey = false, keyCode) {
|
|
56
|
+
const event = { target: canvas, key, shiftKey, keyCode, preventDefault() { this.defaultPrevented = true; } };
|
|
57
|
+
for (const listener of windowHandlers[type]) listener(event);
|
|
58
|
+
return event.defaultPrevented;
|
|
59
|
+
}
|
|
60
|
+
const keydown = (key, shiftKey, keyCode) => dispatchKey('keydown', key, shiftKey, keyCode);
|
|
61
|
+
const keyup = key => dispatchKey('keyup', key);
|
|
62
|
+
const resize = (width, height) => {
|
|
63
|
+
[sandbox.innerWidth, sandbox.innerHeight] = [width, height];
|
|
64
|
+
for (const listener of windowHandlers.resize ?? []) listener();
|
|
65
|
+
};
|
|
66
|
+
return { root, timeline, selection, handlers, windowHandlers, canvas, document, ctx, keydown, keyup, focusOutlines, resize };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
it('keeps the authored Line Rider file dialog addressable when it contains a field named name', async () => {
|
|
70
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/linerider1.swf'));
|
|
71
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
72
|
+
const { characters } = buildDisplayList(tags, symbolTable, diagnostics);
|
|
73
|
+
const dialog = characters[240].frames[0].places.find(place => place.name === 'fileDialog');
|
|
74
|
+
const widget = characters[dialog.characterId].frames[0].places.find(place => place.name === 'name');
|
|
75
|
+
const input = characters[widget.characterId].frames[0].places.find(place => place.name === 'label');
|
|
76
|
+
expect([widget.characterId, input.characterId]).toEqual([63, 62]);
|
|
77
|
+
|
|
78
|
+
const push = value => {
|
|
79
|
+
const data = typeof value === 'string' ? [0, ...Buffer.from(value), 0] : [7, value, 0, 0, 0];
|
|
80
|
+
return [OP.Push, data.length, 0, ...data];
|
|
81
|
+
};
|
|
82
|
+
const dialogPath = 'fileDialog';
|
|
83
|
+
const bytecode = Uint8Array.from([
|
|
84
|
+
...push('originalName'), ...push(dialogPath), ...push(13), OP.GetProperty, OP.SetVariable,
|
|
85
|
+
...push(dialogPath), ...push(13), ...push('tracks'), OP.SetProperty,
|
|
86
|
+
...push('field'), ...push('tracks'), OP.GetVariable, ...push('name'), OP.GetMember, OP.SetVariable,
|
|
87
|
+
...push('renamed'), ...push('tracks'), OP.GetVariable, ...push('_name'), OP.GetMember, OP.SetVariable,
|
|
88
|
+
OP.End,
|
|
89
|
+
]);
|
|
90
|
+
const { fullJs } = transpileActionScript([{ type: 'DoAction', bytecode }], diagnostics,
|
|
91
|
+
{ swfVersion: doc.header.version });
|
|
92
|
+
const { root, timeline } = mountAvm1Fixture({
|
|
93
|
+
frames: [{ places: [dialog] }, { removes: [dialog.depth] }],
|
|
94
|
+
characters: {
|
|
95
|
+
[dialog.characterId]: { type: 'sprite', frames: [{ places: [widget] }] },
|
|
96
|
+
[widget.characterId]: { type: 'sprite', frames: [{ places: [input] }] },
|
|
97
|
+
[input.characterId]: characters[input.characterId],
|
|
98
|
+
},
|
|
99
|
+
}, fullJs, doc.header.frameRate);
|
|
100
|
+
|
|
101
|
+
expect(root.originalName).toBe(dialogPath);
|
|
102
|
+
expect(root.fileDialog).toBeUndefined();
|
|
103
|
+
expect(root.tracks._name).toBe('tracks');
|
|
104
|
+
expect(root.renamed).toBe('tracks');
|
|
105
|
+
expect(root.field).toBe(root.tracks.name);
|
|
106
|
+
const label = root.field.label;
|
|
107
|
+
expect(label.type).toBe('input');
|
|
108
|
+
expect(label._target).toBe('/tracks/name/label');
|
|
109
|
+
|
|
110
|
+
timeline.tick();
|
|
111
|
+
expect(root.tracks).toBeUndefined();
|
|
112
|
+
expect(root.field.label).toBeUndefined();
|
|
113
|
+
expect(label._target).toBeUndefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('keeps a nested AVM1 input callback on the original timeline scope and its own clip receiver', () => {
|
|
117
|
+
const name = value => [0, ...Buffer.from(value), 0];
|
|
118
|
+
const push = (...values) => {
|
|
119
|
+
const data = values.flat();
|
|
120
|
+
return [OP.Push, data.length, 0, ...data];
|
|
121
|
+
};
|
|
122
|
+
const read = key => [...push(name(key)), OP.GetVariable];
|
|
123
|
+
const configure = (clip, event, body) => [
|
|
124
|
+
...read(clip), ...push(name(event)),
|
|
125
|
+
OP.DefineFunction, 5, 0, 0, 0, 0, body.length & 255, body.length >> 8, ...body, OP.SetMember,
|
|
126
|
+
];
|
|
127
|
+
const onRelease = [
|
|
128
|
+
...push(name('loadedTrack'), name('layout')), OP.SetVariable,
|
|
129
|
+
...push(name('existingSetting'), [5, 1]), OP.SetVariable,
|
|
130
|
+
...read('this'), ...push(name('receivedRelease'), [5, 1]), OP.SetMember, OP.End,
|
|
131
|
+
];
|
|
132
|
+
const bytecode = Uint8Array.from([
|
|
133
|
+
...configure('opener', 'onPress', [...configure('loader', 'onRelease', onRelease), OP.End]),
|
|
134
|
+
OP.End,
|
|
135
|
+
]);
|
|
136
|
+
const { fullJs } = transpileActionScript([{ type: 'DoAction', bytecode }], undefined, { swfVersion: 8 });
|
|
137
|
+
const shape = { type: 'shape', bounds: { x: 0, y: 0, w: 10, h: 10 }, draws: [{
|
|
138
|
+
fill: { type: 'solid', color: '#fff' }, path: [['M', 0, 0], ['L', 10, 0], ['L', 10, 10], ['L', 0, 10], ['Z']],
|
|
139
|
+
}] };
|
|
140
|
+
const { root, handlers, canvas } = mountAvm1Fixture({
|
|
141
|
+
frames: [{ places: [
|
|
142
|
+
{ name: 'opener', depth: 1, characterId: 2 },
|
|
143
|
+
{ name: 'loader', depth: 2, characterId: 3, matrix: { a: 1, b: 0, c: 0, d: 1, tx: 400, ty: 0 } },
|
|
144
|
+
] }],
|
|
145
|
+
characters: {
|
|
146
|
+
1: shape,
|
|
147
|
+
2: { type: 'button', buttonHitStates: [{ characterId: 1 }] },
|
|
148
|
+
3: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 1 }] }] },
|
|
149
|
+
},
|
|
150
|
+
}, fullJs);
|
|
151
|
+
root.loader.existingSetting = false;
|
|
152
|
+
const click = x => {
|
|
153
|
+
for (const type of ['pointermove', 'pointerdown', 'pointerup']) {
|
|
154
|
+
const event = { target: canvas, pointerId: 1, button: 0, buttons: type === 'pointerdown' ? 1 : 0,
|
|
155
|
+
clientX: x, clientY: 5, preventDefault() {} };
|
|
156
|
+
for (const handler of handlers.get(type) ?? []) handler(event);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
click(5);
|
|
161
|
+
expect(root.loader.onRelease).toBeTypeOf('function');
|
|
162
|
+
click(25);
|
|
163
|
+
expect(root.loadedTrack).toBe('layout');
|
|
164
|
+
expect(root.opener.loadedTrack).toBeUndefined();
|
|
165
|
+
expect(root.loader.loadedTrack).toBeUndefined();
|
|
166
|
+
expect([root.loader.existingSetting, root.loader.receivedRelease]).toEqual([true, true]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('delivers one AVM1 press and release for a primary touch and ignores the compatibility mouse events', () => {
|
|
170
|
+
const { root, handlers, canvas } = mountAvm1Fixture({
|
|
171
|
+
frames: [{ places: [{ name: 'pad', depth: 1, characterId: 1 }] }],
|
|
172
|
+
characters: { 1: { type: 'sprite', frames: [{}], bounds: { x: 0, y: 0, w: 80, h: 40 } } },
|
|
173
|
+
}, AVM1_RUNTIME_STUB);
|
|
174
|
+
const order = [];
|
|
175
|
+
root.pad.onPress = function () { order.push('press'); };
|
|
176
|
+
root.pad.onRelease = function () { order.push('release'); };
|
|
177
|
+
let captured = null;
|
|
178
|
+
canvas.setPointerCapture = id => { captured = id; };
|
|
179
|
+
const send = (type, pointerType) => {
|
|
180
|
+
const event = {
|
|
181
|
+
target: canvas, pointerId: 7, pointerType, button: 0,
|
|
182
|
+
buttons: type.endsWith('down') ? 1 : 0, clientX: 5, clientY: 5, isPrimary: true,
|
|
183
|
+
preventDefault() { this.defaultPrevented = true; },
|
|
184
|
+
};
|
|
185
|
+
for (const handler of handlers.get(type) ?? []) handler(event);
|
|
186
|
+
return event;
|
|
187
|
+
};
|
|
188
|
+
const down = send('pointerdown', 'touch');
|
|
189
|
+
send('mousedown', 'touch');
|
|
190
|
+
send('pointerup', 'touch');
|
|
191
|
+
send('mouseup', 'touch');
|
|
192
|
+
expect(order).toEqual(['press', 'release']);
|
|
193
|
+
expect(captured).toBe(7);
|
|
194
|
+
expect(down.defaultPrevented).toBe(true);
|
|
195
|
+
order.length = 0;
|
|
196
|
+
send('pointerdown', 'mouse');
|
|
197
|
+
send('mousedown', 'mouse');
|
|
198
|
+
send('pointerup', 'mouse');
|
|
199
|
+
send('mouseup', 'mouse');
|
|
200
|
+
expect(order).toEqual(['press', 'release']);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it.each([true, false])('uses the original Minesweeper hit-area artwork with PointerEvent=%s', async pointerEvents => {
|
|
204
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Minesweeper.swf'));
|
|
205
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
206
|
+
const { characters } = buildDisplayList(tags, symbolTable, diagnostics);
|
|
207
|
+
const location = (x, y) => ({ a: 1, b: 0, c: 0, d: 1, tx: x * 20, ty: y * 20 });
|
|
208
|
+
const { root, handlers, canvas } = mountAvm1Fixture({
|
|
209
|
+
frames: [{ places: [
|
|
210
|
+
{ name: 'radio', depth: 1, characterId: 37, matrix: location(10, 10) },
|
|
211
|
+
{ name: 'area', depth: 2, characterId: 2, matrix: location(150, 20) },
|
|
212
|
+
] }],
|
|
213
|
+
characters,
|
|
214
|
+
}, `var SWF_VERSION = ${doc.header.version};\n${AVM1_RUNTIME_STUB}`, doc.header.frameRate, { pointerEvents });
|
|
215
|
+
const releases = [];
|
|
216
|
+
root.radio.onRelease = function () { releases.push(this._name); };
|
|
217
|
+
root.area._visible = false;
|
|
218
|
+
root.area._xscale = 200;
|
|
219
|
+
const click = (x, y) => {
|
|
220
|
+
const types = pointerEvents ? ['pointermove', 'pointerdown', 'pointerup'] : ['mousemove', 'mousedown', 'mouseup'];
|
|
221
|
+
for (const type of types) {
|
|
222
|
+
const event = { target: canvas, pointerId: 1, button: 0, buttons: type.endsWith('down') ? 1 : 0,
|
|
223
|
+
clientX: x, clientY: y, preventDefault() {} };
|
|
224
|
+
for (const handler of handlers.get(type) ?? []) handler(event);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
click(15, 15);
|
|
228
|
+
expect(releases).toEqual(['radio']);
|
|
229
|
+
root.radio.hitArea = root.area;
|
|
230
|
+
click(15, 15);
|
|
231
|
+
expect(releases).toEqual(['radio']);
|
|
232
|
+
click(155, 25);
|
|
233
|
+
expect(releases).toEqual(['radio', 'radio']);
|
|
234
|
+
root.area._x = 175;
|
|
235
|
+
click(155, 25);
|
|
236
|
+
expect(releases).toHaveLength(2);
|
|
237
|
+
click(180, 25);
|
|
238
|
+
expect(releases).toHaveLength(3);
|
|
239
|
+
root.radio.hitArea = null;
|
|
240
|
+
click(15, 15);
|
|
241
|
+
expect(releases).toHaveLength(4);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('selects the original Minesweeper difficulty and keeps the covered board after Play', async () => {
|
|
245
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Minesweeper.swf'));
|
|
246
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
247
|
+
const options = { swfVersion: doc.header.version };
|
|
248
|
+
const { fullJs } = transpileActionScript(tags, diagnostics, options);
|
|
249
|
+
const exports = tags.filter(tag => tag.type === 'ExportAssets').flatMap(tag => tag.assets);
|
|
250
|
+
const displayList = buildDisplayList(tags, symbolTable, diagnostics, options);
|
|
251
|
+
const { root, timeline, handlers, canvas, ctx } = mountAvm1Fixture(
|
|
252
|
+
displayList, `var EXPORT_ASSETS = ${JSON.stringify(exports)};\n${fullJs}
|
|
253
|
+
root.framesLoaded = root.totalFrames = ${displayList.frames.length};`,
|
|
254
|
+
doc.header.frameRate, { width: 500, height: 335 }
|
|
255
|
+
);
|
|
256
|
+
for (let i = 0; i < 20; i++) timeline.tick();
|
|
257
|
+
expect(root._currentframe).toBe(5);
|
|
258
|
+
expect(root.bombs_amount).toBe(70);
|
|
259
|
+
expect(root.level_tough.hitArea?._swoofCharacterId).toBe(2);
|
|
260
|
+
expect(root.level_tough.hitArea._visible).toBe(false);
|
|
261
|
+
const click = (x, y) => {
|
|
262
|
+
for (const type of ['pointermove', 'pointerdown', 'pointerup']) {
|
|
263
|
+
const event = { target: canvas, pointerId: 1, button: 0, buttons: type === 'pointerdown' ? 1 : 0,
|
|
264
|
+
clientX: x, clientY: y, preventDefault() {} };
|
|
265
|
+
for (const handler of handlers.get(type) ?? []) handler(event);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
for (const [y, mines] of [[185, 100], [145, 40]]) {
|
|
269
|
+
click(360, y);
|
|
270
|
+
expect(root.bombs_amount).toBe(mines);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const label = root.level_tough.flabel_mc;
|
|
274
|
+
const field = label.labelField;
|
|
275
|
+
expect(field._swoofCharacterId).toBe(4);
|
|
276
|
+
const previous = field.getTextFormat();
|
|
277
|
+
const style = new previous.constructor('Arial', 24, 0xd83221);
|
|
278
|
+
field.setNewTextFormat(style);
|
|
279
|
+
expect(field.getTextFormat()).toMatchObject({ font: previous.font, size: previous.size, color: previous.color });
|
|
280
|
+
expect(field.getNewTextFormat()).toMatchObject({ font: 'Arial', size: 24, color: 0xd83221 });
|
|
281
|
+
field.getNewTextFormat().size = 6;
|
|
282
|
+
expect(field.getNewTextFormat().size).toBe(24);
|
|
283
|
+
|
|
284
|
+
label.textStyle = style;
|
|
285
|
+
label.setLabel('Hard Puzzle');
|
|
286
|
+
const draws = [];
|
|
287
|
+
ctx.fillText = function (text) { draws.push({ text, font: this.font, color: this.fillStyle }); };
|
|
288
|
+
timeline.render();
|
|
289
|
+
expect(field.text).toBe('Hard Puzzle');
|
|
290
|
+
expect(field.getTextFormat()).toMatchObject({ font: 'Arial', size: 24, color: 0xd83221 });
|
|
291
|
+
expect(draws).toContainEqual({ text: 'Hard Puzzle', font: '24px "Arial"', color: '#d83221' });
|
|
292
|
+
|
|
293
|
+
click(250, 301);
|
|
294
|
+
for (let i = 0; i < 5; i++) timeline.tick(true);
|
|
295
|
+
expect(root._currentframe).toBe(11);
|
|
296
|
+
expect([root.fwidth, root.fheight, root.bombs_left]).toEqual([30, 16, 40]);
|
|
297
|
+
const cells = Object.values(root._swoofChildren);
|
|
298
|
+
expect(cells).toHaveLength(480);
|
|
299
|
+
// Sprite 104's Unknown label is on frame 12, where its authored Stop holds the covered artwork.
|
|
300
|
+
expect(new Set(cells.map(cell => cell._currentframe))).toEqual(new Set([12]));
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('follows the original Riddle Transfer 2 Play Game and Credits buttons', async () => {
|
|
304
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Riddle School - Transfer 2.swf'));
|
|
305
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
306
|
+
const originalFrames = buildFramesFromTags(tags);
|
|
307
|
+
const menu = originalFrames.findIndex(frame => frame.label === 'mainmenu');
|
|
308
|
+
const symbols = new SymbolTable();
|
|
309
|
+
for (const id of [96, 186, 188]) symbols.set(id, symbolTable.get(id));
|
|
310
|
+
const { characters } = buildDisplayList([], symbols, diagnostics, { swfVersion: doc.header.version });
|
|
311
|
+
const frames = originalFrames.map((frame, index) => ({
|
|
312
|
+
label: frame.label,
|
|
313
|
+
removes: frame.removes,
|
|
314
|
+
places: index === menu ? frame.places.filter(place => ['b1', 'b4'].includes(place.name)) : [],
|
|
315
|
+
}));
|
|
316
|
+
const { root, timeline, canvas, handlers } = mountAvm1Fixture({ frames, characters },
|
|
317
|
+
`var SWF_VERSION = ${doc.header.version};\n${AVM1_RUNTIME_STUB}`, doc.header.frameRate,
|
|
318
|
+
{ width: 800, height: 600 });
|
|
319
|
+
const click = (x, y) => {
|
|
320
|
+
for (const type of ['pointermove', 'pointerdown', 'pointerup']) {
|
|
321
|
+
const event = { target: canvas, pointerId: 1, button: 0, buttons: type === 'pointerdown' ? 1 : 0,
|
|
322
|
+
clientX: x, clientY: y, preventDefault() {} };
|
|
323
|
+
for (const handler of handlers.get(type) ?? []) handler(event);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
root.gotoAndStop('mainmenu');
|
|
327
|
+
click(500, 355);
|
|
328
|
+
expect(frames[timeline.frame].label).toBe('menucredz');
|
|
329
|
+
root.gotoAndStop('mainmenu');
|
|
330
|
+
click(500, 205);
|
|
331
|
+
expect(frames[timeline.frame].label).toBe('letthegamesbegin');
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('uses clip-local pointer coordinates and a wrapped angle in Portal Flash’s authored weapon action', async () => {
|
|
335
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Portal Flash.swf'));
|
|
336
|
+
const { tags } = decode(doc, diagnostics);
|
|
337
|
+
const actor = tags.find(tag => tag.type === 'Sprite' && tag.characterId === 972);
|
|
338
|
+
const [weaponTag, weapon] = actor.tags.filter(tag => tag.code === TAG.PlaceObject2)
|
|
339
|
+
.map(tag => [tag, decodeTag(tag, { header: doc.header }, diagnostics)])
|
|
340
|
+
.find(([, placement]) => placement.name === 'wpn');
|
|
341
|
+
expect(weapon.characterId).toBe(811);
|
|
342
|
+
const { fullJs } = transpileActionScript([{ ...actor, tags: [weaponTag] }], diagnostics,
|
|
343
|
+
{ swfVersion: doc.header.version });
|
|
344
|
+
const matrix = { a: 0.8, b: 0.1, c: 0.3, d: 0.9, tx: 2000, ty: 2800 };
|
|
345
|
+
const { root, timeline, handlers, canvas } = mountAvm1Fixture({
|
|
346
|
+
frames: [{ places: [{ depth: 1, name: 'actor', characterId: actor.characterId, matrix }] }],
|
|
347
|
+
characters: {
|
|
348
|
+
[actor.characterId]: { type: 'sprite', frames: [{ places: [weapon] }] },
|
|
349
|
+
[weapon.characterId]: { type: 'sprite', frames: [{}] },
|
|
350
|
+
},
|
|
351
|
+
}, `${fullJs}
|
|
352
|
+
root.pointerSamples = [];
|
|
353
|
+
globals.Math.atan2 = function (y, x) {
|
|
354
|
+
root.pointerSamples.push([x, y]);
|
|
355
|
+
return Math.atan2(y, x);
|
|
356
|
+
};
|
|
357
|
+
`);
|
|
358
|
+
root.running = true;
|
|
359
|
+
const transform = (m, { x, y }) => ({ x: m.a * x + m.c * y + m.tx / 20, y: m.b * x + m.d * y + m.ty / 20 });
|
|
360
|
+
const point = transform(matrix, transform(weapon.matrix, { x: 20, y: 15 }));
|
|
361
|
+
const event = { target: canvas, isPrimary: true, pointerType: 'mouse', pointerId: 1,
|
|
362
|
+
button: 0, buttons: 0, clientX: point.x, clientY: point.y, preventDefault() {} };
|
|
363
|
+
for (const listener of handlers.get('pointermove') ?? []) listener(event);
|
|
364
|
+
expect([root._xmouse, root._ymouse]).toEqual([point.x, point.y]);
|
|
365
|
+
const clip = root.actor.wpn;
|
|
366
|
+
const initialRotation = clip._rotation;
|
|
367
|
+
clip._xmouse = 100;
|
|
368
|
+
clip._ymouse = 200;
|
|
369
|
+
expect(clip._xmouse).toBeCloseTo(20);
|
|
370
|
+
expect(clip._ymouse).toBeCloseTo(15);
|
|
371
|
+
|
|
372
|
+
timeline.tick();
|
|
373
|
+
expect(root.pointerSamples).toHaveLength(1);
|
|
374
|
+
expect(root.pointerSamples[0][0]).toBeCloseTo(20);
|
|
375
|
+
expect(root.pointerSamples[0][1]).toBeCloseTo(15);
|
|
376
|
+
expect(clip._rotation).toBeCloseTo(initialRotation + 14);
|
|
377
|
+
|
|
378
|
+
clip._rotation = 450;
|
|
379
|
+
expect(clip._rotation).toBe(90);
|
|
380
|
+
clip._rotation = -810;
|
|
381
|
+
expect(clip._rotation).toBe(-90);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('clears Riddle School 3’s authored mouse state on outside release or input cancellation', async () => {
|
|
385
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Riddle School 3.swf'));
|
|
386
|
+
const { tags } = decode(doc, diagnostics);
|
|
387
|
+
const authored = tags.find(tag => tag.type === 'DoAction' && Buffer.from(tag.bytecode).includes('mouseIzDown\0'));
|
|
388
|
+
const { fullJs } = transpileActionScript([authored], diagnostics, { swfVersion: doc.header.version });
|
|
389
|
+
const { root, canvas, handlers, windowHandlers } = mountAvm1Fixture(
|
|
390
|
+
{ frames: [{}], characters: {} }, `${fullJs}\nroot.heldMouse = () => globals.Key.isDown(1);`);
|
|
391
|
+
const original = root.onMouseUp;
|
|
392
|
+
let upCount = 0;
|
|
393
|
+
root.onMouseUp = function () { upCount++; original.call(this); };
|
|
394
|
+
const body = {};
|
|
395
|
+
const event = (target, pointerId, buttons, button = 0) => ({ target, isPrimary: true, pointerId,
|
|
396
|
+
pointerType: 'mouse', buttons, button, clientX: target === canvas ? 44 : 249,
|
|
397
|
+
clientY: target === canvas ? 66 : 419, preventDefault() {} });
|
|
398
|
+
const stage = (type, sample) => { for (const listener of handlers.get(type) ?? []) listener(sample); };
|
|
399
|
+
const page = (type, sample) => { for (const listener of windowHandlers[type] ?? []) listener(sample); };
|
|
400
|
+
|
|
401
|
+
stage('pointerdown', event(canvas, 1, 1));
|
|
402
|
+
expect(root.mouseIzDown).toBe(true);
|
|
403
|
+
page('pointerup', event(body, 2, 0));
|
|
404
|
+
expect(root.mouseIzDown).toBe(true);
|
|
405
|
+
page('pointerup', event(body, 1, 0));
|
|
406
|
+
expect([root.mouseIzDown, upCount, root._xmouse, root._ymouse]).toEqual([false, 1, 249, 419]);
|
|
407
|
+
|
|
408
|
+
stage('pointerdown', event(canvas, 1, 1));
|
|
409
|
+
const inside = event(canvas, 1, 0);
|
|
410
|
+
stage('pointerup', inside);
|
|
411
|
+
page('pointerup', inside);
|
|
412
|
+
expect([root.mouseIzDown, upCount]).toEqual([false, 2]);
|
|
413
|
+
|
|
414
|
+
stage('pointerdown', event(canvas, 1, 1));
|
|
415
|
+
page('pointercancel', event(body, 1, 0, -1));
|
|
416
|
+
page('pointerup', event(body, 1, 0));
|
|
417
|
+
expect([root.mouseIzDown, upCount]).toEqual([false, 3]);
|
|
418
|
+
|
|
419
|
+
stage('pointerdown', event(canvas, 17, 1));
|
|
420
|
+
page('blur', {});
|
|
421
|
+
expect([root.mouseIzDown, upCount, root._xmouse, root._ymouse]).toEqual([false, 4, 44, 66]);
|
|
422
|
+
page('blur', {});
|
|
423
|
+
stage('pointerup', event(canvas, 17, 0));
|
|
424
|
+
expect([root.mouseIzDown, upCount]).toEqual([false, 4]);
|
|
425
|
+
stage('pointerdown', event(canvas, 17, 1));
|
|
426
|
+
stage('pointerup', event(canvas, 17, 0));
|
|
427
|
+
expect([root.mouseIzDown, upCount]).toEqual([false, 5]);
|
|
428
|
+
|
|
429
|
+
stage('pointerdown', event(canvas, 21, 1));
|
|
430
|
+
expect(root.heldMouse()).toBe(true);
|
|
431
|
+
stage('lostpointercapture', { ...event(canvas, 22, 0), clientX: 0, clientY: 0 });
|
|
432
|
+
expect([root.mouseIzDown, upCount]).toEqual([true, 5]);
|
|
433
|
+
stage('lostpointercapture', { ...event(canvas, 21, 0), clientX: 0, clientY: 0 });
|
|
434
|
+
expect([root.mouseIzDown, upCount, root._xmouse, root._ymouse]).toEqual([false, 6, 44, 66]);
|
|
435
|
+
expect(root.heldMouse()).toBe(false);
|
|
436
|
+
stage('pointerup', event(canvas, 21, 0));
|
|
437
|
+
expect([root.mouseIzDown, upCount, root._xmouse, root._ymouse]).toEqual([false, 6, 44, 66]);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('honors the Caps Lock state in N’s authored debug tick', async () => {
|
|
441
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/N.swf'));
|
|
442
|
+
const { tags } = decode(doc, diagnostics);
|
|
443
|
+
const authored = tags.find(tag => tag.type === 'DoAction' && Buffer.from(tag.bytecode).includes('App_Tick_RunningGame_Debug\0'));
|
|
444
|
+
const { fullJs } = transpileActionScript([authored], diagnostics, { swfVersion: doc.header.version });
|
|
445
|
+
const { root, canvas, windowHandlers } = mountAvm1Fixture({ frames: [{}], characters: {} }, `${fullJs}\nroot.flashKey = Key;`);
|
|
446
|
+
let mouseSamples = 0;
|
|
447
|
+
root.input = { MousePressed() { mouseSamples++; return false; } };
|
|
448
|
+
const sendKey = (type, locks) => {
|
|
449
|
+
const event = { target: canvas, key: 'a', code: 'KeyA', keyCode: 65,
|
|
450
|
+
getModifierState: name => locks.includes(name), preventDefault() {} };
|
|
451
|
+
for (const listener of windowHandlers[type]) listener(event);
|
|
452
|
+
root.App_Tick_RunningGame_Debug();
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
sendKey('keydown', []);
|
|
456
|
+
expect(mouseSamples).toBe(1);
|
|
457
|
+
sendKey('keydown', ['CapsLock', 'NumLock']);
|
|
458
|
+
expect(mouseSamples).toBe(1);
|
|
459
|
+
expect(root.flashKey.isToggled(root.flashKey.CAPSLOCK)).toBe(true);
|
|
460
|
+
expect(root.flashKey.isToggled(144)).toBe(true);
|
|
461
|
+
expect(root.flashKey.isToggled(65)).toBe(false);
|
|
462
|
+
|
|
463
|
+
sendKey('keyup', ['NumLock']);
|
|
464
|
+
expect(mouseSamples).toBe(2);
|
|
465
|
+
expect(root.flashKey.isToggled(20)).toBe(false);
|
|
466
|
+
expect(root.flashKey.isToggled(144)).toBe(true);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it('broadcasts AVM1 Key events to script listeners once until they are removed', () => {
|
|
470
|
+
const name = value => [0, ...Buffer.from(value), 0];
|
|
471
|
+
const push = (...values) => {
|
|
472
|
+
const data = values.flat();
|
|
473
|
+
return [0x96, data.length, 0, ...data];
|
|
474
|
+
};
|
|
475
|
+
const register = listener => [
|
|
476
|
+
...push(name(listener)), 0x1c, // GetVariable
|
|
477
|
+
...push([7, 1, 0, 0, 0], name('Key')), 0x1c,
|
|
478
|
+
...push(name('addListener')), 0x52, 0x17, // CallMethod, Pop
|
|
479
|
+
];
|
|
480
|
+
const { fullJs } = transpileActionScript([
|
|
481
|
+
{ type: 'DoAction', bytecode: Uint8Array.from([...register('listener'), ...register('listener'), ...register('panel'), 0]) },
|
|
482
|
+
], undefined, { swfVersion: 8 });
|
|
483
|
+
const { root, keydown, keyup } = mountAvm1Fixture({
|
|
484
|
+
frames: [{ places: [{ depth: 1, characterId: 2, name: 'panel' }] }],
|
|
485
|
+
characters: { 2: { type: 'sprite', frames: [{}] } },
|
|
486
|
+
}, `${fullJs}
|
|
487
|
+
FRAME_SCRIPTS[0].unshift(function () {
|
|
488
|
+
root.listener = {
|
|
489
|
+
events: [],
|
|
490
|
+
onKeyDown() { this.events.push(['down', globals.Key.isDown(68), arguments.length]); },
|
|
491
|
+
onKeyUp() { this.events.push(['up', globals.Key.isDown(68), arguments.length]); },
|
|
492
|
+
};
|
|
493
|
+
root.panel.onKeyDown = function () { this.downCount = (this.downCount || 0) + 1; };
|
|
494
|
+
root.unregister = function () { return globals.Key.removeListener(root.listener); };
|
|
495
|
+
});
|
|
496
|
+
`);
|
|
497
|
+
|
|
498
|
+
keydown('d', false, 68);
|
|
499
|
+
keyup('d');
|
|
500
|
+
expect(root.listener.events).toEqual([['down', true, 0], ['up', false, 0]]);
|
|
501
|
+
expect(root.panel.downCount).toBe(1);
|
|
502
|
+
|
|
503
|
+
expect(root.unregister()).toBe(true);
|
|
504
|
+
expect(root.unregister()).toBe(false);
|
|
505
|
+
keydown('d', false, 68);
|
|
506
|
+
keyup('d');
|
|
507
|
+
expect(root.listener.events).toHaveLength(2);
|
|
508
|
+
expect(root.panel.downCount).toBe(2);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
it('delivers AVM1 key events from the parent through siblings from back to front', () => {
|
|
512
|
+
const { root, keydown } = mountAvm1Fixture({
|
|
513
|
+
frames: [{ places: [{ depth: 2, characterId: 2, name: 'authored' }] }],
|
|
514
|
+
characters: { 2: { type: 'sprite', frames: [{}] } },
|
|
515
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
516
|
+
FRAME_SCRIPTS[0] = FRAME_SCRIPTS[0] || [];
|
|
517
|
+
FRAME_SCRIPTS[0].push(function () {
|
|
518
|
+
root.order = [];
|
|
519
|
+
root.onKeyDown = function () { root.order.push('root'); };
|
|
520
|
+
root.authored.onKeyDown = function () { root.order.push('authored'); };
|
|
521
|
+
var back = root.createEmptyMovieClip('back', -3);
|
|
522
|
+
var front = root.createEmptyMovieClip('front', 4);
|
|
523
|
+
back.onKeyDown = function () { root.order.push('back'); };
|
|
524
|
+
front.onKeyDown = function () { root.order.push('front'); };
|
|
525
|
+
});
|
|
526
|
+
`);
|
|
527
|
+
keydown('a', false, 65);
|
|
528
|
+
expect(root.authored.getDepth()).toBe(2 - 16384);
|
|
529
|
+
expect([root.back.getDepth(), root.front.getDepth()]).toEqual([-3, 4]);
|
|
530
|
+
expect(root.order).toEqual(['root', 'authored', 'back', 'front']);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it('runs AVM1 clip key events before listeners and holds new registrations for the next key', () => {
|
|
534
|
+
const { root, keydown } = mountAvm1Fixture({
|
|
535
|
+
frames: [{ places: [{ depth: 1, characterId: 2, name: 'panel' }] }],
|
|
536
|
+
characters: { 2: { type: 'sprite', frames: [{}] } },
|
|
537
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
538
|
+
FRAME_SCRIPTS[0] = FRAME_SCRIPTS[0] || [];
|
|
539
|
+
FRAME_SCRIPTS[0].push(function () {
|
|
540
|
+
root.order = [];
|
|
541
|
+
root.early = { onKeyDown() { root.order.push('early'); globals.Key.removeListener(root.second); globals.Key.addListener(root.nested); } };
|
|
542
|
+
root.second = { onKeyDown() { root.order.push('second'); } };
|
|
543
|
+
root.nested = { onKeyDown() { root.order.push('nested'); } };
|
|
544
|
+
root.late = { onKeyDown() { root.order.push('late'); } };
|
|
545
|
+
root.panel.onKeyDown = function () { root.order.push('clip'); globals.Key.addListener(root.late); };
|
|
546
|
+
globals.Key.addListener(root.early);
|
|
547
|
+
globals.Key.addListener(root.second);
|
|
548
|
+
});
|
|
549
|
+
`);
|
|
550
|
+
keydown('a', false, 65);
|
|
551
|
+
expect(root.order).toEqual(['clip', 'early']);
|
|
552
|
+
root.order.length = 0;
|
|
553
|
+
keydown('b', false, 66);
|
|
554
|
+
expect(root.order).toEqual(['clip', 'early', 'late', 'nested']);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('releases held AVM1 keys once on blur with their own key and character codes', () => {
|
|
558
|
+
const { root, keydown, keyup, windowHandlers } = mountAvm1Fixture(
|
|
559
|
+
{ frames: [{}], characters: {} }, `${AVM1_RUNTIME_STUB}
|
|
560
|
+
root.releases = [];
|
|
561
|
+
globals.Key.addListener({
|
|
562
|
+
onKeyUp() {
|
|
563
|
+
const code = globals.Key.getCode();
|
|
564
|
+
root.releases.push([code, globals.Key.getAscii(), globals.Key.isDown(code)]);
|
|
565
|
+
},
|
|
566
|
+
});
|
|
567
|
+
`);
|
|
568
|
+
const blur = () => { for (const handler of windowHandlers.blur ?? []) handler({}); };
|
|
569
|
+
keydown('a', false, 65);
|
|
570
|
+
keydown('a', false, 65);
|
|
571
|
+
keydown('ArrowDown', false, 40);
|
|
572
|
+
blur();
|
|
573
|
+
expect(root.releases).toEqual([[65, 97, false], [40, 0, false]]);
|
|
574
|
+
|
|
575
|
+
blur();
|
|
576
|
+
keyup('a');
|
|
577
|
+
keyup('ArrowDown');
|
|
578
|
+
expect(root.releases).toHaveLength(2);
|
|
579
|
+
keydown('ArrowDown', false, 40);
|
|
580
|
+
keyup('ArrowDown');
|
|
581
|
+
expect(root.releases.at(-1)).toEqual([40, 0, false]);
|
|
582
|
+
expect(root.releases).toHaveLength(3);
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
it('writes timeline variables from an AVM1 listener while preserving its receiver', () => {
|
|
586
|
+
const name = value => [0, ...Buffer.from(value), 0];
|
|
587
|
+
const push = (...values) => {
|
|
588
|
+
const data = values.flat();
|
|
589
|
+
return [OP.Push, data.length, 0, ...data];
|
|
590
|
+
};
|
|
591
|
+
const set = [5, 1];
|
|
592
|
+
const handler = [
|
|
593
|
+
...push(name('localFlag'), [5, 0]), OP.DefineLocal,
|
|
594
|
+
...push(name('localFlag'), set), OP.SetVariable,
|
|
595
|
+
...push(name('timelineFlag'), set), OP.SetVariable,
|
|
596
|
+
...push(name('presentOnListener'), set), OP.SetVariable,
|
|
597
|
+
...push(name('this')), OP.GetVariable, ...push(name('receiverFlag')), ...push(name('localFlag')), OP.GetVariable, OP.SetMember,
|
|
598
|
+
OP.End,
|
|
599
|
+
];
|
|
600
|
+
const header = [0, 0, 0, handler.length & 255, handler.length >> 8];
|
|
601
|
+
const bytecode = Uint8Array.from([
|
|
602
|
+
...push(name('listener')), OP.GetVariable, ...push(name('onKeyDown')),
|
|
603
|
+
OP.DefineFunction, header.length, 0, ...header, ...handler, OP.SetMember, OP.End,
|
|
604
|
+
]);
|
|
605
|
+
const { fullJs } = transpileActionScript([{ type: 'DoAction', bytecode }], undefined, { swfVersion: 8 });
|
|
606
|
+
const { root, keydown } = mountAvm1Fixture({
|
|
607
|
+
frames: [{ places: [{ depth: 1, characterId: 2, name: 'panel' }] }],
|
|
608
|
+
characters: { 2: { type: 'sprite', frames: [{}] } },
|
|
609
|
+
}, `${fullJs}
|
|
610
|
+
FRAME_SCRIPTS[0].unshift(function () { root.listener = { presentOnListener: false }; });
|
|
611
|
+
FRAME_SCRIPTS[0].push(function () {
|
|
612
|
+
runClipScript(root.panel, function () { globals.Key.addListener(root.listener); });
|
|
613
|
+
});
|
|
614
|
+
`);
|
|
615
|
+
|
|
616
|
+
keydown('d', false, 68);
|
|
617
|
+
expect(root.timelineFlag).toBe(true);
|
|
618
|
+
expect(root.panel.timelineFlag).toBeUndefined();
|
|
619
|
+
expect(root.listener.timelineFlag).toBeUndefined();
|
|
620
|
+
expect(root.listener.presentOnListener).toBe(true);
|
|
621
|
+
expect(root.listener.receiverFlag).toBe(true);
|
|
622
|
+
expect(root.localFlag).toBeUndefined();
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
it('changes the timeline level from Tetris’s authored difficulty button', async () => {
|
|
626
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Tetris.swf'));
|
|
627
|
+
const { tags } = decode(doc, diagnostics);
|
|
628
|
+
const settings = tags.find(tag => tag.type === 'DoAction' && Buffer.from(tag.bytecode).includes('checkButtons\0'));
|
|
629
|
+
const { fullJs } = transpileActionScript([settings], diagnostics, { swfVersion: doc.header.version });
|
|
630
|
+
const { root, canvas, handlers } = mountAvm1Fixture({
|
|
631
|
+
frames: [{ places: [
|
|
632
|
+
{ depth: 1, characterId: 2, name: 'up_btn' },
|
|
633
|
+
{ depth: 2, characterId: 2, name: 'down_btn', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 600, ty: 0 } },
|
|
634
|
+
{ depth: 3, characterId: 2, name: 'ok_btn', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 1200, ty: 0 } },
|
|
635
|
+
] }],
|
|
636
|
+
characters: {
|
|
637
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 20 }, draws: [{
|
|
638
|
+
fill: { type: 'solid', color: '#000' }, path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']],
|
|
639
|
+
}] },
|
|
640
|
+
2: { type: 'button', buttonHitStates: [{ characterId: 1 }] },
|
|
641
|
+
},
|
|
642
|
+
}, `${fullJs}
|
|
643
|
+
root.startLevel = 1;
|
|
644
|
+
root.increaseLevel = () => _callMethod(root.up_btn, 'onPress', []);
|
|
645
|
+
`, doc.header.frameRate);
|
|
646
|
+
const click = x => {
|
|
647
|
+
for (const type of ['pointerdown', 'pointerup']) {
|
|
648
|
+
const event = { target: canvas, pointerId: 1, pointerType: 'mouse', button: 0,
|
|
649
|
+
buttons: type === 'pointerdown' ? 1 : 0, clientX: x, clientY: 10, preventDefault() {} };
|
|
650
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
expect(root.down_btn.enabled).toBe(false);
|
|
654
|
+
click(40);
|
|
655
|
+
expect(root.startLevel).toBe(1);
|
|
656
|
+
|
|
657
|
+
click(10);
|
|
658
|
+
expect(root.startLevel).toBe(2);
|
|
659
|
+
expect(root.down_btn.enabled).toBe(true);
|
|
660
|
+
expect(root.up_btn.startLevel).toBeUndefined();
|
|
661
|
+
|
|
662
|
+
root.increaseLevel();
|
|
663
|
+
expect(root.startLevel).toBe(3);
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
it('reads the primary mouse press through AVM1 Key without changing keyboard state', () => {
|
|
667
|
+
const { root, canvas, handlers, windowHandlers, keydown, keyup } = mountAvm1Fixture(
|
|
668
|
+
{ frames: [{}], characters: {} }, `${AVM1_RUNTIME_STUB}\nroot.avm1Key = globals.Key;`);
|
|
669
|
+
const key = root.avm1Key;
|
|
670
|
+
const pointer = (type, buttons, target = canvas) => {
|
|
671
|
+
const event = { target, pointerType: 'mouse', pointerId: 1, button: 0, buttons,
|
|
672
|
+
clientX: 10, clientY: 20, preventDefault() {} };
|
|
673
|
+
for (const listener of windowHandlers[type] ?? []) listener(event);
|
|
674
|
+
if (target === canvas) for (const listener of handlers.get(type) ?? []) listener(event);
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
keydown('d', false, 68);
|
|
678
|
+
expect(key.isDown(1)).toBe(false);
|
|
679
|
+
pointer('pointerdown', 1);
|
|
680
|
+
expect([key.isDown(1), key.isDown(68), key.getCode()]).toEqual([true, true, 68]);
|
|
681
|
+
pointer('pointerup', 0, {});
|
|
682
|
+
expect([key.isDown(1), key.isDown(68), key.getCode()]).toEqual([false, true, 68]);
|
|
683
|
+
keyup('d');
|
|
684
|
+
|
|
685
|
+
pointer('pointerdown', 1);
|
|
686
|
+
expect(key.isDown(1)).toBe(true);
|
|
687
|
+
pointer('pointercancel', 0);
|
|
688
|
+
expect(key.isDown(1)).toBe(false);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it('delivers held rollovers to AVM1 sprites while preserving captured releases', () => {
|
|
692
|
+
const { root, canvas, handlers, windowHandlers } = mountAvm1Fixture({
|
|
693
|
+
frames: [{ places: [
|
|
694
|
+
{ depth: 1, characterId: 2, name: 'first' },
|
|
695
|
+
{ depth: 2, characterId: 2, name: 'second', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 600, ty: 0 } },
|
|
696
|
+
{ depth: 3, characterId: 3, name: 'button', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 1200, ty: 0 } },
|
|
697
|
+
] }],
|
|
698
|
+
characters: {
|
|
699
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 20 }, draws: [{
|
|
700
|
+
fill: { type: 'solid', color: '#111' }, path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']],
|
|
701
|
+
}] },
|
|
702
|
+
2: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 1 }] }] },
|
|
703
|
+
3: { type: 'button', buttonHitStates: [{ characterId: 1 }] },
|
|
704
|
+
},
|
|
705
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
706
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
707
|
+
root.events = [];
|
|
708
|
+
root.first.onPress = function () { root.events.push('first press'); };
|
|
709
|
+
root.first.onDragOut = function () { root.events.push('first drag out'); };
|
|
710
|
+
root.first.onReleaseOutside = function () { root.events.push('first release outside'); };
|
|
711
|
+
root.second.onRollOver = function () { root.events.push(['second over', globals.Key.isDown(1)]); };
|
|
712
|
+
root.second.onRollOut = function () { root.events.push('second out'); };
|
|
713
|
+
root.second.onRelease = function () { root.events.push('second release'); };
|
|
714
|
+
root.button.onRollOver = function () { root.events.push('button over'); };
|
|
715
|
+
}];
|
|
716
|
+
`);
|
|
717
|
+
const pointer = (type, x, buttons) => {
|
|
718
|
+
const event = { target: canvas, pointerType: 'mouse', pointerId: 1, button: 0, buttons,
|
|
719
|
+
clientX: x, clientY: 10, preventDefault() {} };
|
|
720
|
+
for (const fn of windowHandlers[type] ?? []) fn(event);
|
|
721
|
+
for (const fn of handlers.get(type) ?? []) fn(event);
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
pointer('pointermove', 10, 0);
|
|
725
|
+
pointer('pointerdown', 10, 1);
|
|
726
|
+
pointer('pointermove', 40, 1);
|
|
727
|
+
pointer('pointermove', 70, 1);
|
|
728
|
+
pointer('pointermove', 40, 1);
|
|
729
|
+
pointer('pointerup', 40, 0);
|
|
730
|
+
expect(root.events).toEqual([
|
|
731
|
+
'first press', 'first drag out', ['second over', true], 'second out',
|
|
732
|
+
['second over', true], 'first release outside',
|
|
733
|
+
]);
|
|
734
|
+
|
|
735
|
+
root.events.length = 0;
|
|
736
|
+
pointer('pointermove', 70, 0);
|
|
737
|
+
pointer('pointerdown', 70, 1);
|
|
738
|
+
pointer('pointermove', 40, 1);
|
|
739
|
+
expect(root.events).toEqual(['second out', 'button over']);
|
|
740
|
+
pointer('pointerup', 40, 0);
|
|
741
|
+
expect(root.events.at(-1)).toEqual(['second over', false]);
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
it('shows and hides the HUD in Flash Sonic’s authored level keyboard action', async () => {
|
|
745
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Flash Sonic.swf'));
|
|
746
|
+
const tag = doc.tags.find(tag => tag.code === TAG.PlaceObject2 && Buffer.from(tag.data).includes('HOME\0'));
|
|
747
|
+
const placed = decodeTag(tag, { header: doc.header }, diagnostics);
|
|
748
|
+
expect(placed.name).toBe('sonic1');
|
|
749
|
+
const placement = { ...placed, clipActions: placed.clipActions.filter(action => action.eventFlags === 2) };
|
|
750
|
+
const { fullJs } = transpileActionScript([placement], diagnostics, { swfVersion: doc.header.version });
|
|
751
|
+
const names = ['h', 'h1', 'h2', 'h3'];
|
|
752
|
+
const { root, timeline, keydown, keyup } = mountAvm1Fixture({
|
|
753
|
+
frames: [{ places: [placement] }],
|
|
754
|
+
characters: { [placement.characterId]: { type: 'sprite', frames: [{}] } },
|
|
755
|
+
}, fullJs);
|
|
756
|
+
root.sonic1.dead = 'off';
|
|
757
|
+
root.pause = 0;
|
|
758
|
+
for (const [index, name] of names.entries()) root.createEmptyMovieClip(name, 100 + index).visible = false;
|
|
759
|
+
const visibility = () => names.map(name => root[name].visible);
|
|
760
|
+
|
|
761
|
+
keydown('Home');
|
|
762
|
+
timeline.tick();
|
|
763
|
+
expect(visibility()).toEqual([true, true, true, true]);
|
|
764
|
+
keyup('Home');
|
|
765
|
+
keydown('End');
|
|
766
|
+
timeline.tick();
|
|
767
|
+
expect(visibility()).toEqual([false, false, false, false]);
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
it('uses the viewport for Line Rider’s authored AVM1 noScale stage', async () => {
|
|
771
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/linerider1.swf'));
|
|
772
|
+
const { tags } = decode(doc, diagnostics);
|
|
773
|
+
const authored = tags.find(tag => tag.type === 'DoAction' && Buffer.from(tag.bytecode).includes('noScale\0'));
|
|
774
|
+
const { fullJs } = transpileActionScript([authored], diagnostics, { swfVersion: doc.header.version });
|
|
775
|
+
const { root, canvas, resize } = mountAvm1Fixture({
|
|
776
|
+
frames: [{}], characters: {},
|
|
777
|
+
}, `${fullJs}\nroot.avm1Stage = globals.Stage;`, doc.header.frameRate,
|
|
778
|
+
{ width: 800, height: 600, viewport: [980, 730] });
|
|
779
|
+
const stage = root.avm1Stage;
|
|
780
|
+
const size = () => [stage.width, stage.height, canvas.width, canvas.height];
|
|
781
|
+
expect(stage.scaleMode).toBe('noScale');
|
|
782
|
+
expect(size()).toEqual([980, 730, 980, 730]);
|
|
783
|
+
const listener = { sizes: [], onResize() { this.sizes.push(size()); } };
|
|
784
|
+
stage.addListener?.(listener);
|
|
785
|
+
stage.addListener?.(listener);
|
|
786
|
+
|
|
787
|
+
resize(625, 475);
|
|
788
|
+
expect(size()).toEqual([625, 475, 625, 475]);
|
|
789
|
+
resize(625, 475);
|
|
790
|
+
expect(listener.sizes).toEqual([[625, 475, 625, 475]]);
|
|
791
|
+
expect([canvas.style.width, canvas.style.height]).toEqual(['625px', '475px']);
|
|
792
|
+
|
|
793
|
+
stage.scaleMode = 'showAll';
|
|
794
|
+
expect(size()).toEqual([800, 600, 800, 600]);
|
|
795
|
+
expect([canvas.style.width, canvas.style.height]).toEqual(['625px', '468.75px']);
|
|
796
|
+
resize(700, 500);
|
|
797
|
+
expect(listener.sizes).toHaveLength(1);
|
|
798
|
+
|
|
799
|
+
expect(stage.removeListener(listener)).toBe(true);
|
|
800
|
+
expect(stage.removeListener(listener)).toBe(false);
|
|
801
|
+
stage.scaleMode = 'noScale';
|
|
802
|
+
resize(700, 530);
|
|
803
|
+
expect(listener.sizes).toHaveLength(1);
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
it('picks authored buttons within the live AVM1 noScale viewport', () => {
|
|
807
|
+
const { root, canvas, handlers, resize } = mountAvm1Fixture({
|
|
808
|
+
frames: [{ places: [{ depth: 1, characterId: 2, name: 'toolbarButton',
|
|
809
|
+
matrix: { a: 1, b: 0, c: 0, d: 1, tx: 1600, ty: 1200 } }] }],
|
|
810
|
+
characters: {
|
|
811
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 20 }, draws: [{
|
|
812
|
+
fill: { type: 'solid', color: '#000' }, path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']],
|
|
813
|
+
}] },
|
|
814
|
+
2: { type: 'button', buttonHitStates: [{ characterId: 1 }] },
|
|
815
|
+
},
|
|
816
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
817
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
818
|
+
root.stage = globals.Stage;
|
|
819
|
+
root.stage.scaleMode = 'noScale';
|
|
820
|
+
root.activations = 0;
|
|
821
|
+
root.toolbarButton.onRelease = function () { root.activations++; };
|
|
822
|
+
}];
|
|
823
|
+
`, 24, { width: 60, height: 40, viewport: [120, 100] });
|
|
824
|
+
const click = () => {
|
|
825
|
+
for (const type of ['pointermove', 'pointerdown', 'pointerup']) {
|
|
826
|
+
const event = { target: canvas, pointerType: 'mouse', pointerId: 1, button: 0,
|
|
827
|
+
buttons: type === 'pointerdown' ? 1 : 0, clientX: 90, clientY: 70, preventDefault() {} };
|
|
828
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
click();
|
|
833
|
+
expect(root.activations).toBe(1);
|
|
834
|
+
resize(75, 65);
|
|
835
|
+
click();
|
|
836
|
+
expect(root.activations).toBe(1);
|
|
837
|
+
root.stage.scaleMode = 'showAll';
|
|
838
|
+
click();
|
|
839
|
+
expect(root.activations).toBe(1);
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
it('runs Line Rider’s linked UIObject stop action on its own movie clip playhead', async () => {
|
|
843
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/linerider1.swf'));
|
|
844
|
+
const { tags } = decode(doc, diagnostics);
|
|
845
|
+
const linkage = tags.filter(tag => tag.type === 'ExportAssets').flatMap(tag => tag.assets)
|
|
846
|
+
.find(asset => asset.name === 'UIObject');
|
|
847
|
+
const sprite = tags.find(tag => tag.type === 'Sprite' && tag.characterId === linkage.id);
|
|
848
|
+
const { fullJs } = transpileActionScript([sprite], diagnostics, { swfVersion: doc.header.version });
|
|
849
|
+
const { root, timeline } = mountAvm1Fixture({
|
|
850
|
+
frames: [{}], characters: { [sprite.characterId]: { type: 'sprite', frames: [{}, {}] } },
|
|
851
|
+
}, `var EXPORT_ASSETS = [${JSON.stringify(linkage)}];\n${fullJs}
|
|
852
|
+
function UIObject() { this.constructedAs = this.name; }
|
|
853
|
+
UIObject.prototype = Object.create(globals.MovieClip.prototype);
|
|
854
|
+
UIObject.prototype.fromClass = function () { return this.constructedAs; };
|
|
855
|
+
globals.Object.registerClass('UIObject', UIObject);
|
|
856
|
+
root.componentPrototype = UIObject.prototype;
|
|
857
|
+
`);
|
|
858
|
+
const child = root.attachMovie('UIObject', 'component', 1);
|
|
859
|
+
expect(Object.getPrototypeOf(child)).toBe(root.componentPrototype);
|
|
860
|
+
expect(child.fromClass()).toBe('component');
|
|
861
|
+
expect(child._swoofClonePlayhead.playing).toBe(false);
|
|
862
|
+
timeline.tick();
|
|
863
|
+
expect(child.currentFrame).toBe(1);
|
|
864
|
+
|
|
865
|
+
child.nextFrame();
|
|
866
|
+
expect(child.currentFrame).toBe(2);
|
|
867
|
+
child.gotoAndPlay(2);
|
|
868
|
+
expect(child._swoofClonePlayhead.playing).toBe(true);
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
it('runs a dynamically attached linked class load before its first EnterFrame', () => {
|
|
872
|
+
const { root, timeline } = mountAvm1Fixture({
|
|
873
|
+
frames: [{}], characters: { 1: { type: 'sprite', frames: [{}] } },
|
|
874
|
+
}, `
|
|
875
|
+
var EXPORT_ASSETS = [{ id: 1, name: 'Runner' }];
|
|
876
|
+
${AVM1_RUNTIME_STUB}
|
|
877
|
+
root.events = [];
|
|
878
|
+
function Runner() { root.events.push([this.name, 'construct']); }
|
|
879
|
+
Runner.prototype = Object.create(globals.MovieClip.prototype);
|
|
880
|
+
Runner.prototype.onLoad = function () { root.events.push([this.name, 'load', this.x]); };
|
|
881
|
+
Runner.prototype.onEnterFrame = function () { root.events.push([this.name, 'frame']); };
|
|
882
|
+
globals.Object.registerClass('Runner', Runner);
|
|
883
|
+
SPRITE_FRAME_SCRIPTS[1] = [[function () { root.events.push([this.name, 'first frame']); }]];
|
|
884
|
+
`);
|
|
885
|
+
root.onEnterFrame = function () {
|
|
886
|
+
delete root.onEnterFrame;
|
|
887
|
+
root.attachMovie('Runner', 'replaced', 1);
|
|
888
|
+
const runner = root.attachMovie('Runner', 'runner', 1);
|
|
889
|
+
runner.x = 42;
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
timeline.tick();
|
|
893
|
+
const attached = [['replaced', 'construct'], ['runner', 'construct'],
|
|
894
|
+
['replaced', 'first frame'], ['runner', 'first frame']];
|
|
895
|
+
expect(root.events).toEqual(attached);
|
|
896
|
+
timeline.tick();
|
|
897
|
+
expect(root.events).toEqual([...attached, ['runner', 'load', 42], ['runner', 'frame']]);
|
|
898
|
+
timeline.tick();
|
|
899
|
+
expect(root.events).toEqual([...attached, ['runner', 'load', 42], ['runner', 'frame'], ['runner', 'frame']]);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
it('lets an attached sprite frame see fields the caller assigns after attachMovie', () => {
|
|
903
|
+
const { root, timeline } = mountAvm1Fixture({
|
|
904
|
+
frames: [{}], characters: { 1: { type: 'sprite', frames: [{}] } },
|
|
905
|
+
}, `
|
|
906
|
+
var EXPORT_ASSETS = [{ id: 1, name: 'Unit' }];
|
|
907
|
+
${AVM1_RUNTIME_STUB}
|
|
908
|
+
SPRITE_FRAME_SCRIPTS[1] = [[function () { this.reward = this.id * 2; }]];
|
|
909
|
+
`);
|
|
910
|
+
root.onEnterFrame = function () {
|
|
911
|
+
delete root.onEnterFrame;
|
|
912
|
+
const unit = root.attachMovie('Unit', 'unit', 1);
|
|
913
|
+
unit.id = 5;
|
|
914
|
+
};
|
|
915
|
+
timeline.tick();
|
|
916
|
+
expect(root.unit.id).toBe(5);
|
|
917
|
+
expect(root.unit.reward).toBe(10);
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
it.each([5, 6])('dispatches nested clip actions using SWF %i event flag widths', async version => {
|
|
921
|
+
function record(code, data = []) {
|
|
922
|
+
const header = Buffer.alloc(data.length < 63 ? 2 : 6);
|
|
923
|
+
header.writeUInt16LE(code * 64 + Math.min(63, data.length));
|
|
924
|
+
if (header.length === 6) header.writeUInt32LE(data.length, 2);
|
|
925
|
+
return [...header, ...data];
|
|
926
|
+
}
|
|
927
|
+
function flags(bits) {
|
|
928
|
+
return version < 6 ? [bits, 0] : [bits, 0, 0, 0];
|
|
929
|
+
}
|
|
930
|
+
function handler(event, variable) {
|
|
931
|
+
const operands = [0, ...Buffer.from(variable), 0, 5, 1];
|
|
932
|
+
const actions = [0x96, operands.length, 0, ...operands, 0x1d, 0];
|
|
933
|
+
return [...flags(event), actions.length, 0, 0, 0, ...actions];
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
const onLoad = 0x01;
|
|
937
|
+
const onKeyDown = 0x40;
|
|
938
|
+
const childPlacement = record(TAG.PlaceObject2, [
|
|
939
|
+
0xa6, 1, 0, 1, 0, 0, ...Buffer.from('child\0'),
|
|
940
|
+
0, 0, ...flags(onLoad | onKeyDown),
|
|
941
|
+
...handler(onLoad, 'loaded'), ...handler(onKeyDown, 'keyReceived'), ...flags(0),
|
|
942
|
+
]);
|
|
943
|
+
const showFrame = record(TAG.ShowFrame);
|
|
944
|
+
const end = record(TAG.End);
|
|
945
|
+
const bytes = Buffer.from([
|
|
946
|
+
70, 87, 83, version, 0, 0, 0, 0, 8, 0, 0, 24, 1, 0,
|
|
947
|
+
...record(TAG.DefineSprite, [1, 0, 1, 0, ...showFrame, ...end]),
|
|
948
|
+
...record(TAG.DefineSprite, [2, 0, 1, 0, ...childPlacement, ...showFrame, ...end]),
|
|
949
|
+
...record(TAG.PlaceObject2, [0x26, 1, 0, 2, 0, 0, ...Buffer.from('container\0')]),
|
|
950
|
+
...showFrame, ...end,
|
|
951
|
+
]);
|
|
952
|
+
bytes.writeUInt32LE(bytes.length, 4);
|
|
953
|
+
const { doc, diagnostics } = await parse(bytes);
|
|
954
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
955
|
+
const opts = { swfVersion: doc.header.version };
|
|
956
|
+
const { fullJs } = transpileActionScript(tags, diagnostics, opts);
|
|
957
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
958
|
+
|
|
959
|
+
const { root, keydown } = mountAvm1Fixture(buildDisplayList(tags, symbolTable, diagnostics, opts), fullJs);
|
|
960
|
+
expect(root.container.child.loaded).toBe(true);
|
|
961
|
+
expect(root.container.child.keyReceived).toBeUndefined();
|
|
962
|
+
keydown('ArrowRight');
|
|
963
|
+
expect(root.container.child.keyReceived).toBe(true);
|
|
964
|
+
expect(root.keyReceived).toBeUndefined();
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
it.each([false, true])('inherits nested ClipActions when the parent clones before frame entry with shared runtime %s', async sharedAvm1Runtime => {
|
|
968
|
+
const record = (code, data = []) => {
|
|
969
|
+
const header = Buffer.alloc(data.length < 63 ? 2 : 6);
|
|
970
|
+
header.writeUInt16LE(code * 64 + Math.min(63, data.length));
|
|
971
|
+
if (header.length === 6) header.writeUInt32LE(data.length, 2);
|
|
972
|
+
return [...header, ...data];
|
|
973
|
+
};
|
|
974
|
+
const push = (...values) => {
|
|
975
|
+
const operands = values.flatMap(value =>
|
|
976
|
+
typeof value === 'string' ? [0, ...Buffer.from(value), 0] : [7, value & 255, value >> 8, 0, 0]);
|
|
977
|
+
return [OP.Push, operands.length, 0, ...operands];
|
|
978
|
+
};
|
|
979
|
+
const handler = (event, actions) => [event, 0, 0, 0, actions.length + 1, 0, 0, 0, ...actions, OP.End];
|
|
980
|
+
const placement = (name, id, depth, flags, ...handlers) => record(TAG.PlaceObject2, [
|
|
981
|
+
0xa6, depth, 0, id, 0, 0, ...Buffer.from(name), 0,
|
|
982
|
+
0, 0, flags, 0, 0, 0, ...handlers.flat(), 0, 0, 0, 0,
|
|
983
|
+
]);
|
|
984
|
+
const template = placement('template', 1, 1, 0x41,
|
|
985
|
+
handler(0x01, [
|
|
986
|
+
...push('seenPhase', '_parent'), OP.GetVariable, ...push('phase'), OP.GetMember, OP.SetVariable,
|
|
987
|
+
...push('_parent'), OP.GetVariable, ...push('loads', '_parent'), OP.GetVariable,
|
|
988
|
+
...push('loads'), OP.GetMember, ...push(1), OP.Add2, OP.SetMember,
|
|
989
|
+
]),
|
|
990
|
+
handler(0x40, [...push('keyReceived', 1), OP.SetVariable]));
|
|
991
|
+
const sibling = placement('sibling', 1, 2, 0x40,
|
|
992
|
+
handler(0x40, [...push('siblingReceived', 1), OP.SetVariable]));
|
|
993
|
+
const owner = placement('container', 2, 1, 0x01, handler(0x01, [
|
|
994
|
+
...push('loads', 0), OP.SetVariable,
|
|
995
|
+
...push('template', 'early', 16394), OP.CloneSprite,
|
|
996
|
+
...push('templateHandler', 'template'), OP.GetVariable, ...push('onKeyDown'), OP.GetMember, OP.SetVariable,
|
|
997
|
+
...push('phase', 'ready'), OP.SetVariable,
|
|
998
|
+
]));
|
|
999
|
+
const showFrame = record(TAG.ShowFrame);
|
|
1000
|
+
const end = record(TAG.End);
|
|
1001
|
+
const bytes = Buffer.from([
|
|
1002
|
+
70, 87, 83, 6, 0, 0, 0, 0, 8, 0, 0, 24, 1, 0,
|
|
1003
|
+
...record(TAG.DefineSprite, [1, 0, 1, 0, ...showFrame, ...end]),
|
|
1004
|
+
...record(TAG.DefineSprite, [2, 0, 1, 0, ...template, ...sibling, ...showFrame, ...end]),
|
|
1005
|
+
...owner, ...showFrame, ...end,
|
|
1006
|
+
]);
|
|
1007
|
+
bytes.writeUInt32LE(bytes.length, 4);
|
|
1008
|
+
const { doc, diagnostics } = await parse(bytes);
|
|
1009
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
1010
|
+
const opts = { swfVersion: doc.header.version, sharedAvm1Runtime };
|
|
1011
|
+
const { fullJs } = transpileActionScript(tags, diagnostics, opts);
|
|
1012
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1013
|
+
|
|
1014
|
+
const sharedRuntime = sharedAvm1Runtime ? `
|
|
1015
|
+
__swoof_swflib.timelineHelpers = ${timelineHelpersSource()};
|
|
1016
|
+
__swoof_swflib.createAvm1Runtime = ${AVM1_RUNTIME_FACTORY_SOURCE};
|
|
1017
|
+
` : '';
|
|
1018
|
+
const { root, keydown } = mountAvm1Fixture(buildDisplayList(tags, symbolTable, diagnostics, opts),
|
|
1019
|
+
`var EXPORT_ASSETS = [];\n${sharedRuntime}\n${fullJs}`);
|
|
1020
|
+
const { container } = root;
|
|
1021
|
+
expect(container.templateHandler).toBeUndefined();
|
|
1022
|
+
expect(container.early.seenPhase).toBe('ready');
|
|
1023
|
+
expect(container.template.seenPhase).toBe('ready');
|
|
1024
|
+
expect(container.loads).toBe(2);
|
|
1025
|
+
const late = container.template.duplicateMovieClip('late', 11);
|
|
1026
|
+
expect(late.seenPhase).toBe('ready');
|
|
1027
|
+
expect(container.loads).toBe(3);
|
|
1028
|
+
keydown('ArrowRight');
|
|
1029
|
+
expect(container.early.keyReceived).toBe(1);
|
|
1030
|
+
expect(late.keyReceived).toBe(1);
|
|
1031
|
+
expect(container.early.siblingReceived).toBeUndefined();
|
|
1032
|
+
expect(container.sibling.siblingReceived).toBe(1);
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
it('matches an authored ClipEventKeyPress by its typed ASCII or special key', () => {
|
|
1036
|
+
const onKeyPress = [0, 0, 2, 0];
|
|
1037
|
+
const handler = (key, label) => {
|
|
1038
|
+
const operands = [0, ...Buffer.from('matched\0'), 0, ...Buffer.from(label + '\0')];
|
|
1039
|
+
const actions = [0x96, operands.length, 0, ...operands, 0x1d, 0];
|
|
1040
|
+
return [...onKeyPress, actions.length + 1, 0, 0, 0, key, ...actions];
|
|
1041
|
+
};
|
|
1042
|
+
const place = decodeTag({
|
|
1043
|
+
code: TAG.PlaceObject2,
|
|
1044
|
+
data: Uint8Array.from([
|
|
1045
|
+
0xa6, 1, 0, 1, 0, 0, ...Buffer.from('control\0'),
|
|
1046
|
+
0, 0, ...onKeyPress,
|
|
1047
|
+
...handler(99, 'lower'), ...handler(67, 'upper'), ...handler(112, 'letter-p'),
|
|
1048
|
+
...handler(2, 'arrow'), ...handler(32, 'space'), ...handler(0, 'invalid'), 0, 0, 0, 0,
|
|
1049
|
+
]),
|
|
1050
|
+
}, { header: { version: 7 } });
|
|
1051
|
+
const tags = [place, { type: 'ShowFrame' }];
|
|
1052
|
+
const { fullJs } = transpileActionScript(tags, undefined, { swfVersion: 7 });
|
|
1053
|
+
const { root, keydown } = mountAvm1Fixture({
|
|
1054
|
+
frames: buildFramesFromTags(tags),
|
|
1055
|
+
characters: { 1: { type: 'sprite', frames: [{}] } },
|
|
1056
|
+
}, fullJs);
|
|
1057
|
+
keydown('c', false, 67);
|
|
1058
|
+
expect(root.control.matched).toBe('lower');
|
|
1059
|
+
keydown('C', true, 67);
|
|
1060
|
+
expect(root.control.matched).toBe('upper');
|
|
1061
|
+
keydown('F1', false, 112);
|
|
1062
|
+
expect(root.control.matched).toBe('upper');
|
|
1063
|
+
keydown('p', false, 80);
|
|
1064
|
+
expect(root.control.matched).toBe('letter-p');
|
|
1065
|
+
keydown('ArrowRight');
|
|
1066
|
+
expect(root.control.matched).toBe('arrow');
|
|
1067
|
+
keydown(undefined, false, 67);
|
|
1068
|
+
expect(root.control.matched).toBe('upper');
|
|
1069
|
+
keydown(undefined, false, 0);
|
|
1070
|
+
expect(root.control.matched).toBe('upper');
|
|
1071
|
+
for (const key of [' ', 'Space', 'Spacebar']) {
|
|
1072
|
+
root.control.matched = undefined;
|
|
1073
|
+
keydown(key);
|
|
1074
|
+
expect(root.control.matched).toBe('space');
|
|
1075
|
+
}
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
it.each([false, true])('resolves clip action variables on the clip and globals with ActionWith=%s', withScope => {
|
|
1079
|
+
const push = value => {
|
|
1080
|
+
const operands = [0, ...Buffer.from(value), 0];
|
|
1081
|
+
return [0x96, operands.length, 0, ...operands];
|
|
1082
|
+
};
|
|
1083
|
+
const read = name => [...push(name), 0x1c];
|
|
1084
|
+
const save = (name, operands) => [...push(name), ...operands, 0x1d];
|
|
1085
|
+
const body = [
|
|
1086
|
+
...save('missingBeforeWrite', read('rootOnly')),
|
|
1087
|
+
...save('globalFallback', read('service')),
|
|
1088
|
+
...save('ownValue', read('shared')),
|
|
1089
|
+
...save('computedMissing', [...read('missingName'), 0x1c]),
|
|
1090
|
+
...save('computedGlobal', [...read('globalName'), 0x1c]),
|
|
1091
|
+
...save('explicitRoot', read('_root:rootOnly')),
|
|
1092
|
+
...save('computedRoot', [...read('rootName'), 0x1c]),
|
|
1093
|
+
];
|
|
1094
|
+
const functionBody = [...read('rootOnly'), 0x3e, 0];
|
|
1095
|
+
const functionHeader = [...Buffer.from('readFromFunction\0'), 0, 0, functionBody.length, 0];
|
|
1096
|
+
const withBody = [
|
|
1097
|
+
...save('gotWithValue', read('withValue')),
|
|
1098
|
+
...save('missingWhileWith', read('rootOnly')),
|
|
1099
|
+
...save('globalWhileWith', read('service')),
|
|
1100
|
+
];
|
|
1101
|
+
const withActions = [...read('scope'), 0x94, 2, 0, withBody.length, 0, ...withBody];
|
|
1102
|
+
const bytecode = Uint8Array.from([
|
|
1103
|
+
...body,
|
|
1104
|
+
...(withScope ? withActions : []),
|
|
1105
|
+
0x9b, functionHeader.length, 0, ...functionHeader, ...functionBody,
|
|
1106
|
+
0,
|
|
1107
|
+
]);
|
|
1108
|
+
const { fullJs } = transpileActionScript([
|
|
1109
|
+
{ type: 'PlaceObject2', depth: 1, name: 'child', characterId: 1, clipActions: [{ eventFlags: 1, bytecode }] },
|
|
1110
|
+
], undefined, { swfVersion: 5 });
|
|
1111
|
+
const { root } = mountAvm1Fixture({
|
|
1112
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'child' }] }],
|
|
1113
|
+
characters: { 1: { type: 'sprite', frames: [{}] } },
|
|
1114
|
+
}, `${fullJs}
|
|
1115
|
+
root.rootOnly = 'movie';
|
|
1116
|
+
root.service = 'wrong receiver';
|
|
1117
|
+
globals.service = 'global';
|
|
1118
|
+
globals.shared = 'global';
|
|
1119
|
+
FRAME_SCRIPTS[0].unshift(function () {
|
|
1120
|
+
this.child.shared = 'instance';
|
|
1121
|
+
this.child.missingName = 'RoOtOnLy';
|
|
1122
|
+
this.child.globalName = 'SeRvIcE';
|
|
1123
|
+
this.child.rootName = '_RoOt:RoOtOnLy';
|
|
1124
|
+
this.child.scope = { withValue: 'active With' };
|
|
1125
|
+
});
|
|
1126
|
+
`);
|
|
1127
|
+
expect(root.child.missingBeforeWrite).toBeUndefined();
|
|
1128
|
+
expect(root.child.computedMissing).toBeUndefined();
|
|
1129
|
+
expect(root.child.globalFallback).toBe('global');
|
|
1130
|
+
expect(root.child.computedGlobal).toBe('global');
|
|
1131
|
+
expect(root.child.ownValue).toBe('instance');
|
|
1132
|
+
expect(root.child.explicitRoot).toBe('movie');
|
|
1133
|
+
expect(root.child.computedRoot).toBe('movie');
|
|
1134
|
+
if (withScope) {
|
|
1135
|
+
expect(root.child.gotWithValue).toBe('active With');
|
|
1136
|
+
expect(root.child.missingWhileWith).toBeUndefined();
|
|
1137
|
+
expect(root.child.globalWhileWith).toBe('global');
|
|
1138
|
+
}
|
|
1139
|
+
expect(root.child.readFromFunction()).toBe('movie');
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
it('broadcasts pointer down and up once and targets the separate button transitions', () => {
|
|
1143
|
+
const { root, handlers, canvas } = mountAvm1Fixture({
|
|
1144
|
+
frames: [{ places: [
|
|
1145
|
+
{ depth: 1, characterId: 2, name: 'button' },
|
|
1146
|
+
{ depth: 2, characterId: 2, name: 'other', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 1000, ty: 0 } },
|
|
1147
|
+
] }],
|
|
1148
|
+
characters: {
|
|
1149
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 20 }, draws: [{
|
|
1150
|
+
fill: { type: 'solid', color: '#f00' },
|
|
1151
|
+
path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']],
|
|
1152
|
+
}] },
|
|
1153
|
+
2: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 1 }] }] },
|
|
1154
|
+
},
|
|
1155
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
1156
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1157
|
+
root.events = [];
|
|
1158
|
+
for (const clip of [root.button, root.other]) {
|
|
1159
|
+
for (const name of ['onMouseDown', 'onMouseUp', 'onPress', 'onRelease', 'onReleaseOutside']) {
|
|
1160
|
+
clip[name] = function () { root.events.push(this.name + ':' + name); };
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}];
|
|
1164
|
+
`);
|
|
1165
|
+
function point(type, x) {
|
|
1166
|
+
const event = { pointerId: 1, button: 0, target: canvas, clientX: x, clientY: 5, preventDefault() {} };
|
|
1167
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
point('pointermove', 5);
|
|
1171
|
+
point('pointerdown', 5);
|
|
1172
|
+
expect(Array.from(root.events).sort()).toEqual(['button:onMouseDown', 'button:onPress', 'other:onMouseDown']);
|
|
1173
|
+
root.events.length = 0;
|
|
1174
|
+
point('pointerup', 5);
|
|
1175
|
+
expect(Array.from(root.events).sort()).toEqual(['button:onMouseUp', 'button:onRelease', 'other:onMouseUp']);
|
|
1176
|
+
|
|
1177
|
+
point('pointerdown', 5);
|
|
1178
|
+
point('pointermove', 55);
|
|
1179
|
+
root.events.length = 0;
|
|
1180
|
+
point('pointerup', 55);
|
|
1181
|
+
expect(Array.from(root.events).sort()).toEqual(['button:onMouseUp', 'button:onReleaseOutside', 'other:onMouseUp']);
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
it('captures an AVM1 press so a release outside the browser window still broadcasts mouse-up', () => {
|
|
1185
|
+
const { root, handlers, canvas } = mountAvm1Fixture({ frames: [{}], characters: {} }, `${AVM1_RUNTIME_STUB}
|
|
1186
|
+
root.ups = [];
|
|
1187
|
+
root.onMouseUp = function () { root.ups.push([root._xmouse, root._ymouse]); };
|
|
1188
|
+
`);
|
|
1189
|
+
const captured = [];
|
|
1190
|
+
canvas.setPointerCapture = id => captured.push(id);
|
|
1191
|
+
function send(type, x, y) {
|
|
1192
|
+
const event = {
|
|
1193
|
+
pointerId: 9, button: 0, buttons: type === 'pointerdown' ? 1 : 0, isPrimary: true,
|
|
1194
|
+
pointerType: 'mouse', target: canvas, clientX: x, clientY: y, preventDefault() {},
|
|
1195
|
+
};
|
|
1196
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
1197
|
+
}
|
|
1198
|
+
send('pointerdown', 10, 12);
|
|
1199
|
+
expect(captured).toEqual([9]);
|
|
1200
|
+
expect([root._xmouse, root._ymouse]).toEqual([10, 12]);
|
|
1201
|
+
send('pointerup', -30, -8);
|
|
1202
|
+
expect(root.ups).toEqual([[-30, -8]]);
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
it('broadcasts AVM1 mouse events from back to front and holds listener changes for the next event', () => {
|
|
1206
|
+
const { root, handlers, canvas } = mountAvm1Fixture({
|
|
1207
|
+
frames: [{ places: [{ depth: 2, characterId: 2, name: 'authored' }] }],
|
|
1208
|
+
characters: { 2: { type: 'sprite', frames: [{}] } },
|
|
1209
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
1210
|
+
FRAME_SCRIPTS[0] = FRAME_SCRIPTS[0] || [];
|
|
1211
|
+
FRAME_SCRIPTS[0].push(function () {
|
|
1212
|
+
root.order = [];
|
|
1213
|
+
root.onMouseDown = function () { root.order.push('root'); };
|
|
1214
|
+
root.authored.onMouseDown = function () { root.order.push('authored'); globals.Mouse.addListener(root.late); };
|
|
1215
|
+
var back = root.createEmptyMovieClip('back', -3);
|
|
1216
|
+
var front = root.createEmptyMovieClip('front', 4);
|
|
1217
|
+
back.onMouseDown = function () { root.order.push('back'); };
|
|
1218
|
+
front.onMouseDown = function () { root.order.push('front'); };
|
|
1219
|
+
root.early = { onMouseDown() { root.order.push('early'); globals.Mouse.removeListener(root.second); } };
|
|
1220
|
+
root.second = { onMouseDown() { root.order.push('second'); } };
|
|
1221
|
+
root.late = { onMouseDown() { root.order.push('late'); } };
|
|
1222
|
+
globals.Mouse.addListener(root.early);
|
|
1223
|
+
globals.Mouse.addListener(root.second);
|
|
1224
|
+
});
|
|
1225
|
+
`);
|
|
1226
|
+
const down = { pointerId: 1, button: 0, buttons: 1, isPrimary: true, target: canvas,
|
|
1227
|
+
clientX: 5, clientY: 5, preventDefault() {} };
|
|
1228
|
+
for (const listener of handlers.get('pointerdown') ?? []) listener(down);
|
|
1229
|
+
expect(root.order).toEqual(['root', 'authored', 'back', 'front', 'early']);
|
|
1230
|
+
root.order.length = 0;
|
|
1231
|
+
for (const listener of handlers.get('pointerdown') ?? []) listener(down);
|
|
1232
|
+
expect(root.order).toEqual(['root', 'authored', 'back', 'front', 'early', 'late']);
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
it.each(['pointermove', 'mousemove'])('broadcasts %s once after updating stage coordinates', input => {
|
|
1236
|
+
const { root, handlers, canvas } = mountAvm1Fixture({
|
|
1237
|
+
frames: [{ places: [
|
|
1238
|
+
{ depth: 1, characterId: 1, name: 'first' },
|
|
1239
|
+
{ depth: 2, characterId: 1, name: 'second' },
|
|
1240
|
+
] }],
|
|
1241
|
+
characters: { 1: { type: 'sprite', frames: [{}] } },
|
|
1242
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
1243
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1244
|
+
root.moves = [];
|
|
1245
|
+
for (const clip of [root, root.first, root.second]) {
|
|
1246
|
+
clip.onMouseMove = function () { root.moves.push([this.name, root._xmouse, root._ymouse]); };
|
|
1247
|
+
}
|
|
1248
|
+
}];
|
|
1249
|
+
`, 24, { pointerEvents: input === 'pointermove' });
|
|
1250
|
+
function move(type, x, y, isPrimary) {
|
|
1251
|
+
const event = { pointerId: 1, button: 0, target: canvas, clientX: x, clientY: y, isPrimary, preventDefault() {} };
|
|
1252
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
move(input, 11, 22, input === 'pointermove' ? true : undefined);
|
|
1256
|
+
if (input === 'pointermove') move('mousemove', 30, 50, undefined);
|
|
1257
|
+
move('pointermove', 40, 60, false);
|
|
1258
|
+
expect(root.moves).toEqual([['root', 11, 22], ['first', 11, 22], ['second', 11, 22]]);
|
|
1259
|
+
expect([root._xmouse, root._ymouse]).toEqual([11, 22]);
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
it('dispatches stage mouse events to an AVM1 Mouse listener until it is removed', () => {
|
|
1263
|
+
const name = value => [0, ...Buffer.from(value), 0];
|
|
1264
|
+
const push = (...values) => {
|
|
1265
|
+
const data = values.flat();
|
|
1266
|
+
return [0x96, data.length, 0, ...data];
|
|
1267
|
+
};
|
|
1268
|
+
const register = method => [
|
|
1269
|
+
...push(name('listener')), 0x1c, // GetVariable
|
|
1270
|
+
...push([7, 1, 0, 0, 0], name('Mouse')), 0x1c,
|
|
1271
|
+
...push(name(method)), 0x52, // CallMethod
|
|
1272
|
+
];
|
|
1273
|
+
const { fullJs } = transpileActionScript([
|
|
1274
|
+
{ type: 'DoAction', bytecode: Uint8Array.from([...register('addListener'), 0x17, ...register('addListener'), 0x17, 0]) },
|
|
1275
|
+
], undefined, { swfVersion: 8 });
|
|
1276
|
+
const { root, handlers, canvas } = mountAvm1Fixture({
|
|
1277
|
+
frames: [{ places: [{ depth: 1, characterId: 2, name: 'panel' }] }],
|
|
1278
|
+
characters: {
|
|
1279
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 20 }, draws: [{
|
|
1280
|
+
fill: { type: 'solid', color: '#f00' }, path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']],
|
|
1281
|
+
}] },
|
|
1282
|
+
2: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 3, name: 'top' }] }] },
|
|
1283
|
+
3: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 1 }] }] },
|
|
1284
|
+
},
|
|
1285
|
+
}, `${fullJs}
|
|
1286
|
+
FRAME_SCRIPTS[0].unshift(function () {
|
|
1287
|
+
root.listener = {
|
|
1288
|
+
events: [],
|
|
1289
|
+
onMouseWheel(delta, target) { this.events.push([delta, target.name, root._xmouse]); },
|
|
1290
|
+
onMouseMove() { this.events.push('move'); },
|
|
1291
|
+
onMouseDown() { this.events.push('down'); },
|
|
1292
|
+
onMouseUp() { this.events.push('up'); },
|
|
1293
|
+
};
|
|
1294
|
+
root.unregister = function () { return globals.Mouse.removeListener(root.listener); };
|
|
1295
|
+
});
|
|
1296
|
+
`);
|
|
1297
|
+
function dispatch(type, options = {}) {
|
|
1298
|
+
const event = { pointerId: 1, button: 0, target: canvas, clientX: 5, clientY: 5, preventDefault() {}, ...options };
|
|
1299
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
1300
|
+
}
|
|
1301
|
+
dispatch('wheel', { deltaMode: 1, deltaY: -3 });
|
|
1302
|
+
dispatch('wheel', { deltaMode: 0, deltaY: 80, clientX: 25 });
|
|
1303
|
+
dispatch('wheel', { deltaY: 0, deltaX: 30 });
|
|
1304
|
+
dispatch('pointermove');
|
|
1305
|
+
dispatch('pointerdown');
|
|
1306
|
+
dispatch('pointerup');
|
|
1307
|
+
expect(root.listener.events).toEqual([[3, 'top', 5], [-2, 'root', 25], 'move', 'down', 'up']);
|
|
1308
|
+
|
|
1309
|
+
expect(root.unregister()).toBe(true);
|
|
1310
|
+
expect(root.unregister()).toBe(false);
|
|
1311
|
+
dispatch('wheel', { deltaMode: 1, deltaY: -1 });
|
|
1312
|
+
dispatch('pointerdown');
|
|
1313
|
+
expect(root.listener.events).toHaveLength(5);
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
it.each(['pointerdown', 'mousedown'])('wheel-scrolls AVM1 Canvas text selected through %s within its painted bounds and mask', clickEvent => {
|
|
1317
|
+
const translate = (x, y) => ({ a: 1, b: 0, c: 0, d: 1, tx: x * 20, ty: y * 20 });
|
|
1318
|
+
const lines = 'One\nTwo\nThree\nFour';
|
|
1319
|
+
const { root, timeline, handlers, canvas, selection } = mountAvm1Fixture({
|
|
1320
|
+
frames: [{ places: [
|
|
1321
|
+
{ depth: 1, characterId: 1, clipDepth: 2, matrix: translate(36, 10) },
|
|
1322
|
+
{ depth: 2, characterId: 2, name: 'credits', matrix: translate(10, 10) },
|
|
1323
|
+
] }],
|
|
1324
|
+
characters: {
|
|
1325
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 30, h: 20 }, draws: [{
|
|
1326
|
+
fill: { type: 'solid', color: '#000' }, path: [['M', 0, 0], ['L', 30, 0], ['L', 30, 20], ['L', 0, 20], ['Z']],
|
|
1327
|
+
}] },
|
|
1328
|
+
2: { type: 'text', kind: 'edit', readOnly: true, multiline: true, wordWrap: true, fontSize: 10,
|
|
1329
|
+
bounds: { x: 30, y: 3, w: 100, h: 12 }, text: lines },
|
|
1330
|
+
},
|
|
1331
|
+
}, `var SWF_VERSION = 8; ${AVM1_RUNTIME_STUB}
|
|
1332
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1333
|
+
root.paintedText = [];
|
|
1334
|
+
ctx.fillText = function (text) { root.paintedText.push(text); };
|
|
1335
|
+
root.createTextField('notes', 100, 10, 60, 160, 12);
|
|
1336
|
+
root.notes.multiline = true;
|
|
1337
|
+
root.notes.defaultTextFormat.size = 10;
|
|
1338
|
+
root.notes.text = ${JSON.stringify(lines)};
|
|
1339
|
+
root.createEmptyMovieClip('focusTarget', 101).focusEnabled = true;
|
|
1340
|
+
}];
|
|
1341
|
+
`, 24, { pointerEvents: clickEvent === 'pointerdown' });
|
|
1342
|
+
function pointer(type, x, y, options = {}) {
|
|
1343
|
+
const event = { pointerId: 1, button: 0, target: canvas, clientX: x, clientY: y, ...options,
|
|
1344
|
+
preventDefault() { this.defaultPrevented = true; } };
|
|
1345
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
1346
|
+
return event.defaultPrevented;
|
|
1347
|
+
}
|
|
1348
|
+
function wheel(x, y, deltaY = 2) {
|
|
1349
|
+
return pointer('wheel', x, y, { deltaMode: 1, deltaY });
|
|
1350
|
+
}
|
|
1351
|
+
const positions = [];
|
|
1352
|
+
root.credits.addListener({ onScroller: field => positions.push(field.scroll) });
|
|
1353
|
+
|
|
1354
|
+
expect(wheel(50, 15)).toBeUndefined();
|
|
1355
|
+
expect(root.credits.scroll).toBe(1);
|
|
1356
|
+
pointer(clickEvent, 80, 15); // Inside the field, outside its stencil.
|
|
1357
|
+
expect(wheel(50, 15)).toBeUndefined();
|
|
1358
|
+
pointer(clickEvent, 50, 15);
|
|
1359
|
+
expect(wheel(80, 15)).toBeUndefined();
|
|
1360
|
+
root.paintedText.length = 0;
|
|
1361
|
+
expect(wheel(50, 15)).toBe(true);
|
|
1362
|
+
expect(root.credits.scroll).toBe(3);
|
|
1363
|
+
expect(root.paintedText).toContain('Three');
|
|
1364
|
+
expect(wheel(50, 15, 99)).toBe(true);
|
|
1365
|
+
expect(root.credits.scroll).toBe(4);
|
|
1366
|
+
expect(wheel(50, 15, 1)).toBeUndefined();
|
|
1367
|
+
expect(positions).toEqual([3, 4]);
|
|
1368
|
+
|
|
1369
|
+
pointer(clickEvent, 15, 65);
|
|
1370
|
+
root.notes.mouseWheelEnabled = false;
|
|
1371
|
+
expect(wheel(15, 65)).toBeUndefined();
|
|
1372
|
+
root.notes.mouseWheelEnabled = true;
|
|
1373
|
+
expect(wheel(15, 65)).toBe(true);
|
|
1374
|
+
expect(root.notes.scroll).toBe(3);
|
|
1375
|
+
expect(wheel(15, 65, -99)).toBe(true);
|
|
1376
|
+
expect(root.notes.scroll).toBe(1);
|
|
1377
|
+
expect(wheel(50, 15, -3)).toBeUndefined();
|
|
1378
|
+
expect(root.credits.scroll).toBe(4);
|
|
1379
|
+
root.credits.scroll = 99;
|
|
1380
|
+
root.credits.scroll = 2;
|
|
1381
|
+
expect(positions).toEqual([3, 4, 2]);
|
|
1382
|
+
root.credits.text = 'Replacement';
|
|
1383
|
+
timeline.render();
|
|
1384
|
+
timeline.render();
|
|
1385
|
+
expect(root.credits.scroll).toBe(1);
|
|
1386
|
+
expect(positions).toEqual([3, 4, 2, 1]);
|
|
1387
|
+
|
|
1388
|
+
expect(selection.setFocus(root.focusTarget)).toBe(true);
|
|
1389
|
+
expect(wheel(15, 65)).toBeUndefined();
|
|
1390
|
+
root.notes.selectable = false;
|
|
1391
|
+
pointer(clickEvent, 15, 65);
|
|
1392
|
+
expect(wheel(15, 65)).toBeUndefined();
|
|
1393
|
+
root.notes.selectable = true;
|
|
1394
|
+
expect(wheel(15, 65)).toBeUndefined();
|
|
1395
|
+
pointer(clickEvent, 15, 65);
|
|
1396
|
+
expect(wheel(15, 65)).toBe(true);
|
|
1397
|
+
|
|
1398
|
+
const viewports = [];
|
|
1399
|
+
root.notes.onScroller = field => viewports.push([field.scroll, field.hscroll]);
|
|
1400
|
+
root.notes.text = 'This line is wider than the field '.repeat(3) + '\nTwo\nThree\nFour';
|
|
1401
|
+
root.notes.hscroll = 10;
|
|
1402
|
+
timeline.render();
|
|
1403
|
+
expect(viewports).toEqual([[3, 10]]);
|
|
1404
|
+
root.notes.text = 'Replacement';
|
|
1405
|
+
timeline.render();
|
|
1406
|
+
expect(viewports).toEqual([[3, 10], [1, 0]]);
|
|
1407
|
+
});
|
|
1408
|
+
|
|
1409
|
+
it.each([
|
|
1410
|
+
['Motherload', 49],
|
|
1411
|
+
['Super Smash Flash', 2528],
|
|
1412
|
+
])('notifies the original %s scrollbar component registered with its TextField', async (title, spriteId) => {
|
|
1413
|
+
const source = readFileSync(new URL(`../../archive/flasharchive/${title}.swf`, import.meta.url));
|
|
1414
|
+
const { doc, diagnostics } = await parse(source);
|
|
1415
|
+
const { tags } = decode(doc, diagnostics);
|
|
1416
|
+
const init = tags.find(tag => tag.type === 'DoInitAction' && tag.spriteId === spriteId);
|
|
1417
|
+
const { jsFragments } = transpileActionScript([init], diagnostics, { swfVersion: doc.header.version });
|
|
1418
|
+
const motherload = title === 'Motherload';
|
|
1419
|
+
const { root, timeline } = mountAvm1Fixture({ frames: [{}], characters: {} }, `
|
|
1420
|
+
var SWF_VERSION = ${doc.header.version};
|
|
1421
|
+
${AVM1_RUNTIME_STUB}
|
|
1422
|
+
globals.FUIComponentClass = function () {};
|
|
1423
|
+
globals.mx.controls = { scrollClasses: { ScrollBar: function () {} } };
|
|
1424
|
+
globals.mx.core = { UIObject: { mergeClipParameters: function () { return {}; } } };
|
|
1425
|
+
${jsFragments.join('\n')}
|
|
1426
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1427
|
+
root.Scrollbar = ${motherload ? 'root.FScrollBarClass' : 'globals.mx.controls.UIScrollBar'};
|
|
1428
|
+
}];
|
|
1429
|
+
`);
|
|
1430
|
+
const field = root.createTextField('notes', 1, 0, 0, 80, 12);
|
|
1431
|
+
field.multiline = true;
|
|
1432
|
+
field.text = 'One\nTwo\nThree\nFour';
|
|
1433
|
+
|
|
1434
|
+
const updates = [];
|
|
1435
|
+
const scrollbar = Object.create(root.Scrollbar.prototype);
|
|
1436
|
+
scrollbar.horizontal = false;
|
|
1437
|
+
scrollbar.__get__horizontal = () => false;
|
|
1438
|
+
scrollbar.onTextChanged = () => {};
|
|
1439
|
+
if (motherload) scrollbar.setScrollPosition = value => updates.push(value);
|
|
1440
|
+
else Object.defineProperty(scrollbar, 'scrollPosition', { set: value => updates.push(value) });
|
|
1441
|
+
|
|
1442
|
+
scrollbar.setScrollTarget(field);
|
|
1443
|
+
expect(scrollbar.textField).toBe(field);
|
|
1444
|
+
field.scroll = 2;
|
|
1445
|
+
field.scroll = 3;
|
|
1446
|
+
timeline.render();
|
|
1447
|
+
expect(updates).toEqual([2, 3]);
|
|
1448
|
+
field.text = 'Replacement';
|
|
1449
|
+
timeline.render();
|
|
1450
|
+
timeline.render();
|
|
1451
|
+
expect(field.scroll).toBe(1);
|
|
1452
|
+
expect(updates).toEqual([2, 3, 1]);
|
|
1453
|
+
});
|
|
1454
|
+
|
|
1455
|
+
it('runs Motherload root library initializers when their frames are reached and only once per movie', async () => {
|
|
1456
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Motherload.swf'));
|
|
1457
|
+
const { tags } = decode(doc, diagnostics);
|
|
1458
|
+
const initializers = new Map();
|
|
1459
|
+
let frame = 0;
|
|
1460
|
+
for (const tag of tags) {
|
|
1461
|
+
if (tag.type === 'ShowFrame') frame++;
|
|
1462
|
+
if (tag.type === 'DoInitAction' && [49, 166].includes(tag.spriteId)) {
|
|
1463
|
+
initializers.set(tag.spriteId, { tag, frame });
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
expect([initializers.get(49).frame, initializers.get(166).frame]).toEqual([0, 2]);
|
|
1467
|
+
const showFrame = { type: 'ShowFrame' };
|
|
1468
|
+
const { jsFragments } = transpileActionScript([
|
|
1469
|
+
initializers.get(49).tag, showFrame, showFrame, initializers.get(166).tag,
|
|
1470
|
+
], diagnostics, { swfVersion: doc.header.version });
|
|
1471
|
+
const openMovie = () => mountAvm1Fixture({ frames: [{}, {}, {}, {}], characters: {} }, `
|
|
1472
|
+
var SWF_VERSION = ${doc.header.version};
|
|
1473
|
+
${AVM1_RUNTIME_STUB}
|
|
1474
|
+
globals.FUIComponentClass = function () {};
|
|
1475
|
+
${jsFragments.join('\n')}
|
|
1476
|
+
FRAME_SCRIPTS[2] = [function () { this.onInitializerFrame = this.FScrollBarClass; }];
|
|
1477
|
+
`);
|
|
1478
|
+
const { root, timeline } = openMovie();
|
|
1479
|
+
const first = root.FScrollBarClass;
|
|
1480
|
+
expect(first).toBeTypeOf('function');
|
|
1481
|
+
expect(root.onInitializerFrame).toBeUndefined();
|
|
1482
|
+
timeline.tick();
|
|
1483
|
+
expect(root.FScrollBarClass).toBe(first);
|
|
1484
|
+
timeline.tick();
|
|
1485
|
+
const later = root.FScrollBarClass;
|
|
1486
|
+
expect(later).toBeTypeOf('function');
|
|
1487
|
+
expect(later).not.toBe(first);
|
|
1488
|
+
expect(root.onInitializerFrame).toBe(later);
|
|
1489
|
+
timeline.gotoAndStop(1);
|
|
1490
|
+
timeline.gotoAndStop(3);
|
|
1491
|
+
expect(root.FScrollBarClass).toBe(later);
|
|
1492
|
+
|
|
1493
|
+
const seek = openMovie();
|
|
1494
|
+
const beforeSeek = seek.root.FScrollBarClass;
|
|
1495
|
+
seek.timeline.gotoAndStop(4);
|
|
1496
|
+
expect(seek.root.FScrollBarClass).toBeTypeOf('function');
|
|
1497
|
+
expect(seek.root.FScrollBarClass).not.toBe(beforeSeek);
|
|
1498
|
+
expect(seek.root.onInitializerFrame).toBeUndefined();
|
|
1499
|
+
});
|
|
1500
|
+
|
|
1501
|
+
it('registers Minecraft TD library classes in tag order before the same frame’s placements', async () => {
|
|
1502
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Minecraft TD.swf'));
|
|
1503
|
+
const { tags } = decode(doc, diagnostics);
|
|
1504
|
+
const secondFrame = [];
|
|
1505
|
+
let frame = 0;
|
|
1506
|
+
for (const tag of tags) {
|
|
1507
|
+
if (tag.type === 'ShowFrame') frame++;
|
|
1508
|
+
else if (frame === 1) secondFrame.push(tag);
|
|
1509
|
+
}
|
|
1510
|
+
const spriteId = 171;
|
|
1511
|
+
const placement = secondFrame.find(tag => tag.type === 'PlaceObject2' && tag.characterId === spriteId);
|
|
1512
|
+
const initializers = secondFrame.filter(tag => tag.type === 'DoInitAction' && [171, 187].includes(tag.spriteId));
|
|
1513
|
+
const exports = secondFrame.filter(tag => tag.type === 'ExportAssets').flatMap(tag => tag.assets)
|
|
1514
|
+
.filter(asset => [171, 187].includes(asset.id));
|
|
1515
|
+
expect(initializers.map(tag => tag.spriteId)).toEqual([171, 187]);
|
|
1516
|
+
const showFrame = { type: 'ShowFrame' };
|
|
1517
|
+
const { jsFragments } = transpileActionScript([showFrame, ...initializers], diagnostics, { swfVersion: doc.header.version });
|
|
1518
|
+
const { root, timeline } = mountAvm1Fixture({
|
|
1519
|
+
frames: buildFramesFromTags([showFrame, placement, showFrame]),
|
|
1520
|
+
characters: { [spriteId]: { type: 'sprite', frames: [{}] } },
|
|
1521
|
+
}, `
|
|
1522
|
+
var SWF_VERSION = ${doc.header.version};
|
|
1523
|
+
var EXPORT_ASSETS = ${JSON.stringify(exports)};
|
|
1524
|
+
${AVM1_RUNTIME_STUB}
|
|
1525
|
+
root.registrations = [];
|
|
1526
|
+
var registerClass = globals.Object.registerClass;
|
|
1527
|
+
globals.Object.registerClass = function (linkage, ctor) {
|
|
1528
|
+
root.registrations.push(linkage);
|
|
1529
|
+
return registerClass.call(this, linkage, ctor);
|
|
1530
|
+
};
|
|
1531
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1532
|
+
this.water_map = function () { this.constructed = true; };
|
|
1533
|
+
this.water_map.prototype.ready = true;
|
|
1534
|
+
this.egg = function () {};
|
|
1535
|
+
}];
|
|
1536
|
+
${jsFragments.join('\n')}
|
|
1537
|
+
FRAME_SCRIPTS[1] = [function () {
|
|
1538
|
+
this.sawLinkedPlacement = this._swoofRootChildren[${placement.depth}]?.ready;
|
|
1539
|
+
}];
|
|
1540
|
+
`);
|
|
1541
|
+
expect(root.registrations).toEqual([]);
|
|
1542
|
+
timeline.tick();
|
|
1543
|
+
expect(root.registrations).toEqual(['water_map', 'egg']);
|
|
1544
|
+
expect(root.sawLinkedPlacement).toBe(true);
|
|
1545
|
+
const waterMap = root._swoofRootChildren[placement.depth];
|
|
1546
|
+
expect(waterMap.constructed).toBe(true);
|
|
1547
|
+
timeline.gotoAndStop(1);
|
|
1548
|
+
timeline.gotoAndStop(2);
|
|
1549
|
+
expect(root.registrations).toEqual(['water_map', 'egg']);
|
|
1550
|
+
});
|
|
1551
|
+
|
|
1552
|
+
it('finishes the active load handler before dispatching loads from sprite navigation', () => {
|
|
1553
|
+
const { root, selection } = mountAvm1Fixture({
|
|
1554
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'controller' },
|
|
1555
|
+
{ depth: 2, characterId: 2, name: 'map' }] }],
|
|
1556
|
+
characters: {
|
|
1557
|
+
1: { type: 'sprite', frames: [{}] },
|
|
1558
|
+
2: { type: 'sprite', frames: [{}, { places: [{ depth: 1, characterId: 1, name: 'first' },
|
|
1559
|
+
{ depth: 2, characterId: 1, name: 'removed' }] }, { removes: [2],
|
|
1560
|
+
places: [{ depth: 2, characterId: 1, name: 'second' }] }] },
|
|
1561
|
+
},
|
|
1562
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
1563
|
+
function registerLoad(clip) {
|
|
1564
|
+
_avm1InstallClipAction(clip, 1, clip.name, function () {
|
|
1565
|
+
root.events.push([this.name, root.ready]);
|
|
1566
|
+
this.createEmptyMovieClip('focusTarget', 50).focusEnabled = true;
|
|
1567
|
+
Selection.setFocus('focusTarget');
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
SPRITE_FRAME_SCRIPTS[2] = [[function () {
|
|
1571
|
+
this.initializations = (this.initializations || 0) + 1;
|
|
1572
|
+
}], [function () {
|
|
1573
|
+
root.events.push(['initializations', this.initializations]);
|
|
1574
|
+
registerLoad(this.first);
|
|
1575
|
+
registerLoad(this.removed);
|
|
1576
|
+
}], [function () { registerLoad(this.second); }]];
|
|
1577
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1578
|
+
root.events = [];
|
|
1579
|
+
_avm1InstallClipAction(this.controller, 1, 'controller', function () {
|
|
1580
|
+
var map = this.parent.map;
|
|
1581
|
+
map.gotoAndStop(2);
|
|
1582
|
+
root.events.push(['frame', map.currentFrame, typeof map.first.onLoad]);
|
|
1583
|
+
map.gotoAndStop(3);
|
|
1584
|
+
root.ready = true;
|
|
1585
|
+
});
|
|
1586
|
+
}];
|
|
1587
|
+
`);
|
|
1588
|
+
expect(root.events).toEqual([['initializations', 1], ['frame', 2, 'function'], ['first', true], ['second', true]]);
|
|
1589
|
+
expect(selection.getFocus()).toBe('_level0.map.second.focusTarget');
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
it('round-trips Selection focus through unnamed depth path segments', () => {
|
|
1593
|
+
const { root, selection } = mountAvm1Fixture({
|
|
1594
|
+
frames: [{ places: [] }],
|
|
1595
|
+
characters: {},
|
|
1596
|
+
}, AVM1_RUNTIME_STUB);
|
|
1597
|
+
const holder = root.createEmptyMovieClip('holder', 1);
|
|
1598
|
+
const unnamed = holder.createEmptyMovieClip('temp', 7);
|
|
1599
|
+
unnamed.focusEnabled = true;
|
|
1600
|
+
delete holder.temp;
|
|
1601
|
+
unnamed.name = '';
|
|
1602
|
+
expect(unnamed.getDepth()).toBe(7);
|
|
1603
|
+
expect(selection.setFocus(unnamed)).toBe(true);
|
|
1604
|
+
expect(selection.getFocus()).toBe('_level0.holder.#7');
|
|
1605
|
+
expect(unnamed._target).toBe('/holder/#7');
|
|
1606
|
+
selection.setFocus(null);
|
|
1607
|
+
expect(selection.setFocus('_level0.holder.#7')).toBe(true);
|
|
1608
|
+
expect(selection.getFocus()).toBe('_level0.holder.#7');
|
|
1609
|
+
expect(selection.setFocus('/holder/#7')).toBe(true);
|
|
1610
|
+
expect(selection.getFocus()).toBe('_level0.holder.#7');
|
|
1611
|
+
});
|
|
1612
|
+
|
|
1613
|
+
it('resolves relative Selection focus paths from lifecycle, frame and mouse callback clips', () => {
|
|
1614
|
+
const { root, timeline, selection, handlers, canvas } = mountAvm1Fixture({
|
|
1615
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'controller' }] }],
|
|
1616
|
+
characters: { 1: { type: 'sprite', frames: [{}] } },
|
|
1617
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
1618
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1619
|
+
root.focusByEvent = {};
|
|
1620
|
+
root.createEmptyMovieClip('focusTarget', 50).focusEnabled = true;
|
|
1621
|
+
this.controller.createEmptyMovieClip('focusTarget', 50).focusEnabled = true;
|
|
1622
|
+
for (const [flag, event] of [[0x200, 'initialize'], [0x40000, 'construct'], [1, 'load'], [2, 'frame'], [8, 'move']]) {
|
|
1623
|
+
_avm1InstallClipAction(this.controller, flag, event, function () {
|
|
1624
|
+
Selection.setFocus('focusTarget');
|
|
1625
|
+
root.focusByEvent[event] = Selection.getFocus();
|
|
1626
|
+
if (event === 'initialize') throw new Error('fixture initializer error');
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
}];
|
|
1630
|
+
`);
|
|
1631
|
+
const childPath = '_level0.controller.focusTarget';
|
|
1632
|
+
expect(root.focusByEvent.initialize).toBe(childPath);
|
|
1633
|
+
expect(root.focusByEvent.construct).toBe(childPath);
|
|
1634
|
+
expect(root.focusByEvent.load).toBe(childPath);
|
|
1635
|
+
selection.setFocus(null);
|
|
1636
|
+
timeline.tick();
|
|
1637
|
+
expect(root.focusByEvent.frame).toBe(childPath);
|
|
1638
|
+
|
|
1639
|
+
selection.setFocus(null);
|
|
1640
|
+
const pointer = { pointerId: 1, button: 0, isPrimary: true, target: canvas, clientX: 5, clientY: 5 };
|
|
1641
|
+
for (const handler of handlers.get('pointermove') ?? []) handler(pointer);
|
|
1642
|
+
expect(root.focusByEvent.move).toBe(childPath);
|
|
1643
|
+
|
|
1644
|
+
expect(selection.setFocus('focusTarget')).toBe(true);
|
|
1645
|
+
expect(selection.getFocus()).toBe('_level0.focusTarget');
|
|
1646
|
+
});
|
|
1647
|
+
|
|
1648
|
+
it.each([true, false])('resolves Selection paths from the input callback clip with pointer events=%s', pointerEvents => {
|
|
1649
|
+
const { root, selection, handlers, canvas, keydown, keyup } = mountAvm1Fixture({
|
|
1650
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'controller' }] }],
|
|
1651
|
+
characters: {
|
|
1652
|
+
1: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 2 }] }] },
|
|
1653
|
+
2: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 20 }, draws: [{
|
|
1654
|
+
fill: { type: 'solid', color: '#f00' },
|
|
1655
|
+
path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']],
|
|
1656
|
+
}] },
|
|
1657
|
+
},
|
|
1658
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
1659
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1660
|
+
root.focusByEvent = [];
|
|
1661
|
+
root.createEmptyMovieClip('focusTarget', 50).focusEnabled = true;
|
|
1662
|
+
this.controller.createEmptyMovieClip('focusTarget', 50).focusEnabled = true;
|
|
1663
|
+
for (const [flag, event] of [[64, 'keydown'], [128, 'keyup'], [0x20000, '65:0:keyPress'], [1024, 'press'], [2048, 'release']]) {
|
|
1664
|
+
_avm1InstallClipAction(this.controller, flag, event, function () {
|
|
1665
|
+
Selection.setFocus('focusTarget');
|
|
1666
|
+
root.focusByEvent.push([event, Selection.getFocus()]);
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
}];
|
|
1670
|
+
`, 24, { pointerEvents });
|
|
1671
|
+
|
|
1672
|
+
keydown('A');
|
|
1673
|
+
keyup('A');
|
|
1674
|
+
const prefix = pointerEvents ? 'pointer' : 'mouse';
|
|
1675
|
+
for (const type of ['move', 'down', 'up']) {
|
|
1676
|
+
const event = { pointerId: 1, button: 0, isPrimary: true, target: canvas,
|
|
1677
|
+
clientX: 5, clientY: 5, preventDefault() {} };
|
|
1678
|
+
for (const handler of handlers.get(prefix + type) ?? []) handler(event);
|
|
1679
|
+
}
|
|
1680
|
+
expect(root.focusByEvent).toEqual(['keydown', '65:0:keyPress', 'keyup', 'press', 'release']
|
|
1681
|
+
.map(event => [event, '_level0.controller.focusTarget']));
|
|
1682
|
+
|
|
1683
|
+
root.controller.onKeyDown = null;
|
|
1684
|
+
expect(selection.setFocus(root.controller)).toBe(true);
|
|
1685
|
+
expect(keydown('Enter')).toBe(true);
|
|
1686
|
+
expect(root.focusByEvent.slice(-2)).toEqual([
|
|
1687
|
+
['press', '_level0.controller.focusTarget'], ['release', '_level0.controller.focusTarget'],
|
|
1688
|
+
]);
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
it('picks script-drawn AVM1 controls by painted depth, geometry and masks on primary pointer input', () => {
|
|
1692
|
+
const { root, handlers, canvas, document } = mountAvm1Fixture({
|
|
1693
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'authored' },
|
|
1694
|
+
{ depth: 2, characterId: 3, name: 'holder', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 2000, ty: 1800 } }] }],
|
|
1695
|
+
characters: {
|
|
1696
|
+
1: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 2 }] }] },
|
|
1697
|
+
2: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 20 }, draws: [{
|
|
1698
|
+
fill: { type: 'solid', color: '#f00' },
|
|
1699
|
+
path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']],
|
|
1700
|
+
}] },
|
|
1701
|
+
3: { type: 'sprite', frames: [{}] },
|
|
1702
|
+
},
|
|
1703
|
+
}, `${AVM1_RUNTIME_STUB}
|
|
1704
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
1705
|
+
root.events = [];
|
|
1706
|
+
function makeDrawing(owner, name, depth, offset, width) {
|
|
1707
|
+
const clip = owner.createEmptyMovieClip(name, depth);
|
|
1708
|
+
clip.x = clip.y = offset;
|
|
1709
|
+
clip.beginFill(0x00f); clip.drawRect(0, 0, width, 20); clip.endFill();
|
|
1710
|
+
return clip;
|
|
1711
|
+
}
|
|
1712
|
+
const drawing = makeDrawing(root, 'drawing', 100, 5, 20);
|
|
1713
|
+
drawing.setMask(makeDrawing(root, 'mask', 101, 5, 10));
|
|
1714
|
+
drawing.onRollOver = function () { this.useHandCursor = false; };
|
|
1715
|
+
const nested = makeDrawing(root.holder, 'nested', 1, 10, 20);
|
|
1716
|
+
root.authored.addProperty('skinOffset', function () { return this.skin?._x; }, function (offset) {
|
|
1717
|
+
const skin = makeDrawing(this, 'skin', 1, offset, 20);
|
|
1718
|
+
skin.setMask(makeDrawing(this, 'skinMask', 2, offset, 10));
|
|
1719
|
+
});
|
|
1720
|
+
root.authored.skinOffset = 40;
|
|
1721
|
+
for (const clip of [root.authored, drawing, nested]) {
|
|
1722
|
+
clip.onPress = function () { root.events.push(this.name + ':press'); };
|
|
1723
|
+
clip.onRelease = function () { root.events.push(this.name + ':release'); };
|
|
1724
|
+
clip.onReleaseOutside = function () { root.events.push(this.name + ':outside'); };
|
|
1725
|
+
}
|
|
1726
|
+
}];
|
|
1727
|
+
`);
|
|
1728
|
+
const dispatch = (type, x, y) => {
|
|
1729
|
+
const event = { pointerId: 1, pointerType: 'mouse', button: 0, isPrimary: true, target: canvas,
|
|
1730
|
+
clientX: x, clientY: y, preventDefault() { this.defaultPrevented = true; } };
|
|
1731
|
+
for (const handler of handlers.get(type) ?? []) handler(event);
|
|
1732
|
+
return event.defaultPrevented;
|
|
1733
|
+
};
|
|
1734
|
+
const click = (x, y, releaseX = x, releaseY = y) => {
|
|
1735
|
+
dispatch('pointermove', x, y);
|
|
1736
|
+
const consumed = dispatch('pointerdown', x, y);
|
|
1737
|
+
dispatch('pointerup', releaseX, releaseY);
|
|
1738
|
+
return consumed;
|
|
1739
|
+
};
|
|
1740
|
+
expect(click(2, 2)).toBe(true);
|
|
1741
|
+
expect(canvas.style.cursor).toBe('pointer');
|
|
1742
|
+
document.activeElement = { tagName: 'BUTTON' };
|
|
1743
|
+
expect(click(8, 8)).toBe(true);
|
|
1744
|
+
expect(document.activeElement).toBe(canvas);
|
|
1745
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
1746
|
+
expect(Object.getOwnPropertyDescriptor(root.drawing, 'useHandCursor')).toMatchObject({
|
|
1747
|
+
value: false, enumerable: false, writable: true,
|
|
1748
|
+
});
|
|
1749
|
+
expect(click(18, 8)).toBe(true);
|
|
1750
|
+
expect(canvas.style.cursor).toBe('pointer');
|
|
1751
|
+
expect(click(28, 8)).toBeUndefined();
|
|
1752
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
1753
|
+
expect(root.authored.skin.parent).toBe(root.authored);
|
|
1754
|
+
expect(click(45, 45)).toBe(true);
|
|
1755
|
+
expect(click(55, 45)).toBeUndefined();
|
|
1756
|
+
root.authored.skin._visible = false;
|
|
1757
|
+
expect(click(45, 45)).toBeUndefined();
|
|
1758
|
+
expect(click(115, 105)).toBe(true);
|
|
1759
|
+
expect(click(8, 8, 40, 40)).toBe(true);
|
|
1760
|
+
expect(root.events).toEqual([
|
|
1761
|
+
'authored:press', 'authored:release', 'drawing:press', 'drawing:release',
|
|
1762
|
+
'authored:press', 'authored:release', 'authored:press', 'authored:release',
|
|
1763
|
+
'nested:press', 'nested:release', 'drawing:press', 'drawing:outside',
|
|
1764
|
+
]);
|
|
1765
|
+
expect(document.activeElement).toBe(canvas);
|
|
1766
|
+
});
|
|
1767
|
+
|
|
1768
|
+
it('dispatches authored roll events on a clip with no press or release handler', async () => {
|
|
1769
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Duck Life 2 - World Champion.swf'));
|
|
1770
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
1771
|
+
const place = tags.find(tag => tag.characterId === 59 && tag.depth === 20 && tag.clipActions?.length === 2);
|
|
1772
|
+
expect(place.clipActions.map(action => action.eventFlags)).toEqual([0x2000, 0x4000]);
|
|
1773
|
+
const authored = [place, { type: 'ShowFrame' }];
|
|
1774
|
+
const options = { swfVersion: doc.header.version };
|
|
1775
|
+
const { characters } = buildDisplayList(tags, symbolTable, diagnostics, options);
|
|
1776
|
+
const { fullJs } = transpileActionScript(authored, diagnostics, options);
|
|
1777
|
+
const { root, handlers, canvas } = mountAvm1Fixture({ frames: buildFramesFromTags(authored), characters }, fullJs);
|
|
1778
|
+
const clip = root._swoofRootChildren[20];
|
|
1779
|
+
expect(clip.onPress).toBeUndefined();
|
|
1780
|
+
expect(clip.onRelease).toBeUndefined();
|
|
1781
|
+
expect(clip.hitTest(45, 346, true)).toBe(true);
|
|
1782
|
+
|
|
1783
|
+
function move(x, y) {
|
|
1784
|
+
const event = { pointerId: 1, pointerType: 'mouse', isPrimary: true, target: canvas,
|
|
1785
|
+
clientX: x, clientY: y, preventDefault() {} };
|
|
1786
|
+
for (const handler of handlers.get('pointermove') ?? []) handler(event);
|
|
1787
|
+
}
|
|
1788
|
+
expect(clip.alpha).toBe(100);
|
|
1789
|
+
move(45, 346);
|
|
1790
|
+
expect(clip.alpha).toBe(50);
|
|
1791
|
+
move(239, 20);
|
|
1792
|
+
expect(clip.alpha).toBe(100);
|
|
1793
|
+
});
|
|
1794
|
+
|
|
1795
|
+
it('runs each unnamed Doodle Jump placement’s load and release actions on its own instance', async () => {
|
|
1796
|
+
const { doc } = await parse(readFileSync('archive/flasharchive/Doodle Jump.swf'));
|
|
1797
|
+
const { tags, symbolTable } = decode(doc);
|
|
1798
|
+
const displayList = buildDisplayList(tags, symbolTable);
|
|
1799
|
+
const { fullJs } = transpileActionScript(tags);
|
|
1800
|
+
const { root, timeline, selection, handlers, canvas, keydown } = mountAvm1Fixture(displayList, fullJs, doc.header.frameRate);
|
|
1801
|
+
|
|
1802
|
+
for (const [depth, text, frame] of [[3, 'scores', 5], [5, 'options', 4], [7, 'info', 6], [8, 'play', 2]]) {
|
|
1803
|
+
timeline.gotoAndStop(1);
|
|
1804
|
+
const clip = root._swoofRootChildren[depth];
|
|
1805
|
+
expect(clip.name).toBe('');
|
|
1806
|
+
expect(clip.button_txt.text).toBe(text);
|
|
1807
|
+
const label = clip.button_txt;
|
|
1808
|
+
const point = { x: label.x + label.width / 2, y: label.y + label.height / 2 };
|
|
1809
|
+
clip.localToGlobal(point);
|
|
1810
|
+
for (const type of ['pointermove', 'pointerdown', 'pointerup']) {
|
|
1811
|
+
const event = { pointerId: 1, button: 0, target: canvas, clientX: point.x, clientY: point.y, preventDefault() {} };
|
|
1812
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
1813
|
+
}
|
|
1814
|
+
expect(root.currentFrame).toBe(frame);
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
timeline.gotoAndStop(1);
|
|
1818
|
+
const focus = [];
|
|
1819
|
+
selection.addListener({ onSetFocus: (_old, next) => focus.push(next) });
|
|
1820
|
+
expect(keydown('Tab')).toBe(true);
|
|
1821
|
+
expect(focus.at(-1)).toBe(root._swoofRootChildren[8]);
|
|
1822
|
+
expect(keydown('Enter')).toBe(true);
|
|
1823
|
+
expect(root.currentFrame).toBe(2);
|
|
1824
|
+
expect(focus.at(-1)).toBeNull();
|
|
1825
|
+
|
|
1826
|
+
const first = root.createEmptyMovieClip('first', 100);
|
|
1827
|
+
const second = root.createEmptyMovieClip('second', 101);
|
|
1828
|
+
first.focusEnabled = true;
|
|
1829
|
+
first.tabIndex = 2;
|
|
1830
|
+
second.tabIndex = 1;
|
|
1831
|
+
expect(selection.setFocus('_root.first')).toBe(true);
|
|
1832
|
+
expect(selection.getFocus()).toBe('_level0.first');
|
|
1833
|
+
expect([selection.getBeginIndex(), selection.getEndIndex(), selection.getCaretIndex()]).toEqual([-1, -1, -1]);
|
|
1834
|
+
expect(keydown('Tab', true)).toBe(true);
|
|
1835
|
+
expect(selection.getFocus()).toBe('_level0.second');
|
|
1836
|
+
let keyPresses = 0, releases = 0;
|
|
1837
|
+
second.onRelease = () => { releases++; };
|
|
1838
|
+
second._swoofKeyPressHandlers = { '13:0:0': () => { keyPresses++; } };
|
|
1839
|
+
expect(keydown('Enter')).toBe(true);
|
|
1840
|
+
expect(keyPresses).toBe(1);
|
|
1841
|
+
expect(releases).toBe(0);
|
|
1842
|
+
second.removeMovieClip();
|
|
1843
|
+
expect(selection.getFocus()).toBeNull();
|
|
1844
|
+
});
|
|
1845
|
+
|
|
1846
|
+
it('activates focused controls with Space while the page body still has DOM focus', () => {
|
|
1847
|
+
const engine = generateTimelineEngine({ frames: [{ places: [] }], characters: {} }, {
|
|
1848
|
+
stageW: 240, stageH: 400, frameRate: 24, frameCount: 1,
|
|
1849
|
+
});
|
|
1850
|
+
const windowHandlers = { keydown: [], keyup: [] };
|
|
1851
|
+
const canvas = { width: 240, height: 400, style: {}, focus() {}, setPointerCapture() {},
|
|
1852
|
+
getBoundingClientRect: () => ({ width: 240, height: 400, left: 0, top: 0 }),
|
|
1853
|
+
addEventListener() {},
|
|
1854
|
+
};
|
|
1855
|
+
const body = { nodeName: 'BODY' };
|
|
1856
|
+
const document = {
|
|
1857
|
+
activeElement: body,
|
|
1858
|
+
body,
|
|
1859
|
+
documentElement: { nodeName: 'HTML' },
|
|
1860
|
+
getElementById: id => id === 'stage' ? canvas : null,
|
|
1861
|
+
createElement: () => ({ getContext: () => null }),
|
|
1862
|
+
};
|
|
1863
|
+
const sandbox = {
|
|
1864
|
+
STAGE_WIDTH: 240, STAGE_HEIGHT: 400, FRAME_RATE: 24, BACKGROUND: '#fff', loaded: {},
|
|
1865
|
+
document, ctx: new Proxy({ canvas, globalAlpha: 1 }, { get: (t, k) => t[k] ?? (() => {}) }),
|
|
1866
|
+
PointerEvent: function () {},
|
|
1867
|
+
Path2D: class { moveTo() {} lineTo() {} closePath() {} },
|
|
1868
|
+
requestAnimationFrame: () => 1,
|
|
1869
|
+
addEventListener(type, handler) { (windowHandlers[type] ??= []).push(handler); },
|
|
1870
|
+
};
|
|
1871
|
+
sandbox.window = sandbox;
|
|
1872
|
+
const { root, selection } = runInNewContext(`
|
|
1873
|
+
${SWFLIB_SOURCE}
|
|
1874
|
+
${engine}
|
|
1875
|
+
var __swoof_root = timeline;
|
|
1876
|
+
${AVM1_RUNTIME_STUB}
|
|
1877
|
+
window.__swoof = { root, timeline };
|
|
1878
|
+
timeline.enter();
|
|
1879
|
+
({ root, selection: Selection });
|
|
1880
|
+
`, sandbox);
|
|
1881
|
+
const button = root.createEmptyMovieClip('start', 1);
|
|
1882
|
+
button.focusEnabled = true;
|
|
1883
|
+
button.buttonMode = true;
|
|
1884
|
+
let clicks = 0;
|
|
1885
|
+
button.onRelease = () => { clicks++; };
|
|
1886
|
+
expect(selection.setFocus(button)).toBe(true);
|
|
1887
|
+
const event = { target: body, key: ' ', keyCode: 32, preventDefault() { this.defaultPrevented = true; } };
|
|
1888
|
+
for (const listener of windowHandlers.keydown) listener(event);
|
|
1889
|
+
expect(clicks).toBe(1);
|
|
1890
|
+
expect(event.defaultPrevented).toBe(true);
|
|
1891
|
+
});
|
|
1892
|
+
|
|
1893
|
+
it('tabs to and activates an authored DefineButton with its transformed focus outline', () => {
|
|
1894
|
+
const matrix = tx => ({ a: 1, b: 0, c: 0, d: 1, tx, ty: 0 });
|
|
1895
|
+
const buttonRecord = { characterId: 1, depth: 1, matrix: matrix(200) };
|
|
1896
|
+
const { root, selection, keydown, focusOutlines } = mountAvm1Fixture({
|
|
1897
|
+
frames: [{ places: [{ depth: 1, characterId: 2, name: 'button', matrix: matrix(100) }] }],
|
|
1898
|
+
characters: {
|
|
1899
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 10 }, draws: [] },
|
|
1900
|
+
2: { type: 'button', buttonStates: { up: [buttonRecord] }, buttonHitStates: [buttonRecord],
|
|
1901
|
+
actions: [
|
|
1902
|
+
{ conditions: { overDownToOverUp: true }, script: 'root.activations = (root.activations || 0) + 1;' },
|
|
1903
|
+
{ conditions: { keyPress: 32 }, script: 'root.special = true;' },
|
|
1904
|
+
] },
|
|
1905
|
+
},
|
|
1906
|
+
}, AVM1_RUNTIME_STUB);
|
|
1907
|
+
expect(keydown('Tab')).toBe(true);
|
|
1908
|
+
expect(selection.getFocus()).toBe('_level0.button');
|
|
1909
|
+
expect(focusOutlines.at(-1)).toEqual([15, 0, 20, 10]);
|
|
1910
|
+
expect(keydown('Enter')).toBe(true);
|
|
1911
|
+
expect(root.activations).toBe(1);
|
|
1912
|
+
expect(keydown(' ')).toBe(true);
|
|
1913
|
+
expect(root.special).toBe(true);
|
|
1914
|
+
expect(root.activations).toBe(1);
|
|
1915
|
+
root.button._focusrect = false;
|
|
1916
|
+
keydown('Enter');
|
|
1917
|
+
expect(root.activations).toBe(1);
|
|
1918
|
+
});
|
|
1919
|
+
|
|
1920
|
+
it('uses an authored SetTabIndex of zero in the AVM1 tab order', () => {
|
|
1921
|
+
const setIndex = (depth, index) => decodeTag({
|
|
1922
|
+
code: TAG.SetTabIndex,
|
|
1923
|
+
data: Uint8Array.of(depth, 0, index, 0),
|
|
1924
|
+
});
|
|
1925
|
+
const { root, selection, keydown } = mountAvm1Fixture({
|
|
1926
|
+
frames: buildFramesFromTags([
|
|
1927
|
+
{ type: 'PlaceObject2', depth: 1, characterId: 1, name: 'one' },
|
|
1928
|
+
setIndex(1, 1),
|
|
1929
|
+
{ type: 'PlaceObject2', depth: 2, characterId: 1, name: 'zero' },
|
|
1930
|
+
setIndex(2, 0),
|
|
1931
|
+
{ type: 'ShowFrame' },
|
|
1932
|
+
]),
|
|
1933
|
+
characters: { 1: { type: 'sprite', frames: [{}] } },
|
|
1934
|
+
}, AVM1_RUNTIME_STUB);
|
|
1935
|
+
const scriptZero = root.createEmptyMovieClip('scriptZero', 10);
|
|
1936
|
+
scriptZero.tabEnabled = true;
|
|
1937
|
+
scriptZero.tabIndex = 0;
|
|
1938
|
+
expect(root.zero.tabIndex).toBe(0);
|
|
1939
|
+
|
|
1940
|
+
expect(keydown('Tab')).toBe(true);
|
|
1941
|
+
expect(selection.getFocus()).toBe('_level0.zero');
|
|
1942
|
+
expect(keydown('Tab')).toBe(true);
|
|
1943
|
+
expect(selection.getFocus()).toBe('_level0.one');
|
|
1944
|
+
expect(keydown('Tab', true)).toBe(true);
|
|
1945
|
+
expect(selection.getFocus()).toBe('_level0.zero');
|
|
1946
|
+
|
|
1947
|
+
root.zero.tabIndex = -1;
|
|
1948
|
+
expect(keydown('Tab')).toBe(true);
|
|
1949
|
+
expect(selection.getFocus()).toBe('_level0.one');
|
|
1950
|
+
});
|
|
1951
|
+
|
|
1952
|
+
it.each(['member', 'indexed'])('hides and restores an AVM1 button through a numeric %s visibility write', mode => {
|
|
1953
|
+
const string = value => [0, ...Buffer.from(value), 0];
|
|
1954
|
+
const number = value => [7, value, 0, 0, 0];
|
|
1955
|
+
const push = (...values) => {
|
|
1956
|
+
const payload = values.flat();
|
|
1957
|
+
return [0x96, payload.length, 0, ...payload];
|
|
1958
|
+
};
|
|
1959
|
+
const setVisibility = value => Uint8Array.from([
|
|
1960
|
+
...(mode === 'member'
|
|
1961
|
+
? [...push(string('button')), 0x1c, ...push(string('_visible'), number(value)), 0x4f]
|
|
1962
|
+
: [...push(string('button'), number(7), number(value)), 0x23]),
|
|
1963
|
+
...push(string('observed'), string('button'), number(7)), 0x22, 0x1d,
|
|
1964
|
+
0,
|
|
1965
|
+
]);
|
|
1966
|
+
const { fullJs } = transpileActionScript([
|
|
1967
|
+
{ type: 'DoAction', bytecode: setVisibility(0) },
|
|
1968
|
+
{ type: 'ShowFrame' },
|
|
1969
|
+
{ type: 'DoAction', bytecode: setVisibility(1) },
|
|
1970
|
+
], undefined, { swfVersion: 7 });
|
|
1971
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
1972
|
+
const buttonRecord = { characterId: 1, depth: 1, matrix };
|
|
1973
|
+
const { root, timeline, handlers, canvas, selection } = mountAvm1Fixture({
|
|
1974
|
+
frames: [{ places: [{ depth: 1, characterId: 2, name: 'button', matrix }] }, {}],
|
|
1975
|
+
characters: {
|
|
1976
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 20, h: 20 }, draws: [{
|
|
1977
|
+
fill: { type: 'solid', color: '#f00' }, path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']],
|
|
1978
|
+
}] },
|
|
1979
|
+
2: { type: 'button', buttonStates: { up: [buttonRecord] }, buttonHitStates: [buttonRecord],
|
|
1980
|
+
actions: [{ conditions: { overDownToOverUp: true }, script: 'root.activated = true;' }] },
|
|
1981
|
+
},
|
|
1982
|
+
}, fullJs);
|
|
1983
|
+
function click() {
|
|
1984
|
+
for (const type of ['pointermove', 'pointerdown', 'pointerup']) {
|
|
1985
|
+
const event = { pointerId: 1, button: 0, target: canvas, clientX: 5, clientY: 5, preventDefault() {} };
|
|
1986
|
+
for (const listener of handlers.get(type) ?? []) listener(event);
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
expect(root.button._visible).toBe(false);
|
|
1991
|
+
expect(root.observed).toBe(false);
|
|
1992
|
+
expect(selection.setFocus(root.button)).toBe(false);
|
|
1993
|
+
click();
|
|
1994
|
+
expect(root.activated).toBeUndefined();
|
|
1995
|
+
|
|
1996
|
+
timeline.gotoAndStop(2);
|
|
1997
|
+
expect(root.button._visible).toBe(true);
|
|
1998
|
+
expect(root.observed).toBe(true);
|
|
1999
|
+
expect(selection.setFocus(root.button)).toBe(true);
|
|
2000
|
+
click();
|
|
2001
|
+
expect(root.activated).toBe(true);
|
|
2002
|
+
});
|