Basic, stub implementation of `MovieClipLoader.getProgress`, plus test.
This implementation just returns the size of the current loaded movie. The test is also deliberately written to be loose on timings so that it likely won't see a partially loaded movie. (I don't want it to be a test of load events, so I just wait a few frames, rather than the correct way of waiting for `onLoadComplete`.) Until we support streaming file loads, we can't faithfully support these properties. Still, it's better to have them, just in case.
This commit is contained in:
parent
3f7e3a9ed8
commit
c00ecccd1f
|
@ -189,6 +189,46 @@ pub fn unload_clip<'gc>(
|
||||||
Ok(false.into())
|
Ok(false.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_progress<'gc>(
|
||||||
|
_avm: &mut Avm1<'gc>,
|
||||||
|
context: &mut UpdateContext<'_, 'gc, '_>,
|
||||||
|
_this: Object<'gc>,
|
||||||
|
args: &[Value<'gc>],
|
||||||
|
) -> Result<ReturnValue<'gc>, Error> {
|
||||||
|
let target = args.get(0).cloned().unwrap_or(Value::Undefined);
|
||||||
|
|
||||||
|
if let Value::Object(target) = target {
|
||||||
|
if let Some(movieclip) = target
|
||||||
|
.as_display_object()
|
||||||
|
.and_then(|dobj| dobj.as_movie_clip())
|
||||||
|
{
|
||||||
|
let ret_obj = ScriptObject::object(context.gc_context, None);
|
||||||
|
ret_obj.define_value(
|
||||||
|
context.gc_context,
|
||||||
|
"bytesLoaded",
|
||||||
|
movieclip
|
||||||
|
.movie()
|
||||||
|
.map(|mv| (mv.data().len() + 21).into())
|
||||||
|
.unwrap_or(Value::Undefined),
|
||||||
|
EnumSet::empty(),
|
||||||
|
);
|
||||||
|
ret_obj.define_value(
|
||||||
|
context.gc_context,
|
||||||
|
"bytesTotal",
|
||||||
|
movieclip
|
||||||
|
.movie()
|
||||||
|
.map(|mv| (mv.data().len() + 21).into())
|
||||||
|
.unwrap_or(Value::Undefined),
|
||||||
|
EnumSet::empty(),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Ok(ret_obj.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Undefined.into())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_proto<'gc>(
|
pub fn create_proto<'gc>(
|
||||||
gc_context: MutationContext<'gc, '_>,
|
gc_context: MutationContext<'gc, '_>,
|
||||||
proto: Object<'gc>,
|
proto: Object<'gc>,
|
||||||
|
@ -231,6 +271,13 @@ pub fn create_proto<'gc>(
|
||||||
EnumSet::empty(),
|
EnumSet::empty(),
|
||||||
Some(fn_proto),
|
Some(fn_proto),
|
||||||
);
|
);
|
||||||
|
mcl_proto.as_script_object().unwrap().force_set_function(
|
||||||
|
"getProgress",
|
||||||
|
get_progress,
|
||||||
|
gc_context,
|
||||||
|
EnumSet::empty(),
|
||||||
|
Some(fn_proto),
|
||||||
|
);
|
||||||
|
|
||||||
mcl_proto.into()
|
mcl_proto.into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,7 @@ swf_tests! {
|
||||||
(unloadmovie_method, "avm1/unloadmovie_method", 11),
|
(unloadmovie_method, "avm1/unloadmovie_method", 11),
|
||||||
(mcl_loadclip, "avm1/mcl_loadclip", 11),
|
(mcl_loadclip, "avm1/mcl_loadclip", 11),
|
||||||
(mcl_unloadclip, "avm1/mcl_unloadclip", 11),
|
(mcl_unloadclip, "avm1/mcl_unloadclip", 11),
|
||||||
|
(mcl_getprogress, "avm1/mcl_getprogress", 6),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Child movie loaded!
|
||||||
|
68
|
||||||
|
68
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue