trucoshi 0.0.19 → 0.0.21
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/lib/classes/Hand.js +4 -4
- package/dist/lib/classes/Play.js +2 -2
- package/dist/lib/classes/Player.js +19 -5
- package/dist/lib/classes/Team.js +16 -0
- package/dist/lib/types.d.ts +12 -10
- package/dist/server/classes/MatchTable.d.ts +3 -2
- package/dist/server/classes/MatchTable.js +13 -20
- package/dist/server/index.js +50 -28
- package/dist/server/types.d.ts +3 -1
- package/dist/test/autoplay.js +1 -1
- package/dist/test/play.js +6 -5
- package/package.json +1 -1
package/dist/lib/classes/Hand.js
CHANGED
|
@@ -172,16 +172,16 @@ function Hand(match, deck, idx) {
|
|
|
172
172
|
play: function () {
|
|
173
173
|
return (0, Play_1.PlayInstance)(hand, match.teams);
|
|
174
174
|
},
|
|
175
|
-
use: function (idx) {
|
|
175
|
+
use: function (idx, card) {
|
|
176
176
|
var player = hand.currentPlayer;
|
|
177
177
|
var round = hand.currentRound;
|
|
178
178
|
if (!player || !round) {
|
|
179
179
|
return null;
|
|
180
180
|
}
|
|
181
|
-
var
|
|
182
|
-
if (
|
|
181
|
+
var playerCard = player.useCard(idx, card);
|
|
182
|
+
if (playerCard) {
|
|
183
183
|
hand.nextTurn();
|
|
184
|
-
return round.use((0, Deck_1.PlayedCard)(player,
|
|
184
|
+
return round.use((0, Deck_1.PlayedCard)(player, playerCard));
|
|
185
185
|
}
|
|
186
186
|
return null;
|
|
187
187
|
},
|
package/dist/lib/classes/Play.js
CHANGED
|
@@ -14,8 +14,8 @@ function PlayInstance(hand, teams) {
|
|
|
14
14
|
player: hand.currentPlayer,
|
|
15
15
|
commands: [],
|
|
16
16
|
rounds: hand.rounds,
|
|
17
|
-
use: function (idx) {
|
|
18
|
-
return hand.use(idx);
|
|
17
|
+
use: function (idx, card) {
|
|
18
|
+
return hand.use(idx, card);
|
|
19
19
|
},
|
|
20
20
|
say: function (command) {
|
|
21
21
|
var _a;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
14
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
15
|
if (ar || !(i in from)) {
|
|
@@ -21,6 +32,9 @@ function Player(id, teamIdx) {
|
|
|
21
32
|
prevHand: [],
|
|
22
33
|
disabled: false,
|
|
23
34
|
ready: false,
|
|
35
|
+
getPublicPlayer: function () {
|
|
36
|
+
return __assign(__assign({}, player), { hand: player.hand.map(function () { return "xx"; }), session: undefined });
|
|
37
|
+
},
|
|
24
38
|
setSession: function (session) {
|
|
25
39
|
player.session = session;
|
|
26
40
|
},
|
|
@@ -39,11 +53,11 @@ function Player(id, teamIdx) {
|
|
|
39
53
|
player.usedHand = [];
|
|
40
54
|
return hand;
|
|
41
55
|
},
|
|
42
|
-
useCard: function (idx) {
|
|
43
|
-
if (player.hand[idx]) {
|
|
44
|
-
var
|
|
45
|
-
player.usedHand.push(
|
|
46
|
-
return
|
|
56
|
+
useCard: function (idx, card) {
|
|
57
|
+
if (player.hand[idx] && player.hand[idx] === card) {
|
|
58
|
+
var card_1 = player.hand.splice(idx, 1)[0];
|
|
59
|
+
player.usedHand.push(card_1);
|
|
60
|
+
return card_1;
|
|
47
61
|
}
|
|
48
62
|
return null;
|
|
49
63
|
},
|
package/dist/lib/classes/Team.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.Team = void 0;
|
|
4
15
|
function Team(players) {
|
|
@@ -12,6 +23,11 @@ function Team(players) {
|
|
|
12
23
|
malas: 0,
|
|
13
24
|
winner: false,
|
|
14
25
|
},
|
|
26
|
+
getPublicTeam: function (playerSession) {
|
|
27
|
+
return __assign(__assign({}, team), { players: team.players.map(function (player) {
|
|
28
|
+
return player.session === playerSession ? player : player.getPublicPlayer();
|
|
29
|
+
}) });
|
|
30
|
+
},
|
|
15
31
|
isTeamDisabled: function () {
|
|
16
32
|
return team.players.reduce(function (prev, curr) { return prev && curr.disabled; }, true);
|
|
17
33
|
},
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -23,20 +23,22 @@ export interface IPlayer {
|
|
|
23
23
|
prevHand: Array<ICard>;
|
|
24
24
|
disabled: boolean;
|
|
25
25
|
ready: boolean;
|
|
26
|
+
getPublicPlayer(): IPlayer;
|
|
26
27
|
setSession(session: string): void;
|
|
27
28
|
enable(): void;
|
|
28
29
|
disable(): void;
|
|
29
30
|
setReady(ready: boolean): void;
|
|
30
31
|
setHand(hand: Array<ICard>): Array<ICard>;
|
|
31
|
-
useCard(idx: number): ICard | null;
|
|
32
|
+
useCard(idx: number, card: ICard): ICard | null;
|
|
32
33
|
}
|
|
33
34
|
export interface ITeam {
|
|
34
35
|
_players: Map<string, IPlayer>;
|
|
35
36
|
players: Array<IPlayer>;
|
|
36
|
-
points:
|
|
37
|
+
points: ITeamPoints;
|
|
38
|
+
getPublicTeam(playerSession?: string): ITeam;
|
|
37
39
|
isTeamDisabled(): boolean;
|
|
38
40
|
disable(player: IPlayer): boolean;
|
|
39
|
-
addPoints(matchPoint: number, points: number):
|
|
41
|
+
addPoints(matchPoint: number, points: number): ITeamPoints;
|
|
40
42
|
}
|
|
41
43
|
export interface IMatch {
|
|
42
44
|
teams: [ITeam, ITeam];
|
|
@@ -45,22 +47,22 @@ export interface IMatch {
|
|
|
45
47
|
currentHand: IHand | null;
|
|
46
48
|
table: ITable;
|
|
47
49
|
play(): IPlayInstance | null;
|
|
48
|
-
addPoints(points:
|
|
50
|
+
addPoints(points: IHandPoints): [ITeam, ITeam];
|
|
49
51
|
pushHand(hand: IHand): void;
|
|
50
52
|
setCurrentHand(hand: IHand | null): IHand | null;
|
|
51
53
|
setWinner(winner: ITeam): void;
|
|
52
54
|
getNextTurn(): IteratorResult<IMatch | null, IMatch | null | void>;
|
|
53
55
|
}
|
|
54
|
-
export interface
|
|
56
|
+
export interface ITeamPoints {
|
|
55
57
|
buenas: number;
|
|
56
58
|
malas: number;
|
|
57
59
|
winner: boolean;
|
|
58
60
|
}
|
|
59
|
-
export interface
|
|
61
|
+
export interface IHandPoints {
|
|
60
62
|
0: number;
|
|
61
63
|
1: number;
|
|
62
64
|
}
|
|
63
|
-
export interface
|
|
65
|
+
export interface IRoundPoints {
|
|
64
66
|
0: number;
|
|
65
67
|
1: number;
|
|
66
68
|
ties: number;
|
|
@@ -111,7 +113,7 @@ export interface IPlayInstance {
|
|
|
111
113
|
player: IPlayer | null;
|
|
112
114
|
commands: Array<ECommand> | null;
|
|
113
115
|
rounds: Array<IRound> | null;
|
|
114
|
-
use(idx: number): ICard | null;
|
|
116
|
+
use(idx: number, card: ICard): ICard | null;
|
|
115
117
|
say(command: ECommand): ECommand | null;
|
|
116
118
|
}
|
|
117
119
|
export declare enum EHandState {
|
|
@@ -127,7 +129,7 @@ export interface IHand {
|
|
|
127
129
|
idx: number;
|
|
128
130
|
state: EHandState;
|
|
129
131
|
turn: number;
|
|
130
|
-
points:
|
|
132
|
+
points: IHandPoints;
|
|
131
133
|
truco: ITruco;
|
|
132
134
|
envido: EnvidoState;
|
|
133
135
|
rounds: Array<IRound>;
|
|
@@ -139,7 +141,7 @@ export interface IHand {
|
|
|
139
141
|
finished: () => boolean;
|
|
140
142
|
play(): IPlayInstance | null;
|
|
141
143
|
nextTurn(): void;
|
|
142
|
-
use(idx: number): ICard | null;
|
|
144
|
+
use(idx: number, card: ICard): ICard | null;
|
|
143
145
|
pushRound(round: IRound): IRound;
|
|
144
146
|
setTurn(turn: number): IPlayer;
|
|
145
147
|
addPoints(team: 0 | 1, points: number): void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { IPublicPlayer } from "../../lib/classes/Player";
|
|
2
2
|
import { IPublicTeam } from "../../lib/classes/Team";
|
|
3
|
-
import { ILobby, IPlayedCard, ITeam } from "../../lib/types";
|
|
3
|
+
import { IHandPoints, ILobby, IPlayedCard, ITeam } from "../../lib/types";
|
|
4
4
|
export interface IPublicMatch {
|
|
5
|
+
state: EMatchTableState;
|
|
5
6
|
winner: ITeam | null;
|
|
6
7
|
matchSessionId: string;
|
|
7
8
|
teams: Array<IPublicTeam>;
|
|
@@ -9,7 +10,7 @@ export interface IPublicMatch {
|
|
|
9
10
|
me: IPublicPlayer;
|
|
10
11
|
rounds: IPlayedCard[][];
|
|
11
12
|
prevRounds: IPlayedCard[][] | null;
|
|
12
|
-
|
|
13
|
+
prevHandPoints?: IHandPoints | null;
|
|
13
14
|
}
|
|
14
15
|
export interface IMatchTable {
|
|
15
16
|
matchSessionId: string;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.MatchTable = exports.EMatchTableState = void 0;
|
|
15
4
|
var lib_1 = require("../../lib");
|
|
@@ -48,34 +37,38 @@ function MatchTable(matchSessionId, teamSize) {
|
|
|
48
37
|
return search || null;
|
|
49
38
|
},
|
|
50
39
|
getPublicMatch: function (userSession) {
|
|
51
|
-
var _a, _b, _c, _d, _e, _f;
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
52
41
|
var lobby = matchTable.lobby;
|
|
53
42
|
var winner = ((_a = lobby.gameLoop) === null || _a === void 0 ? void 0 : _a.winner) || null;
|
|
54
43
|
var lastHandIdx = (((_b = lobby.gameLoop) === null || _b === void 0 ? void 0 : _b.hands.length) || 1) - 1;
|
|
55
44
|
var rounds = ((_d = (_c = lobby.gameLoop) === null || _c === void 0 ? void 0 : _c.hands[lastHandIdx]) === null || _d === void 0 ? void 0 : _d.rounds.map(function (round) { return round.cards; })) || [];
|
|
56
45
|
var prevHandIdx = lastHandIdx - 1;
|
|
57
|
-
var
|
|
58
|
-
|
|
46
|
+
var hasPrevHand = prevHandIdx !== -1;
|
|
47
|
+
var newHandNotStarted = ((_e = rounds[0]) === null || _e === void 0 ? void 0 : _e.length) === 0;
|
|
48
|
+
var prevRounds = hasPrevHand && newHandNotStarted
|
|
49
|
+
? (_g = (_f = lobby.gameLoop) === null || _f === void 0 ? void 0 : _f.hands[prevHandIdx]) === null || _g === void 0 ? void 0 : _g.rounds.map(function (round) { return round.cards; })
|
|
59
50
|
: null;
|
|
51
|
+
var prevHandPoints = prevRounds && ((_j = (_h = lobby.gameLoop) === null || _h === void 0 ? void 0 : _h.hands[prevHandIdx]) === null || _j === void 0 ? void 0 : _j.points);
|
|
60
52
|
var players = lobby.players.filter(function (player) { return Boolean(player); });
|
|
61
53
|
var currentPlayerIdx = players.findIndex(function (player) { return player && player.session === userSession; });
|
|
62
54
|
var me = players[currentPlayerIdx];
|
|
63
55
|
var cut = players.slice(currentPlayerIdx, players.length);
|
|
64
56
|
var end = players.slice(0, currentPlayerIdx);
|
|
65
|
-
var publicPlayers = cut
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
57
|
+
var publicPlayers = cut
|
|
58
|
+
.concat(end)
|
|
59
|
+
.map(function (player) { return ((player === null || player === void 0 ? void 0 : player.session) === userSession ? player : player.getPublicPlayer()); });
|
|
60
|
+
var teams = ((_k = lobby.gameLoop) === null || _k === void 0 ? void 0 : _k.teams) || lobby.teams;
|
|
61
|
+
var publicTeams = teams.map(function (team) { return team.getPublicTeam(userSession); });
|
|
70
62
|
return {
|
|
71
63
|
me: me,
|
|
72
64
|
winner: winner,
|
|
73
65
|
matchSessionId: matchTable.matchSessionId,
|
|
74
66
|
state: matchTable.state(),
|
|
75
|
-
teams:
|
|
67
|
+
teams: publicTeams,
|
|
76
68
|
players: publicPlayers,
|
|
77
69
|
rounds: rounds || [[]],
|
|
78
70
|
prevRounds: prevRounds || null,
|
|
71
|
+
prevHandPoints: prevHandPoints,
|
|
79
72
|
};
|
|
80
73
|
},
|
|
81
74
|
};
|
package/dist/server/index.js
CHANGED
|
@@ -82,6 +82,15 @@ var getTable = function (matchSessionId) {
|
|
|
82
82
|
io.on("connection", function (_socket) {
|
|
83
83
|
var socket = _socket;
|
|
84
84
|
console.log("New socket", socket.id);
|
|
85
|
+
socket.on("disconnect", function (_reason) {
|
|
86
|
+
try {
|
|
87
|
+
var user = getUser(socket.session);
|
|
88
|
+
user.matchSocketIds.forEach(function (sockets) { return sockets.delete(socket.id); });
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
console.error(e);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
85
94
|
var getTableSockets = function (table, callback) {
|
|
86
95
|
return new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
|
|
87
96
|
var sockets, _i, sockets_1, playerSocket;
|
|
@@ -158,43 +167,43 @@ io.on("connection", function (_socket) {
|
|
|
158
167
|
callback({ success: false, error: new Error("Can't create match without an ID") });
|
|
159
168
|
});
|
|
160
169
|
var sendWaitingForPlay = function (table, play) { return __awaiter(void 0, void 0, void 0, function () {
|
|
170
|
+
var player, sock;
|
|
161
171
|
return __generator(this, function (_a) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
172
|
+
player = null;
|
|
173
|
+
sock = null;
|
|
174
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
175
|
+
return getTableSockets(table, function (playerSocket) { return __awaiter(void 0, void 0, void 0, function () {
|
|
176
|
+
var _a;
|
|
177
|
+
return __generator(this, function (_b) {
|
|
166
178
|
if (playerSocket.session && playerSocket.session === ((_a = play.player) === null || _a === void 0 ? void 0 : _a.session)) {
|
|
179
|
+
sock = playerSocket.id;
|
|
180
|
+
player = play.player;
|
|
167
181
|
playerSocket.emit(types_1.EServerEvent.WAITING_PLAY, table.getPublicMatch(playerSocket.session), function (data) {
|
|
168
182
|
if (!data) {
|
|
169
|
-
return;
|
|
183
|
+
return reject(new Error("Callback returned empty"));
|
|
170
184
|
}
|
|
171
|
-
var cardIdx = data.cardIdx, command = data.command;
|
|
172
|
-
if (cardIdx !== undefined) {
|
|
173
|
-
var playedCard = play.use(cardIdx);
|
|
185
|
+
var cardIdx = data.cardIdx, card = data.card, command = data.command;
|
|
186
|
+
if (cardIdx !== undefined && card) {
|
|
187
|
+
var playedCard = play.use(cardIdx, card);
|
|
174
188
|
if (playedCard) {
|
|
175
189
|
return resolve();
|
|
176
190
|
}
|
|
177
|
-
return
|
|
191
|
+
return reject(new Error("Invalid Card"));
|
|
178
192
|
}
|
|
179
193
|
if (command) {
|
|
180
194
|
var saidCommand = play.say(command);
|
|
181
195
|
if (saidCommand) {
|
|
182
196
|
return resolve();
|
|
183
197
|
}
|
|
184
|
-
return
|
|
198
|
+
return reject(new Error("Invalid Command"));
|
|
185
199
|
}
|
|
186
|
-
return
|
|
200
|
+
return reject(new Error("Invalid Callback response"));
|
|
187
201
|
});
|
|
188
202
|
}
|
|
189
|
-
|
|
190
|
-
resolve();
|
|
191
|
-
}
|
|
203
|
+
return [2 /*return*/];
|
|
192
204
|
});
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
_a.sent();
|
|
196
|
-
return [2 /*return*/];
|
|
197
|
-
}
|
|
205
|
+
}); });
|
|
206
|
+
})];
|
|
198
207
|
});
|
|
199
208
|
}); };
|
|
200
209
|
var startMatch = function (tableId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -207,7 +216,7 @@ io.on("connection", function (_socket) {
|
|
|
207
216
|
.startMatch()
|
|
208
217
|
.onTurn(function (play) {
|
|
209
218
|
return new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
|
|
210
|
-
var session, user, e_1;
|
|
219
|
+
var session, user, e_1, e_2;
|
|
211
220
|
var _a;
|
|
212
221
|
return __generator(this, function (_b) {
|
|
213
222
|
switch (_b.label) {
|
|
@@ -216,7 +225,7 @@ io.on("connection", function (_socket) {
|
|
|
216
225
|
turns.set(table_1.matchSessionId, { play: play, resolve: resolve });
|
|
217
226
|
_b.label = 1;
|
|
218
227
|
case 1:
|
|
219
|
-
_b.trys.push([1,
|
|
228
|
+
_b.trys.push([1, 7, , 8]);
|
|
220
229
|
session = (_a = play.player) === null || _a === void 0 ? void 0 : _a.session;
|
|
221
230
|
if (!session || !play) {
|
|
222
231
|
throw new Error("Unexpected Error");
|
|
@@ -228,15 +237,23 @@ io.on("connection", function (_socket) {
|
|
|
228
237
|
return [4 /*yield*/, emitMatchUpdate(table_1)];
|
|
229
238
|
case 2:
|
|
230
239
|
_b.sent();
|
|
231
|
-
|
|
240
|
+
_b.label = 3;
|
|
232
241
|
case 3:
|
|
233
|
-
_b.
|
|
234
|
-
return [
|
|
242
|
+
_b.trys.push([3, 5, , 6]);
|
|
243
|
+
return [4 /*yield*/, sendWaitingForPlay(table_1, play)];
|
|
235
244
|
case 4:
|
|
245
|
+
_b.sent();
|
|
246
|
+
return [3 /*break*/, 6];
|
|
247
|
+
case 5:
|
|
236
248
|
e_1 = _b.sent();
|
|
237
|
-
console.error(
|
|
238
|
-
return [
|
|
239
|
-
case
|
|
249
|
+
console.error(e_1);
|
|
250
|
+
return [2 /*return*/];
|
|
251
|
+
case 6: return [2 /*return*/, resolve()];
|
|
252
|
+
case 7:
|
|
253
|
+
e_2 = _b.sent();
|
|
254
|
+
console.error("ERROR", e_2);
|
|
255
|
+
return [3 /*break*/, 8];
|
|
256
|
+
case 8: return [2 /*return*/];
|
|
240
257
|
}
|
|
241
258
|
});
|
|
242
259
|
}); });
|
|
@@ -267,7 +284,12 @@ io.on("connection", function (_socket) {
|
|
|
267
284
|
}
|
|
268
285
|
});
|
|
269
286
|
var addSocketToUser = function (session, socketId, table) {
|
|
287
|
+
var _a;
|
|
270
288
|
var user = getUser(session);
|
|
289
|
+
var socketIds = (_a = user.matchSocketIds) === null || _a === void 0 ? void 0 : _a.get(table.matchSessionId);
|
|
290
|
+
if (socketIds && socketIds.has(socketId)) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
271
293
|
console.log("User got new match socket", { socketId: socketId, session: session, matchId: table.matchSessionId });
|
|
272
294
|
var currentMatchSockets = user.matchSocketIds.has(table.matchSessionId)
|
|
273
295
|
? user.matchSocketIds.get(table.matchSessionId)
|
|
@@ -331,7 +353,7 @@ io.on("connection", function (_socket) {
|
|
|
331
353
|
if (!play) {
|
|
332
354
|
throw new Error("Unexpected Error");
|
|
333
355
|
}
|
|
334
|
-
sendWaitingForPlay(currentTable, play).then(resolve);
|
|
356
|
+
sendWaitingForPlay(currentTable, play).then(resolve).catch(console.error);
|
|
335
357
|
}
|
|
336
358
|
catch (e) {
|
|
337
359
|
console.error("ERROR", e);
|
package/dist/server/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Socket } from "socket.io";
|
|
2
|
-
import { ECommand } from "../lib/types";
|
|
2
|
+
import { ECommand, ICard } from "../lib/types";
|
|
3
3
|
export declare enum EClientEvent {
|
|
4
4
|
PING = "PING",
|
|
5
5
|
PLAY = "PLAY",
|
|
@@ -25,9 +25,11 @@ export declare enum ETrucoshiMatchState {
|
|
|
25
25
|
}
|
|
26
26
|
export type IWaitingPlayData = {
|
|
27
27
|
cardIdx: number;
|
|
28
|
+
card: ICard;
|
|
28
29
|
command?: undefined;
|
|
29
30
|
} | {
|
|
30
31
|
cardIdx?: undefined;
|
|
32
|
+
card?: undefined;
|
|
31
33
|
command: ECommand;
|
|
32
34
|
};
|
|
33
35
|
export type IWaitingPlayCallback = (data: IWaitingPlayData) => void | null;
|
package/dist/test/autoplay.js
CHANGED
|
@@ -68,7 +68,7 @@ var lib_1 = require("../lib");
|
|
|
68
68
|
: "");
|
|
69
69
|
randomIdx = Math.round(Math.random() * (play.player.hand.length - 1));
|
|
70
70
|
handString = JSON.stringify(play.player.hand);
|
|
71
|
-
card = play.use(randomIdx);
|
|
71
|
+
card = play.use(randomIdx, play.player.hand[randomIdx]);
|
|
72
72
|
console.log("\n".concat(handString, "\nUsing ").concat(card));
|
|
73
73
|
console.log(play.rounds && play.rounds.length
|
|
74
74
|
? play.rounds.map(function (round) {
|
package/dist/test/play.js
CHANGED
|
@@ -113,14 +113,15 @@ var command = function (title, onLine) {
|
|
|
113
113
|
var playCommand = function (play) {
|
|
114
114
|
var _a, _b, _d;
|
|
115
115
|
return command("".concat((_a = play.player) === null || _a === void 0 ? void 0 : _a.id, " elije una carta [").concat((_b = play.player) === null || _b === void 0 ? void 0 : _b.hand.map(function (_c, i) { return i + 1; }), "]: ").concat(JSON.stringify((_d = play.player) === null || _d === void 0 ? void 0 : _d.hand), "\n"), function (idx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
116
|
-
var playedCard, handString;
|
|
117
|
-
var _a;
|
|
118
|
-
return __generator(this, function (
|
|
119
|
-
|
|
116
|
+
var card, playedCard, handString;
|
|
117
|
+
var _a, _b;
|
|
118
|
+
return __generator(this, function (_d) {
|
|
119
|
+
card = (_a = play.player) === null || _a === void 0 ? void 0 : _a.hand[Number(idx) - 1];
|
|
120
|
+
playedCard = play.use(Number(idx) - 1, card);
|
|
120
121
|
if (!playedCard) {
|
|
121
122
|
return [2 /*return*/, Promise.reject()];
|
|
122
123
|
}
|
|
123
|
-
handString = JSON.stringify((
|
|
124
|
+
handString = JSON.stringify((_b = play.player) === null || _b === void 0 ? void 0 : _b.hand);
|
|
124
125
|
console.log("\n".concat(handString, "\nUsing ").concat(playedCard));
|
|
125
126
|
console.log(play.rounds && play.rounds.length
|
|
126
127
|
? play.rounds.map(function (round) {
|