@civ-clone/core-treasury 0.1.5 → 0.1.7
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.
|
@@ -6,9 +6,34 @@ jobs:
|
|
|
6
6
|
build:
|
|
7
7
|
runs-on: ubuntu-latest
|
|
8
8
|
steps:
|
|
9
|
-
- uses: actions/checkout@
|
|
10
|
-
- uses:
|
|
9
|
+
- uses: actions/checkout@v4
|
|
10
|
+
- uses: pnpm/action-setup@v4
|
|
11
11
|
with:
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
12
|
+
version: 11
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: 22
|
|
16
|
+
# No lock file, so this tests what a consumer resolves. The settings match
|
|
17
|
+
# web-renderer's pnpm-workspace.yaml: several @civ-clone packages depend on
|
|
18
|
+
# each other as `github:` URLs, this project's own releases are often only
|
|
19
|
+
# minutes old, and nothing here needs a dependency's build script.
|
|
20
|
+
- run: >-
|
|
21
|
+
pnpm install --no-frozen-lockfile
|
|
22
|
+
--config.block-exotic-subdeps=false
|
|
23
|
+
--config.minimum-release-age=0
|
|
24
|
+
--config.strict-dep-builds=false
|
|
25
|
+
- run: npm run --if-present prettier:check
|
|
26
|
+
# The tests load the committed `.js`, so compile to prove the source
|
|
27
|
+
# type-checks, and fail if the committed output is stale. `--force`
|
|
28
|
+
# because a fresh checkout's timestamps can make `tsc --build` treat the
|
|
29
|
+
# committed output as up to date and skip the compile entirely.
|
|
30
|
+
- run: npm run --if-present ts:compile -- --force
|
|
31
|
+
- run: npm run --if-present prettier:format
|
|
32
|
+
# Stale *or never committed* output fails: `git diff` alone misses a new
|
|
33
|
+
# module whose `.js` was never added, which the published package would
|
|
34
|
+
# then omit. Only the compiled extensions, so the lock file the install
|
|
35
|
+
# writes cannot fail it; `node_modules` is ignored, so it stays out.
|
|
36
|
+
- run: |
|
|
37
|
+
git status --short --untracked-files=all -- '*.js' '*.d.ts' '*.js.map'
|
|
38
|
+
test -z "$(git status --porcelain --untracked-files=all -- '*.js' '*.d.ts' '*.js.map')"
|
|
39
|
+
- run: npm run --if-present test
|
package/PlayerTreasury.d.ts
CHANGED
package/PlayerTreasury.js
CHANGED
|
@@ -47,7 +47,7 @@ class PlayerTreasury extends DataObject_1.default {
|
|
|
47
47
|
}
|
|
48
48
|
subtract(value) {
|
|
49
49
|
if (value instanceof Yield_1.default) {
|
|
50
|
-
this.
|
|
50
|
+
this.subtract(value.value());
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
this._value -= value;
|
|
@@ -60,5 +60,6 @@ class PlayerTreasury extends DataObject_1.default {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
exports.PlayerTreasury = PlayerTreasury;
|
|
63
|
+
PlayerTreasury.transient = ['_cityBuildRegistry', '_ruleRegistry'];
|
|
63
64
|
exports.default = PlayerTreasury;
|
|
64
65
|
//# sourceMappingURL=PlayerTreasury.js.map
|
package/PlayerTreasury.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlayerTreasury.js","sourceRoot":"","sources":["PlayerTreasury.ts"],"names":[],"mappings":";;;AAAA,oFAGsD;AACtD,oEAG2C;AAE3C,uEAAgE;AAEhE,yCAAkC;AAElC,uDAAgD;AAChD,uCAAgC;AAYhC,MAAa,cAAe,SAAQ,oBAAU;
|
|
1
|
+
{"version":3,"file":"PlayerTreasury.js","sourceRoot":"","sources":["PlayerTreasury.ts"],"names":[],"mappings":";;;AAAA,oFAGsD;AACtD,oEAG2C;AAE3C,uEAAgE;AAEhE,yCAAkC;AAElC,uDAAgD;AAChD,uCAAgC;AAYhC,MAAa,cAAe,SAAQ,oBAAU;IAQ5C,YACE,MAAc,EACd,SAAuB,EACvB,oBAAuC,4BAAyB,EAChE,eAA6B,uBAAoB;QAEjD,KAAK,EAAE,CAAC;QATF,WAAM,GAAW,CAAC,CAAC;QAWzB,IAAI,CAAC,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O,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,eAAK,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,KAAqB;QACvB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAEhB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IAED,QAAQ,CAAC,KAAqB;QAC5B,IAAI,KAAK,YAAY,eAAK,EAAE;YAC1B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;YAE7B,OAAO;SACR;QAED,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;IACvB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;;AApFH,wCAqFC;AApFiB,wBAAS,GAAG,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;AAsFtE,kBAAe,cAAc,CAAC"}
|
package/PlayerTreasury.ts
CHANGED
|
@@ -25,6 +25,7 @@ export interface IPlayerTreasury {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
28
|
+
static readonly transient = ['_cityBuildRegistry', '_ruleRegistry'];
|
|
28
29
|
private _cityBuildRegistry: CityBuildRegistry;
|
|
29
30
|
private _player: Player;
|
|
30
31
|
private _ruleRegistry: RuleRegistry;
|
|
@@ -93,7 +94,7 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
93
94
|
|
|
94
95
|
subtract(value: Yield | number): void {
|
|
95
96
|
if (value instanceof Yield) {
|
|
96
|
-
this.
|
|
97
|
+
this.subtract(value.value());
|
|
97
98
|
|
|
98
99
|
return;
|
|
99
100
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civ-clone/core-treasury",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": "git@github.com:civ-clone/core-treasury.git",
|
|
6
6
|
"keywords": [
|
|
@@ -12,18 +12,27 @@
|
|
|
12
12
|
"private": false,
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "npm run ts:compile && npm run prettier:format",
|
|
15
|
-
"prettier:check": "prettier --config .prettierrc '**/*.ts'",
|
|
15
|
+
"prettier:check": "prettier --config .prettierrc --check '**/*.ts'",
|
|
16
16
|
"prettier:format": "prettier --config .prettierrc '**/*.ts' --write",
|
|
17
|
+
"test": "ts-mocha ./tests/*.test.ts",
|
|
18
|
+
"test:coverage": "c8 ts-mocha ./tests/*.test.ts",
|
|
17
19
|
"ts:compile": "tsc --build tsconfig.json"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
22
|
+
"@types/chai": "^4.3.3",
|
|
23
|
+
"@types/mocha": "^9.0",
|
|
24
|
+
"@types/node": "^16.0",
|
|
25
|
+
"c8": "^7.3",
|
|
26
|
+
"chai": "^4.2",
|
|
27
|
+
"mocha": "^9.0",
|
|
20
28
|
"prettier": "^2.1.2",
|
|
29
|
+
"ts-mocha": "^9.0",
|
|
21
30
|
"typescript": "^4.0.3"
|
|
22
31
|
},
|
|
23
32
|
"dependencies": {
|
|
24
33
|
"@civ-clone/core-city": "^0.1.0",
|
|
25
34
|
"@civ-clone/core-city-build": "^0.1.0",
|
|
26
|
-
"@civ-clone/core-data-object": "^0.1.
|
|
35
|
+
"@civ-clone/core-data-object": "^0.1.15",
|
|
27
36
|
"@civ-clone/core-player": "^0.1.0",
|
|
28
37
|
"@civ-clone/core-registry": "^0.1.0",
|
|
29
38
|
"@civ-clone/core-rule": "^0.1.0",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Player from '@civ-clone/core-player/Player';
|
|
2
|
+
import PlayerTreasury from '../PlayerTreasury';
|
|
3
|
+
import Yield from '@civ-clone/core-yield/Yield';
|
|
4
|
+
import { expect } from 'chai';
|
|
5
|
+
|
|
6
|
+
describe('PlayerTreasury', () => {
|
|
7
|
+
const treasury = (value: number): PlayerTreasury => {
|
|
8
|
+
const playerTreasury = new PlayerTreasury(new Player(), Yield);
|
|
9
|
+
|
|
10
|
+
playerTreasury.set(value);
|
|
11
|
+
|
|
12
|
+
return playerTreasury;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
it('adds a number or a Yield', () => {
|
|
16
|
+
const fromNumber = treasury(50),
|
|
17
|
+
fromYield = treasury(50);
|
|
18
|
+
|
|
19
|
+
fromNumber.add(10);
|
|
20
|
+
fromYield.add(new Yield(10));
|
|
21
|
+
|
|
22
|
+
expect(fromNumber.value()).to.equal(60);
|
|
23
|
+
expect(fromYield.value()).to.equal(60);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('subtracts a number or a Yield', () => {
|
|
27
|
+
const fromNumber = treasury(50),
|
|
28
|
+
fromYield = treasury(50);
|
|
29
|
+
|
|
30
|
+
fromNumber.subtract(10);
|
|
31
|
+
fromYield.subtract(new Yield(10));
|
|
32
|
+
|
|
33
|
+
expect(fromNumber.value()).to.equal(40);
|
|
34
|
+
expect(fromYield.value()).to.equal(40);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('sets a number or a Yield', () => {
|
|
38
|
+
const fromNumber = treasury(50),
|
|
39
|
+
fromYield = treasury(50);
|
|
40
|
+
|
|
41
|
+
fromNumber.set(5);
|
|
42
|
+
fromYield.set(new Yield(5));
|
|
43
|
+
|
|
44
|
+
expect(fromNumber.value()).to.equal(5);
|
|
45
|
+
expect(fromYield.value()).to.equal(5);
|
|
46
|
+
});
|
|
47
|
+
});
|