Skip to content

Commit

Permalink
use Array<FlxObject> for item lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Nov 10, 2023
1 parent 3b467eb commit b99bf3b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
33 changes: 21 additions & 12 deletions flixel/system/debug/interaction/Interaction.hx
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@ class Interaction extends Window
* @param area The rectangular area to search
* @since 5.6.0
*/
public function getItemsWithinState(state:FlxState, area:FlxRect):Array<FlxBasic>
public function getItemsWithinState(state:FlxState, area:FlxRect):Array<FlxObject>
{
final items = new Array<FlxBasic>();
final items = new Array<FlxObject>();

addItemsWithinArea(items, state.members, area);
if (state.subState != null)
Expand All @@ -623,7 +623,7 @@ class Interaction extends Window
@:deprecated("findItemsWithinState is deprecated, use getItemsWithinState or addItemsWithinState")
public inline function findItemsWithinState(items:Array<FlxBasic>, state:FlxState, area:FlxRect):Void
{
addItemsWithinState(items, state, area);
addItemsWithinState(cast items, state, area);
}

/**
Expand All @@ -635,7 +635,7 @@ class Interaction extends Window
* @param area The rectangular area to search
* @since 5.6.0
*/
public function addItemsWithinState(items:Array<FlxBasic>, state:FlxState, area:FlxRect):Void
public function addItemsWithinState(items:Array<FlxObject>, state:FlxState, area:FlxRect):Void
{
addItemsWithinArea(items, state.members, area);
if (state.subState != null)
Expand All @@ -649,7 +649,7 @@ class Interaction extends Window
* @param area The rectangular area to search
* @since 5.6.0
*/
public function getTopItemWithinState(state:FlxState, area:FlxRect):FlxBasic
public function getTopItemWithinState(state:FlxState, area:FlxRect):FlxObject
{
if (state.subState != null)
return getTopItemWithinState(state.subState, area);
Expand All @@ -670,7 +670,7 @@ class Interaction extends Window
@:deprecated("findItemsWithinArea is deprecated, use addItemsWithinArea")// since 5.6.0
public inline function findItemsWithinArea(items:Array<FlxBasic>, members:Array<FlxBasic>, area:FlxRect):Void
{
addItemsWithinArea(items, members, area);
addItemsWithinArea(cast items, members, area);
}

/**
Expand All @@ -684,7 +684,7 @@ class Interaction extends Window
* @param area A rectangle that describes the area where the method should search within.
* @since 5.6.0
*/
public function addItemsWithinArea(items:Array<FlxBasic>, members:Array<FlxBasic>, area:FlxRect):Void
public function addItemsWithinArea(items:Array<FlxObject>, members:Array<FlxBasic>, area:FlxRect):Void
{
// we iterate backwards to get the sprites on top first
var i = members.length;
Expand All @@ -698,8 +698,12 @@ class Interaction extends Window
final group = FlxTypedGroup.resolveSelectionGroup(member);
if (group != null)
addItemsWithinArea(items, group.members, area);
else if ((member is FlxObject) && area.overlaps(cast(member, FlxObject).getHitbox()))
items.push(cast member);
else if (member is FlxObject)
{
final object:FlxObject = cast member;
if (area.overlaps(object.getHitbox()))
items.push(object);
}
}
}

Expand All @@ -712,7 +716,7 @@ class Interaction extends Window
* @since 5.6.0
*/
@:access(flixel.group.FlxTypedGroup)
public function getTopItemWithinArea(members:Array<FlxBasic>, area:FlxRect):FlxBasic
public function getTopItemWithinArea(members:Array<FlxBasic>, area:FlxRect):FlxObject
{
// we iterate backwards to get the sprites on top first
var i = members.length;
Expand All @@ -726,8 +730,13 @@ class Interaction extends Window
final group = FlxTypedGroup.resolveGroup(member);
if (group != null)
return getTopItemWithinArea(group.members, area);
else if ((member is FlxObject) && area.overlaps(cast(member, FlxObject).getHitbox()))
return member;

if (member is FlxObject)
{
final object:FlxObject = cast member;
if (area.overlaps(object.getHitbox()))
return object;
}
}
return null;
}
Expand Down
14 changes: 7 additions & 7 deletions flixel/system/debug/interaction/tools/Pointer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ class Pointer extends Tool
/**
* Stop any selection activity that is happening.
*/
public function stopSelectionAndFindItems():Array<FlxBasic>
public function stopSelectionAndFindItems():Array<FlxObject>
{
if (!_selectionHappening)
throw "stopSelectionAndFindItems called when not selecting";

_selectionEndPoint.set(_brain.flixelPointer.x, _brain.flixelPointer.y);
calculateSelectionArea();

var items:Array<FlxBasic> = null;
var items:Array<FlxObject> = null;
if (_selectionArea.width != 0 || _selectionArea.height != 0)
{
items = _brain.getItemsWithinState(FlxG.state, _selectionArea);
Expand All @@ -145,7 +145,7 @@ class Pointer extends Tool
/**
* We register the current selection to the console for easy interaction.
*/
function updateConsoleSelection(items:Array<FlxBasic>)
function updateConsoleSelection(items:Array<FlxObject>)
{
FlxG.console.registerObject("selection", switch (items)
{
Expand All @@ -155,7 +155,7 @@ class Pointer extends Tool
});
}

function updateSelectedItems(items:Array<FlxBasic>, drewRect:Bool):Void
function updateSelectedItems(items:Array<FlxObject>, drewRect:Bool):Void
{
// We add things to the selection list if the user is pressing the "add-new-item" key
final adding = _brain.keyPressed(Keyboard.SHIFT);
Expand All @@ -172,7 +172,7 @@ class Pointer extends Tool
final prevSelectedItems = _brain.selectedItems;
if (adding && !drewRect && items.length == 1)
{
final item:FlxObject = cast items[0];
final item = items[0];
// if they click a single item, toggle it from the selection
if (prevSelectedItems.members.contains(item))
prevSelectedItems.remove(item);
Expand All @@ -182,13 +182,13 @@ class Pointer extends Tool
else if (removing)
{
for (item in items)
prevSelectedItems.remove(cast item);
prevSelectedItems.remove(item);
}
else
{
// add them all
for (item in items)
prevSelectedItems.add(cast item);
prevSelectedItems.add(item);
}
}

Expand Down

0 comments on commit b99bf3b

Please sign in to comment.