@civ-clone/core-treasury 0.1.4 → 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/PlayerTreasury.d.ts +5 -1
- package/PlayerTreasury.js +16 -33
- package/PlayerTreasury.js.map +1 -1
- package/PlayerTreasury.ts +21 -21
- package/SpendCost.d.ts +2 -1
- package/SpendCost.js +4 -19
- package/SpendCost.js.map +1 -1
- package/SpendCost.ts +6 -6
- package/package.json +1 -1
package/PlayerTreasury.d.ts
CHANGED
|
@@ -18,7 +18,11 @@ export declare class PlayerTreasury
|
|
|
18
18
|
extends DataObject
|
|
19
19
|
implements IPlayerTreasury
|
|
20
20
|
{
|
|
21
|
-
|
|
21
|
+
private _cityBuildRegistry;
|
|
22
|
+
private _player;
|
|
23
|
+
private _ruleRegistry;
|
|
24
|
+
private _value;
|
|
25
|
+
private _yield;
|
|
22
26
|
constructor(
|
|
23
27
|
player: Player,
|
|
24
28
|
YieldType: typeof Yield,
|
package/PlayerTreasury.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _PlayerTreasury_cityBuildRegistry, _PlayerTreasury_player, _PlayerTreasury_ruleRegistry, _PlayerTreasury_value, _PlayerTreasury_yield;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.PlayerTreasury = void 0;
|
|
16
4
|
const CityBuildRegistry_1 = require("@civ-clone/core-city-build/CityBuildRegistry");
|
|
@@ -22,43 +10,39 @@ const Rush_1 = require("./Rules/Rush");
|
|
|
22
10
|
class PlayerTreasury extends DataObject_1.default {
|
|
23
11
|
constructor(player, YieldType, cityBuildRegistry = CityBuildRegistry_1.instance, ruleRegistry = RuleRegistry_1.instance) {
|
|
24
12
|
super();
|
|
25
|
-
|
|
26
|
-
_PlayerTreasury_player.set(this, void 0);
|
|
27
|
-
_PlayerTreasury_ruleRegistry.set(this, void 0);
|
|
28
|
-
_PlayerTreasury_value.set(this, 0);
|
|
29
|
-
_PlayerTreasury_yield.set(this, void 0);
|
|
13
|
+
this._value = 0;
|
|
30
14
|
this.addKey('value', 'yield');
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
this._cityBuildRegistry = cityBuildRegistry;
|
|
16
|
+
this._player = player;
|
|
17
|
+
this._ruleRegistry = ruleRegistry;
|
|
18
|
+
this._yield = YieldType;
|
|
35
19
|
}
|
|
36
20
|
add(value) {
|
|
37
21
|
if (value instanceof Yield_1.default) {
|
|
38
22
|
this.add(value.value());
|
|
39
23
|
return;
|
|
40
24
|
}
|
|
41
|
-
|
|
25
|
+
this._value += value;
|
|
42
26
|
}
|
|
43
27
|
buy(city) {
|
|
44
|
-
const cityBuild =
|
|
45
|
-
if (city.player() !==
|
|
28
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city), [spendCost] = this.cost(city).filter((spendCost) => spendCost.resource() === this._yield), cost = spendCost.value();
|
|
29
|
+
if (city.player() !== this._player || this.value() < cost) {
|
|
46
30
|
return;
|
|
47
31
|
}
|
|
48
|
-
|
|
32
|
+
this._ruleRegistry.process(Rush_1.default, cityBuild, spendCost);
|
|
49
33
|
// TODO: do this via Rules and then use Production
|
|
50
34
|
cityBuild.add(new Yield_1.default(cityBuild.remaining()));
|
|
51
35
|
this.subtract(cost);
|
|
52
36
|
}
|
|
53
37
|
cost(city) {
|
|
54
|
-
const cityBuild =
|
|
55
|
-
return
|
|
38
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city);
|
|
39
|
+
return this._ruleRegistry.process(Spend_1.default, cityBuild);
|
|
56
40
|
}
|
|
57
41
|
player() {
|
|
58
|
-
return
|
|
42
|
+
return this._player;
|
|
59
43
|
}
|
|
60
44
|
set(value) {
|
|
61
|
-
|
|
45
|
+
this._value = 0;
|
|
62
46
|
this.add(value);
|
|
63
47
|
}
|
|
64
48
|
subtract(value) {
|
|
@@ -66,16 +50,15 @@ class PlayerTreasury extends DataObject_1.default {
|
|
|
66
50
|
this.add(value.value());
|
|
67
51
|
return;
|
|
68
52
|
}
|
|
69
|
-
|
|
53
|
+
this._value -= value;
|
|
70
54
|
}
|
|
71
55
|
value() {
|
|
72
|
-
return
|
|
56
|
+
return this._value;
|
|
73
57
|
}
|
|
74
58
|
yield() {
|
|
75
|
-
return
|
|
59
|
+
return this._yield;
|
|
76
60
|
}
|
|
77
61
|
}
|
|
78
62
|
exports.PlayerTreasury = PlayerTreasury;
|
|
79
|
-
_PlayerTreasury_cityBuildRegistry = new WeakMap(), _PlayerTreasury_player = new WeakMap(), _PlayerTreasury_ruleRegistry = new WeakMap(), _PlayerTreasury_value = new WeakMap(), _PlayerTreasury_yield = new WeakMap();
|
|
80
63
|
exports.default = PlayerTreasury;
|
|
81
64
|
//# sourceMappingURL=PlayerTreasury.js.map
|
package/PlayerTreasury.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlayerTreasury.js","sourceRoot":"","sources":["P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AE;YACzD,OAAO;SACR;QAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,cAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QACvD,kDAAkD;QAClD,SAAS,CAAC,GAAG,CAAC,IAAI,eAAK,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAEhD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,IAAU;QACb,MAAM,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAE1D,OAAO,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,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;YAExB,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;CACF;AApFD,wCAoFC;AAED,kBAAe,cAAc,CAAC"}
|
package/PlayerTreasury.ts
CHANGED
|
@@ -25,11 +25,11 @@ export interface IPlayerTreasury {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
private _cityBuildRegistry: CityBuildRegistry;
|
|
29
|
+
private _player: Player;
|
|
30
|
+
private _ruleRegistry: RuleRegistry;
|
|
31
|
+
private _value: number = 0;
|
|
32
|
+
private _yield: typeof Yield;
|
|
33
33
|
|
|
34
34
|
constructor(
|
|
35
35
|
player: Player,
|
|
@@ -41,10 +41,10 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
41
41
|
|
|
42
42
|
this.addKey('value', 'yield');
|
|
43
43
|
|
|
44
|
-
this
|
|
45
|
-
this
|
|
46
|
-
this
|
|
47
|
-
this
|
|
44
|
+
this._cityBuildRegistry = cityBuildRegistry;
|
|
45
|
+
this._player = player;
|
|
46
|
+
this._ruleRegistry = ruleRegistry;
|
|
47
|
+
this._yield = YieldType;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
add(value: Yield | number): void {
|
|
@@ -54,21 +54,21 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
this
|
|
57
|
+
this._value += value;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
buy(city: City): void {
|
|
61
|
-
const cityBuild = this
|
|
61
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city),
|
|
62
62
|
[spendCost] = this.cost(city).filter(
|
|
63
|
-
(spendCost) => spendCost.resource() === this
|
|
63
|
+
(spendCost) => spendCost.resource() === this._yield
|
|
64
64
|
),
|
|
65
65
|
cost = spendCost.value();
|
|
66
66
|
|
|
67
|
-
if (city.player() !== this
|
|
67
|
+
if (city.player() !== this._player || this.value() < cost) {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
this
|
|
71
|
+
this._ruleRegistry.process(Rush, cityBuild, spendCost);
|
|
72
72
|
// TODO: do this via Rules and then use Production
|
|
73
73
|
cityBuild.add(new Yield(cityBuild.remaining()));
|
|
74
74
|
|
|
@@ -76,17 +76,17 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
cost(city: City): SpendCost[] {
|
|
79
|
-
const cityBuild = this
|
|
79
|
+
const cityBuild = this._cityBuildRegistry.getByCity(city);
|
|
80
80
|
|
|
81
|
-
return this
|
|
81
|
+
return this._ruleRegistry.process(Spend, cityBuild);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
player(): Player {
|
|
85
|
-
return this
|
|
85
|
+
return this._player;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
set(value: Yield | number): void {
|
|
89
|
-
this
|
|
89
|
+
this._value = 0;
|
|
90
90
|
|
|
91
91
|
this.add(value);
|
|
92
92
|
}
|
|
@@ -98,15 +98,15 @@ export class PlayerTreasury extends DataObject implements IPlayerTreasury {
|
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
this
|
|
101
|
+
this._value -= value;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
value(): number {
|
|
105
|
-
return this
|
|
105
|
+
return this._value;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
yield(): typeof Yield {
|
|
109
|
-
return this
|
|
109
|
+
return this._yield;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
package/SpendCost.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ interface ISpend {
|
|
|
5
5
|
value(): number;
|
|
6
6
|
}
|
|
7
7
|
export declare class SpendCost extends DataObject implements ISpend {
|
|
8
|
-
|
|
8
|
+
private _resource;
|
|
9
|
+
private _value;
|
|
9
10
|
constructor(resource: typeof Yield, value: number);
|
|
10
11
|
resource(): typeof Yield;
|
|
11
12
|
value(): number;
|
package/SpendCost.js
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _SpendCost_resource, _SpendCost_value;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.SpendCost = void 0;
|
|
16
4
|
const DataObject_1 = require("@civ-clone/core-data-object/DataObject");
|
|
17
5
|
class SpendCost extends DataObject_1.default {
|
|
18
6
|
constructor(resource, value) {
|
|
19
7
|
super();
|
|
20
|
-
_SpendCost_resource.set(this, void 0);
|
|
21
|
-
_SpendCost_value.set(this, void 0);
|
|
22
8
|
this.addKey('resource', 'value');
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
this._resource = resource;
|
|
10
|
+
this._value = value;
|
|
25
11
|
}
|
|
26
12
|
resource() {
|
|
27
|
-
return
|
|
13
|
+
return this._resource;
|
|
28
14
|
}
|
|
29
15
|
value() {
|
|
30
|
-
return
|
|
16
|
+
return this._value;
|
|
31
17
|
}
|
|
32
18
|
}
|
|
33
19
|
exports.SpendCost = SpendCost;
|
|
34
|
-
_SpendCost_resource = new WeakMap(), _SpendCost_value = new WeakMap();
|
|
35
20
|
exports.default = SpendCost;
|
|
36
21
|
//# sourceMappingURL=SpendCost.js.map
|
package/SpendCost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpendCost.js","sourceRoot":"","sources":["SpendCost.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SpendCost.js","sourceRoot":"","sources":["SpendCost.ts"],"names":[],"mappings":";;;AAAA,uEAAgE;AAQhE,MAAa,SAAU,SAAQ,oBAAU;IAIvC,YAAY,QAAsB,EAAE,KAAa;QAC/C,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAEjC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AApBD,8BAoBC;AAED,kBAAe,SAAS,CAAC"}
|
package/SpendCost.ts
CHANGED
|
@@ -7,24 +7,24 @@ interface ISpend {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export class SpendCost extends DataObject implements ISpend {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
private _resource: typeof Yield;
|
|
11
|
+
private _value: number;
|
|
12
12
|
|
|
13
13
|
constructor(resource: typeof Yield, value: number) {
|
|
14
14
|
super();
|
|
15
15
|
|
|
16
16
|
this.addKey('resource', 'value');
|
|
17
17
|
|
|
18
|
-
this
|
|
19
|
-
this
|
|
18
|
+
this._resource = resource;
|
|
19
|
+
this._value = value;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
resource(): typeof Yield {
|
|
23
|
-
return this
|
|
23
|
+
return this._resource;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
value(): number {
|
|
27
|
-
return this
|
|
27
|
+
return this._value;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|