Commit Graph

708 Commits

Author SHA1 Message Date
Mike Welsh 19d0bf64a9 avm1: Preload _parent directly from base clip
When `_parent` is preloaded  in a `DefineFunction2` action,
we previously resolve it on the scope chain. This could cause
double borrow panics as the parent object could already be
borrowed, and also this matches the behavior of the official Flash
player.

Addresses #398.
2020-02-19 23:22:33 -08:00
Mike Welsh 8d7e58011e avm1: undefined coerces to "" in SWFv6 and below
Except in the AVM1 trace op, which will print out "undefined".
2020-02-19 10:47:43 -08:00
Mike Welsh dfde98da7d tests: Add tests for coercing undefined to string in SWF6 2020-02-19 10:47:43 -08:00
Mike Welsh 452ac84f0e tests: Uncomment Number.POSITIVE_INFINITY/Number.NEGATIVE_INFINITY tests 2020-02-18 10:17:55 -08:00
Mike Welsh c073afb077 avm1: Use proper value for Number.MIN_VALUE
This is the smallest positive number, not the most negative value.
This is actually the smallest positive subnormal f64, which Rust
does not provide a constant for. This is ~5e-324.
2020-02-18 10:17:55 -08:00
Mike Welsh 6bbe1dbab8 avm1: Match Flash when converting exotic numbers to string (fix #361)
Match Flash's more closely when converting number to string:
 * NAN -> NaN
 * inf -> Infinity
 * -inf -> -Infinity
 * Use exponential notation for very large/very small

This is a little bit of a cheat by using Rust's number-to-string
formatting for exponentials, and shoving a sign in front of the
exponent.
2020-02-18 10:17:55 -08:00
Mike Welsh 324dd1c5e4 tests: Add swf_tests_approx macro
Use this macro to test numeric calculations that might have some
variance using approx_eq.
2020-02-17 15:42:29 -08:00
Mike Welsh b6249cdb73 tests: Add localToGlobal/globalToLocal test 2020-02-17 15:42:29 -08:00
Mike Welsh 2af21d87e0 avm1: Implement MovieClip.localToGlobal/globalToLocal 2020-02-17 15:42:29 -08:00
Mike Welsh cd94486f7e desktop: Fix stream audio from prematurely ending (fix #222) 2020-02-14 20:32:25 -08:00
Mike Welsh 7c406732c7 audio: Ensure stream sounds stop upon goto/loop (fix #370) 2020-02-14 20:32:25 -08:00
Mike Welsh 9ad069e11a avm1: Improve display object property setters for weird values
Setting a property such as _x to undefined or null should have no
effect. This was working for v7+ SWFs because it would coerce to
NaN and we toss out NaNs. But on v6 and below, these coerce to 0
and would end up setting the property to 0.

Explicitly check for undefined/null and bail out. Fixes #380.

Also adjust the _visible setter, since this actually coerces to a
number (because of its legacy from SWFv4). For example,
_visible = "" should have no effect.
2020-02-14 15:34:14 -08:00
Mike Welsh 3a1a73ae11 tests: Add more tests for display object properties
Add more _x = weirdo value tests, and copy the test into a v6 SWF.
(because undefined etc. can coerce to 0 instead of NaN in SWFv6).
2020-02-14 15:34:14 -08:00
Mike Welsh 7d14b98f3b avm1: Ignore undefined values in Color.setTransform
If a property is not set on the object passed to Color.setTransform,
then that channel is left unmodified. This fixes invisible objects
in some games (fixes #369, addresses #380).

Also improve handling of wrapping/invalid values to better match the
behavior in the Flash Player (some work pending on #193).
2020-02-13 18:06:27 -08:00
Mike Welsh 21f117e7bc avm1: Add Value::coerce_to_i16 2020-02-13 18:06:27 -08:00
Mike Welsh 19df074a79 tests: Add more tests for AVM1 Color object
Include not defined values, wrapping values, invalid values.
2020-02-13 18:06:27 -08:00
David Wendt 18516c8eac Pre-strip HTML from HTML tags, rather than skipping them. 2020-02-03 19:32:05 -05:00
David Wendt 7d225f8b55 Fix overflow when shifting `u8`s 2020-02-03 14:46:36 -05:00
David Wendt 3d6b00c1e4 Impl the remaining text layout properties 2020-02-03 14:46:36 -05:00
David Wendt 517e7ce9ff Add word-wrap for `measure_text` and caching for word-wrap calculations 2020-02-03 14:46:36 -05:00
David Wendt 5e808c8cd6 Adjust the wordwrap machinery to work in break points (indicies where new lines start) so we can cache them later 2020-02-03 14:46:35 -05:00
David Wendt fb8664c818 Implement wordWrap and multiline rendering, poorly 2020-02-03 14:46:35 -05:00
David Wendt 7df8eb7674 Impl `is_multiline`'s effect of respecting newlines 2020-02-03 14:46:35 -05:00
David Wendt f95ec777de Also impl storage of the `wordWrap` flag 2020-02-03 14:46:34 -05:00
David Wendt 819757e2b6 Fix text measurement now that the underlying SWF tags are correctly parsed as `Twips`.
Transform coordinates are always in twips, so we have to convert pixels to twips when evaluating the font, and then convert back when measuring.
2020-02-03 14:46:34 -05:00
David Wendt 63b7d172f4 `TextRecord.height` is also in `Twips`.
Notably, the `Text` rendering code does not appear to actually work in pixel scale.
2020-02-03 14:46:34 -05:00
David Wendt fde7715fb8 `EditText.height` is in `Twips` 2020-02-03 14:46:33 -05:00
David Wendt 75022f36d2 Pull `TextFormat` into the `font` module.
Also, since there's a separate function for attaching virtual properties to an AVM1 `TextField` object, let's use that!
2020-02-03 14:46:33 -05:00
David Wendt 4b3660bf2c Impl get/set for `is_multiline`. 2020-02-03 14:46:32 -05:00
David Wendt c1ff1d94d5 Pull the `EditText.evaluateFont` method into `Font`.
`Text` itself doesn't use this method, but it probably could with some changes.
2020-02-03 14:46:32 -05:00
David Wendt 81b7958090 Impl `textWidth` / `textHeight`, although it currently only works well for single-line scenarios. 2020-02-03 14:46:32 -05:00
David Wendt 2181f0d0d0 Impl `getNewTextFormat`/`setNewTextFormat`.
These don't actually do anything yet, because we don't track text spans, nor do we actually use those text spans to alter rendering or text layout.
2020-02-03 14:46:30 -05:00
David Wendt db56217f20 `TextFormat` does *not* coerce `undefined` or `null`; instead those both become `null`. 2020-02-03 14:46:30 -05:00
David Wendt 8449d964ef Implement `TextFormat` as a property bag. 2020-02-03 14:46:29 -05:00
David Wendt 2b0600ab1a Impl `createTextField`. 2020-02-03 14:46:29 -05:00
Mike Welsh 2ff76775e0 core: Empty movie clips can not be used as a mask
When a movie clip or button is used as a mask, the masking will be
disabled if that object has no children; the maskee will be
completely visible. An empty movie clip inside an empty movie clip
successfully masks.

An EditText can also not be used as a masker (although it can be
wrapped inside a movie clip, and then the text successfully masks).

Add a `TDisplayObject::allow_mask` trait method that will
return whether the object can be used as a mask.

This fixes characters not being visible in Dad 'n' Me.
2020-02-01 01:15:31 -08:00
Mike Welsh 2e304a81ef core: Flag as transformed-by-script after swapDepths 2020-01-31 19:44:42 -08:00
Mike Welsh a55a378a73 avm1: Improve comments in MovieClip depth methods 2020-01-31 19:44:42 -08:00
Mike Welsh 4d1f7c4d4a tests: Add movieclip depth method tests 2020-01-31 19:44:42 -08:00
Mike Welsh a4e175a790 avm1: Implement MovieClip.getNextHighestDepth 2020-01-31 19:44:42 -08:00
Mike Welsh 4d12cd1566 avm1: Implement MovieClip.getDepth 2020-01-31 19:44:42 -08:00
Mike Welsh 9e337ede34 avm1: Implement MovieClip.swapDepths 2020-01-31 19:44:42 -08:00
dependabot-preview[bot] 2f98fd1a0e build(deps-dev): bump webpack-dev-server in /web/selfhosted
Bumps [webpack-dev-server](https://github.com/webpack/webpack-dev-server) from 3.10.1 to 3.10.2.
- [Release notes](https://github.com/webpack/webpack-dev-server/releases)
- [Changelog](https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-dev-server/compare/v3.10.1...v3.10.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-31 19:44:42 -08:00
Mike Welsh 0d91fb423e core: Goto only runs if frame is an integer 2020-01-30 15:17:01 -08:00
Mike Welsh c079cb3bca core: Don't run frame actions when seeking past end of timeline
If you goto past the final loaded frame of a timeline, for example,
with gotoAndStop(9999), this seeks to the final frame on the
timeline, but it doesn't run the actions on this frame.

MovieClip::goto_frame now will not run the final frame actions if
the target frame was not reached.
2020-01-30 15:17:01 -08:00
Mike Welsh 8aae07bbf3 core: Frame labels are case insensitive 2020-01-30 15:17:01 -08:00
Mike Welsh a835573f3c tests: Add test for global GotoFrame action 2020-01-30 15:17:01 -08:00
Mike Welsh 62467bb880 avm1: Handle invalid parameters in GotoFrame2
Use the same code path for the global GotoFrame2 action and
MovieClip.gotoAndX, which properly handles out-of-range and invalid
values like NaN.

Fixes Disorderly hanging on game start
(https://www.newgrounds.com/portal/view/121896)
2020-01-30 15:17:01 -08:00
David Wendt a57d0e12b3 Do not apply a color filter at all unless rendering a bitmap or gradient.
This significantly improves render times, as browsers appear to apply filters in the most general, inefficient way possible.
2020-01-29 14:19:18 -05:00
dependabot-preview[bot] dc8858505d build(deps): bump smallvec from 1.1.0 to 1.2.0
Bumps [smallvec](https://github.com/servo/rust-smallvec) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/servo/rust-smallvec/releases)
- [Commits](https://github.com/servo/rust-smallvec/compare/v1.1.0...v1.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-29 18:42:28 +00:00