@antha/multiplayer-p2p-authoritative-host 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 +53 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
1
|
# @antha/multiplayer-p2p-authoritative-host
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides a pre-built [Antha game engine](https://www.npmjs.com/package/@antha/engine) mod for peer-to-peer multiplayer where the room host owns the canonical game state. Clients submit inputs to the host, and the host publishes updated state snapshots to the room.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i @antha/multiplayer-p2p-authoritative-host
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
<!-- example-link: src/readme-examples/creating-authoritative-host.example.ts -->
|
|
14
|
+
|
|
15
|
+
```TypeScript
|
|
16
|
+
import {AnthaEngine, defineAnthaMod} from '@antha/engine';
|
|
17
|
+
import {
|
|
18
|
+
type AnthaMultiplayerP2pAuthoritativeHostState,
|
|
19
|
+
createAnthaMultiplayerP2pAuthoritativeHostMod,
|
|
20
|
+
} from '@antha/multiplayer-p2p-authoritative-host';
|
|
21
|
+
|
|
22
|
+
type GameState = AnthaMultiplayerP2pAuthoritativeHostState<number, number>;
|
|
23
|
+
|
|
24
|
+
const engine = new AnthaEngine<GameState>({
|
|
25
|
+
mods: [
|
|
26
|
+
createAnthaMultiplayerP2pAuthoritativeHostMod<number, number>({
|
|
27
|
+
gameId: 'counter-game',
|
|
28
|
+
createInitialState() {
|
|
29
|
+
return 0;
|
|
30
|
+
},
|
|
31
|
+
applyInput({input, state}) {
|
|
32
|
+
return state + input;
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
defineAnthaMod<GameState>({
|
|
36
|
+
modName: 'game-logic',
|
|
37
|
+
execute({state}) {
|
|
38
|
+
const controller = state.multiplayerP2pAuthoritativeHost?.multiplayerController;
|
|
39
|
+
|
|
40
|
+
if (!controller) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!controller.isConnected()) {
|
|
44
|
+
controller.startSingleplayer();
|
|
45
|
+
controller.act(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return `Score: ${controller.getState()}`;
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
engine.startLoop();
|
|
55
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/multiplayer-p2p-authoritative-host",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "P2P authoritative-host multiplayer strategy for the Antha engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"istanbul-smart-text-reporter": "^1.1.5"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@antha/multiplayer-core": "^0.1.
|
|
51
|
+
"@antha/multiplayer-core": "^0.1.2"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22"
|