fix autorepeat and volume save

This commit is contained in:
Adrien MALINGREY 2023-12-11 23:14:26 +01:00
parent 6062f6895b
commit 6d95acddd2
6 changed files with 38 additions and 36 deletions

View File

@ -82,8 +82,9 @@
} }
.ghost.mino { .ghost.mino {
margin: 1px;
background: rgba(0, 0, 0, 10%) !important; background: rgba(0, 0, 0, 10%) !important;
border: 2px solid rgba(150, 150, 150, 33%) !important; border: 3px solid #646464 !important;
box-shadow: box-shadow:
-2px -2px 6px rgba(128, 128, 128, 25%), -2px -2px 6px rgba(128, 128, 128, 25%),
-2px 2px 6px rgba(128, 128, 128, 25%), -2px 2px 6px rgba(128, 128, 128, 25%),

View File

@ -21,6 +21,11 @@ body {
text-shadow: 0 0 8px var(--bs-light); text-shadow: 0 0 8px var(--bs-light);
} }
#statsTable td,
#statsModal td {
text-align: right;
}
.minoes-table { .minoes-table {
--piece-column: 0; --piece-column: 0;
--piece-row : 0; --piece-row : 0;

View File

@ -31,8 +31,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form name="settingsForm" class="needs-validation" novalidate> <form name="settingsForm" class="needs-validation" novalidate>
<fieldset id="keyBindFielset" class="row g-2 mb-3 align-items-center text-center"> <fieldset id="keyBindFielset" class="row g-2 mb-3 align-items-center text-center"><legend class="text-start">Commandes</legend>
<legend class="text-start">Commandes</legend>
<label for="moveLeftInput" title="Gauche" class="col-2 col-form-label d-flex align-items-center justify-content-center"><i class="bi bi-arrow-left"></i></label> <label for="moveLeftInput" title="Gauche" class="col-2 col-form-label d-flex align-items-center justify-content-center"><i class="bi bi-arrow-left"></i></label>
<div class="col-4"><input name="moveLeft" id="moveLeftInput" type="text" class="form-control text-center btn btn-dark" value="←" onclick="changeKey(this)" placeholder="Touche ?" title="Modifier la touche" required></div> <div class="col-4"><input name="moveLeft" id="moveLeftInput" type="text" class="form-control text-center btn btn-dark" value="←" onclick="changeKey(this)" placeholder="Touche ?" title="Modifier la touche" required></div>
<div class="col-4"><input name="moveRight" id="moveRightInput" type="text" class="form-control text-center btn btn-dark" value="→" onclick="changeKey(this)" placeholder="Touche ?" title="Modifier la touche" required></div> <div class="col-4"><input name="moveRight" id="moveRightInput" type="text" class="form-control text-center btn btn-dark" value="→" onclick="changeKey(this)" placeholder="Touche ?" title="Modifier la touche" required></div>
@ -50,15 +49,13 @@
<div class="col-4"><input name="pause" id="pauseInput" type="text" class="form-control text-center btn btn-dark" value="Échap." onclick="changeKey(this)" placeholder="Touche ?" title="Modifier la touche" required></div> <div class="col-4"><input name="pause" id="pauseInput" type="text" class="form-control text-center btn btn-dark" value="Échap." onclick="changeKey(this)" placeholder="Touche ?" title="Modifier la touche" required></div>
<label for="pauseInput" title="Pause" class="col-2 col-form-label d-flex align-items-center justify-content-center"><i class="bi bi-pause"></i></label> <label for="pauseInput" title="Pause" class="col-2 col-form-label d-flex align-items-center justify-content-center"><i class="bi bi-pause"></i></label>
</fieldset> </fieldset>
<fieldset id="autorepeatFieldset" class="row g-2 mb-3 align-items-center text-center"> <fieldset id="autorepeatFieldset" class="row g-2 mb-3 align-items-center text-center"><legend class="text-start">Répétition automatique</legend>
<legend class="text-start">Répétition automatique</legend>
<label for="arrInput" class="col-2 col-form-label"><abbr title="Automatic Repeat Rate : période de répétition de l'action">ARR</abbr></label> <label for="arrInput" class="col-2 col-form-label"><abbr title="Automatic Repeat Rate : période de répétition de l'action">ARR</abbr></label>
<div class="col-4"><div class="input-group"><input name="arr" id="arrInput" type="number" class="form-control text-center" value="50" min="2" max="200" step="1"><div class="input-group-text">ms</div></div></div> <div class="col-4"><div class="input-group"><input name="arr" id="arrInput" type="number" class="form-control text-center" value="50" min="2" max="200" step="1"><div class="input-group-text">ms</div></div></div>
<div class="col-4"><div class="input-group"><input name="das" id="dasInput" type="number" class="form-control text-center" value="300" min="100" max="500" step="5"><div class="input-group-text">ms</div></div></div> <div class="col-4"><div class="input-group"><input name="das" id="dasInput" type="number" class="form-control text-center" value="300" min="100" max="500" step="5"><div class="input-group-text">ms</div></div></div>
<label for="dasInput" class="col-2 col-form-label"><abbr title="Delayed AutoShift : délai initial avant répétition">DAS</abbr></label> <label for="dasInput" class="col-2 col-form-label"><abbr title="Delayed AutoShift : délai initial avant répétition">DAS</abbr></label>
</fieldset> </fieldset>
<fieldset class="row g-2 mb-3 align-items-center text-center"> <fieldset class="row g-2 mb-3 align-items-center text-center"><legend class="text-start">Interface</legend>
<legend class="text-start">Interface</legend>
<label for="stylesheetSelect" class="col-2 col-form-label">Thème</label> <label for="stylesheetSelect" class="col-2 col-form-label">Thème</label>
<div class="col-4"><select name="stylesheet" id="stylesheetSelect" class="form-select" oninput="selectedStyleSheet.href = this.value"> <div class="col-4"><select name="stylesheet" id="stylesheetSelect" class="form-select" oninput="selectedStyleSheet.href = this.value">
<option value="css/classic.css" selected>Classique</option> <option value="css/classic.css" selected>Classique</option>
@ -67,11 +64,10 @@
<option value="css/electro.css">Électro</option> <option value="css/electro.css">Électro</option>
<option value="css/retro.css">Rétro</option> <option value="css/retro.css">Rétro</option>
</select></div> </select></div>
<div class="col-4 d-flex align-items-baseline"><input id="sfxVolumeRange" class="form-range" type="range" min="0" max="1" step="any" value="0.7"></div> <div class="col-4 d-flex align-items-baseline"><input name="sfxVolumeRange" id="sfxVolumeRange" class="form-range" type="range" min="0" max="1" step="any" value="0.7"></div>
<label for="sfxVolumeRange" class="col-2 col-form-label">Volume</label> <label for="sfxVolumeRange" class="col-2 col-form-label">Volume</label>
</fieldset> </fieldset>
<fieldset class="row g-2 mb-3 align-items-center text-center"> <fieldset class="row g-2 mb-3 align-items-center text-center"><legend class="text-start">Partie</legend>
<legend class="text-start">Partie</legend>
<label for="levelInput" class="col-2 col-form-label text-center">Niveau</label> <label for="levelInput" class="col-2 col-form-label text-center">Niveau</label>
<div class="col-4"> <div class="col-4">
<input name="startLevel" id="levelInput" type="number" class="form-control text-center" value="1" min="1" max="15"> <input name="startLevel" id="levelInput" type="number" class="form-control text-center" value="1" min="1" max="15">

View File

@ -122,7 +122,7 @@ let playerActions = {
playSound(hardDropSound) playSound(hardDropSound)
while (matrix.piece.move(TRANSLATION.DOWN, ROTATION.NONE, true)) stats.score += 2 while (matrix.piece.move(TRANSLATION.DOWN, ROTATION.NONE, true)) stats.score += 2
matrixCard.classList.add("hard-dropped-table-animation") matrixCard.classList.add("hard-dropped-table-animation")
lockDown(true) lockDown()
return true return true
}, },
@ -162,7 +162,7 @@ function onkeydown(event) {
if (action()) { if (action()) {
lastActionSucceded = true lastActionSucceded = true
} else if (lastActionSucceded || !(action in REPEATABLE_ACTIONS)) { } else if (lastActionSucceded || !(action in REPEATABLE_ACTIONS)) {
wallSound.play() playSound(wallSound)
lastActionSucceded = false lastActionSucceded = false
} }
if (REPEATABLE_ACTIONS.includes(action)) { if (REPEATABLE_ACTIONS.includes(action)) {
@ -189,7 +189,7 @@ function autorepeat() {
if (actionsQueue[0]()) { if (actionsQueue[0]()) {
lastActionSucceded = true lastActionSucceded = true
} else if (lastActionSucceded) { } else if (lastActionSucceded) {
wallSound.play() playSound(wallSound)
lastActionSucceded = false lastActionSucceded = false
} }
} }
@ -203,9 +203,12 @@ function onkeyup(event) {
action = settings.keyBind[event.key] action = settings.keyBind[event.key]
if (actionsQueue.includes(action)) { if (actionsQueue.includes(action)) {
actionsQueue.splice(actionsQueue.indexOf(action), 1) actionsQueue.splice(actionsQueue.indexOf(action), 1)
if (!actionsQueue.length) {
scheduler.clearTimeout(repeat) scheduler.clearTimeout(repeat)
scheduler.clearInterval(autorepeat) scheduler.clearInterval(autorepeat)
if (actionsQueue.length) {
if (action == playerActions.softDrop) scheduler.setInterval(autorepeat, settings.fallPeriod/20)
else scheduler.setTimeout(repeat, settings.das)
} else {
matrix.drawPiece() matrix.drawPiece()
} }
} }
@ -216,15 +219,12 @@ function fall() {
matrix.piece.move(TRANSLATION.DOWN) matrix.piece.move(TRANSLATION.DOWN)
} }
function lockDown(hardDropped=false) { function lockDown() {
scheduler.clearTimeout(lockDown) scheduler.clearTimeout(lockDown)
scheduler.clearInterval(fall) scheduler.clearInterval(fall)
if (lastActionSucceded && !hardDropped) playSound(wallSound)
if (matrix.lock()) { if (matrix.lock()) {
let tSpin = matrix.piece.tSpin stats.lockDown(matrix.piece.tSpin, matrix.clearLines())
let nbClearedLines = matrix.clearLines()
stats.lockDown(nbClearedLines, tSpin)
generate() generate()
} else { } else {

View File

@ -194,7 +194,7 @@ class Stats {
return new Date() - this.startTime return new Date() - this.startTime
} }
lockDown(nbClearedLines, tSpin) { lockDown(tSpin, nbClearedLines) {
this.totalClearedLines += nbClearedLines this.totalClearedLines += nbClearedLines
if (nbClearedLines == 4) this.nbQuatuors++ if (nbClearedLines == 4) this.nbQuatuors++
if (tSpin == T_SPIN.T_SPIN) this.nbTSpin++ if (tSpin == T_SPIN.T_SPIN) this.nbTSpin++