Python: Add key functions
Jeffrey Pfau jeffrey@endrift.com
Wed, 26 Oct 2016 22:44:42 -0700
5 files changed,
41 insertions(+),
0 deletions(-)
M
src/platform/python/_builder.h
→
src/platform/python/_builder.h
@@ -32,10 +32,12 @@ #endif
#ifdef M_CORE_GBA #include "arm/arm.h" #include "gba/gba.h" +#include "gba/input.h" #include "gba/renderers/tile-cache.h" #endif #ifdef M_CORE_GB #include "lr35902/lr35902.h" #include "gb/gb.h" +#include "gba/input.h" #include "gb/renderers/tile-cache.h" #endif
M
src/platform/python/_builder.py
→
src/platform/python/_builder.py
@@ -13,6 +13,7 @@ #include "core/log.h"
#include "core/tile-cache.h" #include "arm/arm.h" #include "gba/gba.h" +#include "gba/input.h" #include "gba/renderers/tile-cache.h" #include "lr35902/lr35902.h" #include "gb/gb.h"
M
src/platform/python/mgba/core.py
→
src/platform/python/mgba/core.py
@@ -102,6 +102,24 @@
def step(self): self._core.step(self._core) + @staticmethod + def _keysToInt(*args, **kwargs): + keys = 0 + if 'raw' in kwargs: + keys = kwargs['raw'] + for key in args: + keys |= 1 << key + return keys + + def setKeys(self, *args, **kwargs): + self._core.setKeys(self._core, self._keysToInt(*args, **kwargs)) + + def addKeys(self, *args, **kwargs): + self._core.addKeys(self._core, self._keysToInt(*args, **kwargs)) + + def clearKeys(self, *args, **kwargs): + self._core.clearKeys(self._core, self._keysToInt(*args, **kwargs)) + def frameCounter(self): return self._core.frameCounter(self._core)
M
src/platform/python/mgba/gb.py
→
src/platform/python/mgba/gb.py
@@ -9,6 +9,15 @@ from .core import Core
from .tile import Sprite class GB(Core): + KEY_A = lib.GBA_KEY_A + KEY_B = lib.GBA_KEY_B + KEY_SELECT = lib.GBA_KEY_SELECT + KEY_START = lib.GBA_KEY_START + KEY_DOWN = lib.GBA_KEY_DOWN + KEY_UP = lib.GBA_KEY_UP + KEY_LEFT = lib.GBA_KEY_LEFT + KEY_RIGHT = lib.GBA_KEY_RIGHT + def __init__(self, native): super(GB, self).__init__(native) self._native = ffi.cast("struct GB*", native.board)
M
src/platform/python/mgba/gba.py
→
src/platform/python/mgba/gba.py
@@ -9,6 +9,17 @@ from .core import Core
from .tile import Sprite class GBA(Core): + KEY_A = lib.GBA_KEY_A + KEY_B = lib.GBA_KEY_B + KEY_SELECT = lib.GBA_KEY_SELECT + KEY_START = lib.GBA_KEY_START + KEY_DOWN = lib.GBA_KEY_DOWN + KEY_UP = lib.GBA_KEY_UP + KEY_LEFT = lib.GBA_KEY_LEFT + KEY_RIGHT = lib.GBA_KEY_RIGHT + KEY_L = lib.GBA_KEY_L + KEY_R = lib.GBA_KEY_R + def __init__(self, native): super(GBA, self).__init__(native) self._native = ffi.cast("struct GBA*", native.board)