Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #412 from underscorediscovery/input-context
Browse files Browse the repository at this point in the history
Input; wip test for input contexts
  • Loading branch information
ruby0x1 committed Feb 13, 2017
2 parents 78ca88e + 7681370 commit 6275a2c
Show file tree
Hide file tree
Showing 7 changed files with 1,072 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/wip/input_context/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
23 changes: 23 additions & 0 deletions tests/wip/input_context/project.flow
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'
}
}
}
79 changes: 79 additions & 0 deletions tests/wip/input_context/src/AllEndpoints.hx
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();
}
}
17 changes: 17 additions & 0 deletions tests/wip/input_context/src/InputContext.hx
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;
}
43 changes: 43 additions & 0 deletions tests/wip/input_context/src/InputGroup.hx
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?
}
}
Loading

0 comments on commit 6275a2c

Please sign in to comment.