This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #412 from underscorediscovery/input-context
Input; wip test for input contexts
- Loading branch information
Showing
7 changed files
with
1,072 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
project : { | ||
name : 'luxe.input_context', | ||
version : '1.0.0', | ||
author : 'luxeengine', | ||
|
||
app : { | ||
name : 'luxe_input_context', | ||
package : 'com.luxeengine.input_context', | ||
main : 'Main' | ||
}, | ||
|
||
build : { | ||
dependencies : { | ||
luxe : '*', | ||
} | ||
}, | ||
|
||
files : { | ||
config : 'config.json' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package; | ||
import luxe.Input; | ||
import InputContext.InteractType; | ||
import InputMap.InputEvent; | ||
import InputMap.ScreenAxis; | ||
import luxe.Rectangle; | ||
|
||
class Main extends luxe.Game { | ||
var map:InputMap; | ||
|
||
override function ready() { | ||
map = new InputMap(); | ||
|
||
map.bind_key('jump', Key.key_x); | ||
|
||
map.bind_mouse_button('jump', MouseButton.left); | ||
|
||
map.bind_mouse_range('left_move', ScreenAxis.X, 0, 0.5, true, true, true); | ||
map.bind_mouse_wheel('wheel_change'); | ||
map.bind_mouse_area('bottom_left_move', new Rectangle(0, 0.5, 0.5, 0.5), true, true, true); | ||
|
||
map.bind_gamepad_button('jump', 0, null); | ||
map.bind_gamepad_range('run', 0, 0.8, 1.0, true, true, true); | ||
map.bind_gamepad_range('run', 0, -1.0, -0.8, true, true, true); | ||
map.bind_gamepad_range('hold_trigger', 5, 0.25, 0.75, false, true, true); | ||
|
||
map.bind_touch('jump'); | ||
map.bind_touch_range('touch_move', ScreenAxis.X, 0.25, 0.75, false, true, true); | ||
map.bind_touch_area('top_right_touch', new Rectangle(0.5, 0, 0.5, 0.5), true, true, true); | ||
|
||
// map.bind_general_events(true, true, true, true, true, true, true, true); | ||
|
||
map.on(InteractType.down, input_down); | ||
map.on(InteractType.up, input_up); | ||
// map.on(InteractType.change, analog_changed); | ||
} | ||
|
||
override public function update(dt:Float) { | ||
if(map.inputdown('touch_move')) { | ||
trace('update | touch_move down '); | ||
} | ||
if(map.inputpressed('touch_move')) { | ||
trace('update | touch_move pressed'); | ||
} | ||
if(map.inputreleased('touch_move')) { | ||
trace('update | touch_move released'); | ||
} | ||
} | ||
|
||
function input_down(_event:InputEvent) { | ||
trace('down'); | ||
trace(_event.name); | ||
trace(_event.input_type); | ||
// if(_event.name == 'jump') { | ||
// map.unbind_mouse_area('bottom_left_move', new Rectangle(0, 0.5, 0.5, 0.5), true, true, true); | ||
// } | ||
} | ||
|
||
function input_up(_event:InputEvent) { | ||
trace('up'); | ||
trace(_event.name); | ||
trace(_event.input_type); | ||
} | ||
|
||
var count:Int = 0; | ||
function analog_changed(_event:InputEvent) { | ||
if(count % 40 == 0) { | ||
trace('change'); | ||
trace(_event.name); | ||
trace(_event.input_type); | ||
} | ||
count++; | ||
} | ||
|
||
override function onkeyup(e:KeyEvent) { | ||
if(e.keycode == Key.escape) | ||
Luxe.shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ; | ||
|
||
interface InputContext { | ||
function listen():Void; | ||
function unlisten():Void; | ||
|
||
function on<T>(event:InteractType, handler: T->Void):Void; | ||
function off<T>(event:InteractType, handler: T->Void):Bool; | ||
} | ||
|
||
@:enum | ||
abstract InteractType(Int) from Int to Int { //:todo: rename | ||
var down = 0; | ||
var up = 1; | ||
var change = 2; | ||
var none = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ; | ||
import InputContext.InteractType; | ||
|
||
class InputGroup implements InputContext { | ||
var contexts: Array<InputContext>; //:todo: maybe make public? Not much access possible if private | ||
|
||
public function new(?_contexts:Array<InputContext>) { | ||
contexts = _contexts == null ? [] : _contexts; | ||
} | ||
|
||
public function add(_context:InputContext) { | ||
contexts.push(_context); | ||
} | ||
|
||
public function remove(_context:InputContext):Bool { | ||
return contexts.remove(_context); | ||
} | ||
|
||
public function listen():Void { | ||
for(context in contexts) { | ||
context.listen(); | ||
} | ||
} | ||
|
||
public function unlisten():Void { | ||
for(context in contexts) { | ||
context.unlisten(); | ||
} | ||
} | ||
|
||
public function on<T>(event:InteractType, handler:T->Void) { | ||
for(context in contexts) { | ||
context.on(event, handler); | ||
} | ||
} | ||
|
||
public function off<T>(event:InteractType, handler:T->Void) { | ||
for(context in contexts) { | ||
context.off(event, handler); | ||
} | ||
return true; //:todo: Not sure what should be returned here. Maybe aggregate remove? | ||
} | ||
} |
Oops, something went wrong.