@pompidup/kingdomino-engine 1.1.1 → 2.0.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/dist/index.d.ts CHANGED
@@ -1,11 +1,18 @@
1
- declare const ground: readonly ["castle", "wheat", "forest", "sea", "plain", "swamp", "mine"];
2
- type Ground = (typeof ground)[number];
1
+ type GameMode = {
2
+ name: string;
3
+ description: string;
4
+ };
5
+
6
+ declare const GROUND: readonly ["castle", "wheat", "forest", "sea", "plain", "swamp", "mine"];
7
+ type Ground = (typeof GROUND)[number];
8
+ type EmptyGround = "empty";
9
+ type Crown = number;
3
10
  type Tile = {
4
11
  type: Ground;
5
- crowns: number;
12
+ crowns: Crown;
6
13
  };
7
14
  type EmptyTile = {
8
- type: "empty";
15
+ type: EmptyGround;
9
16
  crowns: 0;
10
17
  };
11
18
  type Domino = {
@@ -23,7 +30,6 @@ type RevealsDomino = {
23
30
  type Lord = {
24
31
  id: string;
25
32
  playerId: string;
26
- order: number;
27
33
  turnEnded: boolean;
28
34
  hasPick: boolean;
29
35
  hasPlace: boolean;
@@ -38,21 +44,40 @@ type Orientation = "vertical" | "horizontal";
38
44
  type Rotation = 0 | 180;
39
45
  type Kingdom = (Tile | EmptyTile)[][];
40
46
 
47
+ type ObjectValues<T> = T[keyof T];
48
+
41
49
  type Player = {
42
50
  id: string;
43
51
  name: string;
44
52
  kingdom: Kingdom;
45
53
  };
54
+ declare const playerActions: {
55
+ readonly placeDomino: "placeDomino";
56
+ readonly pickDomino: "pickDomino";
57
+ readonly pass: "pass";
58
+ };
59
+ type PlayerActions = ObjectValues<typeof playerActions>;
46
60
 
47
- declare const availableMode: readonly ["Classic"];
48
- type AvailableMode = (typeof availableMode)[number];
49
-
50
- type Rule = {
61
+ type BasicRules = {
62
+ lords: number;
63
+ maxDominoes: number;
64
+ dominoesPerTurn: number;
65
+ maxTurns: number;
66
+ };
67
+ type ExtraRule = {
51
68
  name: string;
52
69
  description: string;
53
- mode: AvailableMode[];
70
+ mode: GameMode[];
54
71
  playersLimit?: number;
55
72
  };
73
+ type Rules = {
74
+ basic: Record<number, BasicRules>;
75
+ extraRules: ExtraRule[];
76
+ };
77
+ type SelectedRules = {
78
+ basic: BasicRules;
79
+ extra: ExtraRule[];
80
+ };
56
81
 
57
82
  type Game = {
58
83
  id: string;
@@ -61,19 +86,37 @@ type Game = {
61
86
  players: Player[];
62
87
  lords: Lord[];
63
88
  turn: number;
64
- maxTurns: number;
65
- maxDominoes: number;
66
- dominoesPerTurn: number;
67
- order: Record<number, string>;
68
- rules?: Rule[];
89
+ nextAction: NextAction | NextStep;
90
+ rules: SelectedRules;
91
+ mode: GameMode;
92
+ };
93
+ declare const gameSteps: {
94
+ readonly addPlayers: "addPlayers";
95
+ readonly options: "options";
96
+ readonly start: "start";
97
+ readonly result: "result";
98
+ };
99
+ type GameSteps = ObjectValues<typeof gameSteps>;
100
+ type NextAction = {
101
+ type: "action";
102
+ nextLord: string;
103
+ nextAction: PlayerActions;
104
+ };
105
+ type NextStep = {
106
+ type: "step";
107
+ step: GameSteps;
108
+ };
109
+ type GameWithNextAction = Game & {
110
+ nextAction: NextAction;
111
+ };
112
+ type GameWithNextStep = Game & {
113
+ nextAction: NextStep;
69
114
  };
70
-
71
115
  type Score = {
72
- score: number;
116
+ points: number;
73
117
  maxPropertiesSize: number;
74
118
  totalCrowns: number;
75
119
  };
76
-
77
120
  type ScoreResult = {
78
121
  playerId: string;
79
122
  playerName: string;
@@ -82,33 +125,102 @@ type ScoreResult = {
82
125
  type FinalResult = ScoreResult & {
83
126
  position: number;
84
127
  };
128
+ type GameWithResults = Game & {
129
+ result: FinalResult[];
130
+ };
85
131
 
86
- type Resp = {
87
- nextLord: string;
88
- nextAction: "pick" | "place" | "end";
89
- game: Game;
132
+ type GetModesCommand = Record<string, never>;
133
+
134
+ type GetExtraRulesCommand = {
135
+ mode: GameMode["name"];
136
+ players: number;
90
137
  };
91
- type GameResult = {
92
- result: FinalResult[];
93
- game: Game;
94
- };
95
- /** Todo
96
- * Add rules step
97
- *
98
- **/
99
- declare const gameEngine: () => {
100
- init: () => Game;
101
- getMode: () => readonly ["Classic"];
102
- setMode: (mode: string, game: Game) => Game;
103
- getRules: (mode: string) => never[];
104
- setRules: (rules: string[], game: Game) => Game;
105
- start: (game: Game, players: {
106
- name: string;
107
- }[]) => Resp;
108
- pass: (game: Game, lordId: string) => Resp;
109
- placeDomino: (game: Game, lordId: string, position: Position, orientation: Orientation, rotation: Rotation) => Resp;
110
- pickDomino: (game: Game, lordId: string, dominoPick: number) => Resp;
111
- endGame: (game: Game) => GameResult;
112
- };
113
-
114
- export { gameEngine as default };
138
+
139
+ type CreateGameCommand = {
140
+ mode: string;
141
+ };
142
+
143
+ type AddPlayersCommand = {
144
+ game: Game & {
145
+ nextAction: NextStep;
146
+ };
147
+ players: string[];
148
+ };
149
+
150
+ type AddExtraRulesCommand = {
151
+ game: Game & {
152
+ nextAction: NextStep;
153
+ };
154
+ extraRules: string[];
155
+ };
156
+
157
+ type StartGameCommand = {
158
+ game: Game & {
159
+ nextAction: NextStep;
160
+ };
161
+ };
162
+
163
+ type ChooseDominoCommand = {
164
+ game: GameWithNextAction;
165
+ dominoPick: number;
166
+ lordId: string;
167
+ };
168
+
169
+ type PlaceDominoCommand = {
170
+ game: GameWithNextAction;
171
+ lordId: string;
172
+ position: Position;
173
+ orientation: Orientation;
174
+ rotation: Rotation;
175
+ };
176
+
177
+ type DiscardDominoCommand = {
178
+ game: GameWithNextAction;
179
+ lordId: string;
180
+ };
181
+
182
+ type GetResultCommand = {
183
+ game: GameWithNextStep;
184
+ };
185
+
186
+ type GameEngine = {
187
+ getModes: (command: GetModesCommand) => GameMode[];
188
+ getExtraRules: (command: GetExtraRulesCommand) => ExtraRule[];
189
+ createGame: (command: CreateGameCommand) => GameWithNextStep;
190
+ addPlayers: (command: AddPlayersCommand) => GameWithNextStep;
191
+ addExtraRules: (command: AddExtraRulesCommand) => GameWithNextStep;
192
+ startGame: (command: StartGameCommand) => GameWithNextAction;
193
+ chooseDomino: (command: ChooseDominoCommand) => GameWithNextAction;
194
+ placeDomino: (command: PlaceDominoCommand) => GameWithNextAction | GameWithNextStep;
195
+ discardDomino: (command: DiscardDominoCommand) => GameWithNextAction | GameWithNextStep;
196
+ getResults: (command: GetResultCommand) => GameWithResults;
197
+ };
198
+
199
+ type DominoesRepository = {
200
+ getForMode: (mode: GameMode) => Domino[] | [];
201
+ };
202
+
203
+ type ModeRepository = {
204
+ getAvailables: () => GameMode[];
205
+ };
206
+
207
+ type RuleRepository = {
208
+ getAll: () => Rules;
209
+ getAllExtra: () => ExtraRule[];
210
+ };
211
+
212
+ type ShuffleMethod = <T>(array: T[]) => T[];
213
+
214
+ type UuidMethod = () => string;
215
+
216
+ type EngineConfig = {
217
+ modeRepository?: ModeRepository;
218
+ dominoesRepository?: DominoesRepository;
219
+ ruleRepository?: RuleRepository;
220
+ uuidMethod?: UuidMethod;
221
+ shuffleMethod?: ShuffleMethod;
222
+ };
223
+
224
+ declare const createGameEngine: (config: Partial<EngineConfig>) => GameEngine;
225
+
226
+ export { createGameEngine };