2019-08-30 23:25:04 +00:00
|
|
|
use crate::avm1::object::Object;
|
|
|
|
use crate::avm1::Value;
|
|
|
|
use crate::movie_clip::MovieClip;
|
|
|
|
use gc_arena::MutationContext;
|
|
|
|
|
|
|
|
macro_rules! with_movie_clip {
|
|
|
|
( $gc_context: ident, $object:ident, $($name:expr => $fn:expr),* ) => {{
|
|
|
|
$(
|
|
|
|
$object.set_function(
|
|
|
|
$name,
|
2019-09-03 00:44:24 +00:00
|
|
|
|_avm, _context, this, args| -> Value<'gc> {
|
2019-08-30 23:25:04 +00:00
|
|
|
if let Some(display_object) = this.read().display_node() {
|
|
|
|
if let Some(movie_clip) = display_object.read().as_movie_clip() {
|
|
|
|
return $fn(movie_clip, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Value::Undefined
|
|
|
|
},
|
|
|
|
$gc_context,
|
|
|
|
);
|
|
|
|
)*
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! with_movie_clip_mut {
|
|
|
|
( $gc_context: ident, $object:ident, $($name:expr => $fn:expr),* ) => {{
|
|
|
|
$(
|
|
|
|
$object.set_function(
|
|
|
|
$name,
|
2019-09-03 00:44:24 +00:00
|
|
|
|_avm, context, this, args| -> Value<'gc> {
|
2019-08-30 23:25:04 +00:00
|
|
|
if let Some(display_object) = this.read().display_node() {
|
2019-09-02 17:28:38 +00:00
|
|
|
if let Some(movie_clip) = display_object.write(context.gc_context).as_movie_clip_mut() {
|
2019-08-30 23:25:04 +00:00
|
|
|
return $fn(movie_clip, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Value::Undefined
|
|
|
|
},
|
|
|
|
$gc_context,
|
|
|
|
);
|
|
|
|
)*
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create_movie_object<'gc>(gc_context: MutationContext<'gc, '_>) -> Object<'gc> {
|
2019-08-31 15:54:15 +00:00
|
|
|
let mut object = Object::object(gc_context);
|
2019-08-30 23:25:04 +00:00
|
|
|
|
|
|
|
with_movie_clip_mut!(
|
|
|
|
gc_context,
|
|
|
|
object,
|
|
|
|
"nextFrame" => |movie_clip: &mut MovieClip, _args| {
|
|
|
|
movie_clip.next_frame();
|
|
|
|
Value::Undefined
|
|
|
|
},
|
|
|
|
"prevFrame" => |movie_clip: &mut MovieClip, _args| {
|
|
|
|
movie_clip.prev_frame();
|
|
|
|
Value::Undefined
|
|
|
|
},
|
|
|
|
"play" => |movie_clip: &mut MovieClip, _args| {
|
|
|
|
movie_clip.play();
|
|
|
|
Value::Undefined
|
|
|
|
},
|
|
|
|
"stop" => |movie_clip: &mut MovieClip, _args| {
|
|
|
|
movie_clip.stop();
|
|
|
|
Value::Undefined
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
with_movie_clip!(
|
|
|
|
gc_context,
|
|
|
|
object,
|
|
|
|
"getBytesLoaded" => |_movie_clip: &MovieClip, _args| {
|
|
|
|
// TODO find a correct value
|
|
|
|
Value::Number(0.0)
|
|
|
|
},
|
|
|
|
"getBytesTotal" => |_movie_clip: &MovieClip, _args| {
|
|
|
|
// TODO find a correct value
|
|
|
|
Value::Number(0.0)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
object
|
|
|
|
}
|