dyo-tools 0.1.0-rc2 → 0.2.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 (93) hide show
  1. package/.c8rc.json +4 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +47 -0
  4. package/LICENSE +21 -0
  5. package/Makefile +34 -0
  6. package/README.md +0 -7
  7. package/babel.config.js +1 -0
  8. package/cucumber-report.html +48 -0
  9. package/cucumber.js +9 -0
  10. package/dist/constants.d.ts +6 -0
  11. package/dist/constants.js +63 -0
  12. package/dist/constants.js.map +1 -0
  13. package/dist/core/DTBunch.d.ts +11 -15
  14. package/dist/core/DTBunch.js +27 -106
  15. package/dist/core/DTBunch.js.map +1 -1
  16. package/dist/core/DTComponent.d.ts +13 -5
  17. package/dist/core/DTComponent.js +39 -1
  18. package/dist/core/DTComponent.js.map +1 -1
  19. package/dist/core/DTComponentPhysical.d.ts +10 -0
  20. package/dist/core/DTComponentPhysical.js +16 -0
  21. package/dist/core/DTComponentPhysical.js.map +1 -0
  22. package/dist/core/DTComponentWithMeta.d.ts +2 -2
  23. package/dist/core/DTComponentWithMeta.js.map +1 -1
  24. package/dist/core/DTElement.d.ts +2 -7
  25. package/dist/core/DTElement.js +3 -12
  26. package/dist/core/DTElement.js.map +1 -1
  27. package/dist/core/DTManager.d.ts +31 -0
  28. package/dist/core/DTManager.js +180 -0
  29. package/dist/core/DTManager.js.map +1 -0
  30. package/dist/core/DTPlayer.js +1 -1
  31. package/dist/core/DTPlayer.js.map +1 -1
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +5 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/libs/DYOFinder.d.ts +10 -0
  36. package/dist/libs/DYOFinder.js +96 -0
  37. package/dist/libs/DYOFinder.js.map +1 -0
  38. package/dist/tsconfig.tsbuildinfo +1 -1321
  39. package/dist/types/index.d.ts +64 -24
  40. package/dist/types/index.js.map +1 -1
  41. package/docs/.nojekyll +1 -0
  42. package/docs/assets/highlight.css +29 -0
  43. package/docs/assets/main.js +58 -0
  44. package/docs/assets/search.js +1 -0
  45. package/docs/assets/style.css +1367 -0
  46. package/docs/index.html +46 -0
  47. package/e2e/0.2.0/epic1.feature +29 -0
  48. package/e2e/0.2.0/epic2.feature +22 -0
  49. package/e2e/0.2.0/epic3.feature +25 -0
  50. package/e2e/0.2.0/resources/dominion.js +195 -0
  51. package/e2e/0.2.0/resources/utils.js +27 -0
  52. package/e2e/0.2.0/support/steps.js +108 -0
  53. package/e2e/future/epic4.feature +39 -0
  54. package/e2e/future/resources/dominion.js +238 -0
  55. package/e2e/future/resources/utils.js +27 -0
  56. package/jest.config.js +6 -0
  57. package/package.json +33 -23
  58. package/src/constants.ts +85 -0
  59. package/src/core/DTBunch.ts +461 -0
  60. package/src/core/DTComponent.ts +225 -0
  61. package/src/core/DTComponentPhysical.ts +39 -0
  62. package/src/core/DTComponentWithMeta.ts +65 -0
  63. package/src/core/DTElement.ts +69 -0
  64. package/src/core/DTError.ts +78 -0
  65. package/src/core/DTManager.ts +446 -0
  66. package/src/core/DTPlayer.ts +57 -0
  67. package/src/index.ts +9 -0
  68. package/src/libs/DYOFinder.ts +175 -0
  69. package/src/types/index.ts +162 -0
  70. package/test/core/DTBunch.double.ts +253 -0
  71. package/test/core/DTBunch.spec.ts +895 -0
  72. package/test/core/DTComponent.double.ts +164 -0
  73. package/test/core/DTComponent.spec.ts +295 -0
  74. package/test/core/DTComponentPhysical.double.ts +76 -0
  75. package/test/core/DTComponentPhysical.spec.ts +64 -0
  76. package/test/core/DTComponentWithMeta.double.ts +115 -0
  77. package/test/core/DTComponentWithMeta.spec.ts +124 -0
  78. package/test/core/DTElement.double.ts +147 -0
  79. package/test/core/DTElement.spec.ts +102 -0
  80. package/test/core/DTError.double.ts +92 -0
  81. package/test/core/DTError.spec.ts +89 -0
  82. package/test/core/DTManager.double.ts +192 -0
  83. package/test/core/DTManager.spec.ts +902 -0
  84. package/test/core/DTPlayer.double.ts +64 -0
  85. package/test/core/DTPlayer.spec.ts +80 -0
  86. package/test/core/copy.spec.ts +227 -0
  87. package/test/libs/DYOFinder.double.ts +152 -0
  88. package/test/libs/DYOFinder.spec.ts +194 -0
  89. package/tsconfig.dev.json +22 -0
  90. package/tsconfig.json +21 -0
  91. package/dist/utils/filters.d.ts +0 -6
  92. package/dist/utils/filters.js +0 -39
  93. package/dist/utils/filters.js.map +0 -1
@@ -0,0 +1,238 @@
1
+ const {DTElement, DTManager, DTBunch, DTPlayer} = require("../../../dist/src");
2
+
3
+ /****************** CARDS REFERENCE ************************/
4
+ const cards = {
5
+ "COPPER": {
6
+ meta: {
7
+ type: 'treasure',
8
+ cost: 0,
9
+ treasurePoints: 1
10
+ },
11
+ events: {
12
+ play: (ctx) => {
13
+ ctx.getOwner.setMeta('coin', 1);
14
+ }
15
+ }
16
+ },
17
+ "SILVER": {
18
+ meta: {
19
+ type: 'treasure',
20
+ cost: 3,
21
+ treasurePoints: 2
22
+ },
23
+ events: {
24
+ play: (ctx) => {
25
+ ctx.getOwner.setMeta('coin', 2);
26
+ }
27
+ }
28
+ },
29
+ "GOLD": {
30
+ meta: {
31
+ type: 'treasure',
32
+ cost: 6,
33
+ treasurePoints: 3
34
+ },
35
+ events: {
36
+ play: (ctx) => {
37
+ ctx.getOwner.setMeta('coin', 3);
38
+ }
39
+ }
40
+ },
41
+ "ESTATE": {
42
+ meta: {
43
+ type: 'victory',
44
+ cost: 2,
45
+ victoryPoints: 1
46
+ }
47
+ },
48
+ "DUCHY": {
49
+ meta: {
50
+ type: 'victory',
51
+ cost: 5,
52
+ treasurePoints: 3
53
+ }
54
+ },
55
+ "PROVINCE": {
56
+ meta: {
57
+ type: 'victory',
58
+ cost: 8,
59
+ treasurePoints: 6
60
+ }
61
+ },
62
+ "SMITHY": {
63
+ meta: {
64
+ type: 'action',
65
+ cost: 4,
66
+ }
67
+ },
68
+ "WORKSHOP": {
69
+ meta: {
70
+ type: 'action',
71
+ cost: 3,
72
+ }
73
+ },
74
+ "MILITIA": {
75
+ meta: {
76
+ type: 'action',
77
+ cost: 4,
78
+ }
79
+ },
80
+ }
81
+
82
+ /****************** BUILDERS ************************/
83
+
84
+ const buildCard = (key) => {
85
+ const element = new DTElement(key);
86
+ element.setManyMeta(cards[key].meta);
87
+ if (cards[key].events) {
88
+ for (let actionKey of Object.keys(cards[key].events)) {
89
+ element.addEvent(actionKey, cards[key].events[actionKey]);
90
+ }
91
+ }
92
+ return element;
93
+ }
94
+
95
+ const duplicateCard = (card, nb) => {
96
+ const items = [card];
97
+ let i = 1;
98
+ while (i <= nb) {
99
+ items.push(card.copy());
100
+ i++;
101
+ }
102
+ return items;
103
+ }
104
+
105
+ const initializeDominionManager = () => {
106
+ const scopes = [
107
+ 'supply',
108
+ 'hand',
109
+ 'playZone',
110
+ 'discard',
111
+ 'deck'
112
+ ];
113
+ const library = [
114
+ ...duplicateCard(buildCard('COPPER'), 13),
115
+ ...duplicateCard(buildCard('ESTATE'), 5)
116
+ ];
117
+ const manager = new DTManager('dominionCard', library, scopes, { errors: true });
118
+
119
+ // Initialize Supply zone
120
+ const copperPile = new DTBunch('copperPile', duplicateCard(buildCard('COPPER'), 11));
121
+ copperPile.setMeta('cost', cards["COPPER"].cost);
122
+ const silverPile = new DTBunch('silverPile', duplicateCard(buildCard('SILVER'), 11));
123
+ silverPile.setMeta('cost', cards["SILVER"].cost);
124
+ const goldPile = new DTBunch('goldPile', duplicateCard(buildCard('GOLD'), 11));
125
+ goldPile.setMeta('cost', cards["GOLD"].cost);
126
+
127
+ const estatePile = new DTBunch('estatePile', duplicateCard(buildCard('ESTATE'), 7));
128
+ estatePile.setMeta('cost', cards["ESTATE"].cost);
129
+ const duchyPile = new DTBunch('duchyPile', duplicateCard(buildCard('DUCHY'), 7));
130
+ duchyPile.setMeta('cost', cards["DUCHY"].cost);
131
+ const provincePile = new DTBunch('provincePile', duplicateCard(buildCard('PROVINCE'), 7));
132
+ provincePile.setMeta('cost', cards["PROVINCE"].cost);
133
+
134
+ const militiaPile = new DTBunch('militiaPile', duplicateCard(buildCard('MILITIA'), 7));
135
+ militiaPile.setMeta('cost', cards["MILITIA"].cost);
136
+ const smithyPile = new DTBunch('smithyPile', duplicateCard(buildCard('SMITHY'), 7));
137
+ smithyPile.setMeta('cost', cards["SMITHY"].cost);
138
+ const workshopPile = new DTBunch('workshopPile', duplicateCard(buildCard('WORKSHOP'), 7));
139
+ workshopPile.setMeta('cost', cards["WORKSHOP"].cost);
140
+
141
+ manager.addMany([
142
+ copperPile,
143
+ silverPile,
144
+ goldPile,
145
+ estatePile,
146
+ duchyPile,
147
+ provincePile,
148
+ militiaPile,
149
+ smithyPile,
150
+ workshopPile
151
+ ], 'supply');
152
+
153
+ // Initialize players
154
+ const players = [
155
+ new DTPlayer('PRIAM'),
156
+ new DTPlayer('ECTESIAM'),
157
+ ]
158
+
159
+ // Initialize players deck, discard and hand
160
+ let current = {};
161
+ for (let player of players) {
162
+ const deck = new DTBunch('deck');
163
+ deck.setOwner(player);
164
+ manager.add(deck, 'deck');
165
+
166
+ const discard = new DTBunch('discard');
167
+ discard.setOwner(player);
168
+ manager.add(discard, 'discard');
169
+
170
+ const hand = new DTBunch('hand');
171
+ hand.setOwner(player);
172
+ manager.add(hand, 'hand');
173
+
174
+ const playZone = new DTBunch('playZone');
175
+ playZone.setOwner(player);
176
+ manager.add(playZone, 'playZone');
177
+
178
+ const playerCards = new DTBunch('playerCards', [], { virtualContext: true });
179
+ playerCards.setOwner(player);
180
+ manager.add(playerCards);
181
+
182
+ if (player.getKey() === 'PRIAM') {
183
+ current = {
184
+ player,
185
+ deck,
186
+ hand,
187
+ playZone
188
+ }
189
+ }
190
+ }
191
+
192
+ // Initialize actions
193
+ const fakeShuffle = (bunch) => {
194
+ const estates = bunch.find({ key: { $eq: 'ESTATE' }});
195
+ const coppers = bunch.find({ key: { $eq: 'COPPER' }});
196
+
197
+ bunch.removeAll();
198
+ bunch.addMany([
199
+ coppers[0],
200
+ estates[0],
201
+ coppers[1],
202
+ estates[1],
203
+ coppers[2],
204
+ estates[2],
205
+ coppers[3],
206
+ coppers[4],
207
+ coppers[5],
208
+ coppers[6],
209
+ ])
210
+ };
211
+ const fakeShuffleAction = new DTSimpleAction('shuffle', fakeShuffle, {
212
+ target: 'bunch',
213
+ scopes: ['deck']
214
+ });
215
+
216
+ const drawAction = new DTTransferAction('draw', {
217
+ scopes: ['deck'],
218
+ destinationScope: 'hand'
219
+ });
220
+
221
+ const playAction = new DTTransferAction('play', {
222
+ scopes: ['hand'],
223
+ destinationScope: 'playZone'
224
+ });
225
+
226
+ manager.addAction(fakeShuffleAction);
227
+ manager.addAction(drawAction);
228
+ manager.addAction(playAction);
229
+
230
+ // Return
231
+ return {
232
+ manager,
233
+ current,
234
+ players
235
+ }
236
+ }
237
+
238
+ module.exports = initializeDominionManager
@@ -0,0 +1,27 @@
1
+
2
+ const transformDataTableToBunchFinderArgs = (table) => {
3
+ const validArgs = ['key', 'id', 'owner', 'scope'];
4
+ const finalArgs = {};
5
+
6
+ for (let [arg, value] of Object.entries(table.rowsHash())) {
7
+ if (validArgs.includes(arg)) {
8
+ finalArgs[arg] = { $eq: value };
9
+ } else {
10
+ if (!finalArgs.meta) {
11
+ finalArgs.meta = {};
12
+ }
13
+ finalArgs.meta[arg] = { $eq: value };
14
+ }
15
+ }
16
+
17
+ return finalArgs;
18
+ }
19
+
20
+ const extractKeysElement = (elements) => {
21
+ return elements.map((element) => element.getKey());
22
+ }
23
+
24
+ module.exports = {
25
+ transformDataTableToBunchFinderArgs,
26
+ extractKeysElement
27
+ }
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ module.exports = {
3
+ preset: "ts-jest",
4
+ testEnvironment: "node",
5
+ testPathIgnorePatterns: ["<rootDir>/dist/", "<rootDir>/dist_test/", "<rootDir>/node_modules/"]
6
+ };
package/package.json CHANGED
@@ -1,42 +1,52 @@
1
1
  {
2
2
  "name": "dyo-tools",
3
- "version": "0.1.0-rc2",
4
- "description": "Provide component classes to manage any board game instance.",
3
+ "version": "0.2.0",
4
+ "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "build": "tsc",
7
+ "build:prod": "tsc -p tsconfig.json",
8
+ "build:dev": "tsc -p tsconfig.dev.json",
8
9
  "start": "node dist/index.js",
9
10
  "lint": "eslint src/ --ext .ts",
10
11
  "lint:fix": "eslint src/ --ext .ts --fix",
12
+ "typecheck": "tsc --noEmit -p tsconfig.dev.json",
11
13
  "test": "jest",
12
14
  "test:coverage": "c8 --check-coverage npm test",
13
- "test:coverage:verify": "c8 --check-coverage --100 npm test"
15
+ "test:coverage:verify": "c8 --check-coverage --lines 97 --functions 97 --branches 97 --statements 97 npm test",
16
+ "e2e": "cucumber-js --config cucumber.js",
17
+ "typedoc": "typedoc --tsconfig tsconfig.dev.json src/**/*.ts"
14
18
  },
15
19
  "repository": {
16
20
  "type": "git",
17
- "url": "https://github.com/Flaya24/dyo-tools.git"
21
+ "url": "git+https://gitlab.com/dyo-system/dyo-tools.git"
18
22
  },
19
- "author": "Flaya for DYO System",
20
- "license": "MIT",
21
- "keywords": ["game", "DYO", "board game"],
22
- "files": ["dist/*"],
23
+ "author": "",
24
+ "license": "ISC",
25
+ "engines": {
26
+ "node": ">=12.13.0"
27
+ },
28
+ "bugs": {
29
+ "url": "https://gitlab.com/dyo-system/dyo-tools/issues"
30
+ },
31
+ "homepage": "https://gitlab.com/dyo-system/dyo-tools#readme",
23
32
  "devDependencies": {
24
- "@babel/preset-env": "^7.14.7",
25
- "@types/jest": "^27.4.0",
26
- "@types/uuid": "^8.3.3",
27
- "@typescript-eslint/eslint-plugin": "^5.9.0",
28
- "@typescript-eslint/parser": "^5.9.0",
29
- "c8": "^7.11.0",
30
- "eslint": "^8.6.0",
33
+ "@babel/preset-env": "^7.22.5",
34
+ "@types/jest": "^27.5.2",
35
+ "@types/uuid": "^9.0.2",
36
+ "@typescript-eslint/eslint-plugin": "^5.59.11",
37
+ "@typescript-eslint/parser": "^5.59.11",
38
+ "c8": "^8.0.0",
39
+ "eslint": "^8.42.0",
31
40
  "eslint-config-airbnb-base": "^15.0.0",
32
- "eslint-config-airbnb-typescript": "^16.1.0",
33
- "eslint-plugin-import": "^2.25.4",
34
- "jest": "^27.0.6",
35
- "ts-jest": "^27.1.3",
36
- "typedoc": "^0.22.10",
37
- "typescript": "^4.2.4"
41
+ "eslint-config-airbnb-typescript": "^17.0.0",
42
+ "eslint-plugin-import": "^2.27.5",
43
+ "jest": "^27.5.1",
44
+ "ts-jest": "^27.1.5",
45
+ "typedoc": "^0.24.8",
46
+ "typescript": "4.8.4"
38
47
  },
39
48
  "dependencies": {
40
- "uuid": "^8.3.2"
49
+ "@cucumber/cucumber": "^9.1.2",
50
+ "uuid": "^9.0.0"
41
51
  }
42
52
  }
@@ -0,0 +1,85 @@
1
+ import {
2
+ DTAcceptedMetaData,
3
+ DTBunchOptions,
4
+ DTManagerOptions,
5
+ DYOFinderConfiguration,
6
+ FilterOperatorType,
7
+ StandardPrimitiveType,
8
+ } from './types';
9
+ import {
10
+ DTBunch, DTComponentPhysical, DTElement, DTManager,
11
+ } from './index';
12
+
13
+ /* ********************** CORE CONSTANTS ********************** */
14
+ /** DTBunch constants * */
15
+ export const bunchDefaultOptions: DTBunchOptions = {
16
+ errors: false,
17
+ uniqueKey: false,
18
+ inheritOwner: false,
19
+ replaceIndex: false,
20
+ virtualContext: false,
21
+ };
22
+
23
+ /** DTManager constants * */
24
+ export const managerDefaultOptions: DTManagerOptions = {
25
+ errors: false,
26
+ libraryDeletion: false,
27
+ };
28
+
29
+ /** DYOFinder configuration constants * */
30
+ const baseOperators = [
31
+ FilterOperatorType.EQ,
32
+ FilterOperatorType.IN,
33
+ FilterOperatorType.NIN,
34
+ FilterOperatorType.NE,
35
+ ];
36
+ const advancedOperators = [
37
+ ...baseOperators,
38
+ FilterOperatorType.GTE,
39
+ FilterOperatorType.LTE,
40
+ FilterOperatorType.CONTAINS,
41
+ FilterOperatorType.NCONTAINS,
42
+ ];
43
+
44
+ export const componentPhysicalDefaultFinderConfiguration: DYOFinderConfiguration = {
45
+ id: {
46
+ operators: baseOperators,
47
+ getValue: (item: DTComponentPhysical<DTAcceptedMetaData>) => item.getId(),
48
+ objectSearch: false,
49
+ },
50
+ key: {
51
+ operators: baseOperators,
52
+ getValue: (item: DTComponentPhysical<DTAcceptedMetaData>) => item.getKey(),
53
+ objectSearch: false,
54
+ },
55
+ owner: {
56
+ operators: baseOperators,
57
+ getValue: (item: DTComponentPhysical<DTAcceptedMetaData>) => (item.getOwner() ? item.getOwner().getId() : null),
58
+ objectSearch: false,
59
+ },
60
+ meta: {
61
+ operators: advancedOperators,
62
+ getValue: (item: DTComponentPhysical<DTAcceptedMetaData>) => item.getManyMeta(),
63
+ objectSearch: true,
64
+ },
65
+ };
66
+
67
+ export const componentManagerDefaultFinderConfiguration: DYOFinderConfiguration = {
68
+ ...componentPhysicalDefaultFinderConfiguration,
69
+ scope: {
70
+ operators: baseOperators,
71
+ getValue(item: DTBunch<DTElement<DTAcceptedMetaData>>, ctx: DTManager<DTElement<DTAcceptedMetaData>>): StandardPrimitiveType {
72
+ return ctx.getScope(item.getId());
73
+ },
74
+ objectSearch: false,
75
+ },
76
+ };
77
+
78
+ export const componentBunchDefaultFinderConfiguration: DYOFinderConfiguration = {
79
+ ...componentPhysicalDefaultFinderConfiguration,
80
+ context: {
81
+ operators: baseOperators,
82
+ getValue: (item: DTComponentPhysical<DTAcceptedMetaData>) => (item.getContext() ? item.getContext().getId() : null),
83
+ objectSearch: false,
84
+ },
85
+ };