From 4d92455bf360356d1ad9441be733176c2206770b Mon Sep 17 00:00:00 2001 From: Sarahtonin Date: Mon, 31 Aug 2026 16:43:13 +0200 Subject: [PATCH] BIG heap of bugfixes. Deselecting tools, profile colour picker, player name colour contrast, mutation pricing (not really a bug, but still an issue). Signed-off-by: Sarahtonin --- Scripts/Garden/Economy.js | 6 +- Scripts/Garden/Garden.js | 21 ++++++- Scripts/Garden/Leaderboard.js | 12 ++-- Scripts/Garden/Profile.js | 48 +++++++++++----- Scripts/Garden/Users.js | 103 +++++++++++++++++++++++++++++++--- Styles/Style.css | 39 ++++++------- 6 files changed, 174 insertions(+), 55 deletions(-) diff --git a/Scripts/Garden/Economy.js b/Scripts/Garden/Economy.js index edd2860..c4083e0 100644 --- a/Scripts/Garden/Economy.js +++ b/Scripts/Garden/Economy.js @@ -1,4 +1,4 @@ -const MutationTimeFeePerHour = 10; +const MutationTimeFeePerMinute = 15; const PlantKeysById = new Map(); const PlantsById = new Map(); @@ -553,8 +553,8 @@ function GetMutationTimeFee( return Math.ceil( MutationTime / - 3600000 * - MutationTimeFeePerHour + 60000 * + MutationTimeFeePerMinute ); } diff --git a/Scripts/Garden/Garden.js b/Scripts/Garden/Garden.js index 77c93a9..cfb8f24 100644 --- a/Scripts/Garden/Garden.js +++ b/Scripts/Garden/Garden.js @@ -59,8 +59,16 @@ function BindGardenTools() { ShovelButton.addEventListener( "click", () => { - SelectedGardenTool = - "Shovel"; + if ( + SelectedGardenTool === + "Shovel" + ) { + SelectedGardenTool = + null; + } else { + SelectedGardenTool = + "Shovel"; + } RenderSeeds(); RenderTools(); @@ -142,6 +150,15 @@ function EnsureSelectedSeed() { if (SeedIds.length > 0) { SelectedSeedId = SeedIds[0]; + + return; + } + + if ( + SelectedGardenTool === + "Seed" + ) { + SelectedGardenTool = null; } } diff --git a/Scripts/Garden/Leaderboard.js b/Scripts/Garden/Leaderboard.js index 9d8d08b..231e168 100644 --- a/Scripts/Garden/Leaderboard.js +++ b/Scripts/Garden/Leaderboard.js @@ -141,14 +141,12 @@ async function RenderLeaderboard() { Username.textContent = Player.Username; - if ( - Player.Colour !== null - ) { - Username.style.color = - Player.Colour; - } + ApplyPlayerColour( + Username, + Player.Colour + ); - Dew.textContent = + Dew.textContent = Player.Dew.toLocaleString(); diff --git a/Scripts/Garden/Profile.js b/Scripts/Garden/Profile.js index 8303140..42909af 100644 --- a/Scripts/Garden/Profile.js +++ b/Scripts/Garden/Profile.js @@ -56,8 +56,10 @@ async function StartProfile() { ColourInput.addEventListener( "input", () => { - ColourPreview.style.color = - ColourInput.value; + ApplyPlayerColour( + ColourPreview, + ColourInput.value + ); } ); @@ -115,15 +117,24 @@ async function RenderProfilePlayer() { } - if ( - Profile.Colour !== null - ) { - ColourInput.value = - Profile.Colour; + const ProfileColour = + IsValidPlayerColour( + Profile.Colour + ) + ? Profile.Colour + : DefaultPlayerColour; - ColourPreview.style.color = - Profile.Colour; - } + ColourInput.value = + ProfileColour; + + ApplyPlayerColour( + ColourPreview, + IsValidPlayerColour( + Profile.Colour + ) + ? Profile.Colour + : null + ); UsernameMessage.textContent = @@ -244,8 +255,14 @@ async function SubmitProfileColour( } - Preview.style.color = - Result.Colour; + ApplyPlayerColour( + Preview, + IsValidPlayerColour( + Result.Colour + ) + ? Result.Colour + : Input.value + ); Message.textContent = "Colour saved."; @@ -294,10 +311,11 @@ async function ResetProfileColour() { Input.value = - "#cdd6f4"; + DefaultPlayerColour; - Preview.style.removeProperty( - "color" + ApplyPlayerColour( + Preview, + null ); Message.textContent = diff --git a/Scripts/Garden/Users.js b/Scripts/Garden/Users.js index 1ad0245..788d1f7 100644 --- a/Scripts/Garden/Users.js +++ b/Scripts/Garden/Users.js @@ -1,3 +1,89 @@ +const DefaultPlayerColour = "#cdd6f4"; + + +function IsValidPlayerColour( + Colour +) { + return ( + typeof Colour === "string" && + /^#[0-9A-Fa-f]{6}$/.test( + Colour + ) + ); +} + + +function GetPlayerColourOutline( + Colour +) { + const Red = parseInt( + Colour.slice(1, 3), + 16 + ); + + const Green = parseInt( + Colour.slice(3, 5), + 16 + ); + + const Blue = parseInt( + Colour.slice(5, 7), + 16 + ); + + const Brightness = + ( + Red * 299 + + Green * 587 + + Blue * 114 + ) / 1000; + + return Brightness < 150 + ? "var(--Text)" + : "var(--Crust)"; +} + + +function ApplyPlayerColour( + Element, + Colour +) { + Element.style.removeProperty( + "color" + ); + + Element.style.removeProperty( + "text-shadow" + ); + + if ( + !IsValidPlayerColour( + Colour + ) + ) { + return; + } + + const Outline = + GetPlayerColourOutline( + Colour + ); + + Element.style.color = + Colour; + + Element.style.textShadow = + `-1px -1px 0 ${Outline}, ` + + `0 -1px 0 ${Outline}, ` + + `1px -1px 0 ${Outline}, ` + + `-1px 0 0 ${Outline}, ` + + `1px 0 0 ${Outline}, ` + + `-1px 1px 0 ${Outline}, ` + + `0 1px 0 ${Outline}, ` + + `1px 1px 0 ${Outline}`; +} + + async function GetProfile() { const Response = await fetch( ApiUrl + "/Profile.php", @@ -89,14 +175,12 @@ async function RenderUser() { UsernameDisplay.textContent = Profile.Username; - if ( - Profile.Colour !== null - ) { - UsernameDisplay.style.color = - Profile.Colour; - } + ApplyPlayerColour( + UsernameDisplay, + Profile.Colour + ); - UsernameForm.hidden = true; + UsernameForm.hidden = true; return; } @@ -104,6 +188,11 @@ async function RenderUser() { UsernameDisplay.textContent = "Unnamed"; + ApplyPlayerColour( + UsernameDisplay, + null + ); + UsernameForm.hidden = false; } diff --git a/Styles/Style.css b/Styles/Style.css index 1218f10..c2b7b3b 100644 --- a/Styles/Style.css +++ b/Styles/Style.css @@ -7,22 +7,22 @@ :root, :root[data-palette="CatppuccinMocha"] { - --Rosewater: #f5e0dc; + --Rosewater:#f5e0dc; --Flamingo: #f2cdcd; - --Pink: #f5c2e7; - --Mauve: #cba6f7; - --Red: #f38ba8; - --Maroon: #eba0ac; - --Peach: #fab387; - --Yellow: #f9e2af; - --Green: #a6e3a1; - --Teal: #94e2d5; - --Sky: #89dceb; + --Pink: #f5c2e7; + --Mauve: #cba6f7; + --Red: #f38ba8; + --Maroon: #eba0ac; + --Peach: #fab387; + --Yellow: #f9e2af; + --Green: #a6e3a1; + --Teal: #94e2d5; + --Sky: #89dceb; --Sapphire: #74c7ec; - --Blue: #89b4fa; + --Blue: #89b4fa; --Lavender: #b4befe; - --Text: #cdd6f4; + --Text: #cdd6f4; --Subtext1: #bac2de; --Subtext0: #a6adc8; --Overlay2: #9399b2; @@ -31,9 +31,9 @@ --Surface2: #585b70; --Surface1: #45475a; --Surface0: #313244; - --Base: #1e1e2e; - --Mantle: #181825; - --Crust: #11111b; + --Base: #1e1e2e; + --Mantle: #181825; + --Crust: #11111b; } html { @@ -773,18 +773,15 @@ select { color: var(--Green); } -.LeaderboardRank1 .LeaderboardRank, -.LeaderboardRank1 .LeaderboardUsername { +.LeaderboardRank1 .LeaderboardRank { color: var(--Yellow); } -.LeaderboardRank2 .LeaderboardRank, -.LeaderboardRank2 .LeaderboardUsername { +.LeaderboardRank2 .LeaderboardRank { color: var(--Text); } -.LeaderboardRank3 .LeaderboardRank, -.LeaderboardRank3 .LeaderboardUsername { +.LeaderboardRank3 .LeaderboardRank { color: var(--Peach); }