@dchighs/dc-core 0.2.0 → 0.3.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,2 @@
1
+ import { DragonElement } from "../enums";
2
+ export declare function calculateElementResistances(element: string): DragonElement[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateElementResistances = calculateElementResistances;
4
+ const validate_element_name_1 = require("../tools/validate-element-name");
5
+ const elements_1 = require("../settings/elements");
6
+ function calculateElementResistances(element) {
7
+ (0, validate_element_name_1.validateElementName)(element, { throwOnError: true });
8
+ const elementKey = element;
9
+ const elementSetting = elements_1.elementSettings[elementKey];
10
+ const elementWeaknesses = elementSetting.weaknesses;
11
+ return elementWeaknesses;
12
+ }
@@ -1 +1,2 @@
1
- export declare function calculateElementStrengths(element: string): import("..").DragonElement[] | never[];
1
+ import { DragonElement } from "../enums";
2
+ export declare function calculateElementStrengths(element: string): DragonElement[];
@@ -1 +1,2 @@
1
- export declare function calculateElementWeaknesses(element: string): import("..").DragonElement[] | never[];
1
+ import { DragonElement } from "../enums";
2
+ export declare function calculateElementWeaknesses(element: string): DragonElement[];
@@ -5,8 +5,11 @@ const validate_element_name_1 = require("../tools/validate-element-name");
5
5
  const elements_1 = require("../settings/elements");
6
6
  function calculateElementWeaknesses(element) {
7
7
  (0, validate_element_name_1.validateElementName)(element, { throwOnError: true });
8
- const elementKey = element;
9
- const elementSetting = elements_1.elementSettings[elementKey];
10
- const elementWeaknesses = elementSetting.weaknesses;
11
- return elementWeaknesses;
8
+ const weaknesses = [];
9
+ for (const element in elements_1.elementSettings) {
10
+ if (elements_1.elementSettings[element].strengths.includes(element)) {
11
+ weaknesses.push(element);
12
+ }
13
+ }
14
+ return weaknesses;
12
15
  }
@@ -0,0 +1,38 @@
1
+ import { DragonPhase, DragonSpriteQuality, StaticFileUrlPlatformPrefix } from "../enums";
2
+ export declare class DragonStaticFileUrlParser {
3
+ static getPlatformPrefix(url: string): StaticFileUrlPlatformPrefix | null;
4
+ static getImageName(url: string): string | null;
5
+ static getId(url: string): number | null;
6
+ static getPhase(url: string): DragonPhase | null;
7
+ static getSkin(url: string): string | null;
8
+ static getImageQuality(url: string): DragonSpriteQuality;
9
+ static parseFromSprite(url: string): {
10
+ platformPrefix: StaticFileUrlPlatformPrefix | null;
11
+ id: number | null;
12
+ imageName: string | null;
13
+ phase: DragonPhase | null;
14
+ skin: string | null;
15
+ imageQuality: DragonSpriteQuality;
16
+ };
17
+ static parseFromThumbnail(url: string): {
18
+ platformPrefix: StaticFileUrlPlatformPrefix | null;
19
+ id: number | null;
20
+ image_name: string | null;
21
+ phase: DragonPhase | null;
22
+ skin: string | null;
23
+ };
24
+ static parseFromFlashAnimation(url: string): {
25
+ platformPrefix: StaticFileUrlPlatformPrefix | null;
26
+ id: number | null;
27
+ imageName: string | null;
28
+ phase: DragonPhase | null;
29
+ skin: string | null;
30
+ };
31
+ static parseFromSpineAnimation(url: string): {
32
+ platformPrefix: StaticFileUrlPlatformPrefix | null;
33
+ id: number | null;
34
+ imageName: string | null;
35
+ phase: DragonPhase | null;
36
+ skin: string | null;
37
+ };
38
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DragonStaticFileUrlParser = void 0;
4
+ const enums_1 = require("../enums");
5
+ class DragonStaticFileUrlParser {
6
+ static getPlatformPrefix(url) {
7
+ const match = url.match(/https?:\/\/([a-z]+)-static/i);
8
+ if (!match) {
9
+ return null;
10
+ }
11
+ const prefix = match[1];
12
+ return prefix;
13
+ }
14
+ static getImageName(url) {
15
+ const match = url.match(/\/(basic_|thumb_|ui_)?(\d+)_([\w_]+)/);
16
+ if (match) {
17
+ const id = match[2];
18
+ const imageNameWithoutId = match[3];
19
+ const rawImageName = `${id}_${imageNameWithoutId}`;
20
+ let imageNameWithSkin = rawImageName.replace(/_\d+/, "");
21
+ let imageNameWithoutSkin = imageNameWithSkin.replace(/_skin\d+/, "");
22
+ return imageNameWithoutSkin;
23
+ }
24
+ return null;
25
+ }
26
+ static getId(url) {
27
+ const match = url.match(/\/(basic_|thumb_|ui_)?(\d+)_/);
28
+ if (match) {
29
+ return Number(match[2]);
30
+ }
31
+ return null;
32
+ }
33
+ static getPhase(url) {
34
+ const match = url.match(/(\d+)@2x\.(png|swf)|(\d+)\.(png|swf)|(\d+)_HD_tweened_dxt5\.zip|(\d+)_HD_spine-3-8-59_dxt5\.zip/);
35
+ if (match) {
36
+ const phase = match[1] ||
37
+ match[3] ||
38
+ match[5] ||
39
+ match[6];
40
+ return phase ? Number(phase) : null;
41
+ }
42
+ return null;
43
+ }
44
+ static getSkin(url) {
45
+ const match = url.match(/_skin\d+/);
46
+ if (match) {
47
+ return match[0];
48
+ }
49
+ return null;
50
+ }
51
+ static getImageQuality(url) {
52
+ const match = url.match(/@\d+x/);
53
+ if (match) {
54
+ return match[0];
55
+ }
56
+ return enums_1.DragonSpriteQuality.Default;
57
+ }
58
+ static parseFromSprite(url) {
59
+ return {
60
+ platformPrefix: this.getPlatformPrefix(url),
61
+ id: this.getId(url),
62
+ imageName: this.getImageName(url),
63
+ phase: this.getPhase(url),
64
+ skin: this.getSkin(url),
65
+ imageQuality: this.getImageQuality(url),
66
+ };
67
+ }
68
+ static parseFromThumbnail(url) {
69
+ return {
70
+ platformPrefix: this.getPlatformPrefix(url),
71
+ id: this.getId(url),
72
+ image_name: this.getImageName(url),
73
+ phase: this.getPhase(url),
74
+ skin: this.getSkin(url),
75
+ };
76
+ }
77
+ static parseFromFlashAnimation(url) {
78
+ return {
79
+ platformPrefix: this.getPlatformPrefix(url),
80
+ id: this.getId(url),
81
+ imageName: this.getImageName(url),
82
+ phase: this.getPhase(url),
83
+ skin: this.getSkin(url),
84
+ };
85
+ }
86
+ static parseFromSpineAnimation(url) {
87
+ return {
88
+ platformPrefix: this.getPlatformPrefix(url),
89
+ id: this.getId(url),
90
+ imageName: this.getImageName(url),
91
+ phase: this.getPhase(url),
92
+ skin: this.getSkin(url),
93
+ };
94
+ }
95
+ }
96
+ exports.DragonStaticFileUrlParser = DragonStaticFileUrlParser;
@@ -6,4 +6,5 @@ import { validateDragonStars } from "./validate-dragon-stars";
6
6
  import { validateElementName } from "./validate-element-name";
7
7
  import { validateDragonLevel } from "./validate-dragon-level";
8
8
  import { validateDragonRank } from "./validate-dragon-rank";
9
- export { validateDragonLevelCompatibilityWithStars, validateDragonCategory, getMusicKeyNameFromTag, validateDragonRarity, validateDragonStars, validateElementName, validateDragonLevel, validateDragonRank, };
9
+ import { DragonStaticFileUrlParser } from "./dragon-static-file-url-parser";
10
+ export { validateDragonLevelCompatibilityWithStars, validateDragonCategory, getMusicKeyNameFromTag, validateDragonRarity, validateDragonStars, validateElementName, validateDragonLevel, validateDragonRank, DragonStaticFileUrlParser, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateDragonRank = exports.validateDragonLevel = exports.validateElementName = exports.validateDragonStars = exports.validateDragonRarity = exports.getMusicKeyNameFromTag = exports.validateDragonCategory = exports.validateDragonLevelCompatibilityWithStars = void 0;
3
+ exports.DragonStaticFileUrlParser = exports.validateDragonRank = exports.validateDragonLevel = exports.validateElementName = exports.validateDragonStars = exports.validateDragonRarity = exports.getMusicKeyNameFromTag = exports.validateDragonCategory = exports.validateDragonLevelCompatibilityWithStars = void 0;
4
4
  const validate_dragon_level_compatibility_with_stars_1 = require("./validate-dragon-level-compatibility-with-stars");
5
5
  Object.defineProperty(exports, "validateDragonLevelCompatibilityWithStars", { enumerable: true, get: function () { return validate_dragon_level_compatibility_with_stars_1.validateDragonLevelCompatibilityWithStars; } });
6
6
  const validate_dragon_category_1 = require("./validate-dragon-category");
@@ -17,3 +17,5 @@ const validate_dragon_level_1 = require("./validate-dragon-level");
17
17
  Object.defineProperty(exports, "validateDragonLevel", { enumerable: true, get: function () { return validate_dragon_level_1.validateDragonLevel; } });
18
18
  const validate_dragon_rank_1 = require("./validate-dragon-rank");
19
19
  Object.defineProperty(exports, "validateDragonRank", { enumerable: true, get: function () { return validate_dragon_rank_1.validateDragonRank; } });
20
+ const dragon_static_file_url_parser_1 = require("./dragon-static-file-url-parser");
21
+ Object.defineProperty(exports, "DragonStaticFileUrlParser", { enumerable: true, get: function () { return dragon_static_file_url_parser_1.DragonStaticFileUrlParser; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dchighs/dc-core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A library focused on simulating some of the logic of the game Dragon City.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",