@civ-clone/base-unit-action-bribe-unit 0.0.0-stage → 0.1.0

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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ **/*.js linguist-generated=true
2
+
@@ -0,0 +1,39 @@
1
+ name: Build and test application on push to remote
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ - uses: pnpm/action-setup@v4
11
+ with:
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/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true
4
+ }
package/BribeUnit.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { RuleRegistry } from '@civ-clone/core-rule/RuleRegistry';
2
+ import Action from '@civ-clone/core-unit/Action';
3
+ import Tile from '@civ-clone/core-world/Tile';
4
+ import Unit from '@civ-clone/core-unit/Unit';
5
+ /**
6
+ * A Diplomat pays `cost()` for `target()` to desert to its civilization. Whether it can is up to the `UnitBribed`
7
+ * rules. The Diplomat isn't used up, and keeps its moves.
8
+ */
9
+ export declare class BribeUnit extends Action {
10
+ private _cost;
11
+ private _target;
12
+ constructor(
13
+ from: Tile,
14
+ to: Tile,
15
+ unit: Unit,
16
+ target: Unit,
17
+ cost: number,
18
+ ruleRegistry?: RuleRegistry
19
+ );
20
+ cost(): number;
21
+ target(): Unit;
22
+ forUnit(unit: Unit): Action;
23
+ perform(): void;
24
+ }
25
+ export default BribeUnit;
package/BribeUnit.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BribeUnit = void 0;
4
+ const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
5
+ const Action_1 = require("@civ-clone/core-unit/Action");
6
+ const UnitBribed_1 = require("./Rules/UnitBribed");
7
+ /**
8
+ * A Diplomat pays `cost()` for `target()` to desert to its civilization. Whether it can is up to the `UnitBribed`
9
+ * rules. The Diplomat isn't used up, and keeps its moves.
10
+ */
11
+ class BribeUnit extends Action_1.default {
12
+ constructor(from, to, unit, target, cost, ruleRegistry = RuleRegistry_1.instance) {
13
+ super(from, to, unit, ruleRegistry);
14
+ this._cost = cost;
15
+ this._target = target;
16
+ this.addKey('cost');
17
+ }
18
+ cost() {
19
+ return this._cost;
20
+ }
21
+ target() {
22
+ return this._target;
23
+ }
24
+ // `Action.forUnit` rebuilds an action from `(from, to, unit, ruleRegistry)`, which would put the `RuleRegistry` where
25
+ // the target goes.
26
+ // Typed as `Action`: a subclass with a member of its own isn't assignable to it (civ-clone/web-renderer#21).
27
+ forUnit(unit) {
28
+ return new BribeUnit(this.from(), this.to(), unit, this._target, this._cost, this.ruleRegistry());
29
+ }
30
+ perform() {
31
+ this.ruleRegistry().process(UnitBribed_1.default, this.unit(), this._target, this);
32
+ }
33
+ }
34
+ exports.BribeUnit = BribeUnit;
35
+ exports.default = BribeUnit;
36
+ //# sourceMappingURL=BribeUnit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BribeUnit.js","sourceRoot":"","sources":["BribeUnit.ts"],"names":[],"mappings":";;;AAAA,oEAG2C;AAC3C,wDAAiD;AAGjD,mDAA4C;AAE5C;;;GAGG;AACH,MAAa,SAAU,SAAQ,gBAAM;IAInC,YACE,IAAU,EACV,EAAQ,EACR,IAAU,EACV,MAAY,EACZ,IAAY,EACZ,eAA6B,uBAAoB;QAEjD,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QAEpC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAEtB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,sHAAsH;IACtH,mBAAmB;IACnB,6GAA6G;IAC7G,OAAO,CAAC,IAAU;QAChB,OAAO,IAAI,SAAS,CAClB,IAAI,CAAC,IAAI,EAAE,EACX,IAAI,CAAC,EAAE,EAAE,EACT,IAAI,EACJ,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,YAAY,EAAE,CACC,CAAC;IACzB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,YAAY,EAAE,CAAC,OAAO,CAAC,oBAAU,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;CACF;AA7CD,8BA6CC;AAED,kBAAe,SAAS,CAAC"}
package/BribeUnit.ts ADDED
@@ -0,0 +1,61 @@
1
+ import {
2
+ RuleRegistry,
3
+ instance as ruleRegistryInstance,
4
+ } from '@civ-clone/core-rule/RuleRegistry';
5
+ import Action from '@civ-clone/core-unit/Action';
6
+ import Tile from '@civ-clone/core-world/Tile';
7
+ import Unit from '@civ-clone/core-unit/Unit';
8
+ import UnitBribed from './Rules/UnitBribed';
9
+
10
+ /**
11
+ * A Diplomat pays `cost()` for `target()` to desert to its civilization. Whether it can is up to the `UnitBribed`
12
+ * rules. The Diplomat isn't used up, and keeps its moves.
13
+ */
14
+ export class BribeUnit extends Action {
15
+ private _cost: number;
16
+ private _target: Unit;
17
+
18
+ constructor(
19
+ from: Tile,
20
+ to: Tile,
21
+ unit: Unit,
22
+ target: Unit,
23
+ cost: number,
24
+ ruleRegistry: RuleRegistry = ruleRegistryInstance
25
+ ) {
26
+ super(from, to, unit, ruleRegistry);
27
+
28
+ this._cost = cost;
29
+ this._target = target;
30
+
31
+ this.addKey('cost');
32
+ }
33
+
34
+ cost(): number {
35
+ return this._cost;
36
+ }
37
+
38
+ target(): Unit {
39
+ return this._target;
40
+ }
41
+
42
+ // `Action.forUnit` rebuilds an action from `(from, to, unit, ruleRegistry)`, which would put the `RuleRegistry` where
43
+ // the target goes.
44
+ // Typed as `Action`: a subclass with a member of its own isn't assignable to it (civ-clone/web-renderer#21).
45
+ forUnit(unit: Unit): Action {
46
+ return new BribeUnit(
47
+ this.from(),
48
+ this.to(),
49
+ unit,
50
+ this._target,
51
+ this._cost,
52
+ this.ruleRegistry()
53
+ ) as unknown as Action;
54
+ }
55
+
56
+ perform(): void {
57
+ this.ruleRegistry().process(UnitBribed, this.unit(), this._target, this);
58
+ }
59
+ }
60
+
61
+ export default BribeUnit;
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Dom Hastings
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Temporary Holding Version
1
+ # base-unit-action-bribe-unit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The `BribeUnit` unit action. See civ-clone/web-renderer#58.
@@ -0,0 +1,12 @@
1
+ import type BribeUnit from '../BribeUnit';
2
+ import Rule from '@civ-clone/core-rule/Rule';
3
+ import Unit from '@civ-clone/core-unit/Unit';
4
+ /**
5
+ * Processed when a Diplomat (the first `Unit`) bribes the second, by the `BribeUnit` action. `true` when the unit
6
+ * changed sides.
7
+ */
8
+ export declare class UnitBribed extends Rule<
9
+ [Unit, Unit, BribeUnit],
10
+ boolean
11
+ > {}
12
+ export default UnitBribed;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnitBribed = void 0;
4
+ const Rule_1 = require("@civ-clone/core-rule/Rule");
5
+ /**
6
+ * Processed when a Diplomat (the first `Unit`) bribes the second, by the `BribeUnit` action. `true` when the unit
7
+ * changed sides.
8
+ */
9
+ class UnitBribed extends Rule_1.default {
10
+ }
11
+ exports.UnitBribed = UnitBribed;
12
+ exports.default = UnitBribed;
13
+ //# sourceMappingURL=UnitBribed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnitBribed.js","sourceRoot":"","sources":["UnitBribed.ts"],"names":[],"mappings":";;;AACA,oDAA6C;AAG7C;;;GAGG;AACH,MAAa,UAAW,SAAQ,cAAsC;CAAG;AAAzE,gCAAyE;AAEzE,kBAAe,UAAU,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type BribeUnit from '../BribeUnit';
2
+ import Rule from '@civ-clone/core-rule/Rule';
3
+ import Unit from '@civ-clone/core-unit/Unit';
4
+
5
+ /**
6
+ * Processed when a Diplomat (the first `Unit`) bribes the second, by the `BribeUnit` action. `true` when the unit
7
+ * changed sides.
8
+ */
9
+ export class UnitBribed extends Rule<[Unit, Unit, BribeUnit], boolean> {}
10
+
11
+ export default UnitBribed;
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@civ-clone/base-unit-action-bribe-unit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "main": "BribeUnit.js",
5
+ "repository": "git@github.com:civ-clone/base-unit-action-bribe-unit.git",
6
+ "keywords": [
7
+ "typescript",
8
+ "civilization"
9
+ ],
10
+ "author": "dom111 <dom111@users.noreply.github.com>",
11
+ "license": "MIT",
12
+ "private": false,
13
+ "scripts": {
14
+ "build": "npm run ts:compile && npm run prettier:format",
15
+ "prettier:check": "prettier --config .prettierrc --check '**/*.ts'",
16
+ "prettier:format": "prettier --config .prettierrc '**/*.ts' --write",
17
+ "ts:compile": "tsc --build tsconfig.json"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^14.18.63",
21
+ "prettier": "^2.8.8",
22
+ "typescript": "^4.9.5"
23
+ },
24
+ "dependencies": {
25
+ "@civ-clone/core-rule": "^0.1.6",
26
+ "@civ-clone/core-unit": "^0.1.25",
27
+ "@civ-clone/core-world": "^0.1.14"
28
+ }
29
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "lib": [
5
+ "es2019"
6
+ ],
7
+ "module": "commonjs",
8
+ "sourceMap": true,
9
+ "strict": true,
10
+ "target": "ES2018"
11
+ },
12
+ "exclude": [
13
+ "node_modules",
14
+ "tests/*.test.ts"
15
+ ]
16
+ }