mirror of
https://git.srhtnin.garden/sarah/srhtnin.github.io.git
synced 2026-10-13 18:38:11 +02:00
Added player colour choosing. I HOPE.
Signed-off-by: Sarahtonin <[email protected]>
This commit is contained in:
1 parent
2c1f3851e8
commit
2fe5171450
5 files changed
+288
-11
No files matched your search
+40
-1
@@ -66,8 +66,47 @@ $SubNavbarCurrent = "Player";
|
|||||||
class="ProfileMessage"
|
class="ProfileMessage"
|
||||||
></p>
|
></p>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
|
||||||
|
|
||||||
|
<form id="ProfileColourForm">
|
||||||
|
<label
|
||||||
|
for="ProfileColourInput"
|
||||||
|
>
|
||||||
|
Colour
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="ProfileFormRow">
|
||||||
|
<input
|
||||||
|
id="ProfileColourInput"
|
||||||
|
class="ProfileColourInput"
|
||||||
|
type="color"
|
||||||
|
value="#cdd6f4"
|
||||||
|
>
|
||||||
|
|
||||||
|
<strong
|
||||||
|
id="ProfileColourPreview"
|
||||||
|
class="ProfileColourPreview"
|
||||||
|
>
|
||||||
|
Preview
|
||||||
|
</strong>
|
||||||
|
|
||||||
|
<button type="submit">
|
||||||
|
Save colour
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
id="ResetProfileColourButton"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p
|
||||||
|
id="ProfileColourMessage"
|
||||||
|
class="ProfileMessage"
|
||||||
|
></p>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section
|
<section
|
||||||
id="Statistics"
|
id="Statistics"
|
||||||
|
|||||||
@@ -141,6 +141,13 @@ async function RenderLeaderboard() {
|
|||||||
Username.textContent =
|
Username.textContent =
|
||||||
Player.Username;
|
Player.Username;
|
||||||
|
|
||||||
|
if (
|
||||||
|
Player.Colour !== null
|
||||||
|
) {
|
||||||
|
Username.style.color =
|
||||||
|
Player.Colour;
|
||||||
|
}
|
||||||
|
|
||||||
Dew.textContent =
|
Dew.textContent =
|
||||||
Player.Dew.toLocaleString();
|
Player.Dew.toLocaleString();
|
||||||
|
|
||||||
|
|||||||
+185
-10
@@ -2,7 +2,7 @@ let ProfileSave = null;
|
|||||||
|
|
||||||
|
|
||||||
async function StartProfile() {
|
async function StartProfile() {
|
||||||
await RenderProfileUsername();
|
await RenderProfilePlayer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProfileSave =
|
ProfileSave =
|
||||||
@@ -18,7 +18,6 @@ async function StartProfile() {
|
|||||||
RenderProfileStatisticsError();
|
RenderProfileStatisticsError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const UsernameForm =
|
const UsernameForm =
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
"ProfileUsernameForm"
|
"ProfileUsernameForm"
|
||||||
@@ -28,16 +27,64 @@ async function StartProfile() {
|
|||||||
"submit",
|
"submit",
|
||||||
SubmitProfileUsername
|
SubmitProfileUsername
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const ColourForm =
|
||||||
|
document.getElementById(
|
||||||
|
"ProfileColourForm"
|
||||||
|
);
|
||||||
|
|
||||||
|
const ColourInput =
|
||||||
|
document.getElementById(
|
||||||
|
"ProfileColourInput"
|
||||||
|
);
|
||||||
|
|
||||||
|
const ColourPreview =
|
||||||
|
document.getElementById(
|
||||||
|
"ProfileColourPreview"
|
||||||
|
);
|
||||||
|
|
||||||
|
const ResetColourButton =
|
||||||
|
document.getElementById(
|
||||||
|
"ResetProfileColourButton"
|
||||||
|
);
|
||||||
|
|
||||||
|
ColourForm.addEventListener(
|
||||||
|
"submit",
|
||||||
|
SubmitProfileColour
|
||||||
|
);
|
||||||
|
|
||||||
|
ColourInput.addEventListener(
|
||||||
|
"input",
|
||||||
|
() => {
|
||||||
|
ColourPreview.style.color =
|
||||||
|
ColourInput.value;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ResetColourButton.addEventListener(
|
||||||
|
"click",
|
||||||
|
ResetProfileColour
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function RenderProfileUsername() {
|
async function RenderProfilePlayer() {
|
||||||
const Input =
|
const UsernameInput =
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
"ProfileUsernameInput"
|
"ProfileUsernameInput"
|
||||||
);
|
);
|
||||||
|
|
||||||
const Message =
|
const ColourInput =
|
||||||
|
document.getElementById(
|
||||||
|
"ProfileColourInput"
|
||||||
|
);
|
||||||
|
|
||||||
|
const ColourPreview =
|
||||||
|
document.getElementById(
|
||||||
|
"ProfileColourPreview"
|
||||||
|
);
|
||||||
|
|
||||||
|
const UsernameMessage =
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
"ProfileUsernameMessage"
|
"ProfileUsernameMessage"
|
||||||
);
|
);
|
||||||
@@ -53,22 +100,42 @@ async function RenderProfileUsername() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
Profile.Username !== null
|
Profile.Username !== null
|
||||||
) {
|
) {
|
||||||
Input.value =
|
UsernameInput.value =
|
||||||
Profile.Username;
|
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) {
|
} catch (Error) {
|
||||||
console.error(
|
console.error(
|
||||||
"Couldn't load username:",
|
"Couldn't load profile:",
|
||||||
Error
|
Error
|
||||||
);
|
);
|
||||||
|
|
||||||
Message.textContent =
|
UsernameMessage.textContent =
|
||||||
"Couldn't load username.";
|
"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() {
|
function RenderProfileStatistics() {
|
||||||
const CurrentDew =
|
const CurrentDew =
|
||||||
|
|||||||
@@ -40,6 +40,33 @@ async function SetUsername(
|
|||||||
return await Response.json();
|
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() {
|
async function RenderUser() {
|
||||||
const Profile =
|
const Profile =
|
||||||
@@ -62,6 +89,13 @@ async function RenderUser() {
|
|||||||
UsernameDisplay.textContent =
|
UsernameDisplay.textContent =
|
||||||
Profile.Username;
|
Profile.Username;
|
||||||
|
|
||||||
|
if (
|
||||||
|
Profile.Colour !== null
|
||||||
|
) {
|
||||||
|
UsernameDisplay.style.color =
|
||||||
|
Profile.Colour;
|
||||||
|
}
|
||||||
|
|
||||||
UsernameForm.hidden = true;
|
UsernameForm.hidden = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1356,3 +1356,25 @@ select {
|
|||||||
height: 4.5rem;
|
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);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user