add double in

main
Ugo Finnendahl 4 days ago
parent c22b2b8ccd
commit 9e923a5dc6
  1. 1
      assets/js/components/dialog.js
  2. 6
      assets/js/components/init.js
  3. 0
      assets/js/components/playerSelect.js
  4. 28
      assets/js/components/select.js
  5. 9
      assets/js/views/home.js
  6. 499
      assets/js/views/xoi.js.bak
  7. 19
      assets/js/views/xoi/logic.js
  8. 70
      assets/js/views/xoi/main.js
  9. 0
      content/2_seasons/1_2024/1_summer-slam/54kd4kbk/xoi.txt
  10. 0
      content/2_seasons/1_2024/1_summer-slam/7nykca7i/xoi.txt
  11. 0
      content/2_seasons/1_2024/1_summer-slam/her1fj3r/xoi.txt
  12. 0
      content/2_seasons/1_2024/1_summer-slam/jm4ju7pi/xoi.txt
  13. 0
      content/2_seasons/1_2024/1_summer-slam/l0j8jkts/xoi.txt
  14. 0
      content/2_seasons/1_2024/1_summer-slam/lsng5wlg/xoi.txt
  15. 0
      content/2_seasons/1_2024/1_summer-slam/m7tb5bac/xoi.txt
  16. 0
      content/2_seasons/1_2024/1_summer-slam/mxkfs1yq/xoi.txt
  17. 0
      content/2_seasons/1_2024/1_summer-slam/osbkse46/xoi.txt
  18. 0
      content/2_seasons/1_2024/1_summer-slam/rtjuyvsv/xoi.txt
  19. 0
      content/2_seasons/1_2024/1_summer-slam/tournament.txt
  20. 0
      content/2_seasons/1_2024/1_summer-slam/z7nvffvf/xoi.txt
  21. 0
      content/2_seasons/1_2024/2_spring-break/13tntlfj/xoi.txt
  22. 0
      content/2_seasons/1_2024/2_spring-break/3flmnq6b/xoi.txt
  23. 0
      content/2_seasons/1_2024/2_spring-break/cbwvnzxm/xoi.txt
  24. 0
      content/2_seasons/1_2024/2_spring-break/cutywjod/xoi.txt
  25. 0
      content/2_seasons/1_2024/2_spring-break/kkchbr4a/xoi.txt
  26. 0
      content/2_seasons/1_2024/2_spring-break/ovcmf1c0/xoi.txt
  27. 0
      content/2_seasons/1_2024/2_spring-break/sbggpar6/xoi.txt
  28. 0
      content/2_seasons/1_2024/2_spring-break/tournament.txt
  29. 0
      content/2_seasons/1_2024/2_spring-break/utbpew7l/xoi.txt
  30. 0
      content/2_seasons/1_2024/2_spring-break/zxlkihnz/xoi.txt
  31. 0
      content/2_seasons/1_2024/3_wm/1_1-runde/xoi.txt
  32. 0
      content/2_seasons/1_2024/3_wm/2_2-runde/xoi.txt
  33. 0
      content/2_seasons/1_2024/3_wm/3_3-runde/xoi.txt
  34. 0
      content/2_seasons/1_2024/3_wm/tournament.txt
  35. 0
      content/2_seasons/1_2024/4_liga/0tdcwlko/xoi.txt
  36. 0
      content/2_seasons/1_2024/4_liga/1csevwpm/xoi.txt
  37. 0
      content/2_seasons/1_2024/4_liga/5s62p5jp/xoi.txt
  38. 0
      content/2_seasons/1_2024/4_liga/a4iulyd5/xoi.txt
  39. 0
      content/2_seasons/1_2024/4_liga/a9z1tmvh/xoi.txt
  40. 0
      content/2_seasons/1_2024/4_liga/anobo58l/xoi.txt
  41. 0
      content/2_seasons/1_2024/4_liga/cqeaezmg/xoi.txt
  42. 0
      content/2_seasons/1_2024/4_liga/eiwqlmue/xoi.txt
  43. 0
      content/2_seasons/1_2024/4_liga/eqwdsia4/xoi.txt
  44. 0
      content/2_seasons/1_2024/4_liga/gp3pj38u/xoi.txt
  45. 0
      content/2_seasons/1_2024/4_liga/iat8cs7j/xoi.txt
  46. 0
      content/2_seasons/1_2024/4_liga/ix1srhrk/xoi.txt
  47. 0
      content/2_seasons/1_2024/4_liga/jajnvwbu/xoi.txt
  48. 0
      content/2_seasons/1_2024/4_liga/kdcqpxs1/xoi.txt
  49. 0
      content/2_seasons/1_2024/4_liga/lziuhybw/xoi.txt
  50. 0
      content/2_seasons/1_2024/4_liga/mcjcgkbg/xoi.txt
  51. 0
      content/2_seasons/1_2024/4_liga/olf1bjdm/xoi.txt
  52. 0
      content/2_seasons/1_2024/4_liga/ovasmz7s/xoi.txt
  53. 0
      content/2_seasons/1_2024/4_liga/sfln9xej/xoi.txt
  54. 0
      content/2_seasons/1_2024/4_liga/sgl9kqvo/xoi.txt
  55. 2
      content/2_seasons/1_2024/4_liga/tournament.txt
  56. 0
      content/2_seasons/1_2024/4_liga/uslfpwja/xoi.txt
  57. 0
      content/2_seasons/1_2024/4_liga/ut3juonn/xoi.txt
  58. 0
      content/2_seasons/1_2024/4_liga/vmxmfxxs/xoi.txt
  59. 0
      content/2_seasons/1_2024/4_liga/wksontke/xoi.txt
  60. 0
      content/2_seasons/1_2024/4_liga/wuhzwter/xoi.txt
  61. 0
      content/2_seasons/1_2024/4_liga/ypt4e90v/xoi.txt
  62. 0
      content/2_seasons/1_2024/4_liga/zavij0ox/xoi.txt
  63. 25
      content/2_seasons/1_2024/5_autumn-grand-prix/tournament.txt
  64. 52
      content/2_seasons/1_2024/5_autumn-grand-prix/wokuqp02/xoi.txt
  65. 0
      content/2_seasons/1_2024/season.txt
  66. 41
      content/2_seasons/1_season-2024/4_liga/ni9jxqdn/xoi.txt
  67. 2
      site/models/season.php
  68. 610
      site/models/xoi.php

@ -10,6 +10,7 @@ export default {
const handlers = [ArrowHorizontalKeyHandler];
if (props.withshortkey) {
handlers.push(NumberKeyHandler);
console.log(handlers);
}
handleActive(props, handlers);
const elements = computed(() => props.buttons.map((i) => { i.onClick = () => emit('resolve', i.result ); return i; }) );

@ -5,7 +5,8 @@ import plainElem from "./plainElem.js";
import squareElem from "./squareElem.js";
import inputElem from "./inputElem.js";
import playerselect from "./playerselect.js";
import playerSelect from "./playerSelect.js";
import select from "./select.js";
// import overlay from "./overlay.js";
import dialog from "./dialog.js";
@ -16,7 +17,8 @@ export default (app) => {
app.component("d-plainElem", plainElem);
app.component("d-squareElem", squareElem);
app.component("d-inputElem", inputElem);
app.component("d-select", select);
app.component("d-playerselect", playerselect);
app.component("d-playerSelect", playerSelect);
app.component("d-dialog", dialog);
}

@ -0,0 +1,28 @@
import { nextTick, reactive, ref, computed, onMounted, onUnmounted } from "vue";
import { handleActive, ArrowVerticalKeyHandler, ArrowHorizontalKeyHandler, NumberKeyHandler } from "../handlers.js";
const html = (v) => { return v[0] };
export default {
props: ['options', 'title', 'stack', 'active', 'input'],
setup(props, context) {
handleActive(props, [ArrowVerticalKeyHandler]);
const children = computed(() => {
return props.options.map((o) => {
return {
component: "d-plainElem",
props: {"text": o},
onClick: () => {
context.emit('resolve', o);
}
}
})
});
return { children }
},
template: html`
<div class="playerselect">
<d-list :title="title" :withshortkey="true" :elements="children"/>
</div>
`
}

@ -17,15 +17,6 @@ export const selectMode = {
const children = reactive([
{
// component: "d-squareElem",
// props:{
// text: "Create Game",
// icon: "/assets/img/dart-board.svg",
// },
// onClick: () => {
// emit("resolve", "create");
// }
// }, {
component: "d-squareElem",
props:{
text: "Play Game",

@ -1,499 +0,0 @@
import { nextTick, reactive, ref, computed, onMounted, onUnmounted } from "vue";
import { state } from "../stateMgr.js";
import { getQuery } from "../kirby.js";
import { initSubState, ArrowVerticalKeyHandler, ArrowHorizontalKeyHandler, NumberKeyHandler } from "../handlers.js";
const html = (v) => { return v[0] };
function initView(view){
const back = state.view;
state.back.push(() => { state.view = back });
state.backActive.push(state.activeIndex);
state.view = view;
}
const togo = {
props: ['togo'],
setup(props) {
return { }
},
template: html`
<div class="bigToGo">{{ togo }}</div>
`
}
const game = {
props: ['players', 'currentleg', 'max', 'sendvisit', 'modelValue', 'overlay'],
setup(props, context) {
const length = computed(() => props.currentleg?.visits.length );
const visits = computed(() => props.currentleg? props.currentleg.visits:undefined );
const loop = computed(() => Math.max(length.value?length.value+(length.value?length.value%2:0):0,18) );
const getPlayerVisits = (uuid) => {
const vs = visits.value.filter((v) => v.player == uuid);
if (vs.length < 9) {
for (var i = vs.length; i < 9; i++) {
vs.push({ "sum": "", "toGo":["",""]})
}
} else if (vs.length*2 < visits.value.length) {
vs.push({ "sum": "", "toGo":["",""]});
}
return vs;
}
const check_remove = (event) => {
if (!event.repeat && event.target.value.length < 1) {
context.emit('removeLastVisit', event.target);
}
}
const setup = ref(false);
const setupEnter = () => {
setup.value = true;
}
const confirmEnter = (evt) => {
if (setup.value) {
context.emit('sendvisit', evt.target)
}
setup.value = false;
}
return { length, visits, loop, getPlayerVisits, check_remove, confirmEnter, setupEnter }
},
template: html`
<div class="game">
<div class="headding">
<div class="headding points player1">Points</div>
<div class="headding toGo player1">ToGo</div>
<div class="headding rounds">Round</div>
<div class="headding points player2">Points</div>
<div class="headding toGo player2">ToGo</div>
</div>
<div class="body">
<div class="points player1"></div>
<div class="toGo player1">{{ max }}</div>
<div class="rounds">0</div>
<div class="points player2"></div>
<div class="toGo player2">{{ max }}</div>
<template v-for="j in [1,2]" v-if="players">
<template v-for="visit, i in getPlayerVisits(players[j-1].uuid)">
<template v-if="visit.toGo === undefined">
<div :class="'points player'+j+' input'"><input v-autofocus :value="modelValue"
@input="$emit('update:modelValue', $event.target.value)" @keyup.enter="confirmEnter($event)" @keydown.enter="setupEnter($event)" @keydown.backspace="check_remove($event)" v-if="!overlay"></div>
<div :class="'toGo player'+j"></div>
</template>
<template v-if="visit.toGo !== undefined">
<div :class="'points player'+j">{{ visit.sum }}</div>
<div :class="'toGo player'+j">{{ visit.toGo[j-1] }}</div>
</template>
<div class="rounds" v-if="j == 1">{{ (i+1)*3 }}</div>
</template>
</template>
</div>
</div>
`
}
const overlay = {
props: ['data'],
setup(props, context) {
const keyhandler = (event) => {
ArrowHorizontalKeyHandler(event);
NumberKeyHandler(event);
if (event.key == "Escape") {
context.emit("closeOverlay")
}
}
return { keyhandler }
},
template: html`
<div @keyup="keyhandler" class="overlay" v-if="data !== undefined" :class="{active: data.title != '' && data.text != ''}">
<div class="box">
<h1>{{ data.title }}</h1>
<p>{{ data.text }}</p>
<div class="buttons">
<component v-for="(item, index) in data.buttons" :is="item.type" v-index="index+1" @click="item.onClick" :ref="(el) => { item.ref = el }" v-bind="item.props" v-autofocus="item.autofocus"></component>
</div>
</div>
</div>
`
}
const score = {
props: ['page', 'justlegs', 'currentset', 'currentleg'],
setup(props) {
return { }
},
template: html`
<div class="score">
<div v-if="!justlegs" class="sets">
<h2 v-for="(idx) in [0,1]">{{ currentset?.points[idx] }}</h2>
<div class="info">
<h3>Best of {{ page?.sets }}</h3>
<h2>Sets</h2>
</div>
</div>
<div class="legs">
<h2 v-for="(idx) in [0,1]">{{ currentleg?.points[idx] }}</h2>
<div class="info">
<h3>Best of {{ page?.legs }}</h3>
<h2>Legs</h2>
</div>
</div>
</div>
`
}
const player = {
props: ['player', 'stats', "id"],
setup(props) {
const current_set = computed( () => props.stats?.sets[props.stats.sets.length-1]);
const current_leg = computed( () => current_set.value?.legs[current_set.value.legs.length-1]);
const getAverage = (avg) => {
return avg && avg[1] != 0 ? ((3*avg[0])/avg[1]).toFixed(1) : "-";
}
const getCheckout = (checkout) => {
return checkout && checkout[1] != 0 ? Math.round(1000*checkout[0]/checkout[1])/10 : "- "
}
const getMax = (checkouts) => {
if (checkouts && checkouts.length != 0) {
return Math.max(...checkouts);
}
return "-"
}
return { current_set, current_leg, getAverage, getCheckout, getMax }
},
template: html`
<div class="player">
<img style="width: 100%" :src="player?.img? player.img : '/assets/img/placeholder_person.png'">
<h2 class="name">{{ player?.forename }} {{ player?.surname }}</h2>
<h3 class="nickname">{{ player?.nickname }}</h3>
<div class="stats">
<div class="row header">
<div>Stat</div><div>Match</div><div>Leg</div>
</div>
<div class="row">
<div>Average:</div><div>{{ getAverage(stats?.stats[id].average) }}</div><div>{{ getAverage(current_leg?.stats[id].average) }}</div>
</div>
<div class="row">
<div>First 9:</div><div>{{ getAverage(stats?.stats[id].first9) }}</div><div>{{ getAverage(current_leg?.stats[id].first9) }}</div>
</div>
<div class="row">
<div>60+:</div><div>{{ stats?.stats[id]["60+"] }}</div><div>{{ current_leg?.stats[id]["60+"] }}</div>
</div>
<div class="row">
<div>100+:</div><div>{{ stats?.stats[id]["100+"] }}</div><div>{{ current_leg?.stats[id]["100+"] }}</div>
</div>
<div class="row">
<div>140+:</div><div>{{ stats?.stats[id]["140+"] }}</div><div>{{ current_leg?.stats[id]["140+"] }}</div>
</div>
<div class="row">
<div>180:</div><div>{{ stats?.stats[id]["180"] }}</div><div>{{ current_leg?.stats[id]["180"] }}</div>
</div>
<div class="row">
<div>Checkouts:</div><div>{{ getCheckout(stats?.stats[id].checkouts) }}%</div><div></div>
</div>
<div class="row">
<div>Best Checkout:</div><div>{{ getMax(stats?.stats[id].checkoutPoints) }}</div><div></div>
</div>
</div>
</div>
`
}
export const xoi = {
components: {
"d-togo": togo,
"d-score": score,
"d-game": game,
"d-player": player,
"d-overlay": overlay
},
setup(props, context) {
let page = ref();
const updateGame = (reset) => {
getQuery(`site.find('${state.id}')`, {
select: {
title: "page.title",
id: "page.id",
modus: "page.max",
game: "page.rounds.parseJSON",
stats: "page.stats.parseJSON",
sets: "page.sets",
legs: "page.legs",
players: {
query: "page.players.toPages",
select:{
forename: "page.forename",
surname: "page.surname",
nickname: "page.nickname",
uuid: "page.uuid",
img: "page.pic.toFile?.url"
}
}
}
}).then((res) => {
page.value = res;
if (reset != undefined) {
current_input.value = reset;
}
if (res.stats.winner){
console.log(res.stats);
let winner = "Draw";
if (res.players[0].uuid == res.stats.winner){
winner = res.players[0].forename;
} else if (res.players[1].uuid == res.stats.winner) {
winner = res.players[1].forename;
}
overlay.value = {
"title": "Game Ended",
"text": `The winner is ${winner}`,
"buttons": []
};
}
});
};
updateGame();
let game = computed(() => page.value ? page.value.game: undefined)
let current_set = computed(() => {
if (game.value != undefined) {
return game.value.sets[game.value.sets.length-1]
}
return undefined;
})
let current_leg = computed(() => {
if (current_set.value != undefined) {
return current_set.value.legs[current_set.value.legs.length-1]
}
return undefined;
})
let current_toGo = computed(() => {
if (current_leg.value != undefined) {
if (current_leg.value.visits.length < 2) {
return [page.value.modus, page.value.modus]
} else {
return current_leg.value.visits[current_leg.value.visits.length-2].toGo;
}
}
return [0,0];
})
let current_set_points = computed(() => {
if (current_set.value != undefined) {
return current_set.value.points;
}
return undefined;
});
let current_leg_points = computed(() => {
if (current_leg.value != undefined) {
return current_leg.value.points;
}
return undefined;
});
let current_player = computed(() => {
if (current_leg.value != undefined) {
const len = current_leg.value.visits.length;
return current_leg.value.visits[len-1].player == page.value.players[1].uuid;
}
return undefined;
});
const current_input = ref("");
const overlay = ref();
return { page, state, game, current_set, current_leg, current_toGo, current_set_points, current_leg_points, current_player, updateGame, current_input, overlay }
},
methods: {
async removeLastVisit(){
let last = this.current_leg.visits.length-2 >= 0 ? this.current_leg.visits[this.current_leg.visits.length-2].throws : [""];
last = last.join(",");
const response = await fetch(`/${state.id}`, {
method: "POST",
cache: "no-cache",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"action": "deleteLastThrow",
"visit": true,
}),
});
const ret = await response.json();
if (ret.status == "ok"){
this.updateGame(last);
} else {
console.log(ret);
}
},
sum(tr){
const val = tr.trim();;
if (val == "") {
return 0;
}
if (val == "SB"){
return 25;
}
if (val == "DB"){
return 50;
}
if (val[0] == "S" || val[0] == "O" || val[0] == "I"){
return parseFloat(val.substring(1));
}
if (val[0] == "D"){
return 2*parseFloat(val.substring(1));
}
if (val[0] == "T"){
return 3*parseFloat(val.substring(1));
}
if (val[0] == "M"){
return 0;
} else {
// TODO: Check for Na
return parseFloat(val);
}
},
verify(sum){
if (this.current_toGo[this.current_player*1]-sum == 0){
return 0;
} else if (sum > 180 || [179, 178, 176, 175, 173, 172, 169, 166, 163].indexOf(sum) > -1) {
return -1
} else if (this.current_toGo[this.current_player*1]-sum <= 50) {
return 1
}
},
openOverlay(overlay){
this.overlay = overlay;
},
closeOverlay(){
this.overlay = undefined;
},
checkout_question(throws){
const buttons = [];
for (var i = 1; i <= 3; i++) {
const x = i;
buttons.push({
"type": "input",
"props" : {
"type": "button",
"value": `${x} (${x})`
},
"onClick": () => {
this.closeOverlay();
this.checkouttries_question(throws, x, false);
}
})
}
this.openOverlay({
"title": "Congratulations!",
"text": `How many darts did you need?` ,
"buttons": buttons
});
},
checkouttries_question(throws, numDarts, zero=true){
const buttons = [];
for (var i = 1; i <= numDarts; i++) {
const x = i;
buttons.push({
"type": "input",
"props" : {
"type": "button",
"value": `${x} (${x})`
},
"autofocus": (i==1 && !zero),
"onClick": () => {
this.closeOverlay();
this.send_visit(throws, numDarts, x)
}
})
}
if (zero) {
buttons.push({
"type": "input",
"props" : {
"type": "button",
"value": `0 (${numDarts+1})`
},
"autofocus": true,
"onClick": () => {
this.closeOverlay();
this.send_visit(throws, numDarts, 0)
}
})
}
this.openOverlay({
"title": "Checkout Tries",
"text": `How many tries on a Checkout?` ,
"buttons": buttons
});
},
async send_visit(throws, numDarts=3, checkoutTries=0){
const response = await fetch(`/${state.id}`, {
method: "POST",
cache: "no-cache",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"action": "addThrows",
"throws": throws.value.split(","),
"checkoutTries": checkoutTries,
"numDarts": numDarts,
"done": true
}),
});
const ret = await response.json();
if (ret.status == "ok"){
this.updateGame("");
} else {
console.log(ret);
}
},
async preprocess_visit(throws){
const tr = throws.value.split(",");
let sum = 0;
tr.forEach((t, i) => {
sum += this.sum(t);
});
const res = this.verify(sum);
if (res == 0){
// Ask for num Darts
this.checkout_question(throws);
return;
} else if (res == 1){
// Ask for checkoutTries
this.checkouttries_question(throws, 3);
return;
} else if (res == -1){
this.openOverlay({
"title": "Impossible",
"text": `A score of ${sum} is not possible`,
"buttons": [{
"type": "input",
"props" : {
"type": "button",
"value": "ok"
},
"onClick" : this.closeOverlay
}]
});
return;
}
this.send_visit(throws);
}
},
template: html`
<div class="xoi">
<d-overlay @closeOverlay="closeOverlay" :data="overlay"></d-overlay>
<d-togo :togo="current_toGo[0]" class="one" :class="{'active' : current_player==0 }"></d-togo>
<d-togo :togo="current_toGo[1]" class="two" :class="{'active' : current_player==1 }"></d-togo>
<d-score :page="page" :justlegs="page && page.sets == 1" :currentset="current_set" :currentleg="current_leg"></d-score>
<d-game :overlay="overlay!=undefined" :players="page?.players" :max="page?.modus" @sendvisit="preprocess_visit" @removeLastVisit="removeLastVisit" :currentleg="current_leg" v-model="current_input"></d-game>
<d-player class="player1" :player="page?.players[0]" :stats="page?.stats" :id="0"></d-player>
<d-player class="player2" :player="page?.players[1]" :stats="page?.stats" :id="1"></d-player>
<div class="navi"></div>
</div>
`
}
export const initXoiView = (app) => {
app.component('d-xoi', xoi)
}

@ -153,6 +153,8 @@ export function getGameProps(page, current_set, current_leg) {
return 0;
} else if (current_toGo.value[current_player.value * 1] - sum <= 50) {
return 1;
} else if (page.in != "Straight" && current_toGo.value[current_player.value * 1] == page.modus && sum != 0) {
return 3;
}
return 2;
}
@ -176,6 +178,8 @@ function newPlayerStats(player) {
average: [0, 0],
first9: [0, 0],
checkouts: [0, 0],
checkins: [0, 0],
checkinPoints: [],
checkoutPoints: [],
"60+": 0,
"100+": 0,
@ -220,6 +224,7 @@ function newVisit(playerUUID, round) {
throws: [],
visit: round,
checkoutTries: 0,
checkinTries: 0,
numDarts: 0,
};
}
@ -255,7 +260,12 @@ function updateStats(page, visit){
todos[i]["checkouts"][0] += 1;
todos[i]["checkoutPoints"].push(visit["sum"]);
}
if (visit["checkinTries"] != 0 && visit["sum"] != 0) {
todos[i]["checkins"][0] += 1;
todos[i]["checkinPoints"].push(visit["sum"]);
}
todos[i]["checkouts"][1] += visit["checkoutTries"];
todos[i]["checkins"][1] += visit["checkinTries"];
if (visit["sum"] == 180) {
todos[i]["180"] += 1;
} else if (visit["sum"] >= 140) {
@ -322,6 +332,7 @@ function clearLastVisit(page){
const ret = visit["throws"];
visit["throws"] = [];
visit["checkoutTries"] = 0;
visit["checkinTries"] = 0;
visit["numDarts"] = 0;
delete visit["sum"];
delete visit["toGo"];
@ -376,14 +387,15 @@ export function removeLastVisit(page){
return ret;
}
export function storeVisit(page, throws, sum, numDarts, tries) {
export function storeVisit(page, throws, sum, numDarts, outTries, inTries=0) {
const set = page.game.sets[page.game.sets.length-1];
const leg = set.legs[set.legs.length-1];
const visit = leg.visits[leg.visits.length-1];
visit["numDarts"] = numDarts;
visit["throws"] = throws;
visit["checkoutTries"] = tries;
visit["checkoutTries"] = outTries;
visit["checkinTries"] = inTries;
visit["sum"] = sum
const playerUUIDs = page.players.map((p) => p.uuid);
@ -401,6 +413,9 @@ export function storeVisit(page, throws, sum, numDarts, tries) {
toGo[k] = rest;
}
visit["toGo"] = toGo;
if (page.in != "Straight" && page.modus == toGo[k] && visit["sum"] == 0) {
visit["checkinTries"] = 3;
}
// update stats
updateStats(page, visit);

@ -10,7 +10,7 @@ const html = (v) => { return v[0] };
////////////////////////////////////////////////////////////////////////////////
// Components
////////////////////////////////////////////////////////////////////////////////
//////////////////////////in//////////////////////////////////////////////////////
const pregame = {
props: ['page','active', 'stack'],
@ -19,14 +19,32 @@ const pregame = {
const selectPlayer = async (i) => {
if (props.active) {
const [result, error] = await overlayAndPop("d-playerselect", { players: props.page.participants, class:"overlay"}, props.stack);
const [result, error] = await overlayAndPop("d-playerSelect", { players: props.page.participants, class:"overlay"}, props.stack);
if (error === undefined) {
props.page.players[i] = result;
}
}
}
return { selectPlayer }
const selectX01 = async () => {
if (props.active) {
const [result, error] = await overlayAndPop("d-select", { options: [ "301", "501" ], class:"overlay"}, props.stack);
if (error === undefined) {
props.page.modus = result;
}
}
}
const selectIn = async () => {
if (props.active) {
const [result, error] = await overlayAndPop("d-select", { options: [ "Straight", "Double" ], class:"overlay"}, props.stack);
if (error === undefined) {
props.page.in = result;
}
}
}
return { selectPlayer, selectX01, selectIn }
},
template: html`
<nav class="gamesetup" :disabled="!active">
@ -35,7 +53,9 @@ const pregame = {
<!-- <div><span class="label">Name:</span><d-inputElem v-index="active" v-model="game.title"></d-inputElem></div> -->
<div><span class="label">Player 1:</span><d-playerElem v-index="active" @click="selectPlayer(0)" :player="page.players[0]"></d-playerElem></div>
<div><span class="label">Player 2:</span><d-playerElem v-index="active" @click="selectPlayer(1)" :player="page.players[1]"></d-playerElem></div>
<div><span class="label">Best of Sets:</span><d-inputElem v-index="active" v-model="page.sets"></d-inputElem></div>
<div><span class="label">X01:</span><d-plainElem v-index="active" @click="selectX01()" :text="page.modus"></d-plainElem></div>
<div><span class="label">Out:</span><d-plainElem v-index="active" @click="selectIn()" :text="page.in"></d-plainElem></div>
<!-- <div><span class="label">Best of Sets:</span><d-inputElem v-index="active" v-model="page.sets"></d-inputElem></div> -->
<div><span class="label">Best of Legs (per Set):</span><d-inputElem v-index="active" v-model="page.legs"></d-inputElem></div>
<div><d-plainElem text="Start" v-index="active" @click="$emit('resolve', page)"></d-plainElem></div>
</div>
@ -107,6 +127,7 @@ const player = {
props: ['page', 'id', 'current_stat'],
setup(props) {
const addStats = (stat1, stat2) => {
console.log(stat1);
return {
average: [stat1.average[0]+stat2.average[0], stat1.average[1]+stat2.average[1]],
first9: [stat1.first9[0]+stat2.first9[0], stat1.first9[1]+stat2.first9[1]],
@ -191,8 +212,14 @@ const player = {
<div class="row">
<div>180:</div><div>{{ tourStats[id]["180"] }}</div><div>{{ page.stats.stats[id]["180"] }}</div><div>{{ current_stat.stats[id]["180"] }}</div>
</div>
<div class="row" v-if="page.in == 'Double'">
<div>Ch. I. %:</div><div>{{ getCheckout(tourStats[id].checkins) }}%</div><div>{{ getCheckout(page.stats.stats[id].checkins) }}%</div><div>{{ getCheckout(current_stat.stats[id].checkins) }}%</div>
</div>
<div class="row" v-if="page.in == 'Double'">
<div>Best Ch.:</div><div>{{ getMax(tourStats[id].checkinPoints) }}</div><div>{{ getMax(page.stats.stats[id].checkinPoints) }}</div><div>{{ getMax(current_stat.stats[id].checkinPoints) }}</div>
</div>
<div class="row">
<div>Ch. %:</div><div>{{ getCheckout(tourStats[id].checkouts) }}%</div><div>{{ getCheckout(page.stats.stats[id].checkouts) }}%</div><div></div>
<div>Ch. O. %:</div><div>{{ getCheckout(tourStats[id].checkouts) }}%</div><div>{{ getCheckout(page.stats.stats[id].checkouts) }}%</div><div></div>
</div>
<div class="row">
<div>Best Ch.:</div><div>{{ getMax(tourStats[id].checkoutPoints) }}</div><div>{{ getMax(page.stats.stats[id].checkoutPoints) }}</div><div></div>
@ -387,6 +414,27 @@ const numCheckoutTriesDialog = (numDarts, start=1) => {
};
}
const numCheckinTriesDialog = (numDarts, start=1) => {
const buttons = [];
for (var i = start; i <= numDarts; i++) {
buttons.push({
"component": "d-plainElem",
"props" : {
"text": `${i}`,
"autofocus": i == 0,
"data-tabindex": i
},
"result" : i
})
}
return {
"withshortkey": true,
"title": "Checkin Tries",
"text": `How many tries on a Checkin?` ,
"buttons": buttons
};
}
const impossibleDialog = (sum) => {
return {
"withshortkey": true,
@ -433,6 +481,7 @@ function getGame(id){
title: "page.title",
id: "page.id",
modus: "page.max.toInt",
in: "page.in",
out: "page.out",
game: "page.rounds.parseJSON",
stats: "page.stats.parseJSON",
@ -469,6 +518,8 @@ function savePregame(page){
return setKirby(page.id, {
sets: page.sets,
legs: page.legs,
max: page.modus,
in: page.in,
players: page.players.map((p) => p.uuid),
startdate: page.startdate,
rounds: page.game ? JSON.stringify(page.game) : "",
@ -558,6 +609,15 @@ const gameStateMachine = (gamestack, stack, page, computedProps) => {
// Bust TODO
const [_, error] = await overlayAndPop("d-dialog", impossibleDialog(sum), stack);
return [1, visit];
} else if (ret == 3) {
// Checkins
const [ret, error] = await overlayAndPop("d-dialog", numCheckinTriesDialog(3), stack);
if (error) {
return [1, visit];
}
storeVisit(page, visit.split(","), sum, 3, 0, ret);
saveGame(page);
return [1, undefined]
} else if (ret == 2) {
// Normal
storeVisit(page, visit.split(","), sum, 3, 0);

@ -0,0 +1,25 @@
Title: Autumn Grand Prix
----
Participants:
- page://XDZibCkgJ9repYEx
- page://5bw1wQY8DAfxUVAw
- page://Ue0F1SstBqE7xVKr
- page://4CPpeIGeeK8UHTf8
- page://fShTMgFob20fogyr
- page://xRomcRk5I5n4gkq5
- page://90CUYLfokdOm9Gw0
- page://7GAUHPdaKdD2sHm9
- page://x8tm8FzBBY95HqIi
- page://UkQNJytohCGIXySl
- page://2ymjLWSMV1xXil3P
----
Date: 2024-10-19
----
Uuid: xt5fiX8sJ6Dk3ZPT

@ -0,0 +1,52 @@
Title: wOkUqP02
----
Max: 301
----
Sets: 1
----
Legs: 7
----
In: Double
----
Out: Double
----
Players:
- page://fShTMgFob20fogyr
- page://90CUYLfokdOm9Gw0
----
Startdate: 2024-10-14 22:39:00
----
Enddate:
----
Rounds: {"sets":[{"points":[0,0],"legs":[{"points":[0,0],"visits":[{"player":"page://fShTMgFob20fogyr","throws":[],"visit":1,"checkoutTries":0,"checkinTries":0,"numDarts":0}]}]}]}
----
Stats: {"stats":[{"180":0,"player":"page://fShTMgFob20fogyr","average":[0,0],"first9":[0,0],"checkouts":[0,0],"checkins":[0,0],"checkinPoints":[],"checkoutPoints":[],"60+":0,"100+":0,"140+":0},{"180":0,"player":"page://90CUYLfokdOm9Gw0","average":[0,0],"first9":[0,0],"checkouts":[0,0],"checkins":[0,0],"checkinPoints":[],"checkoutPoints":[],"60+":0,"100+":0,"140+":0}],"sets":[{"stats":[{"180":0,"player":"page://fShTMgFob20fogyr","average":[0,0],"first9":[0,0],"checkouts":[0,0],"checkins":[0,0],"checkinPoints":[],"checkoutPoints":[],"60+":0,"100+":0,"140+":0},{"180":0,"player":"page://90CUYLfokdOm9Gw0","average":[0,0],"first9":[0,0],"checkouts":[0,0],"checkins":[0,0],"checkinPoints":[],"checkoutPoints":[],"60+":0,"100+":0,"140+":0}],"legs":[{"stats":[{"180":0,"player":"page://fShTMgFob20fogyr","average":[0,0],"first9":[0,0],"checkouts":[0,0],"checkins":[0,0],"checkinPoints":[],"checkoutPoints":[],"60+":0,"100+":0,"140+":0},{"180":0,"player":"page://90CUYLfokdOm9Gw0","average":[0,0],"first9":[0,0],"checkouts":[0,0],"checkins":[0,0],"checkinPoints":[],"checkoutPoints":[],"60+":0,"100+":0,"140+":0}]}]}]}
----
Comment:
----
Uuid: 934yZZl3DLYrDfWc

@ -1,41 +0,0 @@
Title: Ni9jxqdN
----
Uuid: M0KXAXMXHbG2jPHl
----
Max: 501
----
Sets: 1
----
Legs: 7
----
In: Straight
----
Out: Double
----
Players:
----
Startdate:
----
Enddate:
----
Comment:

@ -11,6 +11,6 @@ class SeasonPage extends Page {
public function getRunningTournaments() {
return $this->children()->filter(
fn ($child) => $child->date()->isEmpty() or $child->date()->toDate()+(60*60*24) > time()
);
)->sortBy('date', 'asc');
}
}

@ -16,29 +16,32 @@ class XoiPage extends Page {
$sum["checkouts"][0] += $stat2["checkouts"][0];
$sum["checkoutPoints"] = array_merge($sum["checkoutPoints"], $stat2["checkoutPoints"]);
$sum["checkouts"][1] += $stat2["checkouts"][1];
$sum["checkins"][0] += $stat2["checkins"][0];
$sum["checkinPoints"] = array_merge($sum["checkinPoints"], $stat2["checkinPoints"]);
$sum["checkins"][1] += $stat2["checkins"][1];
$sum["180"] += $stat2["180"];
$sum["140+"] += $stat2["140+"];
$sum["100+"] += $stat2["100+"];
$sum["60+"] += $stat2["60+"];
return $sum;
}
/**
* @kql-allowed
*/
public function tournamentStats() {
if (count($this->playerUUIDs()) == 2){
return [$this->parent()->getStats($this->playerUUIDs()[0]),$this->parent()->getStats($this->playerUUIDs()[1])];
}
return [];
}
public function reorderPlayer($order){
kirby()->impersonate('kirby');
return $this->update([
"players" => $order
]);
}
//
// /**
// * @kql-allowed
// */
// public function tournamentStats() {
// if (count($this->playerUUIDs()) == 2){
// return [$this->parent()->getStats($this->playerUUIDs()[0]),$this->parent()->getStats($this->playerUUIDs()[1])];
// }
// return [];
// }
//
// public function reorderPlayer($order){
// kirby()->impersonate('kirby');
// return $this->update([
// "players" => $order
// ]);
// }
public function playerUUIDs(){
$pp = $this->players()->toPages();
$players = [];
@ -47,58 +50,58 @@ class XoiPage extends Page {
}
return $players;
}
public function getPlayerPos($playerUUIDs, $uuid)
{
$k = 0;
foreach ($playerUUIDs as $i => $playeruuid) {
if ($playeruuid == $uuid) {
break;
}
$k++;
}
return $k;
}
// entity can be visit, leg or set
public function nextPlayer($playerUUIDs, $uuid)
{
$k = $this->getPlayerPos($playerUUIDs, $uuid);
return $playerUUIDs[($k+1)%count($playerUUIDs)];
}
public function updateStats(&$stats, $visit){
$playerUUIDs = $this->playerUUIDs();
$k = $this->getPlayerPos($playerUUIDs, $visit["player"]);
$todos = [&$stats["stats"][$k]];
$todos[] = &last($stats["sets"])["stats"][$k];
$todos[] = &last(last($stats["sets"])["legs"])["stats"][$k];
foreach ($todos as $i => $value) {
$todos[$i]["average"][0] += $visit["sum"];
$todos[$i]["average"][1] += $visit["numDarts"];
if ($visit["visit"] < 4) {
$todos[$i]["first9"][0] += $visit["sum"];
$todos[$i]["first9"][1] += $visit["numDarts"];
}
if ($visit["toGo"][$k] == 0) {
$todos[$i]["checkouts"][0] += 1;
$todos[$i]["checkoutPoints"][] += $visit["sum"];
}
$todos[$i]["checkouts"][1] += $visit["checkoutTries"];
if ($visit["sum"] == 180) {
$todos[$i]["180"] += 1;
} elseif ($visit["sum"] >= 140) {
$todos[$i]["140+"] += 1;
} elseif ($visit["sum"] >= 100) {
$todos[$i]["100+"] += 1;
} elseif ($visit["sum"] >= 60) {
$todos[$i]["60+"] += 1;
}
}
return $stats;
}
//
// public function getPlayerPos($playerUUIDs, $uuid)
// {
// $k = 0;
// foreach ($playerUUIDs as $i => $playeruuid) {
// if ($playeruuid == $uuid) {
// break;
// }
// $k++;
// }
// return $k;
// }
// // entity can be visit, leg or set
// public function nextPlayer($playerUUIDs, $uuid)
// {
// $k = $this->getPlayerPos($playerUUIDs, $uuid);
// return $playerUUIDs[($k+1)%count($playerUUIDs)];
// }
//
// public function updateStats(&$stats, $visit){
// $playerUUIDs = $this->playerUUIDs();
// $k = $this->getPlayerPos($playerUUIDs, $visit["player"]);
//
// $todos = [&$stats["stats"][$k]];
// $todos[] = &last($stats["sets"])["stats"][$k];
// $todos[] = &last(last($stats["sets"])["legs"])["stats"][$k];
//
// foreach ($todos as $i => $value) {
// $todos[$i]["average"][0] += $visit["sum"];
// $todos[$i]["average"][1] += $visit["numDarts"];
// if ($visit["visit"] < 4) {
// $todos[$i]["first9"][0] += $visit["sum"];
// $todos[$i]["first9"][1] += $visit["numDarts"];
// }
// if ($visit["toGo"][$k] == 0) {
// $todos[$i]["checkouts"][0] += 1;
// $todos[$i]["checkoutPoints"][] += $visit["sum"];
// }
// $todos[$i]["checkouts"][1] += $visit["checkoutTries"];
// if ($visit["sum"] == 180) {
// $todos[$i]["180"] += 1;
// } elseif ($visit["sum"] >= 140) {
// $todos[$i]["140+"] += 1;
// } elseif ($visit["sum"] >= 100) {
// $todos[$i]["100+"] += 1;
// } elseif ($visit["sum"] >= 60) {
// $todos[$i]["60+"] += 1;
// }
// }
// return $stats;
// }
//
private function newVisit($player, $round)
{
return array(
@ -106,171 +109,172 @@ class XoiPage extends Page {
'throws' => [],
'visit' => $round,
'checkoutTries' => 0,
'checkinTries' => 0,
'numDarts' => 0,
);
}
public function calcPoints($throw)
{
$throw = trim($throw);
if ($throw == "") {
return 0;
}
if ($throw == "SB"){
return 25;
}
if ($throw == "DB"){
return 50;
}
if ($throw[0] == "S" || $throw[0] == "O" || $throw[0] == "I"){
return intval(substr($throw, 1));
}
if ($throw[0] == "D"){
return 2*intval(substr($throw, 1));
}
if ($throw[0] == "T"){
return 3*intval(substr($throw, 1));
}
if ($throw[0] == "M"){
return 0;
} else {
// TODO: Check for Na
return intval($throw);
}
}
public function sumPoints($throws)
{
$sum = 0;
foreach ($throws as $i => $throw) {
$points = $this->calcPoints($throw);
$sum += $points;
}
return $sum;
}
public function getWinner($points, $mode)
{
$sum = 0;
$k = 0;
$max = -1;
foreach ($points as $i => $point) {
$sum += $point;
if ($max < $point) {
$max = $point;
$maxidx = $k;
}
$k++;
}
if ($max > $mode/$k) {
return $maxidx;
}
if ($sum == $mode) {
return -2;
}
return -1;
}
public function clearLastVisit()
{
$game = $this->rounds()->parseJSON();
$set = &$game["sets"][count($game["sets"])-1];
$leg = &$set["legs"][count($set["legs"])-1];
$visit = &$leg["visits"][count($leg["visits"])-1];
$visit["throws"] = [];
$visit["checkoutTries"] = 0;
$visit["numDarts"] = 0;
unset($visit["sum"]);
unset($visit["toGo"]);
return $this->storeGame($game);
}
public function addThrows($throws, $numDarts, $checkoutTries, $done=true)
{
$game = $this->rounds()->parseJSON();
$set = &$game["sets"][count($game["sets"])-1];
$leg = &$set["legs"][count($set["legs"])-1];
$visit = &$leg["visits"][count($leg["visits"])-1];
$current_throws = $visit['throws'];
if (count($current_throws)+count($throws) > 3) {
$error = "Two many throws given: ".count($current_throws)." + ".count($throws)." > 3";
throw new \Exception($error, 1);
}
$new_throws = array_merge($current_throws, $throws);
$playerUUIDs = $this->playerUUIDs();
$k = $this->getPlayerPos($playerUUIDs, $visit["player"]);
if (count($leg["visits"])-2 < 0) {
$toGo = array_fill(0, count($playerUUIDs), $this->max()->toInt());
} else {
$toGo = $leg["visits"][count($leg["visits"])-2]["toGo"];
}
$visit["numDarts"] += $numDarts;
$visit["throws"] = $new_throws;
$visit["checkoutTries"] += $checkoutTries;
$visit["sum"] = $this->sumPoints($visit["throws"]);
$rest = $toGo[$k] - $visit["sum"];
if ($rest < 0 or ($this->out()->toString() == "Double" && $rest == 1)) {
$visit["sum"] = 0;
} else {
$toGo[$k] = $rest;
}
$visit["toGo"] = $toGo;
if (!$done) {
$this->storeGame($game);
return;
}
$stats = $this->stats()->parseJSON();
$page = $this->updateStats($stats, $visit);
$update = [];
if ($rest != 0) {
// Normal case...next players turn
$nextPlayer = $this->nextPlayer($playerUUIDs, $visit["player"]);
$isNextRound = 0;
if (last(last($game["sets"])["legs"])['visits'][0]["player"] == $nextPlayer) {
$isNextRound = 1;
}
$newVisit = $this->newVisit($nextPlayer, $visit["visit"]+$isNextRound);
last(last($game["sets"])["legs"])['visits'][] = $newVisit;
} else {
// rest == 0 leg finished
// updates Stats...this is maybe the wrong place to store points
$newlegp = $leg["points"];
$newlegp[$k] += 1;
$winner = $this->getWinner($newlegp, $this->legs()->toInt());
if ($winner != -1) {
$newsetp = $set["points"];
$newsetp[$k] += 1;
$winner = $this->getWinner($newsetp, $this->sets()->toInt());
if ($winner != -1) {
if ($winner == -2) {
$stats["winner"] = "DRAW";
} else {
$stats["winner"] = $visit["player"];
}
// Game Over
$update = [
"enddate" => date("Y-m-d H:i:s")
];
} else {
// new Set
$this->addNewSet($game, $newsetp);
$stats = $this->addNewSetStats($stats);
$stats = $this->addNewLegStats($stats);
}
} else {
// new Leg
$this->addNewLeg($game, $newlegp);
$stats = $this->addNewLegStats($stats);
}
}
$page = $this->storeGame($game);
$page = $page->storeStats($stats);
$page->update($update);
}
//
// public function calcPoints($throw)
// {
// $throw = trim($throw);
// if ($throw == "") {
// return 0;
// }
// if ($throw == "SB"){
// return 25;
// }
// if ($throw == "DB"){
// return 50;
// }
// if ($throw[0] == "S" || $throw[0] == "O" || $throw[0] == "I"){
// return intval(substr($throw, 1));
// }
// if ($throw[0] == "D"){
// return 2*intval(substr($throw, 1));
// }
// if ($throw[0] == "T"){
// return 3*intval(substr($throw, 1));
// }
// if ($throw[0] == "M"){
// return 0;
// } else {
// // TODO: Check for Na
// return intval($throw);
// }
// }
//
// public function sumPoints($throws)
// {
// $sum = 0;
// foreach ($throws as $i => $throw) {
// $points = $this->calcPoints($throw);
// $sum += $points;
// }
// return $sum;
// }
//
// public function getWinner($points, $mode)
// {
// $sum = 0;
// $k = 0;
// $max = -1;
// foreach ($points as $i => $point) {
// $sum += $point;
// if ($max < $point) {
// $max = $point;
// $maxidx = $k;
// }
// $k++;
// }
// if ($max > $mode/$k) {
// return $maxidx;
// }
// if ($sum == $mode) {
// return -2;
// }
// return -1;
// }
//
// public function clearLastVisit()
// {
// $game = $this->rounds()->parseJSON();
// $set = &$game["sets"][count($game["sets"])-1];
// $leg = &$set["legs"][count($set["legs"])-1];
// $visit = &$leg["visits"][count($leg["visits"])-1];
// $visit["throws"] = [];
// $visit["checkoutTries"] = 0;
// $visit["numDarts"] = 0;
// unset($visit["sum"]);
// unset($visit["toGo"]);
// return $this->storeGame($game);
// }
//
// public function addThrows($throws, $numDarts, $checkoutTries, $done=true)
// {
// $game = $this->rounds()->parseJSON();
// $set = &$game["sets"][count($game["sets"])-1];
// $leg = &$set["legs"][count($set["legs"])-1];
// $visit = &$leg["visits"][count($leg["visits"])-1];
// $current_throws = $visit['throws'];
// if (count($current_throws)+count($throws) > 3) {
// $error = "Two many throws given: ".count($current_throws)." + ".count($throws)." > 3";
// throw new \Exception($error, 1);
// }
// $new_throws = array_merge($current_throws, $throws);
//
// $playerUUIDs = $this->playerUUIDs();
// $k = $this->getPlayerPos($playerUUIDs, $visit["player"]);
// if (count($leg["visits"])-2 < 0) {
// $toGo = array_fill(0, count($playerUUIDs), $this->max()->toInt());
// } else {
// $toGo = $leg["visits"][count($leg["visits"])-2]["toGo"];
// }
//
// $visit["numDarts"] += $numDarts;
// $visit["throws"] = $new_throws;
// $visit["checkoutTries"] += $checkoutTries;
// $visit["sum"] = $this->sumPoints($visit["throws"]);
//
// $rest = $toGo[$k] - $visit["sum"];
// if ($rest < 0 or ($this->out()->toString() == "Double" && $rest == 1)) {
// $visit["sum"] = 0;
// } else {
// $toGo[$k] = $rest;
// }
// $visit["toGo"] = $toGo;
// if (!$done) {
// $this->storeGame($game);
// return;
// }
//
// $stats = $this->stats()->parseJSON();
// $page = $this->updateStats($stats, $visit);
// $update = [];
// if ($rest != 0) {
// // Normal case...next players turn
// $nextPlayer = $this->nextPlayer($playerUUIDs, $visit["player"]);
// $isNextRound = 0;
// if (last(last($game["sets"])["legs"])['visits'][0]["player"] == $nextPlayer) {
// $isNextRound = 1;
// }
// $newVisit = $this->newVisit($nextPlayer, $visit["visit"]+$isNextRound);
// last(last($game["sets"])["legs"])['visits'][] = $newVisit;
// } else {
// // rest == 0 leg finished
// // updates Stats...this is maybe the wrong place to store points
// $newlegp = $leg["points"];
// $newlegp[$k] += 1;
// $winner = $this->getWinner($newlegp, $this->legs()->toInt());
// if ($winner != -1) {
// $newsetp = $set["points"];
// $newsetp[$k] += 1;
// $winner = $this->getWinner($newsetp, $this->sets()->toInt());
// if ($winner != -1) {
// if ($winner == -2) {
// $stats["winner"] = "DRAW";
// } else {
// $stats["winner"] = $visit["player"];
// }
// // Game Over
// $update = [
// "enddate" => date("Y-m-d H:i:s")
// ];
// } else {
// // new Set
// $this->addNewSet($game, $newsetp);
// $stats = $this->addNewSetStats($stats);
// $stats = $this->addNewLegStats($stats);
// }
// } else {
// // new Leg
// $this->addNewLeg($game, $newlegp);
// $stats = $this->addNewLegStats($stats);
// }
// }
// $page = $this->storeGame($game);
// $page = $page->storeStats($stats);
// $page->update($update);
// }
private function newSingleStats($player)
{
@ -280,6 +284,8 @@ class XoiPage extends Page {
"first9" => [0, 0],
"checkouts" => [0, 0],
"checkoutPoints" => [],
"checkins" => [0, 0],
"checkinPoints" => [],
"60+" => 0,
"100+" => 0,
"140+" => 0,
@ -298,35 +304,35 @@ class XoiPage extends Page {
}
return $stats;
}
private function addNewSet(&$game, $points){
$playerUUIDs = $this->playerUUIDs();
$set = &$game["sets"][count($game["sets"])-1];
$leg = &$set["legs"][count($set["legs"])-1];
$p = $this->nextPlayer($playerUUIDs, $set["legs"][0]["visits"][0]["player"]);
$game["sets"][] = array(
'points' => $points,
'legs' => [
array(
'points' => array_fill(0, count($playerUUIDs), 0),
'visits' => [$this->newVisit($p, 1)]
)
]
);
return $game;
}
private function addNewLeg(&$game, $points){
$playerUUIDs = $this->playerUUIDs();
$set = &$game["sets"][count($game["sets"])-1];
$leg = &$set["legs"][count($set["legs"])-1];
$p = $this->nextPlayer($playerUUIDs, $leg["visits"][0]["player"]);
$set["legs"][] = array(
'points' => $points,
'visits' => [$this->newVisit($p, 1)]
);
return $game;
}
//
// private function addNewSet(&$game, $points){
// $playerUUIDs = $this->playerUUIDs();
// $set = &$game["sets"][count($game["sets"])-1];
// $leg = &$set["legs"][count($set["legs"])-1];
// $p = $this->nextPlayer($playerUUIDs, $set["legs"][0]["visits"][0]["player"]);
// $game["sets"][] = array(
// 'points' => $points,
// 'legs' => [
// array(
// 'points' => array_fill(0, count($playerUUIDs), 0),
// 'visits' => [$this->newVisit($p, 1)]
// )
// ]
// );
// return $game;
// }
// private function addNewLeg(&$game, $points){
// $playerUUIDs = $this->playerUUIDs();
// $set = &$game["sets"][count($game["sets"])-1];
// $leg = &$set["legs"][count($set["legs"])-1];
// $p = $this->nextPlayer($playerUUIDs, $leg["visits"][0]["player"]);
// $set["legs"][] = array(
// 'points' => $points,
// 'visits' => [$this->newVisit($p, 1)]
// );
// return $game;
// }
//
private function addNewSetStats(&$stats){
$stats["sets"][] = $this->newStats();
$stats["sets"][0]["legs"] = [];
@ -336,32 +342,32 @@ class XoiPage extends Page {
last($stats["sets"])["legs"][] = $this->newStats();
return $stats;
}
public function recalcStats(){
$game = $this->rounds()->parseJSON();
$page = $this->initStats();
$stats = $page->stats()->parseJSON();
$lastset = count($game["sets"])-1;
foreach ($game["sets"] as $i => $set) {
$lastleg = count($set["legs"])-1;
foreach ($set["legs"] as $j => $leg) {
$lastvisit = count($leg["visits"])-1;
foreach ($leg["visits"] as $k => $visit) {
if (!($k == $lastvisit && $j == $lastleg && $i == $lastset)) {
$this->updateStats($stats, $visit);
}
if ($k == $lastvisit && $j != $lastleg) {
$this->addNewLegStats($stats);
}
}
if ($j == $lastleg && $i != $lastset) {
$this->addNewSetStats($stats);
}
}
}
return $this->storeStats($stats);
}
//
// public function recalcStats(){
// $game = $this->rounds()->parseJSON();
// $page = $this->initStats();
// $stats = $page->stats()->parseJSON();
// $lastset = count($game["sets"])-1;
// foreach ($game["sets"] as $i => $set) {
// $lastleg = count($set["legs"])-1;
// foreach ($set["legs"] as $j => $leg) {
// $lastvisit = count($leg["visits"])-1;
// foreach ($leg["visits"] as $k => $visit) {
// if (!($k == $lastvisit && $j == $lastleg && $i == $lastset)) {
// $this->updateStats($stats, $visit);
// }
// if ($k == $lastvisit && $j != $lastleg) {
// $this->addNewLegStats($stats);
// }
// }
// if ($j == $lastleg && $i != $lastset) {
// $this->addNewSetStats($stats);
// }
// }
// }
// return $this->storeStats($stats);
// }
//
private function initStats()
{
$stats = $this->newStats();
@ -394,20 +400,20 @@ class XoiPage extends Page {
kirby()->impersonate('kirby');
return $page->update($update);
}
public function storeStats($stats)
{
kirby()->impersonate('kirby');
return $this->update([
"stats" => json_encode($stats)
]);
}
public function storeGame($game)
{
kirby()->impersonate('kirby');
return $this->update([
"rounds" => json_encode($game)
]);
}
//
// public function storeStats($stats)
// {
// kirby()->impersonate('kirby');
// return $this->update([
// "stats" => json_encode($stats)
// ]);
//
// }
// public function storeGame($game)
// {
// kirby()->impersonate('kirby');
// return $this->update([
// "rounds" => json_encode($game)
// ]);
// }
}

Loading…
Cancel
Save