@gamepark/rules-api 6.30.0 → 6.32.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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HexGridSystem } from './grid.hex.util';
|
|
2
|
+
import { XYCoordinates } from './grid.util';
|
|
3
|
+
export type AdjacentGroup<T = number> = {
|
|
4
|
+
values: T[];
|
|
5
|
+
coordinates: XYCoordinates[];
|
|
6
|
+
};
|
|
7
|
+
type CreateAdjacentGroupsOptions<T = number> = {
|
|
8
|
+
isEmpty?: (value: T) => boolean;
|
|
9
|
+
hexGridSystem?: HexGridSystem;
|
|
10
|
+
};
|
|
11
|
+
export declare function createAdjacentGroups<T = number>(map: T[][], options?: CreateAdjacentGroupsOptions<T>): AdjacentGroup<T>[][];
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAdjacentGroups = void 0;
|
|
4
|
+
var grid_hex_util_1 = require("./grid.hex.util");
|
|
5
|
+
function getPreviousAdjacentCoordinates(_a, hexGridSystem) {
|
|
6
|
+
var x = _a.x, y = _a.y;
|
|
7
|
+
var adjacentCoordinates = [];
|
|
8
|
+
if (hexGridSystem === undefined) {
|
|
9
|
+
if (x > 0)
|
|
10
|
+
adjacentCoordinates.push({ x: x - 1, y: y });
|
|
11
|
+
if (y > 0)
|
|
12
|
+
adjacentCoordinates.push({ x: x, y: y - 1 });
|
|
13
|
+
return adjacentCoordinates;
|
|
14
|
+
}
|
|
15
|
+
switch (hexGridSystem) {
|
|
16
|
+
case grid_hex_util_1.HexGridSystem.Axial:
|
|
17
|
+
if (x > 0)
|
|
18
|
+
adjacentCoordinates.push({ x: x - 1, y: y });
|
|
19
|
+
if (y > 0)
|
|
20
|
+
adjacentCoordinates.push({ x: x, y: y - 1 }, { x: x + 1, y: y - 1 });
|
|
21
|
+
return adjacentCoordinates;
|
|
22
|
+
default:
|
|
23
|
+
throw new Error('Not implemented');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function createAdjacentGroups(map, options) {
|
|
27
|
+
var _a;
|
|
28
|
+
var _b, _c, _d;
|
|
29
|
+
var isEmpty = (_b = options === null || options === void 0 ? void 0 : options.isEmpty) !== null && _b !== void 0 ? _b : (function (value) { return !value; });
|
|
30
|
+
var groups = [];
|
|
31
|
+
for (var y = 0; y < map.length; y++) {
|
|
32
|
+
groups.push([]);
|
|
33
|
+
for (var x = 0; x < map[y].length; x++) {
|
|
34
|
+
var value = map[y][x];
|
|
35
|
+
if (isEmpty(value)) {
|
|
36
|
+
groups[y][x] = { values: [], coordinates: [] };
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
var previousAdjacentCoordinates = getPreviousAdjacentCoordinates({ x: x, y: y }, options === null || options === void 0 ? void 0 : options.hexGridSystem);
|
|
40
|
+
var adjacentGroups = [];
|
|
41
|
+
for (var _i = 0, previousAdjacentCoordinates_1 = previousAdjacentCoordinates; _i < previousAdjacentCoordinates_1.length; _i++) {
|
|
42
|
+
var _e = previousAdjacentCoordinates_1[_i], x_1 = _e.x, y_1 = _e.y;
|
|
43
|
+
if (((_d = (_c = groups[y_1]) === null || _c === void 0 ? void 0 : _c[x_1]) === null || _d === void 0 ? void 0 : _d.values.length) && !adjacentGroups.includes(groups[y_1][x_1])) {
|
|
44
|
+
adjacentGroups.push(groups[y_1][x_1]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!adjacentGroups.length) {
|
|
48
|
+
groups[y][x] = { values: [value], coordinates: [{ x: x, y: y }] };
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
groups[y][x] = adjacentGroups[0];
|
|
52
|
+
groups[y][x].values.push(value);
|
|
53
|
+
groups[y][x].coordinates.push({ x: x, y: y });
|
|
54
|
+
for (var i = 1; i < adjacentGroups.length; i++) {
|
|
55
|
+
(_a = adjacentGroups[0].values).push.apply(_a, adjacentGroups[i].values);
|
|
56
|
+
for (var _f = 0, _g = adjacentGroups[i].coordinates; _f < _g.length; _f++) {
|
|
57
|
+
var _h = _g[_f], x_2 = _h.x, y_2 = _h.y;
|
|
58
|
+
groups[y_2][x_2] = adjacentGroups[0];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return groups;
|
|
66
|
+
}
|
|
67
|
+
exports.createAdjacentGroups = createAdjacentGroups;
|
|
68
|
+
//# sourceMappingURL=adjacent-groups.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adjacent-groups.util.js","sourceRoot":"","sources":["../../src/utils/adjacent-groups.util.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAQ/C,SAAS,8BAA8B,CAAC,EAAuB,EAAE,aAA6B;QAApD,CAAC,OAAA,EAAE,CAAC,OAAA;IAC5C,IAAM,mBAAmB,GAAoB,EAAE,CAAA;IAC/C,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC;YAAE,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAA,EAAE,CAAC,CAAA;QACpD,IAAI,CAAC,GAAG,CAAC;YAAE,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAA,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACpD,OAAO,mBAAmB,CAAA;IAC5B,CAAC;IACD,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,6BAAa,CAAC,KAAK;YACtB,IAAI,CAAC,GAAG,CAAC;gBAAE,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAA,EAAE,CAAC,CAAA;YACpD,IAAI,CAAC,GAAG,CAAC;gB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AAC,CAAC,MAAM,EAAC;wBAC1D,KAAuB,UAA6B,EAA7B,KAAA,cAAc,CAAC,CAAC,CAAC,CAAC,WAAW,EAA7B,cAA6B,EAA7B,IAA6B,EAAE,CAAC;4BAA5C,IAAA,WAAQ,EAAN,GAAC,OAAA,EAAE,GAAC,OAAA;4BACf,MAAM,CAAC,GAAC,CAAC,CAAC,GAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAA;wBAClC,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAlCD,oDAkCC"}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./adjacent-groups.util"), exports);
|
|
17
18
|
__exportStar(require("./action.util"), exports);
|
|
18
19
|
__exportStar(require("./action-view.util"), exports);
|
|
19
20
|
__exportStar(require("./automatic-moves.util"), exports);
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,qDAAkC;AAClC,yDAAsC;AACtC,8CAA2B;AAC3B,mDAAgC;AAChC,8CAA2B;AAC3B,kDAA+B;AAC/B,sDAAmC;AACnC,iDAA8B;AAC9B,+CAA4B;AAC5B,+CAA4B;AAC5B,gDAA6B;AAC7B,8CAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC;AACtC,gDAA6B;AAC7B,qDAAkC;AAClC,yDAAsC;AACtC,8CAA2B;AAC3B,mDAAgC;AAChC,8CAA2B;AAC3B,kDAA+B;AAC/B,sDAAmC;AACnC,iDAA8B;AAC9B,+CAA4B;AAC5B,+CAA4B;AAC5B,gDAA6B;AAC7B,8CAA2B"}
|