avm2: Stub `flash.display.Shape`.
This commit is contained in:
parent
d157a9995b
commit
a5b4e168d3
|
@ -101,6 +101,7 @@ pub struct SystemPrototypes<'gc> {
|
||||||
pub xml: Object<'gc>,
|
pub xml: Object<'gc>,
|
||||||
pub xml_list: Object<'gc>,
|
pub xml_list: Object<'gc>,
|
||||||
pub display_object: Object<'gc>,
|
pub display_object: Object<'gc>,
|
||||||
|
pub shape: Object<'gc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'gc> SystemPrototypes<'gc> {
|
impl<'gc> SystemPrototypes<'gc> {
|
||||||
|
@ -138,6 +139,7 @@ impl<'gc> SystemPrototypes<'gc> {
|
||||||
xml: empty,
|
xml: empty,
|
||||||
xml_list: empty,
|
xml_list: empty,
|
||||||
display_object: empty,
|
display_object: empty,
|
||||||
|
shape: empty,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -553,6 +555,19 @@ pub fn load_player_globals<'gc>(
|
||||||
domain,
|
domain,
|
||||||
script,
|
script,
|
||||||
)?;
|
)?;
|
||||||
|
activation
|
||||||
|
.context
|
||||||
|
.avm2
|
||||||
|
.system_prototypes
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.shape = class(
|
||||||
|
activation,
|
||||||
|
flash::display::shape::create_class(mc),
|
||||||
|
implicit_deriver,
|
||||||
|
domain,
|
||||||
|
script,
|
||||||
|
)?;
|
||||||
class(
|
class(
|
||||||
activation,
|
activation,
|
||||||
flash::display::interactiveobject::create_class(mc),
|
flash::display::interactiveobject::create_class(mc),
|
||||||
|
|
|
@ -6,4 +6,5 @@ pub mod framelabel;
|
||||||
pub mod interactiveobject;
|
pub mod interactiveobject;
|
||||||
pub mod movieclip;
|
pub mod movieclip;
|
||||||
pub mod scene;
|
pub mod scene;
|
||||||
|
pub mod shape;
|
||||||
pub mod sprite;
|
pub mod sprite;
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
//! `flash.display.Shape` builtin/prototype
|
||||||
|
|
||||||
|
use crate::avm2::activation::Activation;
|
||||||
|
use crate::avm2::class::Class;
|
||||||
|
use crate::avm2::method::Method;
|
||||||
|
use crate::avm2::names::{Namespace, QName};
|
||||||
|
use crate::avm2::object::Object;
|
||||||
|
use crate::avm2::value::Value;
|
||||||
|
use crate::avm2::Error;
|
||||||
|
use gc_arena::{GcCell, MutationContext};
|
||||||
|
|
||||||
|
/// Implements `flash.display.Shape`'s instance constructor.
|
||||||
|
pub fn instance_init<'gc>(
|
||||||
|
activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
this: Option<Object<'gc>>,
|
||||||
|
_args: &[Value<'gc>],
|
||||||
|
) -> Result<Value<'gc>, Error> {
|
||||||
|
if let Some(this) = this {
|
||||||
|
activation.super_init(this, &[])?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Undefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implements `flash.display.Shape`'s class constructor.
|
||||||
|
pub fn class_init<'gc>(
|
||||||
|
_activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
_this: Option<Object<'gc>>,
|
||||||
|
_args: &[Value<'gc>],
|
||||||
|
) -> Result<Value<'gc>, Error> {
|
||||||
|
Ok(Value::Undefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct `Shape`'s class.
|
||||||
|
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
|
||||||
|
Class::new(
|
||||||
|
QName::new(Namespace::package("flash.display"), "Shape"),
|
||||||
|
Some(QName::new(Namespace::package("flash.display"), "DisplayObject").into()),
|
||||||
|
Method::from_builtin(instance_init),
|
||||||
|
Method::from_builtin(class_init),
|
||||||
|
mc,
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,9 +1,16 @@
|
||||||
|
use crate::avm1::Object as Avm1Object;
|
||||||
|
use crate::avm2::{
|
||||||
|
Activation as Avm2Activation, Error as Avm2Error, Namespace as Avm2Namespace,
|
||||||
|
Object as Avm2Object, QName as Avm2QName, StageObject as Avm2StageObject,
|
||||||
|
TObject as Avm2TObject,
|
||||||
|
};
|
||||||
use crate::backend::render::ShapeHandle;
|
use crate::backend::render::ShapeHandle;
|
||||||
use crate::context::{RenderContext, UpdateContext};
|
use crate::context::{RenderContext, UpdateContext};
|
||||||
use crate::display_object::{DisplayObjectBase, TDisplayObject};
|
use crate::display_object::{DisplayObjectBase, TDisplayObject};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::tag_utils::SwfMovie;
|
use crate::tag_utils::SwfMovie;
|
||||||
use crate::types::{Degrees, Percent};
|
use crate::types::{Degrees, Percent};
|
||||||
|
use crate::vminterface::{AvmType, Instantiator};
|
||||||
use gc_arena::{Collect, GcCell};
|
use gc_arena::{Collect, GcCell};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -16,6 +23,7 @@ pub struct Graphic<'gc>(GcCell<'gc, GraphicData<'gc>>);
|
||||||
pub struct GraphicData<'gc> {
|
pub struct GraphicData<'gc> {
|
||||||
base: DisplayObjectBase<'gc>,
|
base: DisplayObjectBase<'gc>,
|
||||||
static_data: gc_arena::Gc<'gc, GraphicStatic>,
|
static_data: gc_arena::Gc<'gc, GraphicStatic>,
|
||||||
|
avm2_object: Option<Avm2Object<'gc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'gc> Graphic<'gc> {
|
impl<'gc> Graphic<'gc> {
|
||||||
|
@ -38,6 +46,7 @@ impl<'gc> Graphic<'gc> {
|
||||||
GraphicData {
|
GraphicData {
|
||||||
base: Default::default(),
|
base: Default::default(),
|
||||||
static_data: gc_arena::Gc::allocate(context.gc_context, static_data),
|
static_data: gc_arena::Gc::allocate(context.gc_context, static_data),
|
||||||
|
avm2_object: None,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -96,6 +105,57 @@ impl<'gc> TDisplayObject<'gc> for Graphic<'gc> {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn post_instantiation(
|
||||||
|
&self,
|
||||||
|
context: &mut UpdateContext<'_, 'gc, '_>,
|
||||||
|
display_object: DisplayObject<'gc>,
|
||||||
|
_init_object: Option<Avm1Object<'gc>>,
|
||||||
|
_instantiated_by: Instantiator,
|
||||||
|
run_frame: bool,
|
||||||
|
) {
|
||||||
|
if self.vm_type(context) == AvmType::Avm2 {
|
||||||
|
let mut allocator = || {
|
||||||
|
let mut activation = Avm2Activation::from_nothing(context.reborrow());
|
||||||
|
let mut proto = activation.context.avm2.prototypes().shape;
|
||||||
|
let constr = proto
|
||||||
|
.get_property(
|
||||||
|
proto,
|
||||||
|
&Avm2QName::new(Avm2Namespace::public(), "constructor"),
|
||||||
|
&mut activation,
|
||||||
|
)?
|
||||||
|
.coerce_to_object(&mut activation)?;
|
||||||
|
|
||||||
|
let object = Avm2StageObject::for_display_object(
|
||||||
|
activation.context.gc_context,
|
||||||
|
display_object,
|
||||||
|
proto,
|
||||||
|
)
|
||||||
|
.into();
|
||||||
|
constr.call(Some(object), &[], &mut activation, Some(proto))?;
|
||||||
|
|
||||||
|
Ok(object)
|
||||||
|
};
|
||||||
|
let result: Result<Avm2Object<'gc>, Avm2Error> = allocator();
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(object) => self.0.write(context.gc_context).avm2_object = Some(object),
|
||||||
|
Err(e) => log::error!("Got {} when constructing AVM2 side of display object", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if run_frame {
|
||||||
|
self.run_frame(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn object2(&self) -> Avm2Value<'gc> {
|
||||||
|
self.0
|
||||||
|
.read()
|
||||||
|
.avm2_object
|
||||||
|
.map(Avm2Value::from)
|
||||||
|
.unwrap_or(Avm2Value::Undefined)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Static data shared between all instances of a graphic.
|
/// Static data shared between all instances of a graphic.
|
||||||
|
|
Loading…
Reference in New Issue