Skip to content

Commit 1bb7b48

Browse files
committed
Pointer: register selected items to the console
This allows easily manipulation of what's currently selected via the console.
1 parent f52c73e commit 1bb7b48

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

flixel/system/debug/console/ConsoleCommands.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ConsoleCommands
6464
console.registerClass(FlxCamera);
6565

6666
console.registerObject("FlxDebuggerLayout", FlxDebuggerLayout);
67+
console.registerObject("selection", null);
6768
}
6869

6970
private function help(?Alias:String):String

flixel/system/debug/interaction/tools/Pointer.hx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class Pointer extends Tool
104104
_selectionCancelled = false;
105105
_selectionStartPoint.set(_brain.flixelPointer.x, _brain.flixelPointer.y);
106106
_itemsInSelectionArea.clearArray();
107+
updateConsoleSelection();
107108
}
108109

109110
/**
@@ -134,12 +135,28 @@ class Pointer extends Tool
134135
calculateSelectionArea();
135136

136137
if (findItems)
138+
{
137139
_brain.findItemsWithinState(_itemsInSelectionArea, FlxG.state, _selectionArea);
140+
updateConsoleSelection();
141+
}
138142

139143
// Clear everything
140144
_selectionHappening = false;
141145
_selectionArea.set(0, 0, 0, 0);
142146
}
147+
148+
/**
149+
* We register the current selection to the console for easy interaction.
150+
*/
151+
private function updateConsoleSelection()
152+
{
153+
FlxG.console.registerObject("selection", switch(_itemsInSelectionArea.length)
154+
{
155+
case 0: null;
156+
case 1: _itemsInSelectionArea[0];
157+
case _: _itemsInSelectionArea;
158+
});
159+
}
143160

144161
private function handleItemAddition(itemsInSelectionArea:Array<FlxBasic>):Void
145162
{

0 commit comments

Comments
 (0)