Skip to content

Commit d7532ae

Browse files
Aaron1011Herschel
authored andcommitted
avm2: Add stubs for BitmapFilter, GlowFilter, and DisplayObject.filters
This gets 'Rolling Hero' further in the startup process, since it just tries to set a filter on an object.
1 parent 6649244 commit d7532ae

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed

core/src/avm2/globals.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,18 @@ pub fn load_player_globals<'gc>(
828828
script,
829829
)?;
830830

831+
// package `flash.filters`
832+
class(
833+
activation,
834+
flash::filters::bitmapfilter::create_class(mc),
835+
script,
836+
)?;
837+
class(
838+
activation,
839+
flash::filters::glowfilter::create_class(mc),
840+
script,
841+
)?;
842+
831843
// package `flash.geom`
832844
class(activation, flash::geom::matrix::create_class(mc), script)?;
833845
avm2_system_class!(

core/src/avm2/globals/flash.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod crypto;
44
pub mod display;
55
pub mod events;
66
pub mod external;
7+
pub mod filters;
78
pub mod geom;
89
pub mod media;
910
pub mod net;

core/src/avm2/globals/flash/display/displayobject.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,26 @@ pub fn set_scale_x<'gc>(
236236
Ok(Value::Undefined)
237237
}
238238

239+
/// Implements `filters`'s getter.
240+
pub fn filters<'gc>(
241+
_activation: &mut Activation<'_, 'gc, '_>,
242+
_this: Option<Object<'gc>>,
243+
_args: &[Value<'gc>],
244+
) -> Result<Value<'gc>, Error> {
245+
log::warn!("DisplayObject.filters getter - not yet implemented");
246+
Ok(Value::Undefined)
247+
}
248+
249+
/// Implements `filters`'s setter.
250+
pub fn set_filters<'gc>(
251+
_activation: &mut Activation<'_, 'gc, '_>,
252+
_this: Option<Object<'gc>>,
253+
_args: &[Value<'gc>],
254+
) -> Result<Value<'gc>, Error> {
255+
log::warn!("DisplayObject.filters setter - not yet implemented");
256+
Ok(Value::Undefined)
257+
}
258+
239259
/// Implements `x`'s getter.
240260
pub fn x<'gc>(
241261
_activation: &mut Activation<'_, 'gc, '_>,
@@ -618,6 +638,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>
618638
("mouseX", Some(mouse_x), None),
619639
("mouseY", Some(mouse_y), None),
620640
("loaderInfo", Some(loader_info), None),
641+
("filters", Some(filters), Some(set_filters)),
621642
];
622643
write.define_public_builtin_instance_properties(mc, PUBLIC_INSTANCE_PROPERTIES);
623644

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! `flash.filters` namespace
2+
3+
pub mod bitmapfilter;
4+
pub mod glowfilter;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! `flash.filters.BitmapFilter` builtin/prototype
2+
3+
use crate::avm2::activation::Activation;
4+
use crate::avm2::class::Class;
5+
use crate::avm2::method::Method;
6+
use crate::avm2::names::{Namespace, QName};
7+
use crate::avm2::value::Value;
8+
use crate::avm2::{Error, Object};
9+
use gc_arena::{GcCell, MutationContext};
10+
11+
/// Implements `flash.filters.BitmapFilter`'s class constructor.
12+
pub fn class_init<'gc>(
13+
_activation: &mut Activation<'_, 'gc, '_>,
14+
_this: Option<Object<'gc>>,
15+
_args: &[Value<'gc>],
16+
) -> Result<Value<'gc>, Error> {
17+
Ok(Value::Undefined)
18+
}
19+
20+
/// Implements `flash.filters.BitmapFilter`'s instance constructor.
21+
pub fn instance_init<'gc>(
22+
_activation: &mut Activation<'_, 'gc, '_>,
23+
_this: Option<Object<'gc>>,
24+
_args: &[Value<'gc>],
25+
) -> Result<Value<'gc>, Error> {
26+
Ok(Value::Undefined)
27+
}
28+
29+
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
30+
let class = Class::new(
31+
QName::new(Namespace::package("flash.filters"), "BitmapFilter"),
32+
Some(QName::new(Namespace::public(), "Object").into()),
33+
Method::from_builtin(instance_init, "<BitmapFilter instance initializer>", mc),
34+
Method::from_builtin(class_init, "<BitmapFilter class initializer>", mc),
35+
mc,
36+
);
37+
38+
class
39+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//! `flash.filters.GlowFilter` builtin/prototype
2+
3+
use crate::avm2::activation::Activation;
4+
use crate::avm2::class::{Class, ClassAttributes};
5+
use crate::avm2::method::Method;
6+
use crate::avm2::names::{Namespace, QName};
7+
use crate::avm2::value::Value;
8+
use crate::avm2::{Error, Object};
9+
use gc_arena::{GcCell, MutationContext};
10+
11+
/// Implements `flash.filters.GlowFilter`'s class constructor.
12+
pub fn class_init<'gc>(
13+
_activation: &mut Activation<'_, 'gc, '_>,
14+
_this: Option<Object<'gc>>,
15+
_args: &[Value<'gc>],
16+
) -> Result<Value<'gc>, Error> {
17+
Ok(Value::Undefined)
18+
}
19+
20+
/// Implements `flash.filters.GlowFilter`'s instance constructor.
21+
pub fn instance_init<'gc>(
22+
_activation: &mut Activation<'_, 'gc, '_>,
23+
_this: Option<Object<'gc>>,
24+
_args: &[Value<'gc>],
25+
) -> Result<Value<'gc>, Error> {
26+
Ok(Value::Undefined)
27+
}
28+
29+
pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> {
30+
let class = Class::new(
31+
QName::new(Namespace::package("flash.filters"), "GlowFilter"),
32+
Some(QName::new(Namespace::package("flash.filters"), "BitmapFilter").into()),
33+
Method::from_builtin(instance_init, "<GlowFilter instance initializer>", mc),
34+
Method::from_builtin(class_init, "<GlowFilter class initializer>", mc),
35+
mc,
36+
);
37+
38+
let mut write = class.write(mc);
39+
write.set_attributes(ClassAttributes::FINAL | ClassAttributes::SEALED);
40+
41+
class
42+
}

0 commit comments

Comments
 (0)