avm2: Convert display_object_container to use ParametersExt
This commit is contained in:
parent
37f3ea7077
commit
8db6375c4c
|
@ -124,11 +124,7 @@ pub fn get_child_at<'gc>(
|
||||||
.and_then(|this| this.as_display_object())
|
.and_then(|this| this.as_display_object())
|
||||||
.and_then(|this| this.as_container())
|
.and_then(|this| this.as_container())
|
||||||
{
|
{
|
||||||
let index = args
|
let index = args.get_i32(activation, 0)?;
|
||||||
.get(0)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.coerce_to_i32(activation)?;
|
|
||||||
return if let Some(child) = dobj.child_by_index(index as usize) {
|
return if let Some(child) = dobj.child_by_index(index as usize) {
|
||||||
Ok(child.object2())
|
Ok(child.object2())
|
||||||
} else {
|
} else {
|
||||||
|
@ -174,12 +170,7 @@ pub fn add_child<'gc>(
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
if let Some(ctr) = parent.as_container() {
|
if let Some(ctr) = parent.as_container() {
|
||||||
let child = args
|
let child = args.get_object(activation, 0, "child")?;
|
||||||
.get(0)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.as_object()
|
|
||||||
.ok_or("ArgumentError: Child not a valid display object")?;
|
|
||||||
if child.as_display_object().is_none() {
|
if child.as_display_object().is_none() {
|
||||||
let sprite = activation.avm2().classes().sprite;
|
let sprite = activation.avm2().classes().sprite;
|
||||||
if child.is_of_type(sprite, activation) {
|
if child.is_of_type(sprite, activation) {
|
||||||
|
@ -211,17 +202,10 @@ pub fn add_child_at<'gc>(
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
let child = args
|
let child = args
|
||||||
.get(0)
|
.get_object(activation, 0, "child")?
|
||||||
.cloned()
|
.as_display_object()
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.as_object()
|
|
||||||
.and_then(|o| o.as_display_object())
|
|
||||||
.ok_or("ArgumentError: Child not a valid display object")?;
|
.ok_or("ArgumentError: Child not a valid display object")?;
|
||||||
let target_index = args
|
let target_index = args.get_u32(activation, 1)? as usize;
|
||||||
.get(1)
|
|
||||||
.cloned()
|
|
||||||
.ok_or("ArgumentError: Index to add child at not specified")?
|
|
||||||
.coerce_to_i32(activation)? as usize;
|
|
||||||
|
|
||||||
validate_add_operation(activation, parent, child, target_index)?;
|
validate_add_operation(activation, parent, child, target_index)?;
|
||||||
add_child_to_displaylist(&mut activation.context, parent, child, target_index);
|
add_child_to_displaylist(&mut activation.context, parent, child, target_index);
|
||||||
|
@ -271,19 +255,13 @@ pub fn get_num_children<'gc>(
|
||||||
|
|
||||||
/// Implements `DisplayObjectContainer.contains`
|
/// Implements `DisplayObjectContainer.contains`
|
||||||
pub fn contains<'gc>(
|
pub fn contains<'gc>(
|
||||||
_activation: &mut Activation<'_, 'gc>,
|
activation: &mut Activation<'_, 'gc>,
|
||||||
this: Option<Object<'gc>>,
|
this: Option<Object<'gc>>,
|
||||||
args: &[Value<'gc>],
|
args: &[Value<'gc>],
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
if parent.as_container().is_some() {
|
if parent.as_container().is_some() {
|
||||||
if let Some(child) = args
|
if let Some(child) = args.get_object(activation, 0, "child")?.as_display_object() {
|
||||||
.get(0)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.as_object()
|
|
||||||
.and_then(|o| o.as_display_object())
|
|
||||||
{
|
|
||||||
let mut maybe_child_parent = Some(child);
|
let mut maybe_child_parent = Some(child);
|
||||||
while let Some(child_parent) = maybe_child_parent {
|
while let Some(child_parent) = maybe_child_parent {
|
||||||
if DisplayObject::ptr_eq(child_parent, parent) {
|
if DisplayObject::ptr_eq(child_parent, parent) {
|
||||||
|
@ -301,18 +279,13 @@ pub fn contains<'gc>(
|
||||||
|
|
||||||
/// Implements `DisplayObjectContainer.getChildIndex`
|
/// Implements `DisplayObjectContainer.getChildIndex`
|
||||||
pub fn get_child_index<'gc>(
|
pub fn get_child_index<'gc>(
|
||||||
_activation: &mut Activation<'_, 'gc>,
|
activation: &mut Activation<'_, 'gc>,
|
||||||
this: Option<Object<'gc>>,
|
this: Option<Object<'gc>>,
|
||||||
args: &[Value<'gc>],
|
args: &[Value<'gc>],
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
if let Some(ctr) = parent.as_container() {
|
if let Some(ctr) = parent.as_container() {
|
||||||
let target_child = args
|
let target_child = args.get_object(activation, 0, "child")?.as_display_object();
|
||||||
.get(0)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.as_object()
|
|
||||||
.and_then(|o| o.as_display_object());
|
|
||||||
|
|
||||||
if let Some(target_child) = target_child {
|
if let Some(target_child) = target_child {
|
||||||
for (i, child) in ctr.iter_render_list().enumerate() {
|
for (i, child) in ctr.iter_render_list().enumerate() {
|
||||||
|
@ -335,11 +308,7 @@ pub fn remove_child_at<'gc>(
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
if let Some(mut ctr) = parent.as_container() {
|
if let Some(mut ctr) = parent.as_container() {
|
||||||
let target_child = args
|
let target_child = args.get_i32(activation, 0)?;
|
||||||
.get(0)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.coerce_to_i32(activation)?;
|
|
||||||
|
|
||||||
if target_child >= ctr.num_children() as i32 || target_child < 0 {
|
if target_child >= ctr.num_children() as i32 || target_child < 0 {
|
||||||
// Flash error message: The supplied index is out of bounds.
|
// Flash error message: The supplied index is out of bounds.
|
||||||
|
@ -374,16 +343,8 @@ pub fn remove_children<'gc>(
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
if let Some(mut ctr) = parent.as_container() {
|
if let Some(mut ctr) = parent.as_container() {
|
||||||
let from = args
|
let from = args.get_i32(activation, 0)?;
|
||||||
.get(0)
|
let to = args.get_i32(activation, 1)?;
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| 0.into())
|
|
||||||
.coerce_to_i32(activation)?;
|
|
||||||
let to = args
|
|
||||||
.get(1)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| i32::MAX.into())
|
|
||||||
.coerce_to_i32(activation)?;
|
|
||||||
|
|
||||||
if from >= ctr.num_children() as i32 || from < 0 {
|
if from >= ctr.num_children() as i32 || from < 0 {
|
||||||
// Flash error message: The supplied index is out of bounds.
|
// Flash error message: The supplied index is out of bounds.
|
||||||
|
@ -438,17 +399,10 @@ pub fn set_child_index<'gc>(
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
let child = args
|
let child = args
|
||||||
.get(0)
|
.get_object(activation, 0, "child")?
|
||||||
.cloned()
|
.as_display_object()
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.as_object()
|
|
||||||
.and_then(|o| o.as_display_object())
|
|
||||||
.ok_or("ArgumentError: Child not a valid display object")?;
|
.ok_or("ArgumentError: Child not a valid display object")?;
|
||||||
let target_index = args
|
let target_index = args.get_u32(activation, 1)? as usize;
|
||||||
.get(1)
|
|
||||||
.cloned()
|
|
||||||
.ok_or("ArgumentError: Index to add child at not specified")?
|
|
||||||
.coerce_to_i32(activation)? as usize;
|
|
||||||
|
|
||||||
let child_parent = child.parent();
|
let child_parent = child.parent();
|
||||||
if child_parent.is_none() || !DisplayObject::ptr_eq(child_parent.unwrap(), parent) {
|
if child_parent.is_none() || !DisplayObject::ptr_eq(child_parent.unwrap(), parent) {
|
||||||
|
@ -472,16 +426,8 @@ pub fn swap_children_at<'gc>(
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
if let Some(mut ctr) = parent.as_container() {
|
if let Some(mut ctr) = parent.as_container() {
|
||||||
let index0 = args
|
let index0 = args.get_i32(activation, 0)?;
|
||||||
.get(0)
|
let index1 = args.get_i32(activation, 1)?;
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.coerce_to_i32(activation)?;
|
|
||||||
let index1 = args
|
|
||||||
.get(1)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.coerce_to_i32(activation)?;
|
|
||||||
let bounds = ctr.num_children();
|
let bounds = ctr.num_children();
|
||||||
|
|
||||||
if index0 < 0 || index0 as usize >= bounds {
|
if index0 < 0 || index0 as usize >= bounds {
|
||||||
|
@ -524,18 +470,12 @@ pub fn swap_children<'gc>(
|
||||||
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
if let Some(parent) = this.and_then(|this| this.as_display_object()) {
|
||||||
if let Some(mut ctr) = parent.as_container() {
|
if let Some(mut ctr) = parent.as_container() {
|
||||||
let child0 = args
|
let child0 = args
|
||||||
.get(0)
|
.get_object(activation, 0, "child1")?
|
||||||
.cloned()
|
.as_display_object()
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.as_object()
|
|
||||||
.and_then(|o| o.as_display_object())
|
|
||||||
.ok_or("ArgumentError: Child is not a display object")?;
|
.ok_or("ArgumentError: Child is not a display object")?;
|
||||||
let child1 = args
|
let child1 = args
|
||||||
.get(1)
|
.get_object(activation, 1, "child2")?
|
||||||
.cloned()
|
.as_display_object()
|
||||||
.unwrap_or(Value::Undefined)
|
|
||||||
.as_object()
|
|
||||||
.and_then(|o| o.as_display_object())
|
|
||||||
.ok_or("ArgumentError: Child is not a display object")?;
|
.ok_or("ArgumentError: Child is not a display object")?;
|
||||||
|
|
||||||
let index0 = ctr
|
let index0 = ctr
|
||||||
|
|
Loading…
Reference in New Issue