improved tips code quality
This commit is contained in:
+37
-3
@@ -1,3 +1,10 @@
|
|||||||
|
const PAGES = {
|
||||||
|
null: -1,
|
||||||
|
SYNTHWAVE: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
let CURRENT_PAGE = PAGES.null
|
||||||
|
|
||||||
let isAnimating = true
|
let isAnimating = true
|
||||||
|
|
||||||
function randomFloat(min, max) {
|
function randomFloat(min, max) {
|
||||||
@@ -19,9 +26,9 @@ function clampNearest(n, mul) {
|
|||||||
if(n > 0)
|
if(n > 0)
|
||||||
return Math.ceil(n / mul) * mul;
|
return Math.ceil(n / mul) * mul;
|
||||||
else if( n < 0)
|
else if( n < 0)
|
||||||
return Math.floor(n / mul) * mul;
|
return Math.floor(n / mul) * mul;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -78,4 +85,31 @@ function pauseAnimBtn(state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
localStorage["isAnimating"] = state
|
localStorage["isAnimating"] = state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", async function() {
|
||||||
|
startLoadingScreen()
|
||||||
|
|
||||||
|
setLoadingProgress("Fetching tips...")
|
||||||
|
|
||||||
|
await loadTips()
|
||||||
|
|
||||||
|
newTip()
|
||||||
|
|
||||||
|
setLoadingProgress("Calculating pixel density...")
|
||||||
|
calcPixelDensity()
|
||||||
|
|
||||||
|
switch (CURRENT_PAGE) {
|
||||||
|
case (PAGES.SYNTHWAVE): loadingScreenSynthwave()
|
||||||
|
}
|
||||||
|
|
||||||
|
pauseAnimBtn(localStorage["isAnimating"] || "true")
|
||||||
|
|
||||||
|
if (showLoading != "true") {
|
||||||
|
removeLoadingScreen()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setLoadingProgress("Cleaning up...")
|
||||||
|
}
|
||||||
|
}, false)
|
||||||
+6
-2
@@ -67,12 +67,16 @@
|
|||||||
<p id="loadingText">Loading...<br>Loading files...<br><br>Tip: Tip loading...</p>
|
<p id="loadingText">Loading...<br>Loading files...<br><br>Tip: Tip loading...</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- libs -->
|
||||||
<script src="./globalScript.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.8.1/gl-matrix-min.js"></script>
|
||||||
|
|
||||||
|
<!-- global -->
|
||||||
|
<script src="./globalScript.js"></script> <!-- compact the other global scripts into this global script -->
|
||||||
<script src="./pxDensity.js"></script>
|
<script src="./pxDensity.js"></script>
|
||||||
<script src="/loadingScreen.js"></script>
|
<script src="/loadingScreen.js"></script>
|
||||||
<script src="/screenTransition.js"></script>
|
<script src="/screenTransition.js"></script>
|
||||||
|
|
||||||
|
<!-- local -->
|
||||||
<script src="script.js"></script>
|
<script src="script.js"></script>
|
||||||
<script src="synthwaveEffect.js"></script>
|
<script src="synthwaveEffect.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
+6
-14
@@ -4,25 +4,17 @@ let loadingScreenProgress = document.getElementById("loadingText")
|
|||||||
let loadingScreenEl = document.getElementById("loadingScreen")
|
let loadingScreenEl = document.getElementById("loadingScreen")
|
||||||
|
|
||||||
|
|
||||||
let tipsJson;
|
let tipsJson
|
||||||
|
|
||||||
(function loadTipsSync() {
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("GET", "./loadingScreenTips.json", false)
|
|
||||||
xhr.send(null)
|
|
||||||
|
|
||||||
if (xhr.status === 200) {
|
async function loadTips() {
|
||||||
tipsJson = JSON.parse(xhr.responseText)
|
let tipsText = await fetch("./loadingScreenTips.json").then(response => response.text())
|
||||||
} else {
|
tipsJson = JSON.parse(tipsText)
|
||||||
console.error("Failed to load tips:", xhr.status, xhr.statusText)
|
}
|
||||||
tipsJson = []
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
console.log(tipsJson)
|
|
||||||
|
|
||||||
let selectedTip = tipsJson[randomIntFrom0(tipsJson.length)]
|
|
||||||
const showLoading = localStorage["showLoading"] || "true"
|
const showLoading = localStorage["showLoading"] || "true"
|
||||||
|
let selectedTip = "undefined"
|
||||||
|
|
||||||
|
|
||||||
function newTip() {
|
function newTip() {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"Bad at a game? Just press the \"get good at games\" button!",
|
"Bad at a game? Just press the \"get good at games\" button!",
|
||||||
"I AM NOT A FEMBOY NOR GAY. (I support though :thumbsup:)",
|
"I AM NOT A FEMBOY NOR GAY. (I support though :thumbsup:)",
|
||||||
"You should listen to that song that goes \"do do do do do do do do do.\"",
|
"You should listen to that song that goes \"do do do do do do do do do.\"",
|
||||||
"(Almost) Every pixel in this website's pixel art is positioned pixel perfect.",
|
"(Almost) Every pixel in this website's pixel art is positioned pixel perfectly.",
|
||||||
"Shouldn't I be talking about tips?",
|
"Shouldn't I be talking about tips?",
|
||||||
"Did you know that... uh... hold on let me think... I don't know, I forgot.",
|
"Did you know that... uh... hold on let me think... I don't know, I forgot.",
|
||||||
"This tip is very helpful.",
|
"This tip is very helpful.",
|
||||||
|
|||||||
@@ -1,21 +1,9 @@
|
|||||||
document.addEventListener("DOMContentLoaded", function() {
|
CURRENT_PAGE = PAGES.SYNTHWAVE
|
||||||
startLoadingScreen()
|
|
||||||
|
|
||||||
setLoadingProgress("Calculating pixel density...")
|
function loadingScreenSynthwave() {
|
||||||
calcPixelDensity()
|
|
||||||
|
|
||||||
setLoadingProgress("Adding stars...")
|
setLoadingProgress("Adding stars...")
|
||||||
addStars()
|
addStars()
|
||||||
|
}
|
||||||
pauseAnimBtn(localStorage["isAnimating"] || "true")
|
|
||||||
|
|
||||||
if (showLoading != "true") {
|
|
||||||
removeLoadingScreen()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setLoadingProgress("Cleaning up...")
|
|
||||||
}
|
|
||||||
}, false)
|
|
||||||
|
|
||||||
|
|
||||||
function addStars() {
|
function addStars() {
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ body {
|
|||||||
}
|
}
|
||||||
#synthwaveCanvas {
|
#synthwaveCanvas {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: round(0%, var(--pxDensityPx));
|
top: round(0%, var(--pxDensityPx));
|
||||||
left: round(0%, var(--pxDensityPx));
|
left: round(0%, var(--pxDensityPx));
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user