@dchighs/dc-config-mapper 0.0.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +187 -0
  3. package/dist/data-compiler.d.ts +25 -0
  4. package/dist/data-compiler.js +87 -0
  5. package/dist/dtos/items/dragon.d.ts +74 -0
  6. package/dist/dtos/items/dragon.js +2 -0
  7. package/dist/dtos/items/index.d.ts +2 -0
  8. package/dist/dtos/items/index.js +18 -0
  9. package/dist/dtos/items/restructured-items.d.ts +2624 -0
  10. package/dist/dtos/items/restructured-items.js +2 -0
  11. package/dist/enums/cost-type.d.ts +5 -0
  12. package/dist/enums/cost-type.js +9 -0
  13. package/dist/enums/index.d.ts +2 -0
  14. package/dist/enums/index.js +18 -0
  15. package/dist/enums/item-group-type.d.ts +58 -0
  16. package/dist/enums/item-group-type.js +62 -0
  17. package/dist/enums/reward-resource-type.d.ts +11 -0
  18. package/dist/enums/reward-resource-type.js +15 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +18 -0
  21. package/dist/mapper.d.ts +4 -0
  22. package/dist/mapper.js +9 -0
  23. package/dist/mappers/chest.mapper.d.ts +53 -0
  24. package/dist/mappers/chest.mapper.js +33 -0
  25. package/dist/mappers/heroic-races.mapper.d.ts +558 -0
  26. package/dist/mappers/heroic-races.mapper.js +31 -0
  27. package/dist/mappers/index.d.ts +5 -0
  28. package/dist/mappers/index.js +21 -0
  29. package/dist/mappers/items.mapper.d.ts +2688 -0
  30. package/dist/mappers/items.mapper.js +85 -0
  31. package/dist/mappers/maze-islands.mapper.d.ts +140 -0
  32. package/dist/mappers/maze-islands.mapper.js +29 -0
  33. package/dist/mappers/skills.mapper.d.ts +198 -0
  34. package/dist/mappers/skills.mapper.js +23 -0
  35. package/dist/schemas/chests/chest.schema.d.ts +222 -0
  36. package/dist/schemas/chests/chest.schema.js +33 -0
  37. package/dist/schemas/chests/reward.schema.d.ts +121 -0
  38. package/dist/schemas/chests/reward.schema.js +112 -0
  39. package/dist/schemas/islands/heroic-races/encounter.schema.d.ts +17 -0
  40. package/dist/schemas/islands/heroic-races/encounter.schema.js +17 -0
  41. package/dist/schemas/islands/heroic-races/enemy.schema.d.ts +9 -0
  42. package/dist/schemas/islands/heroic-races/enemy.schema.js +12 -0
  43. package/dist/schemas/islands/heroic-races/island.schema.d.ts +113 -0
  44. package/dist/schemas/islands/heroic-races/island.schema.js +79 -0
  45. package/dist/schemas/islands/heroic-races/lap.schema.d.ts +11 -0
  46. package/dist/schemas/islands/heroic-races/lap.schema.js +13 -0
  47. package/dist/schemas/islands/heroic-races/mission.schema.d.ts +38 -0
  48. package/dist/schemas/islands/heroic-races/mission.schema.js +32 -0
  49. package/dist/schemas/islands/heroic-races/node.schema.d.ts +14 -0
  50. package/dist/schemas/islands/heroic-races/node.schema.js +15 -0
  51. package/dist/schemas/islands/heroic-races/reward.schema.d.ts +29 -0
  52. package/dist/schemas/islands/heroic-races/reward.schema.js +34 -0
  53. package/dist/schemas/islands/maze-islands/island.schema.d.ts +91 -0
  54. package/dist/schemas/islands/maze-islands/island.schema.js +65 -0
  55. package/dist/schemas/islands/maze-islands/node.schema.d.ts +68 -0
  56. package/dist/schemas/islands/maze-islands/node.schema.js +67 -0
  57. package/dist/schemas/islands/maze-islands/path.schema.d.ts +39 -0
  58. package/dist/schemas/islands/maze-islands/path.schema.js +32 -0
  59. package/dist/schemas/items/dragon.schema.d.ts +205 -0
  60. package/dist/schemas/items/dragon.schema.js +159 -0
  61. package/dist/schemas/skills/attack.schema.d.ts +46 -0
  62. package/dist/schemas/skills/attack.schema.js +37 -0
  63. package/dist/utils/element-map.d.ts +2 -0
  64. package/dist/utils/element-map.js +28 -0
  65. package/dist/utils/index.d.ts +3 -0
  66. package/dist/utils/index.js +19 -0
  67. package/dist/utils/number-to-boolean.d.ts +1 -0
  68. package/dist/utils/number-to-boolean.js +9 -0
  69. package/dist/utils/record-keys-conversor.d.ts +10 -0
  70. package/dist/utils/record-keys-conversor.js +18 -0
  71. package/package.json +42 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Marcuth
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 ADDED
@@ -0,0 +1,187 @@
1
+ # @dchighs/dc-config-mapper
2
+
3
+ **@dchighs/dc-config-mapper** is a package for manipulating configuration data from the game [Dragon City](https://dragoncitygame.com/) (this is not an official SocialPoint library; it is fan-made).
4
+
5
+ ## 📦 Installation
6
+
7
+ Installation is straightforward; simply use your preferred package manager. Here is an example using NPM:
8
+
9
+ ```cmd
10
+ npm i @dchighs/dc-config-mapper @dchighs/dc-config @dchighs/dc-localization @dchighs/dc-core
11
+
12
+ ```
13
+
14
+ > You also need to install `@dchighs/dc-config`, `@dchighs/dc-localization`, and `@dchighs/dc-core`. These are set as `peerDependencies`, meaning the package requires them to function but will use the specific versions you have installed in your project.
15
+
16
+ ---
17
+
18
+ ## 🚀 Usage
19
+
20
+ <a href="https://www.buymeacoffee.com/marcuth">
21
+   <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" width="200">
22
+ </a>
23
+
24
+ ### Mapping Chests
25
+
26
+ ```ts
27
+ import { Config, ConfigLangauge } from "@dchighs/dc-config"
28
+ import { ChestsMapper } from "@dchighs/dc-config-mapper"
29
+ import { Localization } from "@dchighs/dc-localization"
30
+
31
+ ;(async () => {
32
+ const userId = process.env.USER_ID
33
+ const authToken = process.env.AUTH_TOKEN
34
+ const url = process.env.URL
35
+
36
+ const config = await Config.create({
37
+ userId: userId,
38
+ authToken: authToken,
39
+ url: url,
40
+ })
41
+
42
+ const localization = await Localization.create(ConfigLangauge.Turkish)
43
+ const chestsMapper = new ChestsMapper(localization)
44
+
45
+ const { chests, rewards } = chestsMapper.map(config.data.game_data.config.chests)
46
+
47
+ console.log({ chests, rewards })
48
+ })();
49
+
50
+ ```
51
+
52
+ ---
53
+
54
+ ### Mapping Items
55
+
56
+ ```ts
57
+ import { ItemsMapper } from "@dchighs/dc-config-mapper"
58
+
59
+ // ...
60
+ const itemsMapper = new ItemsMapper(localization)
61
+
62
+ const items = itemsMapper.map(config.data.game_data.config.items)
63
+
64
+ console.log(items)
65
+ })();
66
+
67
+ ```
68
+
69
+ ---
70
+
71
+ ### Mapping Heroic Races
72
+
73
+ ```ts
74
+ import { HeroicRacesMapper } from "@dchighs/dc-config-mapper"
75
+
76
+ // ...
77
+ const heroicRacesMapper = new HeroicRacesMapper(localization)
78
+
79
+ const heroicRaces = heroicRacesMapper.map(config.data.game_data.config.heroic_races)
80
+
81
+ console.log(heroicRaces)
82
+ })();
83
+
84
+ ```
85
+
86
+ ---
87
+
88
+ ### Mapping Maze Islands
89
+
90
+ ```ts
91
+ import { MazeIslandsMapper } from "@dchighs/dc-config-mapper"
92
+
93
+ // ...
94
+ const mazeIslandsMapper = new MazeIslandsMapper(localization)
95
+
96
+ const mazeIslands = mazeIslandsMapper.map(config.data.game_data.config.maze_island)
97
+
98
+ console.log(mazeIslands)
99
+ })();
100
+
101
+ ```
102
+
103
+ ---
104
+
105
+ ### Mapping Skills
106
+
107
+ ```ts
108
+ import { SkillsMapper } from "@dchighs/dc-config-mapper"
109
+
110
+ // ...
111
+ const skillsMapper = new SkillsMapper(localization)
112
+
113
+ const skills = skillsMapper.map(config.data.game_data.config.skills)
114
+
115
+ console.log(skills)
116
+ })();
117
+
118
+ ```
119
+
120
+ ---
121
+
122
+ ### Compiling Data
123
+
124
+ If you need to populate data for end-use, it is ideal to use the `DataCompiler` and provide the necessary context for data compilation:
125
+
126
+ ```ts
127
+ import { DataCompiler } from "@dchighs/dc-config-mapper"
128
+
129
+ const dataCompiler = new DataCompiler({
130
+ acceptedPrefixes: [
131
+ "basic_",
132
+ "trainable_",
133
+ "top_",
134
+ "middle_",
135
+ "bottom_",
136
+ "1_",
137
+ "2_",
138
+ "3_",
139
+ "4_"
140
+ ]
141
+ })
142
+
143
+ ```
144
+
145
+ Then, use it as follows:
146
+
147
+ ```ts
148
+ const heroicRaces = heroicRacesMapper.map(config.data.game_data.config.heroic_races)
149
+ const skills = skillsMapper.map(config.data.game_data.config.skills)
150
+ const items = itemsMapper.map(config.data.game_data.config.items)
151
+
152
+ const compileContext = {
153
+ laps: heroicRaces.laps,
154
+ nodes: heroicRaces.nodes,
155
+ missions: heroicRaces.missions,
156
+ rewards: heroicRaces.rewards,
157
+ attacks: skills.attacks,
158
+ dragons: items.dragons
159
+ }
160
+
161
+ const firstIsland = heroicRaces.islands[0]
162
+
163
+ const finalData = dataCompiler.compile({
164
+ data: firstIsland,
165
+ context: compileContext,
166
+ })
167
+
168
+ console.log(finalData)
169
+
170
+ ```
171
+
172
+ ---
173
+
174
+ ## 🤝 Contributing
175
+
176
+ * Want to contribute? Follow these steps:
177
+ * Fork the repository.
178
+ * Create a new branch (`git checkout -b feature-new`).
179
+ * Commit your changes (`git commit -m 'Add new feature'`).
180
+ * Push to the branch (`git push origin feature-new`).
181
+ * Open a Pull Request.
182
+
183
+ ---
184
+
185
+ ## 📝 License
186
+
187
+ This project is licensed under the MIT License.
@@ -0,0 +1,25 @@
1
+ export type DataCompilerOptions = {
2
+ acceptedPrefixes?: string[];
3
+ idsSuffix?: string;
4
+ idSuffix?: string;
5
+ };
6
+ export type CompileOptions = {
7
+ data: Record<string, any>;
8
+ context: Record<string, any>;
9
+ };
10
+ export type CompileArrayOptions = {
11
+ data: Record<string, any>[];
12
+ context: Record<string, any>;
13
+ };
14
+ export declare class DataCompiler {
15
+ private readonly acceptedPrefixes;
16
+ private readonly idsSuffix;
17
+ private readonly idSuffix;
18
+ constructor({ acceptedPrefixes, idsSuffix, idSuffix }?: DataCompilerOptions);
19
+ private findMatchingPrefix;
20
+ private processIdsSuffix;
21
+ private processIdSuffix;
22
+ private isArrayOfObjects;
23
+ compileMany({ data, context }: CompileArrayOptions): Record<string, any>[];
24
+ compile({ data, context }: CompileOptions): Record<string, any>;
25
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DataCompiler = void 0;
7
+ const lodash_1 = require("lodash");
8
+ const pluralize_1 = __importDefault(require("pluralize"));
9
+ class DataCompiler {
10
+ constructor({ acceptedPrefixes, idsSuffix, idSuffix } = {}) {
11
+ this.acceptedPrefixes = acceptedPrefixes !== null && acceptedPrefixes !== void 0 ? acceptedPrefixes : [];
12
+ this.idsSuffix = idsSuffix !== null && idsSuffix !== void 0 ? idsSuffix : "_ids";
13
+ this.idSuffix = idSuffix !== null && idSuffix !== void 0 ? idSuffix : "_id";
14
+ }
15
+ findMatchingPrefix(key) {
16
+ for (const acceptedPrefix of this.acceptedPrefixes) {
17
+ if (key.startsWith(acceptedPrefix)) {
18
+ return acceptedPrefix;
19
+ }
20
+ }
21
+ return "";
22
+ }
23
+ processIdsSuffix({ context, data, key, prefix }) {
24
+ const baseKey = key.slice(prefix.length).slice(0, -this.idsSuffix.length);
25
+ const pluralizedKey = (0, pluralize_1.default)(baseKey);
26
+ if (context[pluralizedKey]) {
27
+ const relatedItems = context[pluralizedKey]
28
+ .filter((item) => data[key].includes(item.id))
29
+ .map((item) => (0, lodash_1.isObject)(item) ? this.compile({ data: item, context: context }) : item);
30
+ data[`${prefix}${pluralizedKey}`] = relatedItems;
31
+ delete data[key];
32
+ }
33
+ }
34
+ processIdSuffix({ context, data, key, prefix }) {
35
+ const baseKey = key.slice(prefix.length).slice(0, -this.idSuffix.length);
36
+ const pluralizedKey = (0, pluralize_1.default)(baseKey);
37
+ if (context[pluralizedKey]) {
38
+ const foundItem = context[pluralizedKey].find((item) => item.id === data[key]);
39
+ data[`${prefix}${baseKey}`] = foundItem ? this.compile({ data: foundItem, context: context }) : null;
40
+ delete data[key];
41
+ }
42
+ }
43
+ isArrayOfObjects(value) {
44
+ return Array.isArray(value) && value.every(item => (0, lodash_1.isObject)(item));
45
+ }
46
+ compileMany({ data, context }) {
47
+ return data.map(item => (0, lodash_1.isObject)(item) ? this.compile({ data: item, context: context }) : item);
48
+ }
49
+ compile({ data, context }) {
50
+ const dataCopy = { ...data };
51
+ try {
52
+ for (const [key, value] of Object.entries(dataCopy)) {
53
+ if (this.isArrayOfObjects(value)) {
54
+ data[key] = this.compileMany({ data: value, context: context });
55
+ }
56
+ else if ((0, lodash_1.isObject)(value)) {
57
+ data[key] = this.compile({ data: value, context: context });
58
+ }
59
+ const matchedPrefix = this.findMatchingPrefix(key);
60
+ if (key.endsWith(this.idsSuffix)) {
61
+ this.processIdsSuffix({
62
+ data: data,
63
+ key: key,
64
+ prefix: matchedPrefix,
65
+ context: context
66
+ });
67
+ }
68
+ else if (key.endsWith(this.idSuffix)) {
69
+ this.processIdSuffix({
70
+ data: data,
71
+ key: key,
72
+ prefix: matchedPrefix,
73
+ context: context
74
+ });
75
+ }
76
+ }
77
+ return data;
78
+ }
79
+ catch (error) {
80
+ console.error("Error while compiling data:", error);
81
+ console.log("Data:", data);
82
+ console.log("Data Copy:", dataCopy);
83
+ process.exit(1);
84
+ }
85
+ }
86
+ }
87
+ exports.DataCompiler = DataCompiler;
@@ -0,0 +1,74 @@
1
+ export interface DragonDto {
2
+ id: number;
3
+ name: string;
4
+ group_type: string;
5
+ name_key?: string;
6
+ speed: number;
7
+ mobile_version: number;
8
+ android_version: number;
9
+ display_order: number;
10
+ hatching_time: number;
11
+ breeding_time: number;
12
+ xp: number;
13
+ lvl: number;
14
+ costs: {
15
+ g?: number;
16
+ c?: number;
17
+ };
18
+ sell_price: {
19
+ g: number;
20
+ };
21
+ starting_coins: number;
22
+ coins_added: number;
23
+ can_breed: number;
24
+ breedable: number;
25
+ deity_breeding: number;
26
+ difficulty: number;
27
+ category: number;
28
+ rarity: number;
29
+ dragon_rarity: string;
30
+ attacks: Array<number>;
31
+ attributes: Array<string>;
32
+ trainable_attacks: Array<number>;
33
+ upgrade_levels: Array<number>;
34
+ background_vfx: Array<number>;
35
+ foreground_vfx: Array<number>;
36
+ in_store: number;
37
+ in_store_min_level: number;
38
+ flying_level: number;
39
+ swim: number;
40
+ new_item: number;
41
+ img_name?: string;
42
+ img_name_mobile?: string;
43
+ img_name_android?: string;
44
+ giftable?: number;
45
+ gift_level: number;
46
+ description?: string;
47
+ seeds_to_summon: number;
48
+ hatching_time_10: number;
49
+ breeding_time_40: number;
50
+ breeding_time_10: number;
51
+ hatching_time_40: number;
52
+ base_attack: number;
53
+ base_life: number;
54
+ in_store_ch?: number;
55
+ costs_ch_1?: {
56
+ c?: number;
57
+ g?: number;
58
+ };
59
+ costs_ch_2?: {
60
+ c?: number;
61
+ g?: number;
62
+ };
63
+ hatching_time_reawaken: number;
64
+ breeding_time_reawaken: number;
65
+ hatching_time_ngu_aggressive: number;
66
+ breeding_time_ngu_aggressive: number;
67
+ hatching_time_ngu_soft: number;
68
+ breeding_time_ngu_soft: number;
69
+ dragon_ownership_id: number;
70
+ tags?: Array<string>;
71
+ speed_override?: number;
72
+ passive_skills?: Array<number>;
73
+ post_skills?: Array<number>;
74
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from "./dragon";
2
+ export * from "./restructured-items";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./dragon"), exports);
18
+ __exportStar(require("./restructured-items"), exports);