trucoshi 0.0.20 → 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.
|
@@ -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
|
},
|
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,6 +23,7 @@ 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;
|
|
@@ -33,10 +34,11 @@ export interface IPlayer {
|
|
|
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;
|
|
@@ -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>;
|
|
@@ -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
|
};
|