From b4058bf5923e77c738cadbb47faceede41d478f5 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 22:48:35 +0200 Subject: [PATCH 01/19] refactor: remove duplicate css --- server/stylesheets/main.css | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/stylesheets/main.css b/server/stylesheets/main.css index 158ccdb..46839cf 100644 --- a/server/stylesheets/main.css +++ b/server/stylesheets/main.css @@ -161,7 +161,6 @@ button:active { border-radius: 0.5rem; color: #000; box-sizing: border-box; - cursor: pointer; box-shadow: #00000033 0 4px 12px; cursor: grab; position: relative; @@ -237,9 +236,7 @@ button:active { border: solid 3px transparent; margin: 0; list-style-type: none; - padding: 10px; transition: background-color 0.25s ease-out; - border-radius: 0.5rem; height: 8em; width: 8em; display: flex; @@ -247,7 +244,7 @@ button:active { justify-content: center; border-radius: 0.5rem; cursor: default; - padding: 10; + padding: 10px; } .box-edit>#deleteToken { From 65c390d77d407ba83749d4f0661b024f28986556 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 22:51:38 +0200 Subject: [PATCH 02/19] refactor: prefer for-of loop over for loop --- index.js | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index 58c97dc..a209659 100644 --- a/index.js +++ b/index.js @@ -63,9 +63,7 @@ function getTokenNameFromID(id) { const data = fs.readFileSync(tokenmapPath, "utf8"); const dataset = JSON.parse(data); - for (let i = 0; i < dataset.length; i++) { - const entry = dataset[i]; - + for (let entry of dataset) { if (entry.id == id) { return entry.name; } @@ -78,9 +76,7 @@ function getCharacterNameFromID(id) { const data = fs.readFileSync(charactersMapPath, "utf8"); const dataset = JSON.parse(data); - for (let i = 0; i < dataset.length; i++) { - const entry = dataset[i]; - + for (let entry of dataset) { if (entry.id == id) { return entry.name; } @@ -101,9 +97,7 @@ function getJSONFromUID(uid) { const data = fs.readFileSync(toytagsPath, "utf8"); const dataset = JSON.parse(data); - for (let i = 0; i < dataset.length; i++) { - const entry = dataset[i]; - + for (let entry of dataset) { if (entry.uid == uid) { return entry; } @@ -117,9 +111,7 @@ function updatePadIndex(uid, index) { const data = fs.readFileSync(toytagsPath, "utf8"); const dataset = JSON.parse(data); - for (let i = 0; i < dataset.length; i++) { - const entry = dataset[i]; - + for (let entry of dataset) { if (entry.uid == uid) { entry.index = index; break; @@ -134,9 +126,7 @@ function updatePadIndex(uid, index) { function getUIDFromIndex(index) { const data = fs.readFileSync(toytagsPath, "utf8"); const dataset = JSON.parse(data); - for (let i = 0; i < dataset.length; i++) { - const entry = dataset[i]; - + for (let entry of dataset) { if (entry.index == index) { return entry.uid; } @@ -150,9 +140,7 @@ function writeJSONData(uid, datatype, value) { const tags = fs.readFileSync(toytagsPath, "utf8"); const dataset = JSON.parse(tags); - for (let i = 0; i < dataset.length; i++) { - const entry = dataset[i]; - + for (let entry of dataset) { if (entry.uid == uid) { entry[datatype] = value; break; @@ -168,9 +156,7 @@ function writeJSONBundle(uid, bundle) { const tags = fs.readFileSync(toytagsPath, "utf8"); const dataset = JSON.parse(tags); - for (let i = 0; i < dataset.length; i++) { - const entry = dataset[i]; - + for (let entry of dataset) { if (entry.uid == uid) { bundle.forEach((data) => { entry[data.key] = data.value; @@ -635,9 +621,7 @@ io.on("connection", (socket) => { const dataset = JSON.parse(tags); let index = -1; - for (let i = 0; i < dataset.length; i++) { - const entry = dataset[i]; - + for (let entry of dataset) { if (entry.uid == uid) { index = i; break; From 2f76c6dcfa95edaf279d74a6bc8a8cf135c5aeed Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 22:52:45 +0200 Subject: [PATCH 03/19] refactor: prefer `node:[...]` over `[...]` import --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a209659..e4692d0 100644 --- a/index.js +++ b/index.js @@ -6,13 +6,13 @@ */ const ld = require("node-ld"); -const fs = require("fs"); -const path = require("path"); +const fs = require("node:fs"); +const path = require("node:path"); //Setup Webserver const express = require("express"); const app = express(); -const http = require("http"); +const http = require("node:http"); const server = http.createServer(app); const { Server } = require("socket.io"); const io = new Server(server); From 51dcba84af0d0585349d097b04f8c895166cc048 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 22:55:16 +0200 Subject: [PATCH 04/19] refactor: remove duplicate case --- index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/index.js b/index.js index e4692d0..86ca6df 100644 --- a/index.js +++ b/index.js @@ -214,10 +214,6 @@ function RGBToHex(r, g, b) { case "#f00016": return "#ff2de6"; - //batman stealth - case "#000018": - return "#0000ff"; - //shift keystone (dark colors for blink animation) case "#002007": return "#007575"; @@ -256,8 +252,6 @@ function RGBToHex(r, g, b) { return "#00ff00"; //case "#f00000": //return "#ff0000"; - case "#000016": - return "#00ffff"; //scale keystone case "#ff1e00": From 7be841dd9ecd0fd7a0cb61d761141c581965a8f5 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 23:04:30 +0200 Subject: [PATCH 05/19] refactor: simplify if-condition --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 86ca6df..4a01493 100644 --- a/index.js +++ b/index.js @@ -641,7 +641,7 @@ io.on("connection", (socket) => { }); socket.on("connectionStatus", () => { - if (isConnectedToGame == true) { + if (isConnectedToGame) { io.emit("Connection True"); } }); From e032aab52bf9e35d11407291adc7390fe0697782 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 23:08:44 +0200 Subject: [PATCH 06/19] refactor: remove commented out code --- index.js | 13 +------------ server/scripts/main.js | 5 ----- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/index.js b/index.js index 4a01493..2314b7e 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,7 @@ let isConnectedToGame = false; function createVehicle(id, uid, upgrades = [0, 0]) { const token = Buffer.alloc(180); token.uid = uid; - //console.log(upgrades); + token.writeUInt32LE(upgrades[0], 0x8c); //0x23 * 4 token.writeUInt16LE(id, 0x90); //0x24 * 4 token.writeUInt32LE(upgrades[1], 0x94); //0x25 * 4 @@ -178,7 +178,6 @@ function initializeToyTagsJSON() { }); fs.writeFileSync(toytagsPath, JSON.stringify(dataset, null, 4)); console.log("Initialized toytags.JSON"); - //io.emit("refreshTokens"); } function RGBToHex(r, g, b) { @@ -250,8 +249,6 @@ function RGBToHex(r, g, b) { return "#0000ff"; case "#006700": return "#00ff00"; - //case "#f00000": - //return "#ff0000"; //scale keystone case "#ff1e00": @@ -403,10 +400,6 @@ tp.hook(tp.CMD_FADAL, (req, res) => { right_pad_cycles, right_pad_color, ]); - // setTimeout(function(){io.emit("Fade All", - // [top_pad_speed, top_pad_cycles, 'white', - // left_pad_speed, left_pad_cycles, 'white', - // right_pad_speed, right_pad_cycles, 'white'])}, 2500); }); ///NOT IMPLEMENTED/// @@ -525,8 +518,6 @@ app.post("/place", (request, response) => { console.log("Placing tag: " + request.body.id); const entry = getJSONFromUID(request.body.uid); - //console.log(entry.type); - if (entry.type == "character") { const character = createCharacter(request.body.id, request.body.uid); tp.place( @@ -598,7 +589,6 @@ app.post("/vehicle", (request, response) => { //This is called when a token needs to be removed from the pad. app.delete("/remove", (request, response) => { console.log("Removing item: " + request.body.index); - // console.log('DEBUG: pad-from-token: ', tp._tokens.filter(v => v.index == request.body.index)[0].pad); tp.remove(request.body.index); console.log("Item removed: " + request.body.index); updatePadIndex(request.body.uid, "-1"); @@ -652,7 +642,6 @@ io.on("connection", (socket) => { for (let i = 1; i <= 7; i++) { const uid = getUIDAtPad(i); if (uid != -1) { - //console.log(uid, "is at pad #", i); writeJSONData(uid, "index", i); } } diff --git a/server/scripts/main.js b/server/scripts/main.js index de438f1..bb6ca8e 100644 --- a/server/scripts/main.js +++ b/server/scripts/main.js @@ -47,7 +47,6 @@ $(function () { helper: "clone", appendTo: document.getElementById("focus"), containment: document.getElementById("focus"), - //cursorAt: {left: (-(($(document).width() - $(window).width())/2))}, sort: function (event, ui) { ui.helper[0].style.left = currentMousePos.x - 20; @@ -102,10 +101,6 @@ $(function () { refreshToyBox(); }, 500); } - // else if($this.attr('id') == "edit-tokens") { - // dialog.dialog("open"); - // setTimeout(function () { refreshToyBox(); }, 500) - // } else if ( $this.attr("pad-num") == undefined || ($this.children("li").length > 1 && $this.attr("id") != "toybox-tokens") From 1234f77b3cb9f76c645afe6ce0fd47acef78f8d3 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 23:21:57 +0200 Subject: [PATCH 07/19] refactor: replace `var` with `let` and `const` --- server/scripts/main.js | 90 ++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/server/scripts/main.js b/server/scripts/main.js index bb6ca8e..06559fd 100644 --- a/server/scripts/main.js +++ b/server/scripts/main.js @@ -1,8 +1,10 @@ +let characters; +let vehicles; + +const socket = io(); + $(function () { // Pre-load character and vehicle data, since it is required for the operation of the page and there are multiple places it is used - var characters; - var vehicles; - $.ajax({ dataType: "json", url: "json/charactermap.json", @@ -23,11 +25,10 @@ $(function () { setupFilterInputs(); - var socket = io(); socket.emit("connectionStatus"); socket.emit("syncToyPad"); - var currentMousePos = { x: -1, y: -1 }; + const currentMousePos = { x: -1, y: -1 }; $(document).mousemove(function (event) { currentMousePos.x = event.pageX; currentMousePos.y = event.pageY; @@ -65,11 +66,11 @@ $(function () { }, stop: function (event, ui) { - var parentBox = ui.item.closest(".box"); - var previousPadNum = parseInt(ui.item.attr("previous-pad-num")); - var newPadNum = parseInt(parentBox.attr("pad-num")); - var previousPadIndex = parseInt(ui.item.attr("previousPadIndex")); - var newPadIndex = parseInt(parentBox.attr("pad-index")); + const parentBox = ui.item.closest(".box"); + const previousPadNum = parseInt(ui.item.attr("previous-pad-num")); + const newPadNum = parseInt(parentBox.attr("pad-num")); + const previousPadIndex = parseInt(ui.item.attr("previousPadIndex")); + const newPadIndex = parseInt(parentBox.attr("pad-index")); // If moving to the same space on the Toy Pad, remove and place in the current space if ( @@ -93,7 +94,7 @@ $(function () { applyFilters(); //Refilter in case anything was in the search bar. }, receive: function (event, ui) { - var $this = $(this); + const $this = $(this); if ($this.attr("id") == "remove-tokens") { socket.emit("deleteToken", ui.item.attr("data-uid")); @@ -120,7 +121,7 @@ $(function () { } //If moving from the Toy Box, place tag in the game. else if (parseInt(ui.sender.attr("pad-num")) === -1) { - var content = { + const content = { uid: ui.item.attr("data-uid"), id: parseInt(ui.item.attr("data-id")), position: parseInt($this.attr("pad-num")), @@ -192,9 +193,11 @@ $(function () { cycles = e[1]; padindexs.forEach((element) => { pad = document.getElementById("toypad" + element); - if (element == 2) var color = e[2]; - else if (element == 1 || element == 4 || element == 5) var color = e[5]; - else if (element == 3 || element == 6 || element == 7) var color = e[8]; + let color; + + if (element == 2) color = e[2]; + else if (element == 1 || element == 4 || element == 5) color = e[5]; + else if (element == 3 || element == 6 || element == 7) color = e[8]; console.log("#toypad" + element + " Color: " + color); color = color + "80"; $("#toypad" + element) @@ -228,9 +231,12 @@ $(function () { padindexs.forEach((element) => { pad = document.getElementById("toypad" + element); padnum = pad.pad - num; - if (element == 2) var color = e[0]; - else if (element == 1 || element == 4 || element == 5) var color = e[1]; - else if (element == 3 || element == 6 || element == 7) var color = e[2]; + + let color; + + if (element == 2) color = e[0]; + else if (element == 1 || element == 4 || element == 5) color = e[1]; + else if (element == 3 || element == 6 || element == 7) color = e[2]; pad.setAttribute("color", color); console.log(pad); color = color + "80"; @@ -260,7 +266,7 @@ $(function () { //Remove all token items from the lists and reread toytags.json and repopulate the lists. function refreshToyBox() { //Remove All Current Tokens - var boxes = document.querySelectorAll(".box"); + const boxes = document.querySelectorAll(".box"); boxes.forEach(function (toybox) { while ( @@ -289,7 +295,7 @@ $(function () { } function createItemHtml(item) { - var itemData; + let itemData; if (item.type == "character") { itemData = filterById(characters, item.id); @@ -297,9 +303,10 @@ $(function () { itemData = filterById(vehicles, item.id); } - var content = "

" + itemData.name + "

"; - var path = "images/" + itemData.id + ".png"; - var url = $(location).attr("href") + "/../" + path; + let content = "

" + itemData.name + "

"; + const path = "images/" + itemData.id + ".png"; + const url = $(location).attr("href") + "/../" + path; + if (fileExists(url)) { content = "'); }); - var abilities = []; + let abilities = []; abilities = abilities.concat( characters.map(function (character) { return character.abilities.split(","); @@ -449,7 +456,7 @@ $(function () { } function applyWorldFilter() { - var world = $("#tag-world-filter").val(); + const world = $("#tag-world-filter").val(); if (world != "") { $("#character-list option, #vehicle-list option").each(function ( index, @@ -469,7 +476,7 @@ $(function () { } function applyAbilityFilter() { - var ability = $("#tag-ability-filter").val(); + const ability = $("#tag-ability-filter").val(); if (ability != "") { $("#character-list option, #vehicle-list option").each(function ( index, @@ -506,8 +513,8 @@ $(function () { } function compareWithoutArticles(a, b) { - var aWithoutArticles = removeArticles(a); - var bWithoutArticles = removeArticles(b); + const aWithoutArticles = removeArticles(a); + const bWithoutArticles = removeArticles(b); if (aWithoutArticles > bWithoutArticles) { return 1; @@ -536,15 +543,15 @@ $(function () { $("#character-select").submit(function (e) { e.preventDefault(); - var name = $("#character-name").val(); + const name = $("#character-name").val(); $.ajax({ method: "POST", contentType: "application/json", url: "/character", data: JSON.stringify({ id: filterByName(characters, name).id }), }).done(function () { - var now = Date.now(); - var end = now + 150; + let now = Date.now(); + const end = now + 150; while (now < end) { now = Date.now(); } @@ -556,17 +563,17 @@ $(function () { $("#vehicle-select").submit(function (e) { e.preventDefault(); - var name = $("#vehicle-name").val(); + const name = $("#vehicle-name").val(); console.log(name); - var id = filterByName(vehicles, name).id; + const id = filterByName(vehicles, name).id; $.ajax({ method: "POST", contentType: "application/json", url: "/vehicle", data: JSON.stringify({ id: id }), }).done(function () { - var now = Date.now(); - var end = now + 150; + let now = Date.now(); + const end = now + 150; while (now < end) { now = Date.now(); } @@ -580,8 +587,7 @@ $(function () { }); //**Customize Token** - var dialog; - dialog = $("#dialog-form").dialog({ + const dialog = $("#dialog-form").dialog({ autoOpen: false, height: 400, width: 350, From af8ad5ed16da327a81a9f4a0cddd6e5aaf3c7bd5 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 23:29:18 +0200 Subject: [PATCH 08/19] refactor: replace manual timeouts with `setTimeout` --- server/scripts/main.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/server/scripts/main.js b/server/scripts/main.js index 06559fd..720e9ea 100644 --- a/server/scripts/main.js +++ b/server/scripts/main.js @@ -550,13 +550,11 @@ $(function () { url: "/character", data: JSON.stringify({ id: filterByName(characters, name).id }), }).done(function () { - let now = Date.now(); - const end = now + 150; - while (now < end) { - now = Date.now(); - } - socket.emit("syncToyPad"); - $("#character-select")[0].reset(); + setTimeout(() => + { + socket.emit("syncToyPad"); + $("#character-select")[0].reset(); + }, 150); }); }); @@ -572,13 +570,11 @@ $(function () { url: "/vehicle", data: JSON.stringify({ id: id }), }).done(function () { - let now = Date.now(); - const end = now + 150; - while (now < end) { - now = Date.now(); - } - socket.emit("syncToyPad"); - $("#vehicle-select")[0].reset(); + setTimeout(() => + { + socket.emit("syncToyPad"); + $("#vehicle-select")[0].reset(); + }, 150); }); }); From b57a14815df75b93abb91400d3313b3eb6bfb633 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 23 May 2026 23:38:42 +0200 Subject: [PATCH 09/19] refactor: move functions to global scope --- server/scripts/main.js | 585 +++++++++++++++++++++-------------------- 1 file changed, 294 insertions(+), 291 deletions(-) diff --git a/server/scripts/main.js b/server/scripts/main.js index 720e9ea..d094346 100644 --- a/server/scripts/main.js +++ b/server/scripts/main.js @@ -249,297 +249,6 @@ $(function () { $("#status").css({ display: "none" }); }); - //**Script Functions** - - function filterById(jsonObject, id) { - return jsonObject.filter(function (jsonObject) { - return jsonObject["id"] == id; - })[0]; - } - - function filterByName(jsonObject, name) { - return jsonObject.filter(function (jsonObject) { - return jsonObject["name"] == name; - })[0]; - } - - //Remove all token items from the lists and reread toytags.json and repopulate the lists. - function refreshToyBox() { - //Remove All Current Tokens - const boxes = document.querySelectorAll(".box"); - - boxes.forEach(function (toybox) { - while ( - toybox.lastChild && - toybox.lastChild.id != "deleteToken" && - toybox.lastChild.id != "colorToken" - ) { - toybox.removeChild(toybox.lastChild); - } - }); - - //Reread JSON file - $.getJSON("./json/toytags.json", function (data) { - tags = data; - }).done(function () { - $.each(tags, function (i, item) { - console.log("ID: " + item.id + " UID: " + item.uid); - if (item.name != "N/A" && item.index == "-1") { - $("#toybox-tokens").append(createItemHtml(item)); - } else if (item.index != "-1") { - $("#toypad" + item.index).append(createItemHtml(item)); - } - applyFilters(); - }); - }); - } - - function createItemHtml(item) { - let itemData; - - if (item.type == "character") { - itemData = filterById(characters, item.id); - } else { - itemData = filterById(vehicles, item.id); - } - - let content = "

" + itemData.name + "

"; - const path = "images/" + itemData.id + ".png"; - const url = $(location).attr("href") + "/../" + path; - - if (fileExists(url)) { - content = - " +
-        itemData.name +
-        "; - } - - return ( - "
  • ' + - content + - "
  • " - ); - } - - function fileExists(url) { - const http = new XMLHttpRequest(); - http.open("HEAD", url, false); - http.send(); - return http.status != 404; - } - - function updateToyPadPosition(uid, id, position, currentIndex, newIndex) { - console.log(currentIndex); - $.ajax({ - method: "DELETE", - contentType: "application/json", - url: "/remove", - data: JSON.stringify({ index: currentIndex, uid: uid }), - }).done(function () { - setTimeout(function () { - $.ajax({ - method: "POST", - contentType: "application/json", - url: "/place", - data: JSON.stringify({ - uid: uid, - id: id, - position: position, - index: newIndex, - }), - }); - }, 500); - }); - } - - //Filter the toybox to tags matching the current text of the search bar. - function applyNameFilter() { - const text = $("#name-filter").val().toLowerCase(); - $(".item").each(function (index, item) { - const name = $(item).text().toLowerCase(); - if (!name.includes(text)) { - $(item).addClass("filtered"); - } - }); - } - - function setupFilterInputs() { - $.each(characters, function (i, item) { - if (item.name != "Unknown" || item.name.includes("(unreleased)")) - $("#character-list").append( - '