Added Enable/Disable buttons and functionality

This commit is contained in:
SwingTheVine 2025-08-07 17:25:14 -04:00
parent 07845cb9d3
commit ca34eeeea8
8 changed files with 35 additions and 9 deletions

File diff suppressed because one or more lines are too long

View file

@ -186,6 +186,7 @@ classDiagram
}
class templateManager {
userID : number
templatesShouldBeDrawn : boolean
+createJSON()
+createTemplate()
-storeTemplates()
@ -193,6 +194,7 @@ classDiagram
+drawTemplateOnTile()
+importJSON()
+parseBlueMarble()
+setTemplatesShouldBeDrawn()
}
class Template {
+createTemplateTiles()
@ -216,6 +218,7 @@ classDiagram
apiManager ..> templateManager : calls drawTemplateOnTiles(), sets userID
apiManager ..> utils : calls escapeHTML(), numberToEncoded(), serverTPtoDisplayTP()
Overlay ..> apiManager : uses coordsTilePixel
Overlay ..> templateManager : calls setTemplatesShouldBeDrawn()
templateManager *-- Template : manages
templateManager ..> utils : calls base64ToUint8(), numberToEncoded()
Template ..> utils : calls uint8ToBase64()

View file

@ -44,7 +44,7 @@
<a href="https://github.com/SwingTheVine/Wplace-BlueMarble/blob/main/LICENSE.txt" target="_blank" rel="noopener noreferrer"><img alt="Software License: MPL-2.0" src="https://img.shields.io/badge/Software_License-MPL--2.0-slateblue?style=flat"></a>
<a href="https://discord.gg/tpeBPy46hf" target="_blank" rel="noopener noreferrer"><img alt="Contact Me" src="https://img.shields.io/badge/Contact_Me-gray?style=flat&logo=Discord&logoColor=white&logoSize=auto&labelColor=cornflowerblue"></a>
<a href="" target="_blank" rel="noopener noreferrer"><img alt="WakaTime" src="https://img.shields.io/badge/Coding_Time-91hrs_0mins-blue?style=flat&logo=wakatime&logoColor=black&logoSize=auto&labelColor=white"></a>
<a href="" target="_blank" rel="noopener noreferrer"><img alt="Total Patches" src="https://img.shields.io/badge/Total_Patches-479-black?style=flat"></a>
<a href="" target="_blank" rel="noopener noreferrer"><img alt="Total Patches" src="https://img.shields.io/badge/Total_Patches-483-black?style=flat"></a>
<a href="" target="_blank" rel="noopener noreferrer"><img alt="Total Lines of Code" src="https://tokei.rs/b1/github/SwingTheVine/Wplace-BlueMarble?category=code"></a>
<a href="" target="_blank" rel="noopener noreferrer"><img alt="Total Comments" src="https://tokei.rs/b1/github/SwingTheVine/Wplace-BlueMarble?category=comments"></a>
<a href="" target="_blank" rel="noopener noreferrer"><img alt="Compression" src="https://img.shields.io/badge/Compression-73.73%25-blue"></a>

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "wplace-bluemarble",
"version": "0.73.3",
"version": "0.73.7",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "wplace-bluemarble",
"version": "0.73.3",
"version": "0.73.7",
"devDependencies": {
"esbuild": "^0.25.0",
"terser": "^5.43.1"

View file

@ -1,6 +1,6 @@
{
"name": "wplace-bluemarble",
"version": "0.73.3",
"version": "0.73.7",
"type": "module",
"scripts": {
"build": "node build/build.js",

View file

@ -1,7 +1,7 @@
// ==UserScript==
// @name Blue Marble
// @namespace https://github.com/SwingTheVine/
// @version 0.73.3
// @version 0.73.7
// @description A userscript to automate and/or enhance the user experience on Wplace.live. Make sure to comply with the site's Terms of Service, and rules! This script is not affiliated with Wplace.live in any way, use at your own risk. This script is not affiliated with TamperMonkey. The author of this userscript is not responsible for any damages, issues, loss of data, or punishment that may occur as a result of using this script. This script is provided "as is" under the MPL-2.0 license. The "Blue Marble" icon is licensed under CC0 1.0 Universal (CC0 1.0) Public Domain Dedication. The image is owned by NASA.
// @author SwingTheVine
// @license MPL-2.0

View file

@ -460,6 +460,12 @@ function buildOverlayMain() {
.buildElement()
.addInputFile({'id': 'bm-input-file-template', 'textContent': 'Upload Template', 'accept': 'image/png, image/jpeg, image/webp, image/bmp, image/gif'}).buildElement()
.addDiv({'id': 'bm-contain-buttons-template'})
.addButton({'id': 'bm-button-enable', 'textContent': 'Enable'}, (instance, button) => {
button.onclick = () => {
instance.apiManager?.templateManager?.setTemplatesShouldBeDrawn(true);
instance.handleDisplayStatus(`Enabled templates!`);
}
}).buildElement()
.addButton({'id': 'bm-button-create', 'textContent': 'Create'}, (instance, button) => {
button.onclick = () => {
const input = document.querySelector('#bm-input-file-template');
@ -486,7 +492,12 @@ function buildOverlayMain() {
instance.handleDisplayStatus(`Drew to canvas!`);
}
}).buildElement()
// .addButton({'id': 'bm-button-disable', 'textContent': 'Disable'}).buildElement()
.addButton({'id': 'bm-button-disable', 'textContent': 'Disable'}, (instance, button) => {
button.onclick = () => {
instance.apiManager?.templateManager?.setTemplatesShouldBeDrawn(false);
instance.handleDisplayStatus(`Disabled templates!`);
}
}).buildElement()
.buildElement()
.addTextarea({'id': overlay.outputStatusId, 'placeholder': `Status: Sleeping...\nVersion: ${version}`, 'readOnly': true}).buildElement()
.addDiv({'id': 'bm-contain-buttons-action'})
@ -505,4 +516,4 @@ function buildOverlayMain() {
.buildElement()
.buildElement()
.buildOverlay(document.body);
}
}

View file

@ -59,6 +59,7 @@ export default class TemplateManager {
this.templateState = ''; // The state of the template ('blob', 'proccessing', 'template', etc.)
this.templatesArray = []; // All Template instnaces currently loaded (Template)
this.templatesJSON = null; // All templates currently loaded (JSON)
this.templatesShouldBeDrawn = true; // Should ALL templates be drawn to the canvas?
}
/** Retrieves the pixel art canvas.
@ -203,6 +204,9 @@ export default class TemplateManager {
*/
async drawTemplateOnTile(tileBlob, tileCoords) {
// Returns early if no templates should be drawn
if (!this.templatesShouldBeDrawn) {return tileBlob;}
const drawSize = this.tileSize * this.drawMult; // Calculate draw multiplier for scaling
// Format tile coordinates with proper padding for consistent lookup
@ -374,4 +378,12 @@ export default class TemplateManager {
#parseOSU() {
}
/** Sets the `templatesShouldBeDrawn` boolean to a value.
* @param {boolean} value - The value to set the boolean to
* @since 0.73.7
*/
setTemplatesShouldBeDrawn(value) {
this.templatesShouldBeDrawn = value;
}
}