Commit e7ecbb33 authored by xiaoye's avatar xiaoye

fix

parent 0f70c3c3
Pipeline #39609 passed with stages
in 3 minutes and 6 seconds
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
v-for = '(i, v) in search.result.tournaments' v-for = '(i, v) in search.result.tournaments'
:title = 'i.name' :title = 'i.name'
:note = 'search.rule.note.get(i.rule)' :note = 'search.rule.note.get(i.rule)'
:rightText = '`${i.createdAt.toLocaleDateString()}\n${i.count}`' :rightText = '`${i.createdAt.toLocaleDateString()}`'
:clickable = true :clickable = true
@click = 'page.show.tournament(i.id)' @click = 'page.show.tournament(i.id)'
></uni-list-item> ></uni-list-item>
......
...@@ -62,6 +62,17 @@ ...@@ -62,6 +62,17 @@
:max = 'participant.array.length' :max = 'participant.array.length'
></uni-number-box> ></uni-number-box>
<uni-fav :checked = "searcher.p.chk"
:content-text = "{
contentDefault: '全部',
contentFav: '参与中'
}"
@click = 'searcher.p.btn()'
:star = 'false'
bgColor = 'white'
bgColorChecked = '#e6e6e6'
fgColorChecked = 'black'
/>
</div> </div>
<div> <div>
<view <view
...@@ -100,7 +111,7 @@ ...@@ -100,7 +111,7 @@
<view id = 'header'> <view id = 'header'>
<span>{{ i.name }}</span> <span>{{ i.name }}</span>
<br> <br>
<span class = 'small'>{{ tournament.this.status == 'Ready' ? `${v + 1}` : (i.score ? i.score.rank : '') }}</span> <span class = 'small'>{{ v + 1 }}</span>
</view> </view>
</template> </template>
<template v-slot:footer> <template v-slot:footer>
...@@ -178,7 +189,7 @@ ...@@ -178,7 +189,7 @@
:current = 'participant.page' :current = 'participant.page'
v-model = 'participant.page' v-model = 'participant.page'
pageSize = 20 pageSize = 20
:total = 'searcher.participant ? participant.array.filter(i => searcher.filterParticipant(i)).length : participant.total' :total = 'participant.array.filter(i => searcher.filterParticipant(i)).length'
> >
</uni-pagination> </uni-pagination>
</uni-card> </uni-card>
...@@ -200,6 +211,17 @@ ...@@ -200,6 +211,17 @@
:disabled = "tournament.this.status == 'Ready'" :disabled = "tournament.this.status == 'Ready'"
></uni-number-box> ></uni-number-box>
<span></span> <span></span>
<uni-fav :checked = "searcher.m.chk"
:content-text = "{
contentDefault: '全部',
contentFav: '进行中'
}"
@click = 'searcher.m.btn()'
:star = 'false'
bgColor = 'white'
bgColorChecked = '#e6e6e6'
fgColorChecked = 'black'
/>
</div> </div>
<div> <div>
<view class = 'button' @click = '() => { match.round = 0; }'>全部轮次</view> <view class = 'button' @click = '() => { match.round = 0; }'>全部轮次</view>
...@@ -475,7 +497,7 @@ ...@@ -475,7 +497,7 @@
}, },
copy : () : void => { copy : () : void => {
if (!tournament.this) return; if (!tournament.this) return;
let string = `<--- ${tournament.this.name} - [${tournament.this.rule == 'SingleElimination' ? '淘汰赛' : '瑞士轮'}]${tournament.this.ruleSettings.rounds ? `[${tournament.this.ruleSettings.rounds}轮]` : ''}[${tournament.this.count ?? 0}人] --->\n` let string = `<--- ${tournament.this.name} - [${tournament.this.rule == 'SingleElimination' ? '淘汰赛' : '瑞士轮'}]${tournament.this.ruleSettings.rounds ? `[${tournament.this.ruleSettings.rounds}轮]` : ''}[${participant.array.length}人] --->\n`
for (let round = 1; round <= match.maxRound; round ++) { for (let round = 1; round <= match.maxRound; round ++) {
if (match.round > 0 && match.round != round) continue; if (match.round > 0 && match.round != round) continue;
string += `---------------------------------------------\n第[ ${round} ]轮对决战况表\n---------------------------------------------\n` string += `---------------------------------------------\n第[ ${round} ]轮对决战况表\n---------------------------------------------\n`
...@@ -652,7 +674,7 @@ ...@@ -652,7 +674,7 @@
}, },
copy : () : void => { copy : () : void => {
if (!tournament.this) return; if (!tournament.this) return;
let string = `<--- ${tournament.this.name} - [${tournament.this.rule == 'SingleElimination' ? '淘汰赛' : '瑞士轮'}]${tournament.this.ruleSettings.rounds ? `[${tournament.this.ruleSettings.rounds}轮]` : ''}[${tournament.this.count ?? 0}人] --->\n`; let string = `<--- ${tournament.this.name} - [${tournament.this.rule == 'SingleElimination' ? '淘汰赛' : '瑞士轮'}]${tournament.this.ruleSettings.rounds ? `[${tournament.this.ruleSettings.rounds}轮]` : ''}[${participant.array.length ?? 0}人] --->\n`;
let copyValue = participant.copyValue; let copyValue = participant.copyValue;
if (copyValue == 0) copyValue = participant.array.length; if (copyValue == 0) copyValue = participant.array.length;
const map : Map<number, string> = new Map([ const map : Map<number, string> = new Map([
...@@ -728,14 +750,30 @@ ...@@ -728,14 +750,30 @@
filterMatch : (i : Match) : boolean => { filterMatch : (i : Match) : boolean => {
if ((i.round != match.round && match.round != 0) || (i.status == 'Abandoned' && !i.player1.name || !i.player2.name)) if ((i.round != match.round && match.round != 0) || (i.status == 'Abandoned' && !i.player1.name || !i.player2.name))
return false; return false;
if (searcher.m.chk && i.status != 'Running')
return false;
return searcher.match ? i.player1.name.toUpperCase().includes(searcher.match.toUpperCase()) || i.player2.name.toUpperCase().includes(searcher.match.toUpperCase()) : true; return searcher.match ? i.player1.name.toUpperCase().includes(searcher.match.toUpperCase()) || i.player2.name.toUpperCase().includes(searcher.match.toUpperCase()) : true;
}, },
filterParticipant : (i : Participant) : boolean => { filterParticipant : (i : Participant) : boolean => {
if (searcher.p.chk && i.quit)
return false;
return searcher.participant ? i.name.toUpperCase().includes(searcher.participant.toUpperCase()) : true; return searcher.participant ? i.name.toUpperCase().includes(searcher.participant.toUpperCase()) : true;
}, },
reset : () : void => { reset : () : void => {
searcher.participant = ''; searcher.participant = '';
searcher.match = ''; searcher.match = '';
},
p : {
chk : false,
btn : () : void => {
searcher.p.chk =! searcher.p.chk;
}
},
m : {
chk : false,
btn : () : void => {
searcher.m.chk =! searcher.m.chk;
}
} }
}); });
......
...@@ -19,23 +19,25 @@ class Match { ...@@ -19,23 +19,25 @@ class Match {
winnerId : number | null; winnerId : number | null;
childMatchId : number; childMatchId : number;
constructor(obj : MatchObject) { constructor(obj : MatchObject, p : Array<Participant>) {
this.id = obj.id; this.id = obj.id;
this.tournamentId = obj.tournamentId; this.tournamentId = obj.tournamentId;
this.round = obj.round; this.round = obj.round;
this.isThirdPlaceMatch = obj.isThirdPlaceMatch; this.isThirdPlaceMatch = obj.isThirdPlaceMatch;
this.status = obj.status; this.status = obj.status;
const name1 = obj.player1?.name.split(/[\+\uFF0B]/) ?? []; const name1_str = p.find(i => i.id == obj.player1Id)?.name ?? '';
const name1 = name1_str.split(/[\+\uFF0B]/) ?? [];
this.player1 = { this.player1 = {
id : obj.player1Id, id : obj.player1Id,
name : (name1.length == 2 && !Number.isNaN(name1[0]) && name1[0].length > 3) ? name1[1] : obj.player1?.name ?? '', name : (name1.length == 2 && !Number.isNaN(name1[0]) && name1[0].length > 3) ? name1[1] : name1_str,
qq : (name1.length == 2 && !Number.isNaN(name1[0]) && name1[0].length > 3) ? name1[0] : undefined, qq : (name1.length == 2 && !Number.isNaN(name1[0]) && name1[0].length > 3) ? name1[0] : undefined,
score : obj.player1Score score : obj.player1Score
}; };
const name2 = obj.player2?.name.split(/[\+\uFF0B]/) ?? []; const name2_str = p.find(i => i.id == obj.player2Id)?.name ?? '';
const name2 = name2_str?.split(/[\+\uFF0B]/) ?? [];
this.player2 = { this.player2 = {
id : obj.player2Id, id : obj.player2Id,
name : (name2.length == 2 && !Number.isNaN(name2[0]) && name2[0].length > 3) ? name2[1] : obj.player2?.name ?? '', name : (name2.length == 2 && !Number.isNaN(name2[0]) && name2[0].length > 3) ? name2[1] : name2_str,
qq : (name2.length == 2 && !Number.isNaN(name2[0]) && name2[0].length > 3) ? name2[0] : undefined, qq : (name2.length == 2 && !Number.isNaN(name2[0]) && name2[0].length > 3) ? name2[0] : undefined,
score : obj.player2Score score : obj.player2Score
}; };
......
import { Score, ParticipantObject, Deck } from './type.ts'; import { Score, ParticipantObject, Deck } from './type.ts';
import YGOProDeck from 'ygopro-deck-encode'; import YGOProDeck from 'ygopro-deck-encode';
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
import Match from './match.ts';
import Tournament from './tournament.ts';
class Participant { class Participant {
id : number; id : number;
...@@ -18,7 +20,6 @@ class Participant { ...@@ -18,7 +20,6 @@ class Participant {
this.qq = (name.length == 2 && !Number.isNaN(name[0]) && name[0].length > 3) ? name[0] : undefined; this.qq = (name.length == 2 && !Number.isNaN(name[0]) && name[0].length > 3) ? name[0] : undefined;
this.tournamentId = obj.tournamentId; this.tournamentId = obj.tournamentId;
this.id = obj.id; this.id = obj.id;
this.score = obj.score;
this.deckbuf = obj.deckbuf ?? ''; this.deckbuf = obj.deckbuf ?? '';
this.quit = obj.quit ?? false; this.quit = obj.quit ?? false;
if (obj.deckbuf) if (obj.deckbuf)
...@@ -43,6 +44,32 @@ class Participant { ...@@ -43,6 +44,32 @@ class Participant {
const data = this.deck?.toYdkString() ?? ''; const data = this.deck?.toYdkString() ?? '';
return new Blob([data], { type: 'text/plain' }); return new Blob([data], { type: 'text/plain' });
} }
getScore = (matches : Array<Match>, t : Tournament) : void => {
const m = {
win : matches.filter(i => this.id == i.winnerId).length,
draw : matches.filter(i => (this.id == i.player1.id || this.id == i.player2.id) && Number.isNaN(i.winnerId)).length,
lose : matches.filter(i => (this.id == i.player1.id || this.id == i.player2.id) && !Number.isNaN(i.winnerId) && i.winnerId != this.id).length,
bye : Math.max(...matches.filter(i => i.status == 'Finished' || i.status == 'Running').map(i => i.round)) - matches.filter(i => this.id == i.player1.id || this.id == i.player2.id).length
};
this.score = {
score : m.win * t.ruleSettings.winScore + m.draw * t.ruleSettings.drawScore + m.bye * t.ruleSettings.byeScore,
win : m.win,
draw : m.draw,
bye : m.bye,
lose : m.lose
}
}
getTieBreaker = (participants : Array<Participant>, matches : Array<Match>) : void => {
let tieBreaker = 0;
matches.filter(i => this.id == i.player1.id || this.id == i.player2.id).forEach(i => {
const id = this.id == i.player1.id ? i.player2.id : i.player1.id;
const p = participants.find(p => p.id == id )?.score.score ?? 0;
tieBreaker += p;
});
this.score.tieBreaker = tieBreaker;
}
} }
export default Participant; export default Participant;
...@@ -99,16 +99,28 @@ class TabulatorAPI { ...@@ -99,16 +99,28 @@ class TabulatorAPI {
'x-user-token' : token 'x-user-token' : token
} }
}); });
const tournament = new Tournament(response.data.data);
let participants : Array<Participant> = []; let participants : Array<Participant> = [];
let matches : Array<Match> = []; let matches : Array<Match> = [];
response.data.data.participants.forEach((i : ParticipantObject) => { response.data.data.participants.forEach((i : ParticipantObject) => {
participants.push(new Participant(i)); participants.push(new Participant(i));
}); });
response.data.data.matches.forEach((i : MatchObject) => { response.data.data.matches.forEach((i : MatchObject) => {
matches.push(new Match(i)); matches.push(new Match(i, participants));
}); });
participants.forEach(i => {
i.getScore(matches, tournament);
});
participants.forEach(i => {
i.getTieBreaker(participants, matches);
});
if (tournament.status != 'Ready') {
participants.sort((a, b) => {
return b.score.score - a.score.score
});
}
return { return {
tournament : new Tournament(response.data.data), tournament : tournament,
participant : { participant : {
participants : participants, participants : participants,
total : participants.length total : participants.length
......
...@@ -19,7 +19,6 @@ class Tournament { ...@@ -19,7 +19,6 @@ class Tournament {
creator : number; creator : number;
collaborators : Array<number>; collaborators : Array<number>;
createdAt : Date; createdAt : Date;
count : Number;
constructor(obj : TournamentObject) { constructor(obj : TournamentObject) {
this.name = obj.name; this.name = obj.name;
...@@ -34,7 +33,6 @@ class Tournament { ...@@ -34,7 +33,6 @@ class Tournament {
this.status = obj.status; this.status = obj.status;
this.creator = obj.creator; this.creator = obj.creator;
this.createdAt = new Date(obj.createdAt); this.createdAt = new Date(obj.createdAt);
this.count = obj.participants.length;
if (Number.isNaN(this.ruleSettings.winScore)) this.ruleSettings.winScore = 3; if (Number.isNaN(this.ruleSettings.winScore)) this.ruleSettings.winScore = 3;
if (Number.isNaN(this.ruleSettings.drawScore)) this.ruleSettings.drawScore = 1; if (Number.isNaN(this.ruleSettings.drawScore)) this.ruleSettings.drawScore = 1;
if (Number.isNaN(this.ruleSettings.byeScore)) this.ruleSettings.byeScore = 3; if (Number.isNaN(this.ruleSettings.byeScore)) this.ruleSettings.byeScore = 3;
......
...@@ -80,13 +80,12 @@ interface TournamentFindObject { ...@@ -80,13 +80,12 @@ interface TournamentFindObject {
} }
interface Score { interface Score {
rank : number;
score : number; score : number;
win : number; win : number;
draw : number; draw : number;
lose : number; lose : number;
bye : number; bye : number;
tieBreaker : number; tieBreaker ?: number;
} }
interface ParticipantFindObject { interface ParticipantFindObject {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment