core: Add `DisplayObject` method for setting the AVM2 side of a display object

This commit is contained in:
David Wendt 2021-04-09 22:30:54 -04:00 committed by Mike Welsh
parent 9b19cc1570
commit 815d0fb540
5 changed files with 21 additions and 1 deletions

View File

@ -1,7 +1,9 @@
use crate::avm1::{
Error as Avm1Error, Object as Avm1Object, TObject as Avm1TObject, Value as Avm1Value,
};
use crate::avm2::{Avm2, Event as Avm2Event, TObject as Avm2TObject, Value as Avm2Value};
use crate::avm2::{
Avm2, Event as Avm2Event, Object as Avm2Object, TObject as Avm2TObject, Value as Avm2Value,
};
use crate::context::{RenderContext, UpdateContext};
use crate::drawing::Drawing;
use crate::player::NEWEST_PLAYER_VERSION;
@ -1072,6 +1074,8 @@ pub trait TDisplayObject<'gc>:
Avm2Value::Undefined // todo: see above
}
fn set_object2(&mut self, _mc: MutationContext<'gc, '_>, _to: Avm2Object<'gc>) {}
/// Tests if a given stage position point intersects with the world bounds of this object.
fn hit_test_bounds(&self, pos: (Twips, Twips)) -> bool {
self.world_bounds().contains(pos)

View File

@ -1401,6 +1401,10 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
.unwrap_or(Avm2Value::Undefined)
}
fn set_object2(&mut self, mc: MutationContext<'gc, '_>, to: Avm2Object<'gc>) {
self.0.write(mc).object = Some(to.into());
}
fn self_bounds(&self) -> BoundingBox {
self.0.read().bounds.clone()
}

View File

@ -209,6 +209,10 @@ impl<'gc> TDisplayObject<'gc> for Graphic<'gc> {
.unwrap_or(Avm2Value::Undefined)
}
fn set_object2(&mut self, mc: MutationContext<'gc, '_>, to: Avm2Object<'gc>) {
self.0.write(mc).avm2_object = Some(to);
}
fn as_drawing(&self, gc_context: MutationContext<'gc, '_>) -> Option<RefMut<'_, Drawing>> {
let mut write = self.0.write(gc_context);
if write.drawing.is_none() {

View File

@ -2064,6 +2064,10 @@ impl<'gc> TDisplayObject<'gc> for MovieClip<'gc> {
.unwrap_or(Avm2Value::Undefined)
}
fn set_object2(&mut self, mc: MutationContext<'gc, '_>, to: Avm2Object<'gc>) {
self.0.write(mc).object = Some(to.into());
}
fn unload(&self, context: &mut UpdateContext<'_, 'gc, '_>) {
for child in self.iter_execution_list() {
child.unload(context);

View File

@ -424,4 +424,8 @@ impl<'gc> TDisplayObject<'gc> for Video<'gc> {
context.transform_stack.pop();
}
fn set_object2(&mut self, mc: MutationContext<'gc, '_>, to: Avm2Object<'gc>) {
self.0.write(mc).object = Some(to.into());
}
}