@thzero/black-meridian-library_common 0.0.0-stage → 0.1.5
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 +6 -2
- package/constants.js +35 -0
- package/data/settingsUser.js +12 -0
- package/data/user.js +28 -0
- package/data/userGame.js +17 -0
- package/license.md +9 -0
- package/package.json +26 -3
- package/test/constants.test.js +32 -0
- package/test/user.test.js +32 -0
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# black-meridian-library_common
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
[](https://npmjs.org/package/@thzero/black-meridian-library_common)
|
package/constants.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const Constants = {
|
|
2
|
+
// Pub/sub between vessels (server_vessel) and zones (server_zone).
|
|
3
|
+
PubSub: {
|
|
4
|
+
Channels: {
|
|
5
|
+
// A vessel coming online says which game and system it's in, and that system's zone answers.
|
|
6
|
+
enter: 'meridian:enter',
|
|
7
|
+
// A zone's channels are its game's: every game's zones have the same ids.
|
|
8
|
+
// What changes, as a zone tells everyone in it: in all of it, and in one system.
|
|
9
|
+
changes: (gameId, zoneId) => `meridian:game:${gameId}:zone:${zoneId}:changes`,
|
|
10
|
+
space: (gameId, zoneId, systemId) => `meridian:game:${gameId}:zone:${zoneId}:system:${systemId}`,
|
|
11
|
+
vessel: vesselId => `meridian:vessel:${vesselId}`,
|
|
12
|
+
zone: (gameId, zoneId) => `meridian:game:${gameId}:zone:${zoneId}`
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
// Message rates (a second) and timeouts (seconds).
|
|
16
|
+
Timing: {
|
|
17
|
+
// How often a vessel and a zone tick.
|
|
18
|
+
tickHz: 10,
|
|
19
|
+
// How often a vessel tells its zone where it is, and a zone tells what has changed in a system,
|
|
20
|
+
// and in all of it.
|
|
21
|
+
statusHz: 5,
|
|
22
|
+
changesHz: 5,
|
|
23
|
+
zoneChangesHz: 0.5,
|
|
24
|
+
// With nothing changed in a system, the zone says so this often.
|
|
25
|
+
quietSeconds: 1,
|
|
26
|
+
// A vessel that hasn't heard from its zone for this long holds where it is and enters again.
|
|
27
|
+
lostSeconds: 3,
|
|
28
|
+
// Between a vessel's tries to enter, and to get what it hasn't been told yet.
|
|
29
|
+
enterSeconds: 2,
|
|
30
|
+
// A vessel its zone hasn't heard from for this long is dropped.
|
|
31
|
+
dropSeconds: 10
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default Constants;
|
package/data/user.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import BaseUserData from '@thzero/library_common/data/baseUser.js';
|
|
2
|
+
|
|
3
|
+
import UserSettings from './settingsUser.js';
|
|
4
|
+
|
|
5
|
+
import UserGameData from './userGame.js';
|
|
6
|
+
|
|
7
|
+
class UserData extends BaseUserData {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
this.gameData = new UserGameData();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
map(requested) {
|
|
15
|
+
super.map(requested);
|
|
16
|
+
|
|
17
|
+
if (!requested)
|
|
18
|
+
return;
|
|
19
|
+
|
|
20
|
+
this.gameData = requested.gameData;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_initUserSettings() {
|
|
24
|
+
return new UserSettings();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default UserData;
|
package/data/userGame.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class UserGameData {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.badges = [];
|
|
4
|
+
this.deaths = 0;
|
|
5
|
+
this.defeats = 0;
|
|
6
|
+
this.drops = 0;
|
|
7
|
+
this.kills = 0;
|
|
8
|
+
this.playedFactions = [];
|
|
9
|
+
this.playedMechs = [];
|
|
10
|
+
this.playedScenarios = [];
|
|
11
|
+
this.rating = 0;
|
|
12
|
+
this.victories = 0;
|
|
13
|
+
this.victoryPoints = 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default UserGameData;
|
package/license.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2024 thZero.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thzero/black-meridian-library_common",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.5",
|
|
5
|
+
"version_major": 0,
|
|
6
|
+
"version_minor": 1,
|
|
7
|
+
"version_patch": 5,
|
|
8
|
+
"version_date": "11/28/2026",
|
|
9
|
+
"description": "",
|
|
10
|
+
"author": "thZero",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/thzero/black-meridian-library_common.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/thzero/black-meridian-library_common/issues"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=24"
|
|
20
|
+
},
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"cli-update": "library-cli --updateversion --pi",
|
|
24
|
+
"test": "node --test"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@thzero/library_common": "^0.19"
|
|
28
|
+
}
|
|
6
29
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import Constants from '../constants.js';
|
|
5
|
+
|
|
6
|
+
describe('Constants', () => {
|
|
7
|
+
it('names a channel for each vessel, and for the zones of each game', () => {
|
|
8
|
+
assert.equal(Constants.PubSub.Channels.vessel('v1'), 'meridian:vessel:v1');
|
|
9
|
+
assert.equal(Constants.PubSub.Channels.zone('g1', 'z1'), 'meridian:game:g1:zone:z1');
|
|
10
|
+
assert.equal(Constants.PubSub.Channels.changes('g1', 'z1'), 'meridian:game:g1:zone:z1:changes');
|
|
11
|
+
assert.equal(Constants.PubSub.Channels.space('g1', 'z1', 's1'), 'meridian:game:g1:zone:z1:system:s1');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('keeps the zones of one game apart from those of another with the same id', () => {
|
|
15
|
+
assert.notEqual(Constants.PubSub.Channels.zone('g1', 'galaxy'), Constants.PubSub.Channels.zone('g2', 'galaxy'));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('tells of a whole zone less often than of one system', () => {
|
|
19
|
+
const { changesHz, zoneChangesHz } = Constants.Timing;
|
|
20
|
+
assert.ok(zoneChangesHz < changesHz);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('is never quiet for so long that a vessel takes its zone for lost', () => {
|
|
24
|
+
const { lostSeconds, quietSeconds } = Constants.Timing;
|
|
25
|
+
assert.ok(quietSeconds * 2 < lostSeconds);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('gives a vessel up only after it would have noticed its zone was lost', () => {
|
|
29
|
+
const { dropSeconds, enterSeconds, lostSeconds } = Constants.Timing;
|
|
30
|
+
assert.ok(dropSeconds > lostSeconds + enterSeconds);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import UserData from '../data/user.js';
|
|
5
|
+
import UserSettings from '../data/settingsUser.js';
|
|
6
|
+
import UserGameData from '../data/userGame.js';
|
|
7
|
+
|
|
8
|
+
describe('UserData', () => {
|
|
9
|
+
it('initializes settings and game data', () => {
|
|
10
|
+
const user = new UserData();
|
|
11
|
+
assert.ok(user.settings instanceof UserSettings);
|
|
12
|
+
assert.deepEqual(user.settings.games, {});
|
|
13
|
+
assert.deepEqual(user.settings.gameSystems, []);
|
|
14
|
+
assert.ok(user.gameData instanceof UserGameData);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('maps game data from a request', () => {
|
|
18
|
+
const user = new UserData();
|
|
19
|
+
const gameData = new UserGameData();
|
|
20
|
+
gameData.kills = 3;
|
|
21
|
+
user.map({ email: 'a@b.c', roles: [ 'user' ], gameData });
|
|
22
|
+
assert.equal(user.email, 'a@b.c');
|
|
23
|
+
assert.deepEqual(user.roles, [ 'user' ]);
|
|
24
|
+
assert.equal(user.gameData.kills, 3);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('ignores an empty request', () => {
|
|
28
|
+
const user = new UserData();
|
|
29
|
+
user.map(null);
|
|
30
|
+
assert.ok(user.gameData instanceof UserGameData);
|
|
31
|
+
});
|
|
32
|
+
});
|