@dchighs/dc-config-mapper 0.3.0 → 0.3.1

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/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./data-compiler";
2
2
  export * from "./mappers";
3
+ export { resolveGridDecorationPositions } from "./utils";
package/dist/index.js CHANGED
@@ -14,5 +14,8 @@ 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
+ exports.resolveGridDecorationPositions = void 0;
17
18
  __exportStar(require("./data-compiler"), exports);
18
19
  __exportStar(require("./mappers"), exports);
20
+ var utils_1 = require("./utils");
21
+ Object.defineProperty(exports, "resolveGridDecorationPositions", { enumerable: true, get: function () { return utils_1.resolveGridDecorationPositions; } });
@@ -38,6 +38,7 @@ export declare class GridIslandsMapper {
38
38
  final_square_id: number;
39
39
  name_key: string;
40
40
  square_ids: number[];
41
+ decoration_ids: number[];
41
42
  }>[];
42
43
  squares: {
43
44
  id: number;
@@ -61,8 +62,6 @@ export declare class GridIslandsMapper {
61
62
  filename: string;
62
63
  x: number;
63
64
  y: number;
64
- island_id: number;
65
- episode_id: number;
66
65
  }[];
67
66
  encounters: {
68
67
  id: number;
@@ -13,7 +13,15 @@ class GridIslandsMapper {
13
13
  map(gridIslands) {
14
14
  return {
15
15
  islands: gridIslands.islands.map(island => this.localization.translate(island_schema_1.gridIslandSchema.parse(island))),
16
- episodes: gridIslands.episodes.map(episode => this.localization.translate(episode_schema_1.gridIslandsEpisodeSchema.parse(episode))),
16
+ episodes: gridIslands.episodes.map(episode => {
17
+ const decorationIds = gridIslands.decorations
18
+ .filter(decoration => decoration.episode_id === episode.id)
19
+ .map(decoration => decoration.id);
20
+ return this.localization.translate(episode_schema_1.gridIslandsEpisodeSchema.parse({
21
+ ...episode,
22
+ decoration_ids: decorationIds
23
+ }));
24
+ }),
17
25
  squares: gridIslands.squares.map(square => square_schema_1.gridIslandsSquareSchema.parse(square)),
18
26
  decorations: gridIslands.decorations.map(decoration => decoration_schema_1.gridIslandsDecorationSchema.parse(decoration)),
19
27
  encounters: gridIslands.encounters.map(encounter => encounter_schema_1.gridIslandsEncounterSchema.parse(encounter)),
@@ -11,8 +11,6 @@ export declare const gridIslandsDecorationSchema: z.ZodPipe<z.ZodObject<{
11
11
  filename: string;
12
12
  x: number;
13
13
  y: number;
14
- island_id: number;
15
- episode_id: number;
16
14
  }, {
17
15
  id: number;
18
16
  file: string;
@@ -15,7 +15,5 @@ exports.gridIslandsDecorationSchema = zod_1.z.object({
15
15
  filename: data.file,
16
16
  x: data.x,
17
17
  y: data.y,
18
- island_id: data.island_id,
19
- episode_id: data.episode_id,
20
18
  };
21
19
  });
@@ -14,6 +14,7 @@ export declare const gridIslandsEpisodeSchema: z.ZodPipe<z.ZodObject<{
14
14
  foregrounds: z.ZodArray<z.ZodAny>;
15
15
  foregrounds_plists: z.ZodArray<z.ZodAny>;
16
16
  squares: z.ZodArray<z.ZodNumber>;
17
+ decoration_ids: z.ZodArray<z.ZodNumber>;
17
18
  }, z.core.$strict>, z.ZodTransform<{
18
19
  id: number;
19
20
  board_size: {
@@ -24,6 +25,7 @@ export declare const gridIslandsEpisodeSchema: z.ZodPipe<z.ZodObject<{
24
25
  final_square_id: number;
25
26
  name_key: string;
26
27
  square_ids: number[];
28
+ decoration_ids: number[];
27
29
  }, {
28
30
  id: number;
29
31
  island_id: number;
@@ -39,4 +41,5 @@ export declare const gridIslandsEpisodeSchema: z.ZodPipe<z.ZodObject<{
39
41
  foregrounds: any[];
40
42
  foregrounds_plists: any[];
41
43
  squares: number[];
44
+ decoration_ids: number[];
42
45
  }>>;
@@ -17,6 +17,8 @@ exports.gridIslandsEpisodeSchema = zod_1.z.object({
17
17
  foregrounds: zod_1.z.array(zod_1.z.any()),
18
18
  foregrounds_plists: zod_1.z.array(zod_1.z.any()),
19
19
  squares: zod_1.z.array(zod_1.z.number()),
20
+ // injected props
21
+ decoration_ids: zod_1.z.array(zod_1.z.number())
20
22
  }).strict().transform((data) => {
21
23
  return {
22
24
  id: data.id,
@@ -28,5 +30,6 @@ exports.gridIslandsEpisodeSchema = zod_1.z.object({
28
30
  final_square_id: data.final_square_id,
29
31
  name_key: data.tid_title,
30
32
  square_ids: data.squares,
33
+ decoration_ids: data.decoration_ids,
31
34
  };
32
35
  });
@@ -2,21 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gridIslandsSquareSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- /*
6
- squares: Array<{
7
- id: number;
8
- type: string;
9
- type_id?: number;
10
- highlight: number;
11
- x: number;
12
- y: number;
13
- island_id: number;
14
- episode_id: number;
15
- claim_cost: number;
16
- wall?: string;
17
- wall_suffix?: string;
18
- }
19
- */
20
5
  exports.gridIslandsSquareSchema = zod_1.z.object({
21
6
  id: zod_1.z.number(),
22
7
  type: zod_1.z.string(),
@@ -3,3 +3,4 @@ export * from "./record-keys-conversor.util";
3
3
  export * from "./element-map.util";
4
4
  export * from "./process-rewards.util";
5
5
  export * from "./process-price.util";
6
+ export * from "./resolve-grid-decoration-positions.util";
@@ -19,3 +19,4 @@ __exportStar(require("./record-keys-conversor.util"), exports);
19
19
  __exportStar(require("./element-map.util"), exports);
20
20
  __exportStar(require("./process-rewards.util"), exports);
21
21
  __exportStar(require("./process-price.util"), exports);
22
+ __exportStar(require("./resolve-grid-decoration-positions.util"), exports);
@@ -0,0 +1,20 @@
1
+ import { GameConfigDto } from "@dchighs/dc-config";
2
+ type Square = GameConfigDto["game_data"]["config"]["grid_island"]["squares"][number];
3
+ type Decoration = GameConfigDto["game_data"]["config"]["grid_island"]["decorations"][number];
4
+ type resolveGridDecorationpositionsOptions = {
5
+ squares: Square[];
6
+ decorations: Decoration[];
7
+ boardSize: {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ };
12
+ export declare function resolveGridDecorationPositions({ squares, decorations, boardSize }: resolveGridDecorationpositionsOptions): {
13
+ id: number;
14
+ file: string;
15
+ x: number;
16
+ y: number;
17
+ island_id: number;
18
+ episode_id: number;
19
+ }[];
20
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveGridDecorationPositions = resolveGridDecorationPositions;
4
+ function resolveGridDecorationPositions({ squares, decorations, boardSize }) {
5
+ const squaresBoard = [];
6
+ for (const square of squares) {
7
+ squaresBoard.push(`${square.x},${square.y}`);
8
+ }
9
+ const decorationPositions = [];
10
+ const resolvedDecorations = [];
11
+ for (let x = 1; x < boardSize.width + 1; x++) {
12
+ for (let y = 1; y < boardSize.height + 1; y++) {
13
+ if (!squaresBoard.includes(`${x},${y}`)) {
14
+ decorationPositions.push(`${x},${y}`);
15
+ }
16
+ }
17
+ }
18
+ if (decorationPositions.length !== decorations.length) {
19
+ throw new Error("Number of decoration positions does not match number of decorations");
20
+ }
21
+ for (let i = 0; i < decorations.length; i++) {
22
+ const decorationPosition = decorationPositions[i];
23
+ const [x, y] = decorationPosition.split(",").map(Number);
24
+ resolvedDecorations.push({
25
+ ...decorations[i],
26
+ x: x,
27
+ y: y
28
+ });
29
+ }
30
+ return resolvedDecorations;
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dchighs/dc-config-mapper",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A opined library to restructure and populate configuration for Dragon City.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",