dyo-tools 0.3.0 → 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.
- package/.c8rc.json +4 -4
- package/.eslintignore +1 -1
- package/.eslintrc.json +47 -47
- package/Makefile +34 -34
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -20
- package/dist/constants.js.map +1 -1
- package/dist/core/DTAction.d.ts +6 -4
- package/dist/core/DTAction.d.ts.map +1 -0
- package/dist/core/DTAction.js +3 -6
- package/dist/core/DTAction.js.map +1 -1
- package/dist/core/DTBunch.d.ts +8 -5
- package/dist/core/DTBunch.d.ts.map +1 -0
- package/dist/core/DTBunch.js +54 -20
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponent.d.ts +13 -10
- package/dist/core/DTComponent.d.ts.map +1 -0
- package/dist/core/DTComponent.js +23 -10
- package/dist/core/DTComponent.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +11 -7
- package/dist/core/DTComponentPhysical.d.ts.map +1 -0
- package/dist/core/DTComponentPhysical.js +21 -6
- package/dist/core/DTComponentPhysical.js.map +1 -1
- package/dist/core/DTComponentWithMeta.d.ts +6 -3
- package/dist/core/DTComponentWithMeta.d.ts.map +1 -0
- package/dist/core/DTComponentWithMeta.js +21 -7
- package/dist/core/DTComponentWithMeta.js.map +1 -1
- package/dist/core/DTElement.d.ts +10 -8
- package/dist/core/DTElement.d.ts.map +1 -0
- package/dist/core/DTElement.js +8 -9
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTError.d.ts +8 -7
- package/dist/core/DTError.d.ts.map +1 -0
- package/dist/core/DTError.js +1 -5
- package/dist/core/DTError.js.map +1 -1
- package/dist/core/DTManager.d.ts +17 -14
- package/dist/core/DTManager.d.ts.map +1 -0
- package/dist/core/DTManager.js +84 -26
- package/dist/core/DTManager.js.map +1 -1
- package/dist/core/DTMaster.d.ts +19 -16
- package/dist/core/DTMaster.d.ts.map +1 -0
- package/dist/core/DTMaster.js +48 -31
- package/dist/core/DTMaster.js.map +1 -1
- package/dist/core/DTModule.d.ts +8 -5
- package/dist/core/DTModule.d.ts.map +1 -0
- package/dist/core/DTModule.js +6 -6
- package/dist/core/DTModule.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -28
- package/dist/index.js.map +1 -1
- package/dist/libs/DYOFinder.d.ts +1 -0
- package/dist/libs/DYOFinder.d.ts.map +1 -0
- package/dist/libs/DYOFinder.js +10 -14
- package/dist/libs/DYOFinder.js.map +1 -1
- package/dist/libs/dix/DIXModule.module.d.ts +8 -0
- package/dist/libs/dix/DIXModule.module.d.ts.map +1 -0
- package/dist/libs/dix/DIXModule.module.js +73 -0
- package/dist/libs/player/DTPlayer.element.d.ts +3 -2
- package/dist/libs/player/DTPlayer.element.d.ts.map +1 -0
- package/dist/libs/player/DTPlayer.element.js +2 -6
- package/dist/libs/player/DTPlayer.element.js.map +1 -1
- package/dist/libs/player/DTPlayer.manager.d.ts +8 -7
- package/dist/libs/player/DTPlayer.manager.d.ts.map +1 -0
- package/dist/libs/player/DTPlayer.manager.js +13 -20
- package/dist/libs/player/DTPlayer.manager.js.map +1 -1
- package/dist/tsconfig.dev.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/core.d.ts +40 -12
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +2 -6
- package/dist/types/core.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -19
- package/dist/types/index.js.map +1 -1
- package/dist/types/player.d.ts +1 -1
- package/dist/types/player.d.ts.map +1 -0
- package/dist/types/player.js +1 -3
- package/docs/assets/main.js +59 -59
- package/docs/assets/style.css +1414 -1414
- package/integration/data/components/DTHero.ts +42 -0
- package/integration/data/components/DTHeroManager.ts +11 -0
- package/integration/data/components/DTHeroPlayZone.ts +6 -0
- package/integration/data/components/DTHeroPlayerHand.ts +11 -0
- package/integration/data/components/index.ts +5 -0
- package/integration/data/in/heroIn.helper.ts +8 -0
- package/integration/data/in/playerIn.helper.ts +13 -0
- package/integration/data/out/heroOut.helper.ts +48 -0
- package/integration/endings/synchronisation.ending.ts +25 -0
- package/integration/scenes/drawCard.scene.ts +31 -0
- package/integration/scenes/empty.scene.ts +6 -0
- package/integration/scenes/playCard.scene.ts +23 -0
- package/integration/scenes/playerLeave.scene.ts +33 -0
- package/integration/stages/baseDix.stage.ts +137 -0
- package/integration/stages/syncDix.stage.ts +36 -0
- package/integration/tests/scenario1.spec.ts +55 -0
- package/integration/types/index.ts +24 -0
- package/jest-integration.config.ts +25 -0
- package/jest.config.ts +26 -0
- package/package.json +31 -19
- package/src/constants.ts +87 -85
- package/src/core/DTAction.ts +54 -52
- package/src/core/DTBunch.ts +531 -467
- package/src/core/DTComponent.ts +258 -225
- package/src/core/DTComponentPhysical.ts +88 -53
- package/src/core/DTComponentWithMeta.ts +98 -65
- package/src/core/DTElement.ts +111 -102
- package/src/core/DTError.ts +78 -78
- package/src/core/DTManager.ts +555 -465
- package/src/core/DTMaster.ts +366 -318
- package/src/core/DTModule.ts +96 -90
- package/src/libs/dix/DIXModule.module.ts +98 -0
- package/src/libs/player/DTPlayer.element.ts +9 -9
- package/src/libs/player/DTPlayer.manager.ts +70 -84
- package/src/types/core.ts +204 -169
- package/src/types/player.ts +5 -6
- package/test/core/DTAction.double.ts +12 -28
- package/test/core/DTAction.spec.ts +8 -16
- package/test/core/DTBunch.double.ts +49 -135
- package/test/core/DTBunch.spec.ts +163 -238
- package/test/core/DTComponent.double.ts +17 -2
- package/test/core/DTComponent.spec.ts +6 -4
- package/test/core/DTComponentPhysical.double.ts +29 -43
- package/test/core/DTComponentPhysical.spec.ts +22 -19
- package/test/core/DTComponentWithMeta.double.ts +38 -31
- package/test/core/DTComponentWithMeta.spec.ts +23 -18
- package/test/core/DTElement.double.ts +32 -53
- package/test/core/DTElement.spec.ts +15 -38
- package/test/core/DTError.double.ts +18 -53
- package/test/core/DTError.spec.ts +21 -32
- package/test/core/DTManager.double.ts +74 -141
- package/test/core/DTManager.spec.ts +289 -380
- package/test/core/DTMaster.double.ts +56 -80
- package/test/core/DTMaster.spec.ts +185 -232
- package/test/core/DTModule.double.ts +12 -25
- package/test/core/DTModule.spec.ts +14 -28
- package/test/core/copy.spec.ts +9 -30
- package/tsconfig.dev.json +5 -8
- package/tsconfig.json +5 -8
- package/cucumber-report.html +0 -48
- package/docs/assets/navigation.js +0 -1
- package/docs/classes/core_DTAction.DYOToolsAction.html +0 -89
- package/docs/classes/core_DTBunch.DYOToolsBunch.html +0 -254
- package/docs/classes/core_DTComponent.DYOToolsComponent.html +0 -76
- package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +0 -110
- package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +0 -96
- package/docs/classes/core_DTElement.DYOToolsElement.html +0 -135
- package/docs/classes/core_DTError.DYOToolsError.html +0 -37
- package/docs/classes/core_DTManager.DYOToolsManager.html +0 -237
- package/docs/classes/core_DTMaster.DYOToolsMaster.html +0 -150
- package/docs/classes/core_DTModule.DYOToolsModule.html +0 -92
- package/docs/classes/libs_DYOFinder.DYOFinder.html +0 -34
- package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +0 -134
- package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +0 -243
- package/docs/enums/types_core.FilterOperatorType.html +0 -10
- package/docs/hierarchy.html +0 -1
- package/docs/interfaces/types_core.DTBunchFilters.html +0 -6
- package/docs/interfaces/types_core.DTBunchOptions.html +0 -19
- package/docs/interfaces/types_core.DTBunchToObject.html +0 -7
- package/docs/interfaces/types_core.DTComponentOptions.html +0 -5
- package/docs/interfaces/types_core.DTComponentToObject.html +0 -4
- package/docs/interfaces/types_core.DTElementToObject.html +0 -7
- package/docs/interfaces/types_core.DTManagerFilters.html +0 -6
- package/docs/interfaces/types_core.DTManagerOptions.html +0 -8
- package/docs/interfaces/types_core.DTManagerToObject.html +0 -5
- package/docs/interfaces/types_core.DTMasterToObject.html +0 -8
- package/docs/interfaces/types_core.DTModuleToObject.html +0 -6
- package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +0 -4
- package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +0 -4
- package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +0 -5
- package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +0 -5
- package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +0 -3
- package/docs/modules/constants.html +0 -6
- package/docs/modules/core_DTAction.html +0 -2
- package/docs/modules/core_DTBunch.html +0 -2
- package/docs/modules/core_DTComponent.html +0 -2
- package/docs/modules/core_DTComponentPhysical.html +0 -2
- package/docs/modules/core_DTComponentWithMeta.html +0 -2
- package/docs/modules/core_DTElement.html +0 -2
- package/docs/modules/core_DTError.html +0 -2
- package/docs/modules/core_DTManager.html +0 -2
- package/docs/modules/core_DTMaster.html +0 -2
- package/docs/modules/core_DTModule.html +0 -2
- package/docs/modules/libs_DYOFinder.html +0 -2
- package/docs/modules/libs_player_DTPlayer_element.html +0 -2
- package/docs/modules/libs_player_DTPlayer_manager.html +0 -2
- package/docs/modules/types.html +0 -29
- package/docs/modules/types_core.html +0 -28
- package/docs/modules/types_player.html +0 -2
- package/docs/types/types_core.DTAcceptedMetaData.html +0 -2
- package/docs/types/types_core.DTManagerItemType.html +0 -1
- package/docs/types/types_core.DTManagerItemsType.html +0 -2
- package/docs/types/types_core.DYOFinderComponentType.html +0 -1
- package/docs/types/types_core.DYOFinderConfiguration.html +0 -2
- package/docs/types/types_core.DYOFinderConfigurationProp.html +0 -1
- package/docs/types/types_core.DYOFinderFilterOperator.html +0 -1
- package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +0 -1
- package/docs/types/types_core.DYOFinderFilters.html +0 -1
- package/docs/types/types_core.StandardPrimitiveType.html +0 -2
- package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +0 -1
- package/docs/variables/constants.bunchDefaultOptions.html +0 -2
- package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.managerDefaultOptions.html +0 -2
- package/jest.config.js +0 -6
|
@@ -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,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,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,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
|
+
|
package/package.json
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyo-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/types/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
6
14
|
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
7
16
|
"build:prod": "tsc -p tsconfig.json",
|
|
8
17
|
"build:dev": "tsc -p tsconfig.dev.json",
|
|
9
18
|
"start": "node dist/index.js",
|
|
10
19
|
"lint": "eslint src/ --ext .ts",
|
|
11
20
|
"lint:fix": "eslint src/ --ext .ts --fix",
|
|
12
21
|
"typecheck": "tsc --noEmit -p tsconfig.dev.json",
|
|
13
|
-
"test": "jest",
|
|
14
|
-
"test:
|
|
15
|
-
"test:coverage:
|
|
22
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest.config.ts",
|
|
23
|
+
"test:integration": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest-integration.config.ts",
|
|
24
|
+
"test:coverage:unit": "c8 --temp-directory .coverage/v8 --reports-dir coverage/unit --clean npm run test",
|
|
25
|
+
"test:coverage:integration": "c8 --temp-directory .coverage/v8 --reports-dir coverage/integration --no-clean npm run test:integration",
|
|
26
|
+
"test:coverage": "npm run test:coverage:unit && npm run test:coverage:integration && c8 report --temp-directory .coverage/v8 --reports-dir coverage --reporter=text --reporter=lcov --reporter=html",
|
|
16
27
|
"typedoc": "typedoc --plugin typedoc-plugin-rename-defaults --entryPointStrategy expand ./src --exclude 'src/index.ts'"
|
|
17
28
|
},
|
|
18
29
|
"repository": {
|
|
@@ -29,23 +40,24 @@
|
|
|
29
40
|
},
|
|
30
41
|
"homepage": "https://gitlab.com/dyo-system/dyo-tools#readme",
|
|
31
42
|
"devDependencies": {
|
|
32
|
-
"@babel/preset-env": "^7.
|
|
33
|
-
"@types/jest": "^
|
|
34
|
-
"@types/uuid": "^
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
36
|
-
"@typescript-eslint/parser": "^
|
|
37
|
-
"c8": "^
|
|
38
|
-
"eslint": "^8.
|
|
43
|
+
"@babel/preset-env": "^7.28.5",
|
|
44
|
+
"@types/jest": "^30.0.0",
|
|
45
|
+
"@types/uuid": "^11.0.0",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
47
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
48
|
+
"c8": "^10.1.3",
|
|
49
|
+
"eslint": "^8.57.1",
|
|
39
50
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
40
|
-
"eslint-config-airbnb-typescript": "^
|
|
41
|
-
"eslint-plugin-import": "^2.
|
|
42
|
-
"jest": "^
|
|
43
|
-
"ts-jest": "^29.
|
|
44
|
-
"
|
|
45
|
-
"typedoc
|
|
46
|
-
"
|
|
51
|
+
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
52
|
+
"eslint-plugin-import": "^2.32.0",
|
|
53
|
+
"jest": "^30.2.0",
|
|
54
|
+
"ts-jest": "^29.4.5",
|
|
55
|
+
"ts-node": "^10.9.2",
|
|
56
|
+
"typedoc": "^0.28.15",
|
|
57
|
+
"typedoc-plugin-rename-defaults": "^0.7.3",
|
|
58
|
+
"typescript": "^5.9.3"
|
|
47
59
|
},
|
|
48
60
|
"dependencies": {
|
|
49
|
-
"uuid": "^
|
|
61
|
+
"uuid": "^13.0.0"
|
|
50
62
|
}
|
|
51
63
|
}
|