Skip to content

Commit

Permalink
new version, to amend if ok
Browse files Browse the repository at this point in the history
  • Loading branch information
jparez committed Aug 9, 2024
1 parent 274a503 commit 7d83f25
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 49 deletions.
96 changes: 57 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,67 +169,85 @@ sendData({
### `keymapping`

- #### `setConfig`

supply a config for keymapping

```js
{
dpad:[{
keys: {
z: {
initialX: 20,
initialY: 80,
distanceX: 0,
distanceY: -10,
dPad:[{
keys:[
{
key: 'w',
effect: {
initialX: 20,
initialY: 80,
distanceX: 0,
distanceY: -10,
},
name: 'up',
description: 'move up',
},
s: {
initialX: 20,
initialY: 80,
distanceX: 0,
distanceY: 10,
{
key: 's',
effect: {
initialX: 20,
initialY: 80,
distanceX: 0,
distanceY: 10,
},
name: 'down',
description: 'move down',
},
q: {
initialX: 20,
initialY: 80,
distanceX: -10,
distanceY: 0,
{
key: 'a',
effect: {
initialX: 20,
initialY: 80,
distanceX: -10,
distanceY: 0,
},
name: 'left',
description: 'move left',
},
d: {
initialX: 20,
initialY: 80,
distanceX: 10,
distanceY: 0,
{
key: 'd',
effect: {
initialX: 20,
initialY: 80,
distanceX: 10,
distanceY: 0,
},
name: 'up',
description: 'move right',
},
},
],
name: 'character movement',
description: 'left joystick used to move the character',
}],
tap:[{
key: {
p: {
initialX: 50,
initialY: 50,
},
}
key: 'p',
effect: {
initialX: 50,
initialY: 50,
},
name:'Fire'
}],
swipe: [{
key: {
u: {
initialX: 50,
initialY: 50,
distanceX: -10,
distanceY: 0,
description: 'swipe left',
},
}
name:'Left dodge'
key: 'u',
effect: {
initialX: 50,
initialY: 50,
distanceX: -10,
distanceY: 0,
description: 'swipe left',
},
name:'Left dodge',
description: 'Dodge on the left'
}]
}
```

- #### `activeKeyMappingDebug`

helper to create the config mapping
Expand Down
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interface KeyEffect {
description?: string;
}

interface KeysMap<E> {
keys: Record<string, E>;
interface KeysList<E> {
keys: Key<E>[];
name?: string;
description?: string;
}
Expand All @@ -24,7 +24,7 @@ interface Key<E> {
}

interface KeyMappingConfig {
dpad?: KeysMap<KeyEffect & KeyEffectDistance>[];
dpad?: KeysList<KeyEffect & KeyEffectDistance>[];
tap?: Key<KeyEffect>[];
swipe?: Key<KeyEffect & KeyEffectDistance>[];
}
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/KeyboardMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ module.exports = class KeyboardMapping {
gestureConfig.forEach((gesture) => {
const groupId = generateUID();
this.sequences[groupId] = [];
const keyName = gestureType === 'dPad' ? 'keys' : 'key';
Object.entries(gesture[keyName]).forEach(([key, value]) => {
this.state.workingMappedKeysConfig[key] = {
...value,
key,
const gestureObject = gestureType === 'dPad' ? gesture.keys : gestureConfig;
Object.values(gestureObject).forEach((value) => {
this.state.workingMappedKeysConfig[value.key] = {
...value.effect,
key: value.key,
type: gestureType,
name: gesture.name,
groupId,
Expand Down Expand Up @@ -342,8 +342,8 @@ module.exports = class KeyboardMapping {

generateTouchSequence(key) {
const groupId = this.state.workingMappedKeysConfig[key].groupId;
const x = this.state.workingMappedKeysConfig[key].x;
const y = this.state.workingMappedKeysConfig[key].y;
const x = this.state.workingMappedKeysConfig[key].initialX;
const y = this.state.workingMappedKeysConfig[key].initialY;

this.sequences[groupId].push({
type: 'MULTI_TOUCH',
Expand Down

0 comments on commit 7d83f25

Please sign in to comment.