fix autorepeat and volume save

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

View File

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

View File

@ -327,10 +327,10 @@ class Tetromino {
matrix.drawPiece()
return true
} else if (!hardDropped && translation == TRANSLATION.DOWN) {
this.locked = true
if (!scheduler.timeoutTasks.has(lockDown))
scheduler.setTimeout(lockDown, stats.lockDelay)
matrix.drawPiece()
this.locked = true
if (!scheduler.timeoutTasks.has(lockDown))
scheduler.setTimeout(lockDown, stats.lockDelay)
matrix.drawPiece()
}
}

View File

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