@civ-clone/base-unit-action-goto 0.1.1 → 0.1.3
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/GoTo.d.ts +2 -1
- package/GoTo.js +4 -19
- package/GoTo.js.map +1 -1
- package/GoTo.ts +6 -6
- package/lib/moveAlongPath.d.ts +6 -1
- package/lib/moveAlongPath.js +8 -3
- package/lib/moveAlongPath.js.map +1 -1
- package/lib/moveAlongPath.ts +17 -4
- package/package.json +1 -1
package/GoTo.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import Tile from '@civ-clone/core-world/Tile';
|
|
|
6
6
|
import Unit from '@civ-clone/core-unit/Unit';
|
|
7
7
|
export declare const generateKey: (unit: Unit) => string;
|
|
8
8
|
export declare class GoTo extends Action {
|
|
9
|
-
|
|
9
|
+
private _pathFinderRegistry;
|
|
10
|
+
private _strategyNoteRegistry;
|
|
10
11
|
constructor(
|
|
11
12
|
from: Tile,
|
|
12
13
|
to: Tile,
|
package/GoTo.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 _GoTo_pathFinderRegistry, _GoTo_strategyNoteRegistry;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.GoTo = exports.generateKey = void 0;
|
|
16
4
|
const PathFinderRegistry_1 = require("@civ-clone/core-world-path/PathFinderRegistry");
|
|
@@ -30,13 +18,11 @@ exports.generateKey = generateKey;
|
|
|
30
18
|
class GoTo extends Action_1.default {
|
|
31
19
|
constructor(from, to, unit, ruleRegistry = RuleRegistry_1.instance, pathFinderRegistry = PathFinderRegistry_1.instance, strategyNoteRegistry = StrategyNoteRegistry_1.instance) {
|
|
32
20
|
super(from, to, unit, ruleRegistry);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
__classPrivateFieldSet(this, _GoTo_pathFinderRegistry, pathFinderRegistry, "f");
|
|
36
|
-
__classPrivateFieldSet(this, _GoTo_strategyNoteRegistry, strategyNoteRegistry, "f");
|
|
21
|
+
this._pathFinderRegistry = pathFinderRegistry;
|
|
22
|
+
this._strategyNoteRegistry = strategyNoteRegistry;
|
|
37
23
|
}
|
|
38
24
|
perform() {
|
|
39
|
-
const [PathFinder] =
|
|
25
|
+
const [PathFinder] = this._pathFinderRegistry.entries();
|
|
40
26
|
if (!PathFinder) {
|
|
41
27
|
throw new NoPathFinderAvailable_1.default();
|
|
42
28
|
}
|
|
@@ -47,7 +33,7 @@ class GoTo extends Action_1.default {
|
|
|
47
33
|
this.unit().setBusy();
|
|
48
34
|
// remove the current `Tile` so that the next shift will be the target.
|
|
49
35
|
path.shift();
|
|
50
|
-
|
|
36
|
+
this._strategyNoteRegistry.replace(new StrategyNote_1.StrategyNote((0, exports.generateKey)(this.unit()), path));
|
|
51
37
|
(0, moveAlongPath_1.default)(this.unit(), path);
|
|
52
38
|
this.unit().setBusy(new GoTo_1.default(new Criterion_1.default(() => this.unit().tile() === path.end()), new Effect_1.default(() => {
|
|
53
39
|
this.unit().setActive();
|
|
@@ -57,6 +43,5 @@ class GoTo extends Action_1.default {
|
|
|
57
43
|
}
|
|
58
44
|
}
|
|
59
45
|
exports.GoTo = GoTo;
|
|
60
|
-
_GoTo_pathFinderRegistry = new WeakMap(), _GoTo_strategyNoteRegistry = new WeakMap();
|
|
61
46
|
exports.default = GoTo;
|
|
62
47
|
//# sourceMappingURL=GoTo.js.map
|
package/GoTo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoTo.js","sourceRoot":"","sources":["GoTo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GoTo.js","sourceRoot":"","sources":["GoTo.ts"],"names":[],"mappings":";;;AAAA,sFAGuD;AACvD,oEAG2C;AAC3C,wEAG+C;AAC/C,wFAGuD;AACvD,wDAAiD;AACjD,sCAAmC;AACnC,8DAAuD;AACvD,wDAAiD;AACjD,4DAAqD;AACrD,8DAAuD;AACvD,0EAAmE;AAGnE,uDAAgD;AAEzC,MAAM,WAAW,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,IAAA,0BAAc,EAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AAAlE,QAAA,WAAW,eAAuD;AAE/E,MAAa,IAAK,SAAQ,gBAAM;IAI9B,YACE,IAAU,EACV,EAAQ,EACR,IAAU,EACV,eAA6B,uBAAoB,EACjD,qBAAyC,6BAA0B,EACnE,uBAA6C,+BAA4B;QAEzE,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QAEpC,IAAI,CAAC,mBAAmB,GAAG,kBAAkB,CAAC;QAC9C,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAC;IACpD,CAAC;IAED,OAAO;QACL,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;QAExD,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,+BAAq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, 'currentPath');
|
|
29
29
|
|
|
30
30
|
export class GoTo extends Action {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
private _pathFinderRegistry: PathFinderRegistry;
|
|
32
|
+
private _strategyNoteRegistry: StrategyNoteRegistry;
|
|
33
33
|
|
|
34
34
|
constructor(
|
|
35
35
|
from: Tile,
|
|
@@ -41,12 +41,12 @@ export class GoTo extends Action {
|
|
|
41
41
|
) {
|
|
42
42
|
super(from, to, unit, ruleRegistry);
|
|
43
43
|
|
|
44
|
-
this
|
|
45
|
-
this
|
|
44
|
+
this._pathFinderRegistry = pathFinderRegistry;
|
|
45
|
+
this._strategyNoteRegistry = strategyNoteRegistry;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
perform(): void {
|
|
49
|
-
const [PathFinder] = this
|
|
49
|
+
const [PathFinder] = this._pathFinderRegistry.entries();
|
|
50
50
|
|
|
51
51
|
if (!PathFinder) {
|
|
52
52
|
throw new NoPathFinderAvailable();
|
|
@@ -67,7 +67,7 @@ export class GoTo extends Action {
|
|
|
67
67
|
// remove the current `Tile` so that the next shift will be the target.
|
|
68
68
|
path.shift();
|
|
69
69
|
|
|
70
|
-
this
|
|
70
|
+
this._strategyNoteRegistry.replace(
|
|
71
71
|
new StrategyNote(generateKey(this.unit()), path)
|
|
72
72
|
);
|
|
73
73
|
|
package/lib/moveAlongPath.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { StrategyNoteRegistry } from '@civ-clone/core-strategy/StrategyNoteRegistry';
|
|
1
2
|
import Path from '@civ-clone/core-world-path/Path';
|
|
2
3
|
import Unit from '@civ-clone/core-unit/Unit';
|
|
3
|
-
export declare const moveAlongPath: (
|
|
4
|
+
export declare const moveAlongPath: (
|
|
5
|
+
unit: Unit,
|
|
6
|
+
path: Path,
|
|
7
|
+
strategyNoteRegistry?: StrategyNoteRegistry
|
|
8
|
+
) => void;
|
|
4
9
|
export default moveAlongPath;
|
package/lib/moveAlongPath.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.moveAlongPath = void 0;
|
|
4
|
+
const StrategyNoteRegistry_1 = require("@civ-clone/core-strategy/StrategyNoteRegistry");
|
|
4
5
|
const Move_1 = require("@civ-clone/base-unit-action-move/Move");
|
|
5
6
|
const NoOrders_1 = require("@civ-clone/base-unit-action-no-orders/NoOrders");
|
|
6
|
-
const
|
|
7
|
+
const GoTo_1 = require("../GoTo");
|
|
8
|
+
const moveAlongPath = (unit, path, strategyNoteRegistry = StrategyNoteRegistry_1.instance) => {
|
|
7
9
|
while (unit.moves().value() > 0.25) {
|
|
8
10
|
const [move] = unit
|
|
9
11
|
.actions(path.shift())
|
|
@@ -16,9 +18,12 @@ const moveAlongPath = (unit, path) => {
|
|
|
16
18
|
if (path.length === 0) {
|
|
17
19
|
unit.setBusy();
|
|
18
20
|
unit.setActive();
|
|
21
|
+
const note = strategyNoteRegistry.getByKey((0, GoTo_1.generateKey)(unit));
|
|
22
|
+
if (note) {
|
|
23
|
+
strategyNoteRegistry.unregister(note);
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
|
-
if (unit.moves().value()
|
|
21
|
-
unit.setActive(false);
|
|
26
|
+
if (unit.moves().value() > 0.25) {
|
|
22
27
|
return;
|
|
23
28
|
}
|
|
24
29
|
const [noOrders] = unit
|
package/lib/moveAlongPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moveAlongPath.js","sourceRoot":"","sources":["moveAlongPath.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"moveAlongPath.js","sourceRoot":"","sources":["moveAlongPath.ts"],"names":[],"mappings":";;;AAAA,wFAGuD;AAEvD,gEAAyD;AACzD,6EAAsE;AAGtE,kCAAsC;AAE/B,MAAM,aAAa,GAAG,CAC3B,IAAU,EACV,IAAU,EACV,uBAA6C,+BAA4B,EACnE,EAAE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
|
+
instance as strategyNoteRegistryInstance,
|
|
4
|
+
} from '@civ-clone/core-strategy/StrategyNoteRegistry';
|
|
1
5
|
import Action from '@civ-clone/core-unit/Action';
|
|
2
6
|
import Move from '@civ-clone/base-unit-action-move/Move';
|
|
3
7
|
import NoOrders from '@civ-clone/base-unit-action-no-orders/NoOrders';
|
|
4
8
|
import Path from '@civ-clone/core-world-path/Path';
|
|
5
9
|
import Unit from '@civ-clone/core-unit/Unit';
|
|
10
|
+
import { generateKey } from '../GoTo';
|
|
6
11
|
|
|
7
|
-
export const moveAlongPath = (
|
|
12
|
+
export const moveAlongPath = (
|
|
13
|
+
unit: Unit,
|
|
14
|
+
path: Path,
|
|
15
|
+
strategyNoteRegistry: StrategyNoteRegistry = strategyNoteRegistryInstance
|
|
16
|
+
): void => {
|
|
8
17
|
while (unit.moves().value() > 0.25) {
|
|
9
18
|
const [move] = unit
|
|
10
19
|
.actions(path.shift())
|
|
@@ -22,11 +31,15 @@ export const moveAlongPath = (unit: Unit, path: Path): void => {
|
|
|
22
31
|
if (path.length === 0) {
|
|
23
32
|
unit.setBusy();
|
|
24
33
|
unit.setActive();
|
|
25
|
-
}
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
const note = strategyNoteRegistry.getByKey(generateKey(unit));
|
|
36
|
+
|
|
37
|
+
if (note) {
|
|
38
|
+
strategyNoteRegistry.unregister(note);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
29
41
|
|
|
42
|
+
if (unit.moves().value() > 0.25) {
|
|
30
43
|
return;
|
|
31
44
|
}
|
|
32
45
|
|