avm2: Implement `currentFrameLabel` and `currentFrame`.
This commit is contained in:
parent
6124ed468f
commit
7ca34452a1
|
@ -5,6 +5,7 @@ use crate::avm2::class::Class;
|
||||||
use crate::avm2::method::Method;
|
use crate::avm2::method::Method;
|
||||||
use crate::avm2::names::{Namespace, QName};
|
use crate::avm2::names::{Namespace, QName};
|
||||||
use crate::avm2::object::{Object, TObject};
|
use crate::avm2::object::{Object, TObject};
|
||||||
|
use crate::avm2::string::AvmString;
|
||||||
use crate::avm2::traits::Trait;
|
use crate::avm2::traits::Trait;
|
||||||
use crate::avm2::value::Value;
|
use crate::avm2::value::Value;
|
||||||
use crate::avm2::Error;
|
use crate::avm2::Error;
|
||||||
|
@ -64,7 +65,7 @@ pub fn current_frame<'gc>(
|
||||||
.and_then(|dobj| dobj.as_movie_clip())
|
.and_then(|dobj| dobj.as_movie_clip())
|
||||||
{
|
{
|
||||||
if let Some((_scene, scene_basis)) = mc.current_scene() {
|
if let Some((_scene, scene_basis)) = mc.current_scene() {
|
||||||
return Ok((mc.current_frame() - scene_basis + 1).into());
|
return Ok(((mc.current_frame() + 1) - scene_basis).into());
|
||||||
} else {
|
} else {
|
||||||
return Ok(mc.current_frame().into());
|
return Ok(mc.current_frame().into());
|
||||||
}
|
}
|
||||||
|
@ -73,6 +74,52 @@ pub fn current_frame<'gc>(
|
||||||
Ok(Value::Undefined)
|
Ok(Value::Undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements `currentFrameLabel`.
|
||||||
|
pub fn current_frame_label<'gc>(
|
||||||
|
activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
this: Option<Object<'gc>>,
|
||||||
|
_args: &[Value<'gc>],
|
||||||
|
) -> Result<Value<'gc>, Error> {
|
||||||
|
if let Some(mc) = this
|
||||||
|
.and_then(|o| o.as_display_object())
|
||||||
|
.and_then(|dobj| dobj.as_movie_clip())
|
||||||
|
{
|
||||||
|
return Ok(mc
|
||||||
|
.current_label()
|
||||||
|
.and_then(|(label, start_frame)| {
|
||||||
|
if start_frame < mc.current_frame() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(AvmString::new(activation.context.gc_context, label).into())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or(Value::Null));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Undefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implements `currentLabel`.
|
||||||
|
pub fn current_label<'gc>(
|
||||||
|
activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
this: Option<Object<'gc>>,
|
||||||
|
_args: &[Value<'gc>],
|
||||||
|
) -> Result<Value<'gc>, Error> {
|
||||||
|
if let Some(mc) = this
|
||||||
|
.and_then(|o| o.as_display_object())
|
||||||
|
.and_then(|dobj| dobj.as_movie_clip())
|
||||||
|
{
|
||||||
|
return Ok(mc
|
||||||
|
.current_label()
|
||||||
|
.map(|(label, _start_frame)| {
|
||||||
|
AvmString::new(activation.context.gc_context, label).into()
|
||||||
|
})
|
||||||
|
.unwrap_or(Value::Null));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Undefined)
|
||||||
|
}
|
||||||
|
|
||||||
/// Construct `MovieClip`'s class.
|
/// Construct `MovieClip`'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(
|
||||||
|
@ -95,5 +142,15 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
|
||||||
Method::from_builtin(current_frame),
|
Method::from_builtin(current_frame),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
write.define_instance_trait(Trait::from_getter(
|
||||||
|
QName::new(Namespace::package(""), "currentFrameLabel"),
|
||||||
|
Method::from_builtin(current_frame_label),
|
||||||
|
));
|
||||||
|
|
||||||
|
write.define_instance_trait(Trait::from_getter(
|
||||||
|
QName::new(Namespace::package(""), "currentLabel"),
|
||||||
|
Method::from_builtin(current_label),
|
||||||
|
));
|
||||||
|
|
||||||
class
|
class
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue