Rogue: Savage Rats, a retro-themed dungeon crawler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rogue-savage-rats/src/mightypork/gamecore/input/InputModule.java

97 lines
1.9 KiB

package mightypork.gamecore.input;
import mightypork.gamecore.core.BackendModule;
import mightypork.utils.math.constraints.vect.Vect;
/**
* Abstract input module
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class InputModule extends BackendModule implements KeyBinder {
protected KeyBindingPool keybindings;
@Override
public final void init()
{
initKeyCodes();
initDevices();
keybindings = new KeyBindingPool();
addChildClient(keybindings);
}
/**
* Initialize key codes for keys in {@link Keys}
*/
protected abstract void initKeyCodes();
/**
* Initialize input devices (set up infrastructure for getting the input)
*/
protected abstract void initDevices();
@Override
public void bindKey(KeyStroke stroke, Trigger edge, Runnable task)
{
keybindings.bindKey(stroke, edge, task);
}
@Override
public void unbindKey(KeyStroke stroke)
{
keybindings.unbindKey(stroke);
}
/**
* Get absolute mouse position. Should always return the same Vect instance
* (use a VectVar or similar).
*
* @return mouse position
*/
public abstract Vect getMousePos();
/**
* Check if mouse is inside window
*
* @return true if mouse is inside window.
*/
public abstract boolean isMouseInside();
/**
* Trap mouse cursor in the window / release it
*
* @param grab true to grab, false to release
*/
public abstract void grabMouse(boolean grab);
/**
* Check if key is down. The key comes from the Keys class, so the code is
* the one assigned in initKeyCodes()
*
* @param key key to check
* @return is down
*/
public abstract boolean isKeyDown(Key key);
/**
* Check mouse button state
*
* @param button button to test (0 left, 1 right, 2 middle, 3,4,5... extra)
* @return true if the button exists and is down
*/
public abstract boolean isMouseButtonDown(int button);
}