Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from MahjongPantheon/TYR-other-tables-fixes
Browse files Browse the repository at this point in the history
Fix other tables view
  • Loading branch information
Oleg Klimenko authored May 20, 2017
2 parents b54c137 + 8d4e90c commit 943a4e3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 32 deletions.
75 changes: 53 additions & 22 deletions src/app/components/screen-other-table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export class OtherTableScreen {
*/
private _dataUpdated = false;
private _updateInterval: NodeJS.Timer;
private _lastRoundLocal: RRoundPaymentsInfo;
private _showLastRound: boolean = false;
private _lastRoundTimer: NodeJS.Timer;

get lastRoundInfo() {
if (this._showLastRound) {
return this.lastRound;
}

return null;
}

self: Player;
shimocha: Player;
Expand Down Expand Up @@ -88,7 +99,11 @@ export class OtherTableScreen {
}

viewLastRound() {
this.state.updateOtherTableLastRound(this.currentGameHash);
this.state.updateOtherTableLastRound(this.currentGameHash, () => {
this._showLastRound = true;
clearTimeout(this._lastRoundTimer);
this._lastRoundTimer = setTimeout(() => this._showLastRound = false, 8000);
});
}

rotateTable(dir: boolean) {
Expand All @@ -109,16 +124,32 @@ export class OtherTableScreen {
}

ngOnChanges() {
if (
this.lastRound &&
this._lastRoundLocal &&
this._lastRoundLocal.penaltyFor !== this.lastRound.penaltyFor &&
this._lastRoundLocal.honba !== this.lastRound.honba &&
this._lastRoundLocal.round !== this.lastRound.round
) {
clearTimeout(this._lastRoundTimer);
this._showLastRound = true;
this._lastRoundTimer = setTimeout(() => this._showLastRound = false, 8000);
}

this.updatePlayers();
this._lastRoundLocal = this.lastRound;
}

ngOnInit() {
this._lastRoundTimer = null;
this._showLastRound = false;
this.updatePlayers();
this._updateInterval = setInterval(() => this._dataUpdated && this.reloadOverview(), 5000);
}

ngOnDestroy() {
clearInterval(this._updateInterval);
clearTimeout(this._lastRoundTimer);
}

private updatePlayers() {
Expand Down Expand Up @@ -158,76 +189,76 @@ export class OtherTableScreen {
/// last round related

getWins(): Array<{ winner: string, loser: string, han: number, fu: number, dora: number, yakuList: string }> {
switch (this.lastRound.outcome) {
switch (this._lastRoundLocal.outcome) {
case 'ron':
case 'tsumo':
return [{
winner: this._getPlayerName(this.lastRound.winner),
winner: this._getPlayerName(this._lastRoundLocal.winner),
loser: this._getLoserName(),
yakuList: this._getYakuList(this.lastRound.yaku),
han: this.lastRound.han,
fu: this.lastRound.fu,
dora: this.lastRound.dora
yakuList: this._getYakuList(this._lastRoundLocal.yaku),
han: this._lastRoundLocal.han,
fu: this._lastRoundLocal.fu,
dora: this._lastRoundLocal.dora
}];
case 'multiron':
let wins = [];
for (let idx in this.lastRound.winner) {
for (let idx in this._lastRoundLocal.winner) {
wins.push({
winner: this._getPlayerName(this.lastRound.winner[idx]),
winner: this._getPlayerName(this._lastRoundLocal.winner[idx]),
loser: this._getLoserName(),
yakuList: this._getYakuList(this.lastRound.yaku[idx]),
han: this.lastRound.han[idx],
fu: this.lastRound.fu[idx],
dora: this.lastRound.dora[idx]
yakuList: this._getYakuList(this._lastRoundLocal.yaku[idx]),
han: this._lastRoundLocal.han[idx],
fu: this._lastRoundLocal.fu[idx],
dora: this._lastRoundLocal.dora[idx]
});
}
return wins;
}
}

getOutcomeName() {
switch (this.lastRound.outcome) {
switch (this._lastRoundLocal.outcome) {
case 'ron': return 'Рон';
case 'tsumo': return 'Цумо';
case 'draw': return 'Ничья';
case 'abort': return 'Абортивная ничья';
case 'chombo': return 'Чомбо';
case 'multiron': return this.lastRound.winner.length === 2 ? 'Дабл-рон' : 'Трипл-рон';
case 'multiron': return this._lastRoundLocal.winner.length === 2 ? 'Дабл-рон' : 'Трипл-рон';
}
}

getPenalty() {
if (this.lastRound.outcome !== 'chombo') {
if (this._lastRoundLocal.outcome !== 'chombo') {
return;
}
return this._getPlayerName(this.lastRound.penaltyFor);
return this._getPlayerName(this._lastRoundLocal.penaltyFor);
}

getTempaiPlayers() {
if (this.lastRound.outcome !== 'draw') {
if (this._lastRoundLocal.outcome !== 'draw') {
return;
}

return Object.keys(this.lastRound.payments.direct)
return Object.keys(this._lastRoundLocal.payments.direct)
.map((i) => parseInt(i.split('<-')[0], 10))
.filter((value, index, self) => self.indexOf(value) === index)
.map((i) => this._getPlayerName(i))
.join(', ');
}

getNotenPlayers() {
if (this.lastRound.outcome !== 'draw') {
if (this._lastRoundLocal.outcome !== 'draw') {
return;
}
return Object.keys(this.lastRound.payments.direct)
return Object.keys(this._lastRoundLocal.payments.direct)
.map((i) => parseInt(i.split('<-')[1], 10))
.filter((value, index, self) => self.indexOf(value) === index)
.map((i) => this._getPlayerName(i))
.join(', ');
}

getRiichiPlayers() {
return this.lastRound.riichiIds.map(
return this._lastRoundLocal.riichiIds.map(
(p) => this._getPlayerName(parseInt(p, 10))
).join(', ');
}
Expand Down
16 changes: 8 additions & 8 deletions src/app/components/screen-other-table/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<div class="riichi-table" *ngIf="_loading">
<div class="inline-preloader"></div>
</div>
<div class="round-results-overlay" *ngIf="lastRound">&nbsp;</div>
<div class="round-results-window" *ngIf="lastRound">
<div class="round-results-overlay" *ngIf="lastRoundInfo">&nbsp;</div>
<div class="round-results-window" *ngIf="lastRoundInfo">
<h3>{{getOutcomeName()}}</h3>
<div class="table-info">
<div class="round-info">
Expand All @@ -31,28 +31,28 @@ <h3>{{getOutcomeName()}}</h3>
<div class="indicator">{{lastRound.honba}}</div>
</div>
<hr />
<div *ngIf="lastRound.outcome == 'chombo'">
<div *ngIf="lastRoundInfo.outcome == 'chombo'">
{{getPenalty()}}
</div>
<div *ngIf="lastRound.outcome == 'draw'">
<div *ngIf="lastRoundInfo.outcome == 'draw'">
Темпай: {{getTempaiPlayers()}}
<br>
Нотен: {{getNotenPlayers()}}
</div>
<!-- abortive draws have no info to output -->
<ul *ngIf="lastRound.outcome == 'ron' || lastRound.outcome == 'tsumo' || lastRound.outcome == 'multiron'" class="wins-list">
<ul *ngIf="lastRoundInfo.outcome == 'ron' || lastRoundInfo.outcome == 'tsumo' || lastRoundInfo.outcome == 'multiron'" class="wins-list">
<li *ngFor="let win of getWins()">
<b>{{win.winner}}</b>
&larr;
<span class="loser" *ngIf="lastRound.outcome == 'ron' || lastRound.outcome == 'multiron'">({{win.loser}})</span>
<span class="loser" *ngIf="lastRound.outcome == 'tsumo'">(цумо)</span>
<span class="loser" *ngIf="lastRoundInfo.outcome == 'ron' || lastRoundInfo.outcome == 'multiron'">({{win.loser}})</span>
<span class="loser" *ngIf="lastRoundInfo.outcome == 'tsumo'">(цумо)</span>
<br>
{{win.han | yakuman}} хан<span *ngIf="win.han < 5">, {{win.fu}} фу</span>
<br>
<span class="yaku-list">({{win.yakuList}}<span *ngIf="win.dora">, дора: {{win.dora | defaultsTo:'0'}}</span>)</span>
</li>
</ul>
<div *ngIf="lastRound.riichiIds.length > 0">
<div *ngIf="lastRoundInfo.riichiIds.length > 0">
Риичи: {{getRiichiPlayers()}}
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/app/primitives/appstate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ export class AppState {
}

this._currentOtherTable = table;
this._currentOtherTableLastRound = null;
this._currentOtherTablePlayers = table.players.map<Player>((p) => ({
id: p.id,
ident: p.ident,
Expand All @@ -452,9 +453,11 @@ export class AppState {
}));
});
};
updateOtherTableLastRound = (hash: string) => getLastRound(this.api, hash, (round) => {
updateOtherTableLastRound = (hash: string, onReady?: () => void) => getLastRound(this.api, hash, (round) => {
this._currentOtherTableLastRound = round;
setTimeout(() => this._currentOtherTableLastRound = null, 8000); // show info for 8 secs
if (onReady) {
onReady();
}
});
getOtherTables = () => this._otherTablesList;
getCurrentOtherTable = () => this._currentOtherTable;
Expand Down

0 comments on commit 943a4e3

Please sign in to comment.