From 3a110135eef208ffbc7f969a908f8ff417b8fb74 Mon Sep 17 00:00:00 2001 From: AloeSapling Date: Thu, 28 Aug 2025 14:59:24 +0200 Subject: [PATCH] changed certain coordinate variables to hold arrays of an exact length --- src/createTemplate.ts | 10 +++++----- src/manageTemplates.ts | 1 + types/schemas.ts | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/createTemplate.ts b/src/createTemplate.ts index fc419fb..252e8cd 100644 --- a/src/createTemplate.ts +++ b/src/createTemplate.ts @@ -6,7 +6,7 @@ import { generateUUID } from "./utils"; // Typescript / Javascript for the "createTemplates" window let selectedFile: File | undefined -let tilePixel: {tile: number[], pixel: number[]} +let tilePixel: {tile: [number, number], pixel: [number, number]} /**Closes this window * @since 0.1.0-overhaul @@ -20,7 +20,7 @@ function close(){ * @since 0.1.0-overhaul * @version 2.0 */ -function getCoords(): number[] | undefined{ +function getCoords(): [number, number, number, number] | undefined{ // This code will currently take values from the *last* selected pixel // If the user deselects a pixel, there will still be data which might cause confusion @@ -49,8 +49,8 @@ function setCoords(){ const coordsContainer = document.querySelector("#bm-create-template #coords-container"); if(!coordsContainer){ return } - // If coords is undefined or its length less than 4 - if(!coords || coords.length < 4){ + // If coords is undefined + if(!coords){ // Then the player hadn't clicked on a pixel or a different error occured charity.lib.sonner.toast.error("Click on a pixel first") return; @@ -146,7 +146,7 @@ function getNewTemplateData(): TBlueMarbleTemplate | undefined{ const dataURL = URL.createObjectURL(selectedFile); return { - coords: coords, + coords: coords as [number, number, number, number], enabled: true, uuid: generateUUID(), name: (nameInput as HTMLInputElement).value, diff --git a/src/manageTemplates.ts b/src/manageTemplates.ts index e4297ef..b10f84c 100644 --- a/src/manageTemplates.ts +++ b/src/manageTemplates.ts @@ -54,6 +54,7 @@ function flyToTemplate(idx: number){ // Convert to Px and Py used in mercator's functions const mercatorPixelsX = coordsArr[0]*1000+coordsArr[2]; // Tx * 1000 + Px const mercatorPixelsY = coordsArr[1]*1000+coordsArr[3]; // Ty * 1000 + Px + const lngLatBounds = charity.game.mercator.pixelsToLatLon(mercatorPixelsX, mercatorPixelsY, zoom); if(!lngLatBounds){ return }; charity.game.map.flyTo({center: lngLatBounds, zoom: 9}) // Fly to the template's position diff --git a/types/schemas.ts b/types/schemas.ts index 57353a4..1a25aaf 100644 --- a/types/schemas.ts +++ b/types/schemas.ts @@ -74,7 +74,7 @@ export const CharityJSON = z.object({ */ export const BlueMarbleTemplate = z.object({ name: z.string().optional(), // Name of the template - coords: z.array(z.number()), // 4 element array containing the location of the template + coords: z.array(z.number()).length(4), // 4 element array containing the location of the template authorID: z.number().optional(), // Numerical ID of the author, taken from wplace enabled: z.boolean(), urlLink: z.string().optional(), // Link to the template image's file data