create-vimp-game 0.1.2 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vimp-game",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Scaffolder for VIMP game plugins",
5
5
  "keywords": [
6
6
  "vimp",
@@ -24,7 +24,7 @@
24
24
  "node": ">=20.11.0"
25
25
  },
26
26
  "bin": {
27
- "create-vimp-game": "./bin/create-vimp-game.js"
27
+ "create-vimp-game": "bin/create-vimp-game.js"
28
28
  },
29
29
  "files": [
30
30
  "bin",
@@ -1,4 +1,4 @@
1
1
  {
2
- "engine": "0.10.1",
3
- "core": "0.3.2"
2
+ "engine": "0.11.0",
3
+ "core": "0.4.0"
4
4
  }
@@ -4,6 +4,11 @@ import authSchema from '../config/auth.js';
4
4
  import clientConfig from '../config/client.js';
5
5
  import createModules from './createModules.js';
6
6
  import spawnCommand from './spawnCommand.js';
7
+ import {
8
+ nameCommand,
9
+ newRoundCommand,
10
+ rankCommand,
11
+ } from './metaCommands.js';
7
12
  import systemMessages from './systemMessages.js';
8
13
  import { isNodeCore, loadNodeCore, loadWebCore } from './nodeCore.js';
9
14
 
@@ -41,7 +46,8 @@ export default {
41
46
  authSchema,
42
47
 
43
48
  // REQUIRED array — the engine iterates it unguarded; `[]` for no commands
44
- chatCommands: [spawnCommand],
49
+ // the engine parses no commands of its own: this array IS the registry
50
+ chatCommands: [spawnCommand, nameCommand, newRoundCommand, rankCommand],
45
51
 
46
52
  // merged into the engine chat registry by a blind Object.assign: a code in
47
53
  // an engine group would overwrite an engine message without a word
@@ -0,0 +1,49 @@
1
+ // The chat commands the engine used to own. It owns none now:
2
+ // `CommandProcessor` is a bare registry, so a game that wants a nickname
3
+ // change, a round restart or a rank readout declares them itself — and the
4
+ // same name may mean something else, or nothing, in the next game.
5
+ //
6
+ // Two more the engine used to have are left out here because they only make
7
+ // sense in a game with a round timer and several maps: '/timeleft'
8
+ // (`ctx.timerManager.getMapTimeLeft()`) and '/mapname'
9
+ // (`ctx.roundManager.currentMap`). Add them the same way if yours has both.
10
+ //
11
+ // The message codes below are the engine's own (group 'c'); their texts live
12
+ // in `modules.chat.params.messages` (src/config/client.js).
13
+
14
+ // ctx = { participants, chat, scripted, roundManager, voteCoordinator,
15
+ // timerManager, playerDataSync, teams, spectatorTeam, spectatorId,
16
+ // isDevMode }
17
+
18
+ /// '/name <nickname>' — the engine validates and announces it itself.
19
+ export const nameCommand = {
20
+ name: '/name',
21
+
22
+ handler(ctx, gameId, args) {
23
+ ctx.roundManager.changeName(gameId, args.join(' '));
24
+ },
25
+ };
26
+
27
+ /// '/nr' — restart the round; dev builds only.
28
+ export const newRoundCommand = {
29
+ name: '/nr',
30
+
31
+ handler(ctx, gameId) {
32
+ if (ctx.isDevMode) {
33
+ ctx.roundManager.initiateNewRound();
34
+ } else {
35
+ ctx.chat.pushSystemByUser(gameId, 'COMMANDS_NOT_FOUND');
36
+ }
37
+ },
38
+ };
39
+
40
+ /// '/rank' — the per-(user, game) number the auth service keeps.
41
+ export const rankCommand = {
42
+ name: '/rank',
43
+
44
+ handler(ctx, gameId) {
45
+ ctx.chat.pushSystemByUser(gameId, 'RANK', [
46
+ ctx.playerDataSync.getRank(gameId),
47
+ ]);
48
+ },
49
+ };
@@ -2,9 +2,10 @@
2
2
  // It is also what `npm run dev` uses to get a match going (startupCommands in
3
3
  // dev/main.js).
4
4
  //
5
- // The name must not collide with the engine's own commands (/name, /nr,
6
- // /timeleft, /mapname, /rank): those are matched by a switch BEFORE the game
7
- // registry, so a same-named command registers fine and never fires.
5
+ // The engine has no chat commands of its own: `CommandProcessor` is a bare
6
+ // registry, so every name a player can type is declared by the game here —
7
+ // including the meta ones (/name, /nr, /rank) in src/host/metaCommands.js.
8
+ // A name registered twice silently loses one of the two handlers.
8
9
  export default {
9
10
  name: '/spawn',
10
11
 
@@ -19,13 +19,17 @@ describe('HostPlugin surface', () => {
19
19
  expect(Array.isArray(hostPlugin.chatCommands)).toBe(true);
20
20
  });
21
21
 
22
- it('does not shadow an engine chat command', () => {
23
- const reserved = ['/name', '/nr', '/timeleft', '/mapname', '/rank'];
22
+ // the engine parses no commands of its own: this array is the whole
23
+ // registry, and a name registered twice loses one of its handlers
24
+ it('declares well-formed, unique chat commands', () => {
25
+ const names = hostPlugin.chatCommands.map(command => command.name);
24
26
 
25
27
  for (const command of hostPlugin.chatCommands) {
26
28
  expect(command.name.startsWith('/')).toBe(true);
27
- expect(reserved).not.toContain(command.name);
29
+ expect(typeof command.handler).toBe('function');
28
30
  }
31
+
32
+ expect(new Set(names).size).toBe(names.length);
29
33
  });
30
34
 
31
35
  it('keeps its system message codes out of the engine groups', () => {