dyo-tools 0.3.2 → 0.4.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.
Files changed (209) hide show
  1. package/.c8rc.json +4 -4
  2. package/.eslintignore +1 -1
  3. package/.eslintrc.json +47 -47
  4. package/Makefile +34 -34
  5. package/dist/constants.d.ts +1 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/constants.js +24 -20
  8. package/dist/constants.js.map +1 -1
  9. package/dist/core/DTAction.d.ts +6 -4
  10. package/dist/core/DTAction.d.ts.map +1 -0
  11. package/dist/core/DTAction.js +3 -6
  12. package/dist/core/DTAction.js.map +1 -1
  13. package/dist/core/DTBunch.d.ts +8 -5
  14. package/dist/core/DTBunch.d.ts.map +1 -0
  15. package/dist/core/DTBunch.js +53 -19
  16. package/dist/core/DTBunch.js.map +1 -1
  17. package/dist/core/DTComponent.d.ts +13 -10
  18. package/dist/core/DTComponent.d.ts.map +1 -0
  19. package/dist/core/DTComponent.js +23 -10
  20. package/dist/core/DTComponent.js.map +1 -1
  21. package/dist/core/DTComponentPhysical.d.ts +11 -8
  22. package/dist/core/DTComponentPhysical.d.ts.map +1 -0
  23. package/dist/core/DTComponentPhysical.js +21 -6
  24. package/dist/core/DTComponentPhysical.js.map +1 -1
  25. package/dist/core/DTComponentWithMeta.d.ts +6 -3
  26. package/dist/core/DTComponentWithMeta.d.ts.map +1 -0
  27. package/dist/core/DTComponentWithMeta.js +21 -7
  28. package/dist/core/DTComponentWithMeta.js.map +1 -1
  29. package/dist/core/DTElement.d.ts +10 -8
  30. package/dist/core/DTElement.d.ts.map +1 -0
  31. package/dist/core/DTElement.js +8 -9
  32. package/dist/core/DTElement.js.map +1 -1
  33. package/dist/core/DTError.d.ts +8 -7
  34. package/dist/core/DTError.d.ts.map +1 -0
  35. package/dist/core/DTError.js +1 -5
  36. package/dist/core/DTError.js.map +1 -1
  37. package/dist/core/DTManager.d.ts +17 -14
  38. package/dist/core/DTManager.d.ts.map +1 -0
  39. package/dist/core/DTManager.js +84 -26
  40. package/dist/core/DTManager.js.map +1 -1
  41. package/dist/core/DTMaster.d.ts +19 -16
  42. package/dist/core/DTMaster.d.ts.map +1 -0
  43. package/dist/core/DTMaster.js +48 -31
  44. package/dist/core/DTMaster.js.map +1 -1
  45. package/dist/core/DTModule.d.ts +8 -5
  46. package/dist/core/DTModule.d.ts.map +1 -0
  47. package/dist/core/DTModule.js +6 -6
  48. package/dist/core/DTModule.js.map +1 -1
  49. package/dist/index.d.ts +1 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +12 -28
  52. package/dist/index.js.map +1 -1
  53. package/dist/libs/DYOFinder.d.ts +1 -0
  54. package/dist/libs/DYOFinder.d.ts.map +1 -0
  55. package/dist/libs/DYOFinder.js +10 -14
  56. package/dist/libs/DYOFinder.js.map +1 -1
  57. package/dist/libs/dix/DIXModule.module.d.ts +8 -0
  58. package/dist/libs/dix/DIXModule.module.d.ts.map +1 -0
  59. package/dist/libs/dix/DIXModule.module.js +73 -0
  60. package/dist/libs/player/DTPlayer.element.d.ts +3 -2
  61. package/dist/libs/player/DTPlayer.element.d.ts.map +1 -0
  62. package/dist/libs/player/DTPlayer.element.js +2 -6
  63. package/dist/libs/player/DTPlayer.element.js.map +1 -1
  64. package/dist/libs/player/DTPlayer.manager.d.ts +8 -7
  65. package/dist/libs/player/DTPlayer.manager.d.ts.map +1 -0
  66. package/dist/libs/player/DTPlayer.manager.js +13 -20
  67. package/dist/libs/player/DTPlayer.manager.js.map +1 -1
  68. package/dist/tsconfig.dev.tsbuildinfo +1 -0
  69. package/dist/tsconfig.tsbuildinfo +1 -1
  70. package/dist/types/core.d.ts +40 -12
  71. package/dist/types/core.d.ts.map +1 -0
  72. package/dist/types/core.js +2 -6
  73. package/dist/types/core.js.map +1 -1
  74. package/dist/types/index.d.ts +1 -0
  75. package/dist/types/index.d.ts.map +1 -0
  76. package/dist/types/index.js +2 -19
  77. package/dist/types/index.js.map +1 -1
  78. package/dist/types/player.d.ts +1 -1
  79. package/dist/types/player.d.ts.map +1 -0
  80. package/dist/types/player.js +1 -3
  81. package/integration/data/components/DTHero.ts +42 -0
  82. package/integration/data/components/DTHeroManager.ts +11 -0
  83. package/integration/data/components/DTHeroPlayZone.ts +6 -0
  84. package/integration/data/components/DTHeroPlayerHand.ts +11 -0
  85. package/integration/data/components/index.ts +5 -0
  86. package/integration/data/in/heroIn.helper.ts +8 -0
  87. package/integration/data/in/playerIn.helper.ts +13 -0
  88. package/integration/data/out/heroOut.helper.ts +48 -0
  89. package/integration/endings/synchronisation.ending.ts +25 -0
  90. package/integration/scenes/drawCard.scene.ts +31 -0
  91. package/integration/scenes/empty.scene.ts +6 -0
  92. package/integration/scenes/playCard.scene.ts +23 -0
  93. package/integration/scenes/playerLeave.scene.ts +33 -0
  94. package/integration/stages/baseDix.stage.ts +137 -0
  95. package/integration/stages/syncDix.stage.ts +36 -0
  96. package/integration/tests/scenario1.spec.ts +55 -0
  97. package/integration/types/index.ts +24 -0
  98. package/jest-integration.config.ts +25 -0
  99. package/jest.config.ts +26 -0
  100. package/package.json +31 -19
  101. package/src/constants.ts +2 -0
  102. package/src/core/DTAction.ts +7 -5
  103. package/src/core/DTBunch.ts +78 -14
  104. package/src/core/DTComponent.ts +48 -15
  105. package/src/core/DTComponentPhysical.ts +45 -11
  106. package/src/core/DTComponentWithMeta.ts +37 -4
  107. package/src/core/DTElement.ts +19 -10
  108. package/src/core/DTError.ts +7 -7
  109. package/src/core/DTManager.ts +120 -30
  110. package/src/core/DTMaster.ts +76 -28
  111. package/src/core/DTModule.ts +12 -6
  112. package/src/index.ts +17 -17
  113. package/src/libs/DYOFinder.ts +175 -175
  114. package/src/libs/dix/DIXModule.module.ts +98 -0
  115. package/src/libs/player/DTPlayer.element.ts +2 -2
  116. package/src/libs/player/DTPlayer.manager.ts +20 -34
  117. package/src/types/core.ts +39 -4
  118. package/src/types/index.ts +2 -2
  119. package/src/types/player.ts +0 -1
  120. package/test/core/DTAction.double.ts +12 -28
  121. package/test/core/DTAction.spec.ts +8 -16
  122. package/test/core/DTBunch.double.ts +49 -135
  123. package/test/core/DTBunch.spec.ts +157 -245
  124. package/test/core/DTComponent.double.ts +17 -2
  125. package/test/core/DTComponent.spec.ts +6 -4
  126. package/test/core/DTComponentPhysical.double.ts +29 -43
  127. package/test/core/DTComponentPhysical.spec.ts +22 -19
  128. package/test/core/DTComponentWithMeta.double.ts +38 -31
  129. package/test/core/DTComponentWithMeta.spec.ts +23 -18
  130. package/test/core/DTElement.double.ts +32 -53
  131. package/test/core/DTElement.spec.ts +15 -38
  132. package/test/core/DTError.double.ts +18 -53
  133. package/test/core/DTError.spec.ts +21 -32
  134. package/test/core/DTManager.double.ts +74 -141
  135. package/test/core/DTManager.spec.ts +289 -380
  136. package/test/core/DTMaster.double.ts +56 -80
  137. package/test/core/DTMaster.spec.ts +185 -232
  138. package/test/core/DTModule.double.ts +12 -25
  139. package/test/core/DTModule.spec.ts +14 -28
  140. package/test/core/copy.spec.ts +9 -30
  141. package/tsconfig.dev.json +5 -8
  142. package/tsconfig.json +5 -8
  143. package/cucumber-report.html +0 -48
  144. package/docs/assets/navigation.js +0 -1
  145. package/docs/classes/core_DTAction.DYOToolsAction.html +0 -89
  146. package/docs/classes/core_DTBunch.DYOToolsBunch.html +0 -254
  147. package/docs/classes/core_DTComponent.DYOToolsComponent.html +0 -76
  148. package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +0 -110
  149. package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +0 -96
  150. package/docs/classes/core_DTElement.DYOToolsElement.html +0 -135
  151. package/docs/classes/core_DTError.DYOToolsError.html +0 -37
  152. package/docs/classes/core_DTManager.DYOToolsManager.html +0 -237
  153. package/docs/classes/core_DTMaster.DYOToolsMaster.html +0 -150
  154. package/docs/classes/core_DTModule.DYOToolsModule.html +0 -92
  155. package/docs/classes/libs_DYOFinder.DYOFinder.html +0 -34
  156. package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +0 -134
  157. package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +0 -243
  158. package/docs/enums/types_core.FilterOperatorType.html +0 -10
  159. package/docs/hierarchy.html +0 -1
  160. package/docs/interfaces/types_core.DTBunchFilters.html +0 -6
  161. package/docs/interfaces/types_core.DTBunchOptions.html +0 -19
  162. package/docs/interfaces/types_core.DTBunchToObject.html +0 -7
  163. package/docs/interfaces/types_core.DTComponentOptions.html +0 -5
  164. package/docs/interfaces/types_core.DTComponentToObject.html +0 -4
  165. package/docs/interfaces/types_core.DTElementToObject.html +0 -7
  166. package/docs/interfaces/types_core.DTManagerFilters.html +0 -6
  167. package/docs/interfaces/types_core.DTManagerOptions.html +0 -8
  168. package/docs/interfaces/types_core.DTManagerToObject.html +0 -5
  169. package/docs/interfaces/types_core.DTMasterToObject.html +0 -8
  170. package/docs/interfaces/types_core.DTModuleToObject.html +0 -6
  171. package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +0 -4
  172. package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +0 -4
  173. package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +0 -5
  174. package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +0 -5
  175. package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +0 -3
  176. package/docs/modules/constants.html +0 -6
  177. package/docs/modules/core_DTAction.html +0 -2
  178. package/docs/modules/core_DTBunch.html +0 -2
  179. package/docs/modules/core_DTComponent.html +0 -2
  180. package/docs/modules/core_DTComponentPhysical.html +0 -2
  181. package/docs/modules/core_DTComponentWithMeta.html +0 -2
  182. package/docs/modules/core_DTElement.html +0 -2
  183. package/docs/modules/core_DTError.html +0 -2
  184. package/docs/modules/core_DTManager.html +0 -2
  185. package/docs/modules/core_DTMaster.html +0 -2
  186. package/docs/modules/core_DTModule.html +0 -2
  187. package/docs/modules/libs_DYOFinder.html +0 -2
  188. package/docs/modules/libs_player_DTPlayer_element.html +0 -2
  189. package/docs/modules/libs_player_DTPlayer_manager.html +0 -2
  190. package/docs/modules/types.html +0 -29
  191. package/docs/modules/types_core.html +0 -28
  192. package/docs/modules/types_player.html +0 -2
  193. package/docs/types/types_core.DTAcceptedMetaData.html +0 -2
  194. package/docs/types/types_core.DTManagerItemType.html +0 -1
  195. package/docs/types/types_core.DTManagerItemsType.html +0 -2
  196. package/docs/types/types_core.DYOFinderComponentType.html +0 -1
  197. package/docs/types/types_core.DYOFinderConfiguration.html +0 -2
  198. package/docs/types/types_core.DYOFinderConfigurationProp.html +0 -1
  199. package/docs/types/types_core.DYOFinderFilterOperator.html +0 -1
  200. package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +0 -1
  201. package/docs/types/types_core.DYOFinderFilters.html +0 -1
  202. package/docs/types/types_core.StandardPrimitiveType.html +0 -2
  203. package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +0 -1
  204. package/docs/variables/constants.bunchDefaultOptions.html +0 -2
  205. package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +0 -1
  206. package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +0 -1
  207. package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +0 -1
  208. package/docs/variables/constants.managerDefaultOptions.html +0 -2
  209. package/jest.config.js +0 -6
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FilterOperatorType = void 0;
4
- var FilterOperatorType;
1
+ export var FilterOperatorType;
5
2
  (function (FilterOperatorType) {
6
3
  FilterOperatorType["EQ"] = "$eq";
7
4
  FilterOperatorType["IN"] = "$in";
@@ -11,5 +8,4 @@ var FilterOperatorType;
11
8
  FilterOperatorType["GTE"] = "$gte";
12
9
  FilterOperatorType["CONTAINS"] = "$contains";
13
10
  FilterOperatorType["NCONTAINS"] = "$ncontains";
14
- })(FilterOperatorType = exports.FilterOperatorType || (exports.FilterOperatorType = {}));
15
- //# sourceMappingURL=core.js.map
11
+ })(FilterOperatorType || (FilterOperatorType = {}));
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/types/core.ts"],"names":[],"mappings":";;;AAIA,IAAY,kBASX;AATD,WAAY,kBAAkB;IAC5B,gCAAU,CAAA;IACV,gCAAU,CAAA;IACV,kCAAY,CAAA;IACZ,gCAAU,CAAA;IACV,kCAAY,CAAA;IACZ,kCAAY,CAAA;IACZ,4CAAsB,CAAA;IACtB,8CAAwB,CAAA;AAC1B,CAAC,EATW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAS7B"}
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/types/core.ts"],"names":[],"mappings":"AAIA,MAAM,CAAN,IAAY,kBASX;AATD,WAAY,kBAAkB;IAC5B,gCAAU,CAAA;IACV,gCAAU,CAAA;IACV,kCAAY,CAAA;IACZ,gCAAU,CAAA;IACV,kCAAY,CAAA;IACZ,kCAAY,CAAA;IACZ,4CAAsB,CAAA;IACtB,8CAAwB,CAAA;AAC1B,CAAC,EATW,kBAAkB,KAAlB,kBAAkB,QAS7B"}
@@ -1,2 +1,3 @@
1
1
  export * from './core';
2
2
  export * from './player';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
@@ -1,19 +1,2 @@
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("./core"), exports);
18
- __exportStar(require("./player"), exports);
19
- //# sourceMappingURL=index.js.map
1
+ export * from './core';
2
+ export * from './player';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,2CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { DTPlayer } from '../index';
2
2
  export interface DTPlayerManagerSimpleConfiguration {
3
3
  players?: number | DTPlayer[];
4
- errors?: boolean;
5
4
  }
5
+ //# sourceMappingURL=player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../../src/types/player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,WAAW,kCAAkC;IACjD,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAC;CAC/B"}
@@ -1,3 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=player.js.map
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import {DTElement} from "../../../src";
2
+ import {DIXObject, DTComponentOptions} from "../../../src/types";
3
+
4
+ type DTHeroMeta = {
5
+ damage: number;
6
+ }
7
+
8
+ export default class DTHero extends DTElement<DTHeroMeta> {
9
+ _domain = 'hero';
10
+ name: string;
11
+
12
+ constructor(key?: string, options: Partial<DTComponentOptions> = {}) {
13
+ super(key, options);
14
+ this.name = "";
15
+ this.setMeta('damage', 0);
16
+ }
17
+
18
+ getDamage(): number {
19
+ return this.getMeta('damage');
20
+ }
21
+
22
+ setDamage(damage: number) {
23
+ this.setMeta('damage', damage);
24
+ }
25
+
26
+ toDIXObject(): Record<string, DIXObject> {
27
+ const dixObject = super.toDIXObject()[this.getId()];
28
+ dixObject.name = this.name;
29
+ return {
30
+ [this.getId()]: dixObject
31
+ };
32
+ }
33
+
34
+ updateFromDix(dix: Record<string, DIXObject>) {
35
+ super.updateFromDix(dix);
36
+ const dixObject = dix[this._id];
37
+
38
+ if (dixObject && dixObject.owner) {
39
+ this.name = dixObject.name as string;
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,11 @@
1
+ import {DTManager} from "../../../src";
2
+ import DTHero from "./DTHero";
3
+ import {DTManagerOptions} from "../../../src/types";
4
+
5
+ export default class DTHeroManager extends DTManager<DTHero> {
6
+ _domain = 'hero';
7
+
8
+ constructor(key?: string, elements: DTHero[] = [], scopes: string[] = [], options: Partial<DTManagerOptions> = {}) {
9
+ super(key ?? 'hero', elements, ['hand', 'playZone', ...scopes], options);
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ import {DTBunch} from "../../../src";
2
+ import DTHero from "./DTHero";
3
+
4
+ export default class DTHeroPlayZone extends DTBunch<DTHero> {
5
+ _domain = 'hero';
6
+ }
@@ -0,0 +1,11 @@
1
+ import {DTBunch} from "../../../src";
2
+ import DTHero from "./DTHero";
3
+ import {DTBunchOptions} from "../../../src/types";
4
+
5
+ export default class DTHeroPlayerHand extends DTBunch<DTHero> {
6
+ _domain = 'hero';
7
+
8
+ constructor(key?: string, items: DTHero[] = [], options: Partial<DTBunchOptions> = {}) {
9
+ super(key, items, { ...options, inheritOwner: true });
10
+ }
11
+ }
@@ -0,0 +1,5 @@
1
+
2
+ export { default as DTHeroManager } from "./DTHeroManager";
3
+ export { default as DTHero } from "./DTHero";
4
+ export { default as DTHeroPlayerHand } from "./DTHeroPlayerHand";
5
+ export { default as DTHeroPlayZone } from "./DTHeroPlayZone";
@@ -0,0 +1,8 @@
1
+ import DTHero from "../components/DTHero";
2
+
3
+ export function generateHeroElement(key: string, name: string, damage: number): DTHero {
4
+ const hero = new DTHero(key);
5
+ hero.name = name;
6
+ hero.setDamage(damage);
7
+ return hero;
8
+ }
@@ -0,0 +1,13 @@
1
+ import {DTPlayer} from "../../../src";
2
+
3
+ export function generatePlayers(count: number): DTPlayer[] {
4
+ const playerNames = ['LLHOONN','PRIAM','AXELLE','PAYNHOPES','MORGANE'];
5
+ const players: DTPlayer[] = [];
6
+ for (let i = 0; i < count; i++) {
7
+ if (playerNames[i]) {
8
+ players.push(new DTPlayer(playerNames[i]));
9
+ }
10
+ }
11
+
12
+ return players;
13
+ }
@@ -0,0 +1,48 @@
1
+ import {DIXObject, DTBunchOptions} from "../../../src/types";
2
+ import {bunchDefaultOptions} from "../../../src/constants";
3
+
4
+ export function dixOutDTHero(key: string, name: string, damage: number, owner: string): DIXObject & { name: string } {
5
+ return {
6
+ useClass: 'DTHero',
7
+ componentType: 'element',
8
+ options: JSON.stringify({ errors: false }),
9
+ key,
10
+ meta: JSON.stringify({ damage }),
11
+ owner,
12
+ name,
13
+ }
14
+ }
15
+
16
+ export function dixOutDTHeroBunch(useClass: string, key: string, items: string[], owner?: string, options: Partial<DTBunchOptions> = {}): DIXObject {
17
+ const outputOptionsDix: DTBunchOptions = { ...bunchDefaultOptions, ...options };
18
+ delete outputOptionsDix.syncId;
19
+
20
+ const outputDix: DIXObject = {
21
+ useClass,
22
+ componentType: 'bunch',
23
+ key,
24
+ items,
25
+ options: JSON.stringify(outputOptionsDix),
26
+ }
27
+
28
+ if (owner) {
29
+ outputDix.owner = owner;
30
+ }
31
+
32
+ return outputDix;
33
+ }
34
+
35
+ export function dixOutDTHeroManager(key: string, items: string[], library: string): DIXObject {
36
+ return {
37
+ useClass: 'DTHeroManager',
38
+ componentType: 'manager',
39
+ options: JSON.stringify({ errors: false, libraryDeletion: false }),
40
+ key,
41
+ items,
42
+ library,
43
+ scopes: ['hand', 'playZone']
44
+ }
45
+ }
46
+
47
+
48
+
@@ -0,0 +1,25 @@
1
+ import {DTMaster} from "../../src";
2
+ import {IEnding, IStage, IStageExit} from "../types";
3
+ import DTDIXModule from "../../src/libs/dix/DIXModule.module";
4
+ import * as DIXOverrides from "../data/components";
5
+
6
+ export default class SynchronizationEnding implements IEnding {
7
+ exit(stage: IStage): IStageExit {
8
+ // create a new Master and update From previous DIX
9
+ const { master, outDIX, expectedDIX } = stage.exit(true);
10
+
11
+ const newMaster = new DTMaster(master.getKey(), { syncId: master.getId() });
12
+ const dixModule = new DTDIXModule(DIXOverrides);
13
+ newMaster.addModule(dixModule);
14
+
15
+ newMaster.updateFromDix(outDIX);
16
+ // console.log(newMaster.toDIXObject());
17
+
18
+ return {
19
+ master: newMaster,
20
+ outDIX: newMaster.toDIXObject(),
21
+ expectedDIX,
22
+ }
23
+ }
24
+
25
+ }
@@ -0,0 +1,31 @@
1
+ import {IScene, IStage} from "../types";
2
+ import {generateHeroElement} from "../data/in/heroIn.helper";
3
+ import {dixOutDTHero} from "../data/out/heroOut.helper";
4
+ import {DTHero} from "../data/components";
5
+
6
+ export default class DrawCardScene implements IScene {
7
+ play(stage: IStage): void {
8
+
9
+ // Each player play draw a new Card from nowhere, which increase HAILEI damage
10
+ const heroManager = stage.master.getManager('hero');
11
+ if (heroManager) {
12
+ const hands = heroManager.getAll('hand');
13
+
14
+ hands.forEach(h => {
15
+ const newCard = generateHeroElement('HENEKET', 'HENEKET', 5);
16
+ h.add(newCard);
17
+
18
+ const haileiCard = h.find({ key: { $eq: 'HAILEI' }});
19
+ if (haileiCard[0]) {
20
+ const haileiCardTyped = haileiCard[0] as DTHero;
21
+ haileiCardTyped.setMeta('damage', 10);
22
+ stage.dixExit[haileiCardTyped.getId()] = dixOutDTHero(haileiCardTyped.getKey(), haileiCardTyped.name, 10, h.getOwner());
23
+ }
24
+
25
+ stage.dixExit[h.getId()].items.push(newCard.getId());
26
+ stage.dixExit[heroManager.getLibrary().getId()].items.push(newCard.getId());
27
+ stage.dixExit[newCard.getId()] = dixOutDTHero(newCard.getKey(), newCard.name, newCard.getDamage(), h.getOwner());
28
+ });
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import {IScene, IStage} from "../types";
2
+
3
+ export default class EmptyScene implements IScene {
4
+ play(stage: IStage): void {
5
+ }
6
+ }
@@ -0,0 +1,23 @@
1
+ import {IScene, IStage} from "../types";
2
+
3
+ export default class PlayCardScene implements IScene {
4
+ play(stage: IStage): void {
5
+
6
+ // Each player play first hand Card
7
+ const heroManager = stage.master.getManager('hero');
8
+ if (heroManager) {
9
+ const hands = heroManager.getAll('hand');
10
+ const playZone = heroManager.getAll('playZone');
11
+
12
+ hands.forEach(h => {
13
+ const cardToPlay = h.get(0);
14
+ if (cardToPlay && playZone[0]) {
15
+ playZone[0].add(cardToPlay);
16
+
17
+ stage.dixExit[playZone[0].getId()].items.push(cardToPlay.getId());
18
+ stage.dixExit[h.getId()].items = stage.dixExit[h.getId()].items.slice(1);
19
+ }
20
+ });
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,33 @@
1
+ import {IScene, IStage} from "../types";
2
+ import {DTPlayerManager} from "../../src";
3
+
4
+ export default class PlayerLeaveScene implements IScene {
5
+ play(stage: IStage): void {
6
+
7
+ // A player leave the game
8
+ // Remove player, hand and all cards from the hand (including Library)
9
+ const playerManager = stage.master.getManager('player') as DTPlayerManager;
10
+ const heroManager = stage.master.getManager('hero');
11
+ const leftPlayer = playerManager?.getLibrary()?.find({ key: { $eq: 'PAYNHOPES' }})[0];
12
+ const leftPlayerHand = heroManager?.find({ owner: { $eq: leftPlayer?.getId() } })[0];
13
+
14
+ if (leftPlayer && leftPlayerHand && leftPlayerHand.getKey() === 'hand') {
15
+ playerManager.removePlayer(leftPlayer.getId());
16
+ heroManager.removeMany([ leftPlayerHand.getId() ], { libraryDeletion: true });
17
+
18
+ stage.dixExit[playerManager.getLibrary().getId()].items = stage.dixExit[playerManager.getLibrary().getId()]
19
+ .items.filter((i) => i !== leftPlayer.getId())
20
+ delete stage.dixExit[leftPlayer.getId()];
21
+
22
+ stage.dixExit[heroManager.getId()].items = stage.dixExit[heroManager.getId()]
23
+ .items.filter((i) => i !== leftPlayerHand.getId());
24
+ delete stage.dixExit[leftPlayerHand.getId()];
25
+
26
+ leftPlayerHand.getAll().forEach((c) => {
27
+ stage.dixExit[heroManager.getLibrary().getId()].items = stage.dixExit[heroManager.getLibrary().getId()]
28
+ .items.filter((i) => i !== c.getId());
29
+ delete stage.dixExit[c.getId()];
30
+ });
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,137 @@
1
+ import {DTMaster, DTPlayerManager} from "../../src";
2
+ import {generatePlayers} from "../data/in/playerIn.helper";
3
+ import DTHeroManager from "../data/components/DTHeroManager";
4
+ import DTHero from "../data/components/DTHero";
5
+ import {generateHeroElement} from "../data/in/heroIn.helper";
6
+ import DTHeroPlayZone from "../data/components/DTHeroPlayZone";
7
+ import DTHeroPlayerHand from "../data/components/DTHeroPlayerHand";
8
+ import {DIXObject} from "../../src/types";
9
+ import {dixOutDTHero, dixOutDTHeroBunch, dixOutDTHeroManager} from "../data/out/heroOut.helper";
10
+ import {IEnding, IScene, IStage, IStageExit} from "../types";
11
+ import DTDIXModule from "../../src/libs/dix/DIXModule.module";
12
+ import * as DIXOverrides from "../data/components";
13
+
14
+ export default class BaseDixStage implements IStage {
15
+ master: DTMaster;
16
+ dixExit: Record<string, DIXObject> = {};
17
+
18
+ constructor(private scene: IScene, private ending?: IEnding) {
19
+ this.master = new DTMaster('dix');
20
+ }
21
+
22
+ createMaster(key: string, syncId?: string): DTMaster {
23
+ const master = new DTMaster(key, { syncId: syncId });
24
+
25
+ // Initialize Module
26
+ const dixModule = new DTDIXModule(DIXOverrides);
27
+ master.addModule(dixModule);
28
+
29
+ return master;
30
+ }
31
+
32
+ enter() {
33
+ this.master = this.createMaster('dyo-test');
34
+
35
+ // - Manager player (4 players)
36
+ const playerManager = new DTPlayerManager('player');
37
+
38
+ const playerIds: string[] = [];
39
+ generatePlayers(4).forEach((player) => {
40
+ playerManager.addPlayer(player);
41
+ this.dixExit[player.getId()] = {
42
+ useClass: 'DTPlayer',
43
+ componentType: 'element',
44
+ options: JSON.stringify({ errors: false }),
45
+ key: player.getKey()
46
+ };
47
+ playerIds.push(player.getId());
48
+ });
49
+ this.master.addManager(playerManager);
50
+ this.dixExit[playerManager.getId()] = {
51
+ useClass: 'DTPlayerManager',
52
+ componentType: 'manager',
53
+ options: JSON.stringify({ errors: false, libraryDeletion: false }),
54
+ key: 'player',
55
+ items: [],
56
+ library: playerManager.getLibrary().getId(),
57
+ }
58
+ this.dixExit[playerManager.getLibrary().getId()] = {
59
+ useClass: 'DTBunch',
60
+ key: 'library',
61
+ componentType: 'bunch',
62
+ options: "",
63
+ items: playerIds,
64
+ }
65
+
66
+ // - Manager : Hero
67
+ const heroManager = new DTHeroManager();
68
+
69
+ const bunchesIds: Record<string, string[]> = {};
70
+ playerManager.findPlayers({owner: undefined}).forEach((player) => {
71
+ // -- Hero Elements
72
+ const elems: DTHero[] = [
73
+ generateHeroElement('HAILEI', 'HAILEI', 7),
74
+ generateHeroElement('MELDRINE', 'MELDRINE', 9),
75
+ generateHeroElement('MAYDENA', 'MAYDENA', 5),
76
+ generateHeroElement('ILDRESS', 'ILDRESS', 3),
77
+ generateHeroElement('YSSALIA', 'YSSALIA', 6),
78
+ ]
79
+
80
+ const hand = new DTHeroPlayerHand('hand', elems);
81
+ hand.setOwner(player.getId());
82
+
83
+ elems.forEach(e => {
84
+ this.dixExit[e.getId()] = dixOutDTHero(e.getKey(), e.name, e.getDamage(), player.getId());
85
+ })
86
+
87
+ heroManager.add(hand, 'hand');
88
+ this.dixExit[hand.getId()] = {
89
+ ...dixOutDTHeroBunch('DTHeroPlayerHand','hand', [...elems.map(e => e.getId())], player.getId(), { inheritOwner: true }),
90
+ scope: 'hand',
91
+ }
92
+
93
+ bunchesIds[hand.getId()] = [...elems.map(e => e.getId())];
94
+ });
95
+
96
+ const playZone = new DTHeroPlayZone('playZone');
97
+ heroManager.add(playZone, 'playZone');
98
+ this.dixExit[playZone.getId()] = {
99
+ ...dixOutDTHeroBunch('DTHeroPlayZone', 'playZone', []),
100
+ scope: 'playZone',
101
+ };
102
+
103
+ this.master.addManager(heroManager);
104
+ this.dixExit[heroManager.getId()] = dixOutDTHeroManager('hero', [...Object.keys(bunchesIds), playZone.getId()], heroManager.getLibrary().getId());
105
+ this.dixExit[heroManager.getLibrary().getId()] = {
106
+ useClass: 'DTBunch',
107
+ key: 'library',
108
+ componentType: 'bunch',
109
+ options: "",
110
+ items: Object.values(bunchesIds).reduce((prev, cur) => [...prev, ...cur], []),
111
+ }
112
+
113
+ this.dixExit[this.master.getId()] = {
114
+ useClass: 'DTMaster',
115
+ key: 'dyo-test',
116
+ componentType: 'master',
117
+ options: JSON.stringify({ errors: false }),
118
+ items: [playerManager.getId(), heroManager.getId()]
119
+ }
120
+ }
121
+
122
+ play(): void {
123
+ this.scene.play(this);
124
+ }
125
+
126
+ exit(skipEnding: boolean = false): IStageExit {
127
+ if (this.ending && !skipEnding) {
128
+ return this.ending.exit(this);
129
+ }
130
+
131
+ return {
132
+ master: this.master,
133
+ outDIX: this.master.toDIXObject(),
134
+ expectedDIX: this.dixExit,
135
+ };
136
+ }
137
+ }
@@ -0,0 +1,36 @@
1
+ import BaseDixStage from "./baseDix.stage";
2
+ import {DTMaster} from "../../src";
3
+ import {IStageExit} from "../types";
4
+
5
+ export default class SyncDixStage extends BaseDixStage {
6
+ syncedMaster: DTMaster | undefined;
7
+
8
+ enter() {
9
+ super.enter();
10
+
11
+ // Sync with other master
12
+ const syncedMaster = this.createMaster("dyo-test", this.master.getId());
13
+
14
+ syncedMaster.updateFromDix(this.master.toDIXObject());
15
+ this.syncedMaster = syncedMaster;
16
+ }
17
+
18
+ play() {
19
+ super.play();
20
+
21
+ // Sync with other master
22
+ this.syncedMaster.updateFromDix(this.master.toDIXObject());
23
+ }
24
+
25
+ exit(skipEnding: boolean = false): IStageExit {
26
+ super.exit(skipEnding);
27
+
28
+ return {
29
+ master: this.syncedMaster,
30
+ outDIX: this.syncedMaster.toDIXObject(),
31
+ expectedDIX: this.dixExit,
32
+ }
33
+ }
34
+
35
+
36
+ }
@@ -0,0 +1,55 @@
1
+ import {describe, expect, test,} from '@jest/globals';
2
+ import BaseDixStage from "../stages/baseDix.stage";
3
+ import EmptyScene from "../scenes/empty.scene";
4
+ import SyncDixStage from "../stages/syncDix.stage";
5
+ import PlayCardScene from "../scenes/playCard.scene";
6
+ import DrawCardScene from "../scenes/drawCard.scene";
7
+ import PlayerLeaveScene from "../scenes/playerLeave.scene";
8
+
9
+ describe('Scenario 1 - Play a DYO Test round', () => {
10
+ test('Scene 1 : Empty scene', () => {
11
+ const stage = new BaseDixStage(new EmptyScene());
12
+ stage.enter();
13
+ stage.play();
14
+ const { outDIX, expectedDIX } = stage.exit();
15
+
16
+ expect(outDIX).toStrictEqual(expectedDIX);
17
+ });
18
+
19
+ test('Scene 2 : Empty scene synchronized', () => {
20
+ const stage = new SyncDixStage(new EmptyScene());
21
+ stage.enter();
22
+ stage.play();
23
+ const { outDIX, expectedDIX } = stage.exit();
24
+
25
+ expect(outDIX).toStrictEqual(expectedDIX);
26
+ });
27
+
28
+ test('Scene 3 : Play a card', () => {
29
+ const stage = new SyncDixStage(new PlayCardScene());
30
+ stage.enter();
31
+ stage.play();
32
+ const { outDIX, expectedDIX } = stage.exit();
33
+
34
+ expect(outDIX).toStrictEqual(expectedDIX);
35
+ });
36
+
37
+ test('Scene 4 : Draw a card', () => {
38
+ const stage = new SyncDixStage(new DrawCardScene());
39
+ stage.enter();
40
+ stage.play();
41
+ const { outDIX, expectedDIX } = stage.exit();
42
+
43
+ expect(outDIX).toStrictEqual(expectedDIX);
44
+ });
45
+
46
+ test('Scene 5 : Player leaves', () => {
47
+ const stage = new SyncDixStage(new PlayerLeaveScene());
48
+ stage.enter();
49
+ stage.play();
50
+ const { outDIX, expectedDIX } = stage.exit();
51
+
52
+ expect(outDIX).toStrictEqual(expectedDIX);
53
+ });
54
+
55
+ });
@@ -0,0 +1,24 @@
1
+ import {DTMaster} from "../../src";
2
+ import {DIXObject} from "../../src/types";
3
+
4
+ export interface IStageExit {
5
+ master: DTMaster,
6
+ outDIX: Record<string, DIXObject>,
7
+ expectedDIX: Record<string, DIXObject>,
8
+ }
9
+
10
+ export interface IStage {
11
+ master: DTMaster,
12
+ dixExit: Record<string, DIXObject>,
13
+ enter: () => void,
14
+ play: () => void,
15
+ exit: (skipEnding: boolean) => IStageExit,
16
+ }
17
+
18
+ export interface IScene {
19
+ play: (stage: IStage) => void,
20
+ }
21
+
22
+ export interface IEnding {
23
+ exit: (stage: IStage) => IStageExit,
24
+ }
@@ -0,0 +1,25 @@
1
+ import type { JestConfigWithTsJest } from "ts-jest";
2
+
3
+ // Jest Configuration for Integration Tests
4
+ // Integration Tests are only for the test/integration folder
5
+ const config: JestConfigWithTsJest = {
6
+ verbose: true,
7
+ transform: {
8
+ "^.+\\.ts?$": [
9
+ "ts-jest",
10
+ {
11
+ useESM: true,
12
+ },
13
+ ],
14
+ },
15
+ extensionsToTreatAsEsm: [".ts"],
16
+ moduleNameMapper: {
17
+ "^(\\.{1,2}/.*)\\.js$": "$1",
18
+ },
19
+ testMatch: ["<rootDir>/integration/**/*.spec.ts"],
20
+ testPathIgnorePatterns: ["<rootDir>/dist/", "<rootDir>/node_modules/", "<rootDir>/test/"],
21
+ };
22
+
23
+ export default config;
24
+
25
+
package/jest.config.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { JestConfigWithTsJest } from "ts-jest";
2
+
3
+ // Jest Configuration for Unit Tests
4
+ // Unit Tests are only for the test/core folder, excluding DIX methods
5
+ // Other tests are in the integration folder
6
+ const config: JestConfigWithTsJest = {
7
+ verbose: true,
8
+ transform: {
9
+ "^.+\\.ts?$": [
10
+ "ts-jest",
11
+ {
12
+ useESM: true,
13
+ },
14
+ ],
15
+ },
16
+ extensionsToTreatAsEsm: [".ts"],
17
+ moduleNameMapper: {
18
+ "^(\\.{1,2}/.*)\\.js$": "$1",
19
+ },
20
+ testMatch: ["<rootDir>/test/core/*.spec.ts"],
21
+ testPathIgnorePatterns: ["<rootDir>/dist/", "<rootDir>/node_modules/", "<rootDir>/integration/"],
22
+ };
23
+
24
+ export default config;
25
+
26
+