@antha/input 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,9 +1,59 @@
|
|
|
1
1
|
# @antha/input
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides pre-built [Antha game engine](https://www.npmjs.com/package/@antha/engine) mods that read keyboard and gamepad input, then translate it into named player actions.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
npm i @antha/input
|
|
9
9
|
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
<!-- example-link: src/readme-examples/reading-input-bindings.example.ts -->
|
|
14
|
+
|
|
15
|
+
```TypeScript
|
|
16
|
+
import {AnthaEngine, defineAnthaMod} from '@antha/engine';
|
|
17
|
+
import {
|
|
18
|
+
type AnthaInputBindingsModState,
|
|
19
|
+
createAnthaInputBindingsMod,
|
|
20
|
+
createAnthaReadRawInputMod,
|
|
21
|
+
InputDirection,
|
|
22
|
+
} from '@antha/input';
|
|
23
|
+
|
|
24
|
+
enum GameAction {
|
|
25
|
+
Jump = 'jump',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type GameState = AnthaInputBindingsModState<GameAction>;
|
|
29
|
+
|
|
30
|
+
const engine = new AnthaEngine<GameState>({
|
|
31
|
+
initState: {
|
|
32
|
+
bindingAssignments: {
|
|
33
|
+
'1': {
|
|
34
|
+
[GameAction.Jump]: [
|
|
35
|
+
{
|
|
36
|
+
deviceKey: 'keyboard',
|
|
37
|
+
direction: InputDirection.Positive,
|
|
38
|
+
inputName: 'button-Space',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
mods: [
|
|
45
|
+
createAnthaReadRawInputMod(),
|
|
46
|
+
createAnthaInputBindingsMod<GameAction>(),
|
|
47
|
+
defineAnthaMod<GameState>({
|
|
48
|
+
modName: 'game-logic',
|
|
49
|
+
execute({state}) {
|
|
50
|
+
const jump = state.activeBindings?.['1']?.[GameAction.Jump];
|
|
51
|
+
|
|
52
|
+
return jump?.value ? `Jump strength: ${jump.value}` : undefined;
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
engine.startLoop();
|
|
59
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/input",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "An Antha mod for handling inputs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"test:docs": "virmator docs check"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@antha/gamepad-type": "^0.1.
|
|
36
|
+
"@antha/gamepad-type": "^0.1.2",
|
|
37
37
|
"@augment-vir/assert": "^32.2.2",
|
|
38
38
|
"@augment-vir/common": "^32.2.2",
|
|
39
|
-
"date-vir": "^9.
|
|
39
|
+
"date-vir": "^9.1.0",
|
|
40
40
|
"device-navigation": "^4.7.3",
|
|
41
41
|
"input-device-handler": "^9.0.4",
|
|
42
|
-
"object-shape-tester": "^6.
|
|
43
|
-
"vira": "^31.
|
|
42
|
+
"object-shape-tester": "^6.15.0",
|
|
43
|
+
"vira": "^31.31.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@augment-vir/test": "^32.2.2",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"istanbul-smart-text-reporter": "^1.1.5"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@antha/engine": "^0.1.
|
|
54
|
+
"@antha/engine": "^0.1.2",
|
|
55
55
|
"element-vir": ">=26"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|