From 6d866f8ba0cdbee13d165ce14e680f76c4d6c4e5 Mon Sep 17 00:00:00 2001 From: TitanPlayz <118145727+TitanPlayz100@users.noreply.github.com> Date: Thu, 6 Jun 2024 23:04:42 +1000 Subject: [PATCH] small changes - game smoother, changing number boxes is nicer, can click number next to ranges to change them --- .gitignore | 17 +---------------- README.md | 16 +++++++--------- code.js | 39 +++++++++++++++++++++++++++------------ index.html | 23 +++++++++++++---------- style.css | 14 ++++++++++++++ tauri-build/build.bat | 10 +++++----- 6 files changed, 67 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 1f70b91..f55b329 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,3 @@ -# Logs -logs -*.log -npm-debug.log* - src-temp/ - node_modules/ -dist/ -out/ -target/ -gen/schemas - -dist-ssr -*.local - -# Editor directories and files -.vscode/ \ No newline at end of file +target/ \ No newline at end of file diff --git a/README.md b/README.md index 655a6f1..d042e8c 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,16 @@ Finally a readme Hosted on github pages [here](https://titanplayz100.github.io/teti/) -You can literally just open up [index.html](index.html) in a browser as well to play -*** -You can build this yourself or download the installer from the latest release +You can literally just open up [index.html](index.html) in a browser as well to play -### Self Build With Tauri +## Build With Tauri +Build this yourself or download the installer from the latest release -> You need rust installed +> You need rust installed > https://tauri.app/v1/guides/building/ -To build -- enter tauri-build directory +- open **tauri-build** directory - `npm run build` or run build.bat -should create a file at /target/release/teti.exe -You can delete /src afterwards \ No newline at end of file +Creates exe at **/target/release/teti.exe** +You can delete **/src-temp** \ No newline at end of file diff --git a/code.js b/code.js index 5439247..8e368ea 100644 --- a/code.js +++ b/code.js @@ -683,7 +683,7 @@ function renderToCanvas(cntx, canvas, grid, yPosChange, [dx, dy] = [0, 0]) { function renderingLoop() { renderToCanvas(ctx, canvasField, boardState, 39) if (boardAlphaChange != 0) { updateNext(); updateHold(); } - requestAnimationFrame(renderingLoop); + setTimeout(()=>requestAnimationFrame(renderingLoop), 1); } //#region Menus @@ -702,7 +702,7 @@ function openModal(id) { setting.value = newValue if (setting.classList[1] == 'keybind') setting.textContent = newValue; if (setting.classList[1] == 'check') setting.checked = (newValue); - if (setting.classList[1] == 'range') sliderChange(setting); + if (setting.classList[1] == 'range') {sliderChange(setting); rangeClickListener(setting)}; }); const gamemodeSelect = [...document.getElementsByClassName('gamemodeSelect')] gamemodeSelect.forEach((setting) => { @@ -721,27 +721,32 @@ function closeModal(id) { [...document.getElementsByClassName('option')] .filter((item) => item.parentElement.parentElement.id == id) .forEach((setting) => { - const settingid = setting.id + const settingid = setting.id, type = setting.classList[1]; + if (type == 'number' && setting.value == '') setting.value = currentRangeOption.min; eval(settingGroup)[settingid] = - setting.classList[1] == 'check' ? setting.checked : - setting.classList[1] == 'keybind' ? setting.textContent : + type == 'check' ? setting.checked : + type == 'keybind' ? setting.textContent : setting.classList[2] == 'exp' ? toExpValue(setting.value) : setting.value; - if (setting.id == 'nextQueue') { + if (settingid == 'nextQueue') { nextPieces[0] = setting.value.split(' ').filter((p) => pieceNames.includes(p)) shuffleRemainingPieces(); updateNext(); } - if (setting.id == 'holdQueue') { + if (settingid == 'holdQueue') { const filtp = [setting.value].filter((p) => pieceNames.includes(p)) holdPiece = { piece: getPiece(filtp), occured: false }; updateHold(); } - + if (id == 'changeRangeValue') { + currentRangeOption.value = document.getElementById('rangeValue').value; + sliderChange(currentRangeOption); + } }) closeDialog(document.getElementById(id)); saveSettings(); if (id == 'displaySettingsDialog') renderStyles(); if (id == 'gameSettingsDialog' || id == 'gamemodeDialog' || id == 'gameEnd') startGame(); + if (id == 'changeRangeValue') isDialogOpen = true; } function closeDialog(element) { @@ -763,6 +768,14 @@ function sliderChange(el) { el.parentElement.children[0].textContent = `${text}: ${value}` } +function rangeClickListener(el) { + el.parentElement.children[0].addEventListener('click', () => { + currentRangeOption = el; + openModal('changeRangeValue') + document.getElementById('rangeValue').value = el.value; + }) +} + function buttonInput(el) { document.getElementById('frontdrop').showModal(); bindingKey = el.id; } function setKeybind(key) { @@ -830,13 +843,15 @@ function resetSettings(settingGroup) { } function toggleDialog() { - if (isDialogOpen) { closeDialog(document.querySelectorAll("dialog[open]")[0]) } + if (isDialogOpen) { document.querySelectorAll("dialog[open]").forEach(e=>closeDialog(e)) } else { openModal('settingsPanel'); } } -function checkValue(el) { - if (el.value < currentRangeOption.min) el.value = currentRangeOption.min; - if (el.value > currentRangeOption.max) el.value = currentRangeOption.max; +function checkValue(el, el2 = currentRangeOption) { + currentRangeOption = el2; + if (el.value == '') return; + if (el.value < Number(el2.min)) el.value = Number(el2.min); + if (el.value > Number(el2.max)) el.value = Number(el2.max); } // misc functions diff --git a/index.html b/index.html index dd83e05..59ec654 100644 --- a/index.html +++ b/index.html @@ -117,13 +117,15 @@