trucoshi 0.3.3 → 0.3.5

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 (43) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +60 -60
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +18 -18
  5. package/dist/lib/classes/Deck.d.ts +17 -17
  6. package/dist/lib/classes/Deck.js +41 -41
  7. package/dist/lib/classes/Envido.d.ts +34 -0
  8. package/dist/lib/classes/Envido.js +168 -0
  9. package/dist/lib/classes/Flor.d.ts +0 -0
  10. package/dist/lib/classes/Flor.js +1 -0
  11. package/dist/lib/classes/GameLoop.d.ts +26 -23
  12. package/dist/lib/classes/GameLoop.js +106 -78
  13. package/dist/lib/classes/Hand.d.ts +43 -39
  14. package/dist/lib/classes/Hand.js +295 -197
  15. package/dist/lib/classes/Lobby.d.ts +27 -27
  16. package/dist/lib/classes/Lobby.js +113 -113
  17. package/dist/lib/classes/Match.d.ts +21 -20
  18. package/dist/lib/classes/Match.js +88 -87
  19. package/dist/lib/classes/Play.d.ts +22 -21
  20. package/dist/lib/classes/Play.js +44 -29
  21. package/dist/lib/classes/Player.d.ts +35 -30
  22. package/dist/lib/classes/Player.js +126 -74
  23. package/dist/lib/classes/Round.d.ts +17 -17
  24. package/dist/lib/classes/Round.js +33 -33
  25. package/dist/lib/classes/Table.d.ts +12 -12
  26. package/dist/lib/classes/Table.js +38 -30
  27. package/dist/lib/classes/Team.d.ts +20 -20
  28. package/dist/lib/classes/Team.js +59 -59
  29. package/dist/lib/classes/Truco.d.ts +30 -21
  30. package/dist/lib/classes/Truco.js +97 -131
  31. package/dist/lib/classes/index.d.ts +11 -11
  32. package/dist/lib/classes/index.js +27 -27
  33. package/dist/lib/constants.d.ts +43 -45
  34. package/dist/lib/constants.js +46 -84
  35. package/dist/lib/index.d.ts +2 -2
  36. package/dist/lib/index.js +18 -18
  37. package/dist/lib/types.d.ts +44 -36
  38. package/dist/lib/types.js +21 -18
  39. package/dist/lib/utils.d.ts +5 -5
  40. package/dist/lib/utils.js +58 -58
  41. package/dist/types.d.ts +193 -182
  42. package/dist/types.js +123 -106
  43. package/package.json +1 -1
@@ -1,78 +1,106 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GameLoop = void 0;
13
- const types_1 = require("../../types");
14
- const GameLoop = (match) => {
15
- let gameloop = {
16
- _onTruco: () => Promise.resolve(),
17
- _onTurn: () => Promise.resolve(),
18
- _onWinner: () => Promise.resolve(),
19
- teams: [],
20
- winner: null,
21
- currentPlayer: null,
22
- currentHand: null,
23
- lastCheckedHand: null,
24
- onTruco: (callback) => {
25
- gameloop._onTruco = callback;
26
- return gameloop;
27
- },
28
- onTurn: (callback) => {
29
- gameloop._onTurn = callback;
30
- return gameloop;
31
- },
32
- onWinner: (callback) => {
33
- gameloop._onWinner = callback;
34
- return gameloop;
35
- },
36
- begin() {
37
- var _a;
38
- return __awaiter(this, void 0, void 0, function* () {
39
- gameloop.teams = match.teams;
40
- while (!match.winner) {
41
- const play = match.play();
42
- gameloop.currentHand = match.currentHand;
43
- if (!play || !play.player) {
44
- continue;
45
- }
46
- gameloop.currentPlayer = play.player;
47
- if (play.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
48
- try {
49
- yield gameloop._onTruco(play);
50
- }
51
- catch (e) {
52
- console.error("GAME LOOP ERROR", e);
53
- }
54
- continue;
55
- }
56
- if (play.state === types_1.EHandState.WAITING_PLAY) {
57
- play.player.setTurn(true);
58
- try {
59
- const newHandJustStarted = gameloop.lastCheckedHand !== ((_a = play.prevHand) === null || _a === void 0 ? void 0 : _a.idx);
60
- gameloop.lastCheckedHand = play.prevHand ? play.prevHand.idx : null;
61
- yield gameloop._onTurn(play, newHandJustStarted);
62
- }
63
- catch (e) {
64
- console.error("GAME LOOP ERROR", e);
65
- }
66
- play.player.setTurn(false);
67
- continue;
68
- }
69
- }
70
- gameloop.winner = match.winner;
71
- gameloop.currentPlayer = null;
72
- yield gameloop._onWinner(match.winner, match.teams);
73
- });
74
- },
75
- };
76
- return gameloop;
77
- };
78
- exports.GameLoop = GameLoop;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GameLoop = void 0;
13
+ const types_1 = require("../../types");
14
+ const GameLoop = (match) => {
15
+ let gameloop = {
16
+ _onEnvido: () => Promise.resolve(),
17
+ _onTruco: () => Promise.resolve(),
18
+ _onTurn: () => Promise.resolve(),
19
+ _onWinner: () => Promise.resolve(),
20
+ teams: [],
21
+ winner: null,
22
+ currentPlayer: null,
23
+ currentHand: null,
24
+ lastCheckedHand: null,
25
+ onTruco: (callback) => {
26
+ gameloop._onTruco = callback;
27
+ return gameloop;
28
+ },
29
+ onTurn: (callback) => {
30
+ gameloop._onTurn = callback;
31
+ return gameloop;
32
+ },
33
+ onWinner: (callback) => {
34
+ gameloop._onWinner = callback;
35
+ return gameloop;
36
+ },
37
+ onEnvido: (callback) => {
38
+ gameloop._onEnvido = callback;
39
+ return gameloop;
40
+ },
41
+ begin() {
42
+ var _a, _b;
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ gameloop.teams = match.teams;
45
+ while (!match.winner) {
46
+ const play = match.play();
47
+ gameloop.currentHand = match.currentHand;
48
+ if (!play || !play.player) {
49
+ continue;
50
+ }
51
+ gameloop.currentPlayer = play.player;
52
+ if (play.state === types_1.EHandState.WAITING_ENVIDO_ANSWER) {
53
+ try {
54
+ play.player.setTurn(true);
55
+ yield gameloop._onEnvido(play, false);
56
+ play.player.setTurn(false);
57
+ }
58
+ catch (e) {
59
+ console.error("GAME LOOP ERROR - WAITING ENVIDO ANSWER", e);
60
+ }
61
+ continue;
62
+ }
63
+ if (play.state === types_1.EHandState.WAITING_ENVIDO_POINTS_ANSWER) {
64
+ try {
65
+ play.player.setEnvidoTurn(true);
66
+ yield gameloop._onEnvido(play, true);
67
+ play.player.setEnvidoTurn(false);
68
+ }
69
+ catch (e) {
70
+ console.error("GAME LOOP ERROR - WAITING ENVIDO POINTS ANSWER", e);
71
+ }
72
+ continue;
73
+ }
74
+ if (play.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
75
+ try {
76
+ yield gameloop._onTruco(play);
77
+ }
78
+ catch (e) {
79
+ console.error("GAME LOOP ERROR - WAITING TRUCO ANSWER", e);
80
+ }
81
+ continue;
82
+ }
83
+ if (play.state === types_1.EHandState.WAITING_PLAY) {
84
+ try {
85
+ play.player.setTurn(true);
86
+ const newHandJustStarted = gameloop.lastCheckedHand !== ((_a = play.prevHand) === null || _a === void 0 ? void 0 : _a.idx) &&
87
+ ((_b = gameloop.currentHand) === null || _b === void 0 ? void 0 : _b.rounds[0].cards.length) === 0;
88
+ gameloop.lastCheckedHand = play.prevHand ? play.prevHand.idx : null;
89
+ yield gameloop._onTurn(play, newHandJustStarted);
90
+ play.player.setTurn(false);
91
+ }
92
+ catch (e) {
93
+ console.error("GAME LOOP ERROR - WAITING PLAY", e);
94
+ }
95
+ continue;
96
+ }
97
+ }
98
+ gameloop.winner = match.winner;
99
+ gameloop.currentPlayer = null;
100
+ yield gameloop._onWinner(match.winner, match.teams);
101
+ });
102
+ },
103
+ };
104
+ return gameloop;
105
+ };
106
+ exports.GameLoop = GameLoop;
@@ -1,39 +1,43 @@
1
- import { EHandState, EnvidoState, IHandCommands } from "../../types";
2
- import { ICard, IDeck } from "./Deck";
3
- import { IMatch } from "./Match";
4
- import { IPlayInstance } from "./Play";
5
- import { IPlayer } from "./Player";
6
- import { IRound } from "./Round";
7
- import { ITruco } from "./Truco";
8
- export interface IHandPoints {
9
- 0: number;
10
- 1: number;
11
- }
12
- export interface IHand {
13
- idx: number;
14
- state: EHandState;
15
- turn: number;
16
- started: boolean;
17
- points: IHandPoints;
18
- truco: ITruco;
19
- envido: EnvidoState;
20
- rounds: Array<IRound>;
21
- _currentPlayer: IPlayer | null;
22
- get currentPlayer(): IPlayer | null;
23
- set currentPlayer(player: IPlayer | null);
24
- currentRound: IRound | null;
25
- commands: IHandCommands;
26
- finished: () => boolean;
27
- play(prevHand: IHand | null): IPlayInstance | null;
28
- nextTurn(): void;
29
- use(idx: number, card: ICard): ICard | null;
30
- pushRound(round: IRound): IRound;
31
- setTurn(turn: number): IPlayer;
32
- addPoints(team: 0 | 1, points: number): void;
33
- disablePlayer(player: IPlayer): void;
34
- setCurrentRound(round: IRound | null): IRound | null;
35
- setCurrentPlayer(player: IPlayer | null): IPlayer | null;
36
- setState(state: EHandState): EHandState;
37
- getNextPlayer(): IteratorResult<IHand, IHand | void>;
38
- }
39
- export declare function Hand(match: IMatch, deck: IDeck, idx: number): IHand;
1
+ import { EHandState, IHandCommands } from "../../types";
2
+ import { ICard, IDeck } from "./Deck";
3
+ import { IEnvido } from "./Envido";
4
+ import { IMatch } from "./Match";
5
+ import { IPlayInstance } from "./Play";
6
+ import { IPlayer } from "./Player";
7
+ import { IRound } from "./Round";
8
+ import { ITruco } from "./Truco";
9
+ export interface IHandPoints {
10
+ 0: number;
11
+ 1: number;
12
+ }
13
+ export interface IHand {
14
+ idx: number;
15
+ state: EHandState;
16
+ turn: number;
17
+ started: boolean;
18
+ points: IHandPoints;
19
+ truco: ITruco;
20
+ envido: IEnvido;
21
+ rounds: Array<IRound>;
22
+ _currentPlayer: IPlayer | null;
23
+ get currentPlayer(): IPlayer | null;
24
+ set currentPlayer(player: IPlayer | null);
25
+ currentRound: IRound | null;
26
+ say: IHandCommands;
27
+ finished: () => boolean;
28
+ setTurnCommands(): void;
29
+ play(prevHand: IHand | null): IPlayInstance | null;
30
+ nextTurn(): void;
31
+ endEnvido(): void;
32
+ sayEnvidoPoints(player: IPlayer, points: number): IEnvido;
33
+ use(idx: number, card: ICard): ICard | null;
34
+ pushRound(round: IRound): IRound;
35
+ setTurn(turn: number): IPlayer;
36
+ addPoints(team: 0 | 1, points: number): void;
37
+ disablePlayer(player: IPlayer): void;
38
+ setCurrentRound(round: IRound | null): IRound | null;
39
+ setCurrentPlayer(player: IPlayer | null): IPlayer | null;
40
+ setState(state: EHandState): EHandState;
41
+ getNextPlayer(): IteratorResult<IHand, IHand | void>;
42
+ }
43
+ export declare function Hand(match: IMatch, deck: IDeck, idx: number): IHand;