Skip to content

Commit

Permalink
core: Use unnamed field in Character::Bitmap
Browse files Browse the repository at this point in the history
Since `initial_data` was removed from `Character::Bitmap` in ruffle-rs#9143,
it now holds a single field. Move back to an unnamed field, which
aligns with the other `Character` enum variants.
  • Loading branch information
relrelb committed Feb 16, 2023
1 parent 43628fd commit 694e316
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
11 changes: 4 additions & 7 deletions core/src/avm1/globals/bitmap_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,19 +1309,16 @@ pub fn load_bitmap<'gc>(
.library_for_movie(movie)
.and_then(|l| l.character_by_export_name(name));

if let Some(Character::Bitmap {
bitmap: bitmap_object,
}) = character
{
if let Some(Character::Bitmap(bitmap)) = character {
let new_bitmap_data = BitmapDataObject::empty_object(
activation.context.gc_context,
activation.context.avm1.prototypes().bitmap_data,
);

let width = bitmap_object.width() as u32;
let height = bitmap_object.height() as u32;
let width = bitmap.width() as u32;
let height = bitmap.height() as u32;

let pixels: Vec<_> = bitmap_object.bitmap_data().read().pixels().to_vec();
let pixels: Vec<_> = bitmap.bitmap_data().read().pixels().to_vec();

new_bitmap_data
.as_bitmap_data_object()
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm2/globals/flash/display/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn instance_init<'gc>(
.avm2_class_registry()
.class_symbol(b_class)
{
if let Some(Character::Bitmap { bitmap }) = activation
if let Some(Character::Bitmap(bitmap)) = activation
.context
.library
.library_for_movie_mut(movie)
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm2/globals/flash/display/bitmapdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn instance_init<'gc>(
let new_bitmap_data =
GcCell::allocate(activation.context.gc_context, BitmapData::default());

if let Some(Character::Bitmap { bitmap }) = character {
if let Some(Character::Bitmap(bitmap)) = character {
// Instantiating BitmapData from an Animate-style bitmap asset
fill_bitmap_data_from_symbol(activation, bitmap, new_bitmap_data);
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/src/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Character<'gc> {
EditText(EditText<'gc>),
Graphic(Graphic<'gc>),
MovieClip(MovieClip<'gc>),
Bitmap { bitmap: Bitmap<'gc> },
Bitmap(Bitmap<'gc>),
Avm1Button(Avm1Button<'gc>),
Avm2Button(Avm2Button<'gc>),
Font(Font<'gc>),
Expand Down
10 changes: 5 additions & 5 deletions core/src/display_object/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ impl<'gc> MovieClip<'gc> {
Some(Character::BinaryData(_)) => {}
Some(Character::Font(_)) => {}
Some(Character::Sound(_)) => {}
Some(Character::Bitmap { bitmap, .. }) => {
Some(Character::Bitmap(bitmap)) => {
bitmap.set_avm2_bitmapdata_class(
&mut activation.context,
class_object,
Expand Down Expand Up @@ -3015,7 +3015,7 @@ impl<'gc, 'a> MovieClipData<'gc> {
context
.library
.library_for_movie_mut(self.movie())
.register_character(define_bits_lossless.id, Character::Bitmap { bitmap });
.register_character(define_bits_lossless.id, Character::Bitmap(bitmap));
Ok(())
}

Expand Down Expand Up @@ -3132,7 +3132,7 @@ impl<'gc, 'a> MovieClipData<'gc> {
context
.library
.library_for_movie_mut(self.movie())
.register_character(id, Character::Bitmap { bitmap });
.register_character(id, Character::Bitmap(bitmap));
Ok(())
}

Expand All @@ -3149,7 +3149,7 @@ impl<'gc, 'a> MovieClipData<'gc> {
context
.library
.library_for_movie_mut(self.movie())
.register_character(id, Character::Bitmap { bitmap });
.register_character(id, Character::Bitmap(bitmap));
Ok(())
}

Expand All @@ -3172,7 +3172,7 @@ impl<'gc, 'a> MovieClipData<'gc> {
context
.library
.library_for_movie_mut(self.movie())
.register_character(id, Character::Bitmap { bitmap });
.register_character(id, Character::Bitmap(bitmap));
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'gc> MovieLibrary<'gc> {
gc_context: MutationContext<'gc, '_>,
) -> Result<DisplayObject<'gc>, &'static str> {
match character {
Character::Bitmap { bitmap } => Ok(bitmap.instantiate(gc_context)),
Character::Bitmap(bitmap) => Ok(bitmap.instantiate(gc_context)),
Character::EditText(edit_text) => Ok(edit_text.instantiate(gc_context)),
Character::Graphic(graphic) => Ok(graphic.instantiate(gc_context)),
Character::MorphShape(morph_shape) => Ok(morph_shape.instantiate(gc_context)),
Expand All @@ -218,7 +218,7 @@ impl<'gc> MovieLibrary<'gc> {
}

pub fn get_bitmap(&self, id: CharacterId) -> Option<Bitmap<'gc>> {
if let Some(&Character::Bitmap { bitmap, .. }) = self.characters.get(&id) {
if let Some(&Character::Bitmap(bitmap)) = self.characters.get(&id) {
Some(bitmap)
} else {
None
Expand Down

0 comments on commit 694e316

Please sign in to comment.