add watchmode

main
Ugo Finnendahl 2 months ago
parent b3fa938897
commit 0dc5eb5226
  1. 40
      assets/js/views/xoi/main.js

@ -326,7 +326,7 @@ const gameinput = {
const xoi = { const xoi = {
props: ['page', 'active', 'stack', 'inspect'], props: ['page', 'active', 'stack', 'inspect', 'watch'],
components: { components: {
"d-player": player, "d-player": player,
"d-score": score, "d-score": score,
@ -344,13 +344,20 @@ const xoi = {
current_leg = computed(() => current_set.value.legs[leg_id.value]); current_leg = computed(() => current_set.value.legs[leg_id.value]);
current_stat = computed( () => props.page.stats?.sets[set_id.value].legs[leg_id.value]); current_stat = computed( () => props.page.stats?.sets[set_id.value].legs[leg_id.value]);
} }
if (props.watch) {
setInterval(async () => {
let gs = await refreshGame(props.page.id);
props.page.game = gs.game;
props.page.stats = gs.stats;
}, 2000);
}
const computedProps = getGameProps(props.page, current_set, current_leg); const computedProps = getGameProps(props.page, current_set, current_leg);
if (!props.inspect) { if (!props.inspect) {
current_stat = computed( () => props.page.stats?.sets[props.page.stats.sets.length-1].legs[computedProps.current_set.value.legs.length-1]); current_stat = computed( () => props.page.stats?.sets[props.page.stats.sets.length-1].legs[computedProps.current_set.value.legs.length-1]);
} }
const mounted = onMounted(async () => { const mounted = onMounted(async () => {
if (props.inspect) { if (props.inspect || props.watch) {
} else { } else {
const winner = await gameHandler(gamestack, props.stack, props.page, computedProps) const winner = await gameHandler(gamestack, props.stack, props.page, computedProps)
context.emit('resolve', winner); context.emit('resolve', winner);
@ -483,6 +490,15 @@ const gameOverDialog = (winner, points, breaks) => {
// API // API
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
function refreshGame(id){
return getQuery(`site.find('${id}')`, {
select: {
game: "page.rounds.parseJSON",
stats: "page.stats.parseJSON"
}
})
}
function getGame(id){ function getGame(id){
return getQuery(`site.find('${id}')`, { return getQuery(`site.find('${id}')`, {
select: { select: {
@ -679,12 +695,19 @@ export const gameHandler = async (gamestack, stack, page, computedProps) => {
return powerStateMachine(sm, gamestack); return powerStateMachine(sm, gamestack);
} }
function getUrlParam(name) {
var url_string = window.location;
let url = new URL(url_string);
let params = new URLSearchParams(url.search);
return params.get(name);
}
// General State Machine // General State Machine
const stateMachine = (stack, page) => { const stateMachine = (stack, page) => {
return { return {
0: async (input, reGet) => { 0: async (input, reGet) => {
// Dispatcher // Dispatcher
// Check if in watchmode
// Check Game State: // Check Game State:
if (page.players.length != 2 || page.startdate === undefined || page.startdate === ""){ if (page.players.length != 2 || page.startdate === undefined || page.startdate === ""){
// Pre Game // Pre Game
@ -695,6 +718,10 @@ const stateMachine = (stack, page) => {
return [2, page]; return [2, page];
} else { } else {
// In Game // In Game
if (getUrlParam("w") != null){
// Watch Game
return [5, undefined];
}
return [3, page]; return [3, page];
} }
} else { } else {
@ -750,6 +777,15 @@ const stateMachine = (stack, page) => {
return false; return false;
},1); },1);
return [4, res]; return [4, res];
},
5: async (_, reGet) => {
const [res, e] = await overlayAndPop("d-xoi", { page: page, watch: true }, stack);
var re = /^https?:\/\/[^/]+/i;
window.setTimeout(() => {
window.location.href = re.exec(window.location.href)[0];
return false;
},1);
return [5, res];
} }
}; };
} }

Loading…
Cancel
Save