Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Added all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
DedFishy committed May 23, 2023
1 parent e98080e commit 869eea3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 13 deletions.
15 changes: 15 additions & 0 deletions assets/df.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ <h2>Models</h2>
<h5>Your model list is loading...</h5>
</div>

<button onclick="do_with_loader(update_models())">Update Model Configuration</button>
<button onclick="do_with_loader(update_models)">Update Model Configuration</button>

<h3>Upload New</h3>

<h4>Model file (.cfg)</h4>
<input type="file" id="new-model-cfg" accept=".cfg">
<input type="file" id="new-model-cfg" name="model" accept=".cfg">
<h4>Texture file (.png)</h4>
<input type="file" id="new-model-texture" accept=".png">
<input type="file" id="new-model-texture" name="texture" accept=".png">
<br>
<button onclick="do_with_loader(uploadModel);">Upload</button>
</div>
Expand Down
58 changes: 48 additions & 10 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var _DEBUG = false;
var _DEBUG = true;

var rcURL = "https://recape-server.boyne.dev"

var models = {}
var modelChecks = {}

let modelContainer = document.getElementById("model-list");

function show_notification(text) {
let notification = document.createElement("div");
notification.classList.add("notification");
Expand Down Expand Up @@ -58,7 +60,7 @@ function loginCode() {

}

function parse_login(json) {
async function parse_login(json) {
//Cookies.set("token", token);
//Cookies.set("uuid", uuid);

Expand All @@ -72,7 +74,7 @@ function parse_login(json) {
Cookies.set("uuid", json["uuid"]);
Cookies.set("username", document.getElementById("username").value);
show_notification("Successfully connected your account! Welcome to ReCape.");
login();
await login();
}
else if (json["status"] == "failure") {
show_notification(json["error"]);
Expand Down Expand Up @@ -112,6 +114,8 @@ async function login() {
document.getElementById("loading-popup").style.opacity = "0";

document.body.style.pointerEvents = "all";

loadClientMenu()
});
} else {
console.log("No token and/or no UUID");
Expand Down Expand Up @@ -150,8 +154,13 @@ async function start() {
console.log("Logging in...")

if (!_DEBUG) {
login()
.then(response => loadClientMenu())

try {
await login();
} catch (e) {
console.log(e);
}

} else {

show_notification("ReCape is currently in debug mode!");
Expand Down Expand Up @@ -257,8 +266,6 @@ function updateModelView() {
console.log(models);

modelChecks = {}

let modelContainer = document.getElementById("model-list");
modelContainer.innerHTML = "";

Object.keys(models).forEach(model => {
Expand All @@ -274,7 +281,7 @@ function updateModelView() {
let modelCheck = document.createElement("input");
modelCheck.type = "checkbox";
modelCheck.innerText = "Enabled?"
modelCheck.value = models[model];
modelCheck.checked = models[model];
modelEl.appendChild(modelCheck);

modelContainer.appendChild(modelEl);
Expand All @@ -285,6 +292,7 @@ function updateModelView() {
}

async function loadModels() {
try {
let response = await fetch(rcURL + '/account/get_config', {
method: 'GET',
headers: {
Expand All @@ -308,6 +316,9 @@ async function loadModels() {
} else {
modelContainer.innerHTML = "<h4>You don't have any models yet.</h4>";
}
} catch (e) {
console.log(e);
}
}

async function uploadModel() {
Expand All @@ -316,8 +327,8 @@ async function uploadModel() {
var data = new FormData()
let model = document.getElementById("new-model-cfg").files[0];
let texture = document.getElementById("new-model-texture").files[0];
data.append('files[]', model, "model")
data.append('files[]', texture, "texture")
data.append('model', model, model.name)
data.append('texture', texture, "texture.png")

let response = await fetch(rcURL + '/account/upload_cosmetic', {
method: 'POST',
Expand All @@ -337,4 +348,31 @@ async function uploadModel() {
}
}

async function update_models() {

let data = {}

Object.keys(modelChecks).forEach(model => {
data[model] = modelChecks[model].checked;
})

let response = await fetch(rcURL + '/account/set_config', {
method: 'POST',
body: data,
headers: {
"token": Cookies.get("token"),
"uuid": Cookies.get("uuid"),
"config": JSON.stringify(data)
}
})

let json = await response.json()

if (json["status"] == "success") {
show_notification("Your model has been uploaded.");
} else {
show_notification(json["error"]);
}
}

start();
18 changes: 18 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,21 @@ input[type=file]::file-selector-button {
box-shadow: 0 0 4px 0 black;
border-radius: 10px;
}

#model-list {
display: flex;
align-items: center;
justify-content: center;
background-color: #222;
width: fit-content;
margin-left: auto;
margin-right: auto;
border-radius: 10px;
padding: 10px;
}

.model {
box-shadow: 0 0 4px 0 black;
margin: 4px;
border-radius: 10px;
}

0 comments on commit 869eea3

Please sign in to comment.