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 @@
v-for = '(i, v) in search.result.tournaments'
:title = 'i.name'
:note = 'search.rule.note.get(i.rule)'
:rightText = '`${i.createdAt.toLocaleDateString()}\n${i.count}`'
:rightText = '`${i.createdAt.toLocaleDateString()}`'
:clickable = true
@click = 'page.show.tournament(i.id)'
></uni-list-item>
......
......@@ -62,6 +62,17 @@
:max = 'participant.array.length'
></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>
<view
......@@ -100,7 +111,7 @@
<view id = 'header'>
<span>{{ i.name }}</span>
<br>
<span class = 'small'>{{ tournament.this.status == 'Ready' ? `${v + 1}` : (i.score ? i.score.rank : '') }}</span>
<span class = 'small'>{{ v + 1 }}</span>
</view>
</template>
<template v-slot:footer>
......@@ -178,7 +189,7 @@
:current = 'participant.page'
v-model = 'participant.page'
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-card>
......@@ -200,6 +211,17 @@
:disabled = "tournament.this.status == 'Ready'"
></uni-number-box>
<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>
<view class = 'button' @click = '() => { match.round = 0; }'>全部轮次</view>
......@@ -475,7 +497,7 @@
},
copy : () : void => {
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 ++) {
if (match.round > 0 && match.round != round) continue;
string += `---------------------------------------------\n第[ ${round} ]轮对决战况表\n---------------------------------------------\n`
......@@ -652,7 +674,7 @@
},
copy : () : void => {
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;
if (copyValue == 0) copyValue = participant.array.length;
const map : Map<number, string> = new Map([
......@@ -728,14 +750,30 @@
filterMatch : (i : Match) : boolean => {
if ((i.round != match.round && match.round != 0) || (i.status == 'Abandoned' && !i.player1.name || !i.player2.name))
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;
},
filterParticipant : (i : Participant) : boolean => {
if (searcher.p.chk && i.quit)
return false;
return searcher.participant ? i.name.toUpperCase().includes(searcher.participant.toUpperCase()) : true;
},
reset : () : void => {
searcher.participant = '';
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 {
winnerId : number | null;
childMatchId : number;
constructor(obj : MatchObject) {
constructor(obj : MatchObject, p : Array<Participant>) {
this.id = obj.id;
this.tournamentId = obj.tournamentId;
this.round = obj.round;
this.isThirdPlaceMatch = obj.isThirdPlaceMatch;
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 = {
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,
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 = {
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,
score : obj.player2Score
};
......
import { Score, ParticipantObject, Deck } from './type.ts';
import YGOProDeck from 'ygopro-deck-encode';
import { Base64 } from 'js-base64';
import Match from './match.ts';
import Tournament from './tournament.ts';
class Participant {
id : number;
......@@ -18,7 +20,6 @@ class Participant {
this.qq = (name.length == 2 && !Number.isNaN(name[0]) && name[0].length > 3) ? name[0] : undefined;
this.tournamentId = obj.tournamentId;
this.id = obj.id;
this.score = obj.score;
this.deckbuf = obj.deckbuf ?? '';
this.quit = obj.quit ?? false;
if (obj.deckbuf)
......@@ -43,6 +44,32 @@ class Participant {
const data = this.deck?.toYdkString() ?? '';
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;
......@@ -99,16 +99,28 @@ class TabulatorAPI {
'x-user-token' : token
}
});
const tournament = new Tournament(response.data.data);
let participants : Array<Participant> = [];
let matches : Array<Match> = [];
response.data.data.participants.forEach((i : ParticipantObject) => {
participants.push(new Participant(i));
});
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 {
tournament : new Tournament(response.data.data),
tournament : tournament,
participant : {
participants : participants,
total : participants.length
......
......@@ -19,7 +19,6 @@ class Tournament {
creator : number;
collaborators : Array<number>;
createdAt : Date;
count : Number;
constructor(obj : TournamentObject) {
this.name = obj.name;
......@@ -34,7 +33,6 @@ class Tournament {
this.status = obj.status;
this.creator = obj.creator;
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.drawScore)) this.ruleSettings.drawScore = 1;
if (Number.isNaN(this.ruleSettings.byeScore)) this.ruleSettings.byeScore = 3;
......
......@@ -80,13 +80,12 @@ interface TournamentFindObject {
}
interface Score {
rank : number;
score : number;
win : number;
draw : number;
lose : number;
bye : number;
tieBreaker : number;
tieBreaker ?: number;
}
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