avm2: Implement `visible`.

This commit is contained in:
David Wendt 2020-12-02 22:17:49 -05:00 committed by Mike Welsh
parent d489aca377
commit 06ba2f898a
5 changed files with 64 additions and 0 deletions

View File

@ -371,6 +371,38 @@ pub fn root<'gc>(
Ok(Value::Undefined) Ok(Value::Undefined)
} }
/// Implements `visible`'s getter.
pub fn visible<'gc>(
_activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(dobj) = this.and_then(|this| this.as_display_object()) {
return Ok(dobj.visible().into());
}
Ok(Value::Undefined)
}
/// Implements `visible`'s setter.
pub fn set_visible<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
this: Option<Object<'gc>>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(dobj) = this.and_then(|this| this.as_display_object()) {
let new_visible = args
.get(0)
.cloned()
.unwrap_or(Value::Undefined)
.coerce_to_boolean();
dobj.set_visible(activation.context.gc_context, new_visible);
}
Ok(Value::Undefined)
}
/// Construct `DisplayObject`'s class. /// Construct `DisplayObject`'s class.
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
let class = Class::new( let class = Class::new(
@ -463,6 +495,14 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
QName::new(Namespace::package(""), "root"), QName::new(Namespace::package(""), "root"),
Method::from_builtin(root), Method::from_builtin(root),
)); ));
write.define_instance_trait(Trait::from_getter(
QName::new(Namespace::package(""), "visible"),
Method::from_builtin(visible),
));
write.define_instance_trait(Trait::from_setter(
QName::new(Namespace::package(""), "visible"),
Method::from_builtin(set_visible),
));
class class
} }

View File

@ -440,6 +440,7 @@ swf_tests! {
(as3_displayobject_name, "avm2/displayobject_name", 4), (as3_displayobject_name, "avm2/displayobject_name", 4),
(as3_displayobject_parent, "avm2/displayobject_parent", 4), (as3_displayobject_parent, "avm2/displayobject_parent", 4),
(as3_displayobject_root, "avm2/displayobject_root", 4), (as3_displayobject_root, "avm2/displayobject_root", 4),
(as3_displayobject_visible, "avm2/displayobject_visible", 4),
} }
// TODO: These tests have some inaccuracies currently, so we use approx_eq to test that numeric values are close enough. // TODO: These tests have some inaccuracies currently, so we use approx_eq to test that numeric values are close enough.

View File

@ -0,0 +1,23 @@
//this.visible (Timeline)
true
//this.visible (Symbol 1)
true
//this.visible = false;
//this.visible;
false
//this.visible (Symbol 1)
true
//this.visible = false;
//this.visible;
false
//this.visible (Symbol 2)
true
//this.visible = false;
//this.visible;
false
//var s1 = new MovieClip();
//s1.visible;
true
//this.addChild(s1);
//s1.visible;
true

Binary file not shown.

Binary file not shown.