core: Assign default name to unnamed clips (fix #66)

This commit is contained in:
Mike Welsh 2020-06-17 18:18:40 -07:00
parent 3faa48e599
commit 62cfeb3754
8 changed files with 30 additions and 0 deletions

View File

@ -760,9 +760,11 @@ mod tests {
player: None,
load_manager: &mut LoadManager::new(),
system: &mut SystemProperties::default(),
instance_counter: &mut 0,
};
root.post_instantiation(&mut avm, &mut context, root, None, false);
root.set_name(context.gc_context, "");
let object = ScriptObject::object(gc_context, Some(avm.prototypes().object)).into();

View File

@ -59,8 +59,10 @@ where
player: None,
load_manager: &mut LoadManager::new(),
system: &mut SystemProperties::default(),
instance_counter: &mut 0,
};
root.post_instantiation(&mut avm, &mut context, root, None, false);
root.set_name(context.gc_context, "");
let globals = avm.global_object_cell();
avm.insert_stack_frame(GcCell::allocate(

View File

@ -100,6 +100,9 @@ pub struct UpdateContext<'a, 'gc, 'gc_context> {
/// The system properties
pub system: &'a mut SystemProperties,
/// The current instance ID. Used to generate default `instanceN` names.
pub instance_counter: &'a mut i32,
}
/// A queued ActionScript call.

View File

@ -889,6 +889,15 @@ pub trait TDisplayObject<'gc>: 'gc + Collect + Debug + Into<DisplayObject<'gc>>
})
.expect("All objects must have root")
}
/// Assigns a default instance name `instanceN` to this object.
fn set_default_instance_name(&mut self, context: &mut UpdateContext<'_, 'gc, '_>) {
if self.name().is_empty() {
let name = format!("instance{}", *context.instance_counter);
self.set_name(context.gc_context, &name);
*context.instance_counter = context.instance_counter.wrapping_add(1);
}
}
}
pub enum DisplayObjectPtr {}

View File

@ -124,6 +124,8 @@ impl<'gc> TDisplayObject<'gc> for Button<'gc> {
_init_object: Option<Object<'gc>>,
_instantiated_from_avm: bool,
) {
self.set_default_instance_name(context);
let mut mc = self.0.write(context.gc_context);
if mc.object.is_none() {
let object = StageObject::for_display_object(

View File

@ -435,6 +435,8 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
_init_object: Option<Object<'gc>>,
_instantiated_from_avm: bool,
) {
self.set_default_instance_name(context);
let mut text = self.0.write(context.gc_context);
if text.object.is_none() {
let object = StageObject::for_display_object(

View File

@ -722,6 +722,8 @@ impl<'gc> TDisplayObject<'gc> for MovieClip<'gc> {
init_object: Option<Object<'gc>>,
instantiated_from_avm: bool,
) {
self.set_default_instance_name(context);
if self.0.read().object.is_none() {
// If we are running within the AVM, this must be an immediate action.
// If we are not, then this must be queued to be ran first-thing

View File

@ -139,6 +139,9 @@ pub struct Player {
system: SystemProperties,
/// The current instance ID. Used to generate default `instanceN` names.
instance_counter: i32,
/// Self-reference to ourselves.
///
/// This is a weak reference that is upgraded and handed out in various
@ -238,6 +241,7 @@ impl Player {
input,
self_reference: None,
system: SystemProperties::default(),
instance_counter: 0,
};
player.mutate_with_update_context(|avm, context| {
@ -245,6 +249,7 @@ impl Player {
MovieClip::from_movie(context.gc_context, movie.clone()).into();
root.set_depth(context.gc_context, 0);
root.post_instantiation(avm, context, root, None, false);
root.set_name(context.gc_context, "");
context.levels.insert(0, root);
if let Ok(object) = root.object().as_object() {
@ -846,6 +851,7 @@ impl Player {
stage_height,
player,
system_properties,
instance_counter,
) = (
self.player_version,
self.global_time,
@ -861,6 +867,7 @@ impl Player {
Twips::from_pixels(self.movie_height.into()),
self.self_reference.clone(),
&mut self.system,
&mut self.instance_counter,
);
self.gc_arena.mutate(|gc_context, gc_root| {
@ -891,6 +898,7 @@ impl Player {
player,
load_manager,
system: system_properties,
instance_counter,
};
let ret = f(avm, &mut update_context);