From 2fe5171450723758d07cd6691f250530767e6089 Mon Sep 17 00:00:00 2001 From: Sarahtonin Date: Sun, 30 Aug 2026 21:58:38 +0200 Subject: [PATCH] Added player colour choosing. I HOPE. Signed-off-by: Sarahtonin --- Pages/Profile.php | 41 ++++++- Scripts/Garden/Leaderboard.js | 9 +- Scripts/Garden/Profile.js | 195 ++++++++++++++++++++++++++++++++-- Scripts/Garden/Users.js | 36 ++++++- Styles/Style.css | 22 ++++ 5 files changed, 290 insertions(+), 13 deletions(-) diff --git a/Pages/Profile.php b/Pages/Profile.php index a9388a7..ac4050c 100644 --- a/Pages/Profile.php +++ b/Pages/Profile.php @@ -66,8 +66,47 @@ $SubNavbarCurrent = "Player"; class="ProfileMessage" >

- +
+ + +
+ + + + Preview + + + + + +
+ +

+
+
{ + ColourPreview.style.color = + ColourInput.value; + } + ); + + ResetColourButton.addEventListener( + "click", + ResetProfileColour + ); } -async function RenderProfileUsername() { - const Input = +async function RenderProfilePlayer() { + const UsernameInput = document.getElementById( "ProfileUsernameInput" ); - const Message = + const ColourInput = + document.getElementById( + "ProfileColourInput" + ); + + const ColourPreview = + document.getElementById( + "ProfileColourPreview" + ); + + const UsernameMessage = document.getElementById( "ProfileUsernameMessage" ); @@ -53,22 +100,42 @@ async function RenderProfileUsername() { ); } + if ( Profile.Username !== null ) { - Input.value = + UsernameInput.value = Profile.Username; + + ColourPreview.textContent = + Profile.Username; + } else { + ColourPreview.textContent = + "Preview"; } - Message.textContent = ""; + + if ( + Profile.Colour !== null + ) { + ColourInput.value = + Profile.Colour; + + ColourPreview.style.color = + Profile.Colour; + } + + + UsernameMessage.textContent = + ""; } catch (Error) { console.error( - "Couldn't load username:", + "Couldn't load profile:", Error ); - Message.textContent = - "Couldn't load username."; + UsernameMessage.textContent = + "Couldn't load profile."; } } @@ -137,6 +204,114 @@ async function SubmitProfileUsername( } } +async function SubmitProfileColour( + Event +) { + Event.preventDefault(); + + const Input = + document.getElementById( + "ProfileColourInput" + ); + + const Preview = + document.getElementById( + "ProfileColourPreview" + ); + + const Message = + document.getElementById( + "ProfileColourMessage" + ); + + + Message.textContent = + "Saving..."; + + + try { + const Result = + await SetColour( + Input.value + ); + + if (!Result.Success) { + Message.textContent = + Result.Error ?? + "Couldn't save colour."; + + return; + } + + + Preview.style.color = + Result.Colour; + + Message.textContent = + "Colour saved."; + } catch (Error) { + console.error( + "Couldn't save colour:", + Error + ); + + Message.textContent = + "Couldn't save colour."; + } +} + + +async function ResetProfileColour() { + const Input = + document.getElementById( + "ProfileColourInput" + ); + + const Preview = + document.getElementById( + "ProfileColourPreview" + ); + + const Message = + document.getElementById( + "ProfileColourMessage" + ); + + + try { + const Result = + await SetColour( + null + ); + + if (!Result.Success) { + Message.textContent = + Result.Error ?? + "Couldn't reset colour."; + + return; + } + + + Input.value = + "#cdd6f4"; + + Preview.style.removeProperty( + "color" + ); + + Message.textContent = + "Colour reset."; + } catch (Error) { + console.error( + "Couldn't reset colour:", + Error + ); + + Message.textContent = + "Couldn't reset colour."; + } +} function RenderProfileStatistics() { const CurrentDew = diff --git a/Scripts/Garden/Users.js b/Scripts/Garden/Users.js index 4329886..1ad0245 100644 --- a/Scripts/Garden/Users.js +++ b/Scripts/Garden/Users.js @@ -40,6 +40,33 @@ async function SetUsername( return await Response.json(); } +async function SetColour( + Colour +) { + const Response = + await fetch( + ApiUrl + + "/SetColour.php", + { + method: "POST", + + headers: { + "Content-Type": + "application/json" + }, + + body: JSON.stringify({ + SaveKey: + GetSaveKey(), + + Colour: + Colour + }) + } + ); + + return await Response.json(); +} async function RenderUser() { const Profile = @@ -62,7 +89,14 @@ async function RenderUser() { UsernameDisplay.textContent = Profile.Username; - UsernameForm.hidden = true; + if ( + Profile.Colour !== null + ) { + UsernameDisplay.style.color = + Profile.Colour; + } + + UsernameForm.hidden = true; return; } diff --git a/Styles/Style.css b/Styles/Style.css index 3444b53..945f5b7 100644 --- a/Styles/Style.css +++ b/Styles/Style.css @@ -1356,3 +1356,25 @@ select { height: 4.5rem; } } + +#ProfileColourForm { + margin-top: 1.5rem; +} + +.ProfileColourInput { + width: 4rem; + min-width: 4rem !important; + height: 2.75rem; + + padding: 0.2rem !important; + + cursor: pointer; + + appearance: auto !important; +} + +.ProfileColourPreview { + min-width: 8rem; + + color: var(--Text); +}