Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
thordy committed Nov 8, 2024
2 parents e60a690 + 5ce1a32 commit df912c8
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ A preview of major changes can be found in the Wiki ([Latest Changes](https://gi
- New "Explore" tab on player statistics, to explore darts thrown
- Support for `ANY` and `MASTER` outs for `x01` legs
- Simplified input for `x01` legs
- Ability to configure: "Announcement Volume", "Auto Busting" and "Auto Leg Finish" from frontend

#### Changed
- Updated to use `Node.js v18`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,57 @@ module.exports = {
onCreate(input) {
this.state = {
layouts: [ {id: "wide", name: "Wide"}, {id: "compact", name: "Compact"}, {id: "compact-large", name: "Compact (Large)"} ],
buttonLayout: "wide"
buttonLayout: "wide",
volume: 100,
confirmBusts: true,
autoFinishLegs: false,
autoFinishTime: 10
}
},
onMount() {
const buttonLayout = localStorage.get("button-layout");
if (buttonLayout) {
this.state.buttonLayout = buttonLayout
}

const volume = localStorage.get("volume");
if (volume) {
this.state.volume = Math.min(Math.max(parseInt(volume * 100), 0), 100);
}

const confirmBusts = localStorage.get("confirm-busts");
if (confirmBusts !== null) {
this.state.confirmBusts = confirmBusts === 'true';
}

const autoFinishLegs = localStorage.get("auto-finish-legs");
if (autoFinishLegs !== null) {
this.state.autoFinishLegs = autoFinishLegs === 'true';
}

const autoFinishTime = localStorage.get("auto-finish-time");
if (autoFinishTime !== null) {
this.state.autoFinishTime = parseInt(autoFinishTime, 10) || 10;
}
},
updateVolume(event, selected) {
this.state.volume = selected.value;
},
toggleConfirmBusts(event) {
this.state.confirmBusts = event.target.checked;
},
toggleAutoFinishLegs(event) {
this.state.autoFinishLegs = event.target.checked;
},
updateAutoFinishTime(event) {
this.state.autoFinishTime = parseInt(event.target.value, 10);
},
onSave() {
this.state.buttonLayout = document.getElementById("buttonLayout").value;
localStorage.set('button-layout', this.state.buttonLayout);
localStorage.set('confirm-busts', this.state.confirmBusts);
localStorage.set('auto-finish-legs', this.state.autoFinishLegs);
localStorage.set('auto-finish-time', this.state.autoFinishTime);
localStorage.set('volume', this.state.volume / 100);
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,51 @@
</div>
<div class="block-container-with-header">
<div class="form-group form-check">
<select id="buttonLayout" class="form-select" style="width: 100%" name="button-layout">
<for|layout| of=state.layouts>
<option style="text-transform: capitalize;" value=layout.id selected=(layout.id === state.buttonLayout)>${layout.name}</option>
</for>
</select>
<select id="buttonLayout" class="form-select" style="width: 100%" name="button-layout">
<for|layout| of=state.layouts>
<option style="text-transform: capitalize;" value=layout.id selected=(layout.id === state.buttonLayout)>${layout.name}</option>
</for>
</select>
</div>
</div>
</div>
<div>
<div class="block-container-header">
<span>Announcer Volume</span>
</div>
<div class="block-container-with-header">
<div class="form-group">
<label for="volumeSlider">Set Volume: <span id="volumeValue">${state.volume}</span>%</label>
<input type="range" id="volumeSlider" class="form-range" min="0" max="100" value=`${state.volume}` on-input("updateVolume")>
</div>
</div>
</div>
<div>
<div class="block-container-header">
<span>Leg Options</span>
</div>
<div class="block-container-with-header" style="display: flex; align-items: center; min-height: 81px;">
<div class="form-group form-check mr-2">
<input type="checkbox" id="autoFinishLegs" class="form-check-input" checked=state.autoFinishLegs on-change("toggleAutoFinishLegs")>
<label class="toggle-button" for="autoFinishLegs">
<span class="toggle-slider"></span>
</label>
<span style="margin-left: 8px;">Auto Finish Legs</span>
</div>
<if(state.autoFinishLegs)>
<div class="form-group" style="margin-left: 10px; margin-top: 5px; display: flex; align-items: center;">
<input type="number" id="autoFinishTime" class="form-control" min="0" value=state.autoFinishTime on-input("updateAutoFinishTime") style="width: 70px; margin-right: 5px;">
<span>seconds</span>
</div>
</if>
</div>
<div class="block-container-with-header" style="margin-top: -30px;">
<div class="form-group form-check">
<input type="checkbox" id="confirmBusts" class="form-check-input" checked=state.confirmBusts on-change("toggleConfirmBusts")>
<label class="toggle-button" for="confirmBusts">
<span class="toggle-slider"></span>
</label>
<span style="margin-left: 8px;">Confirm Busts?</span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.block-container-header > span {
font-weight: 700;
}

.form-check-input {
display: none;
}

.toggle-button {
width: 50px;
height: 24px;
background-color: #ccc;
border-radius: 12px;
position: relative;
cursor: pointer;
transition: background-color 0.3s;
margin-bottom: -5px;
}

.toggle-button .toggle-slider {
position: absolute;
top: 2px;
left: 2px;
width: 20px;
height: 20px;
background-color: white;
border-radius: 50%;
transition: transform 0.3s;
}

.form-check-input:checked + .toggle-button {
background-color: #4caf50;
}

.form-check-input:checked + .toggle-button .toggle-slider {
transform: translateX(26px);
}

.block-container-with-header {
display: flex;
align-items: center;
margin-bottom: 0px;
margin-top: 0px;
}

.form-group {
margin-bottom: 0;
}

.toggle-button {
display: inline-block;
}
2 changes: 1 addition & 1 deletion src/components/scorecard-header/scorecard-header.marko
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ const types = require("../scorecard/components/match_types");

<td>
<div style=`position: relative; opacity: ${state.player.lives !== null && state.player.lives <= 0 ? "35%" : "100%"};` class=(input.player.is_current_player ? "scorecard scorecard-active" : "scorecard scorecard-inactive")>
<div style=`position: relative; opacity: ${state.player.lives !== null && state.player.lives <= 0 ? "35%" : "100%"};` class=`${(input.player.is_current_player ? "scorecard scorecard-active" : "scorecard scorecard-inactive")} scorecard-header`>
<if(state.player.player.board_stream_url)>
<i style="position: absolute; top: 5px; right: 5px; cursor: pointer;" class="fas fa-video fa-2x" title="Toggle Camera" on-click("toggleCamera")></i>
</if>
Expand Down
21 changes: 19 additions & 2 deletions src/components/scorecard-header/scorecard-header.style.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*@media (max-width: 1340px) {
.scorecard-header {
overflow: hidden;
transform: scaleY(0.75);
transform-origin: top left;
margin-bottom: -40px !important;
}
.label-player-name {
font-size: 14pt;
}
.label-player-score {
font-size: 24pt;
}
}*/

table {
width: 100%;
table-layout: fixed;
Expand Down Expand Up @@ -35,7 +52,7 @@ table {
}

.label-player-name {
font-size: 10pt;
font-size: 18pt;
padding: 0px;
margin: 0px;
color: #ffffff;
Expand All @@ -50,7 +67,7 @@ table {
.label-player-score {
font-weight: 700;
padding: 10px 0px 0px 0px;
font-size: 40pt;
font-size: 32pt;
}

.player-legs {
Expand Down
39 changes: 21 additions & 18 deletions src/components/scorecard/components/x01.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const alertify = require("../../../util/alertify");
const localStorage = require("../../../util/localstorage");
const types = require("./match_types");

exports.removeLast = function(dart, external) {
Expand Down Expand Up @@ -66,26 +67,27 @@ exports.confirmThrow = function (external) {
const isBust = module.exports.isBust(this.state.player, dart, this.state.totalScore, this.state.leg);
if (isCheckout) {
submitting = true;
alertify.confirm('Leg will be finished.',
() => {
this.emit('leg-finished', true);
}, () => {
this.removeLast();
this.emit('leg-finished', false);
});
} else if (isBust) {
}
else if (isBust) {
submitting = true;
this.state.isBusted = true;
alertify.confirm('Player busted',
() => {
alertify.success('Player busted');
this.emit('player-busted', true);
},
() => {
this.removeLast();
this.state.isBusted = false;
this.emit('player-busted', false);
});
const isConfirmBust = localStorage.getBool('confirm-busts');

if (isConfirmBust) {
alertify.confirm('Player busted',
() => {
alertify.success('Player busted');
this.emit('player-busted', true);
},
() => {
this.removeLast();
this.state.isBusted = false;
this.emit('player-busted', false);
});
} else {
alertify.success('Player busted');
this.emit('player-busted', true);
}
}
if (!this.state.player.player.options || this.state.player.player.options.subtract_per_dart) {
this.state.player.current_score -= scored;
Expand All @@ -96,3 +98,4 @@ exports.confirmThrow = function (external) {
}
return submitting;
}

34 changes: 31 additions & 3 deletions src/components/scorecard/scorecard.component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const alertify = require("../../util/alertify");
const localStorage = require("../../util/localstorage");

const x01 = require("./components/x01");
const shootout = require("./components/shootout");
Expand Down Expand Up @@ -260,12 +261,39 @@ module.exports = {
},

confirmLegFinish() {
alertify.confirm('Leg will be finished.',
let countdown = localStorage.get('auto-finish-time') || 10;
let confirmed = false;

const okFunction = () => {
confirmed = true;
this.emit('leg-finished', true);
};

const confirmDialog = alertify.confirm(`Leg will be finished`,
okFunction,
() => {
this.emit('leg-finished', true);
}, () => {
this.removeLast();
this.emit('leg-finished', false);
}
);

const isAutoFinish = localStorage.getBool('auto-finish-legs');
if (isAutoFinish) {
confirmDialog.setContent(`Leg will be finished (<strong>${countdown}s</strong>)`);
const countdownInterval = setInterval(() => {
countdown--;
confirmDialog.setContent(`Leg will be finished (<strong>${countdown}s</strong>)`);

if (countdown <= 0) {
clearInterval(countdownInterval);
if (!confirmed) {
okFunction();
}
}
}, 1000);
confirmDialog.set('onclose', function() {
clearInterval(countdownInterval);
});
}
}
};
2 changes: 1 addition & 1 deletion src/util/alertify.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports.alert = (text, okFnc) => {
.show();
}
exports.confirm = (text, okFnc, cancelFnc) => {
bootstrap().confirm(text, okFnc, cancelFnc)
return bootstrap().confirm(text, okFnc, cancelFnc)
.setting({
title: TITLE,
defaultFocus: 'ok',
Expand Down
7 changes: 7 additions & 0 deletions src/util/localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ function getKey(key) {

exports.get = key => localStorage.getItem(getKey(key));
exports.getInt = key => parseInt(localStorage.getItem(getKey(key)));
exports.getBool = key => {
const item = localStorage.getItem(getKey(key));
if (!item) {
return false;
}
return item === 'true';
}
exports.set = (key, value) =>
localStorage.setItem(getKey(key), value);
exports.getKey = getKey;
Expand Down
7 changes: 6 additions & 1 deletion src/util/socket.io-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const io = require('socket.io-client');
const alertify = require('./alertify');
const speaker = require('./speaker');
const types = require('../components/scorecard/components/match_types');
const localStorage = require('./localstorage');

exports.connect = (url) => {
const socket = io(url);
Expand Down Expand Up @@ -89,13 +90,17 @@ exports.say = (data, thiz) => {
if (thiz.state.venueConfig) {
voice = thiz.state.venueConfig.tts_voice;
}
let volume = localStorage.get("volume");
volume = volume ? Math.min(Math.max(parseFloat(volume), 0.0), 1.0) : 1.0;

const oldPlayer = thiz.state.audioAnnouncer;
const isAudioAnnouncement = (oldPlayer.duration > 0 && !oldPlayer.paused) || (!isNaN(oldPlayer.duration) && !oldPlayer.ended && oldPlayer.paused);
if (data.audios) {
const audioPlayers = [ ];
for (const file of data.audios) {
audioPlayers.push(file.file ? new Audio(file.file) : speaker.getUtteranceWithVoice(file, voice));
const audioPlayer = file.file ? new Audio(file.file) : speaker.getUtteranceWithVoice(file, voice);
audioPlayer.volume = volume;
audioPlayers.push(audioPlayer);
}

for (let i = 0; i < audioPlayers.length; i++) {
Expand Down

0 comments on commit df912c8

Please sign in to comment.