mirror of
https://github.com/SwingTheVine/Wplace-BlueMarble.git
synced 2026-04-21 15:21:58 +00:00
changed certain coordinate variables to hold arrays of an exact length
This commit is contained in:
parent
622a32bf9d
commit
3a110135ee
3 changed files with 7 additions and 6 deletions
|
|
@ -6,7 +6,7 @@ import { generateUUID } from "./utils";
|
||||||
// Typescript / Javascript for the "createTemplates" window
|
// Typescript / Javascript for the "createTemplates" window
|
||||||
|
|
||||||
let selectedFile: File | undefined
|
let selectedFile: File | undefined
|
||||||
let tilePixel: {tile: number[], pixel: number[]}
|
let tilePixel: {tile: [number, number], pixel: [number, number]}
|
||||||
|
|
||||||
/**Closes this window
|
/**Closes this window
|
||||||
* @since 0.1.0-overhaul
|
* @since 0.1.0-overhaul
|
||||||
|
|
@ -20,7 +20,7 @@ function close(){
|
||||||
* @since 0.1.0-overhaul
|
* @since 0.1.0-overhaul
|
||||||
* @version 2.0
|
* @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
|
// 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
|
// 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");
|
const coordsContainer = document.querySelector("#bm-create-template #coords-container");
|
||||||
if(!coordsContainer){ return }
|
if(!coordsContainer){ return }
|
||||||
|
|
||||||
// If coords is undefined or its length less than 4
|
// If coords is undefined
|
||||||
if(!coords || coords.length < 4){
|
if(!coords){
|
||||||
// Then the player hadn't clicked on a pixel or a different error occured
|
// Then the player hadn't clicked on a pixel or a different error occured
|
||||||
charity.lib.sonner.toast.error("Click on a pixel first")
|
charity.lib.sonner.toast.error("Click on a pixel first")
|
||||||
return;
|
return;
|
||||||
|
|
@ -146,7 +146,7 @@ function getNewTemplateData(): TBlueMarbleTemplate | undefined{
|
||||||
const dataURL = URL.createObjectURL(selectedFile);
|
const dataURL = URL.createObjectURL(selectedFile);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
coords: coords,
|
coords: coords as [number, number, number, number],
|
||||||
enabled: true,
|
enabled: true,
|
||||||
uuid: generateUUID(),
|
uuid: generateUUID(),
|
||||||
name: (nameInput as HTMLInputElement).value,
|
name: (nameInput as HTMLInputElement).value,
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ function flyToTemplate(idx: number){
|
||||||
// Convert to Px and Py used in mercator's functions
|
// Convert to Px and Py used in mercator's functions
|
||||||
const mercatorPixelsX = coordsArr[0]*1000+coordsArr[2]; // Tx * 1000 + Px
|
const mercatorPixelsX = coordsArr[0]*1000+coordsArr[2]; // Tx * 1000 + Px
|
||||||
const mercatorPixelsY = coordsArr[1]*1000+coordsArr[3]; // Ty * 1000 + Px
|
const mercatorPixelsY = coordsArr[1]*1000+coordsArr[3]; // Ty * 1000 + Px
|
||||||
|
|
||||||
const lngLatBounds = charity.game.mercator.pixelsToLatLon(mercatorPixelsX, mercatorPixelsY, zoom);
|
const lngLatBounds = charity.game.mercator.pixelsToLatLon(mercatorPixelsX, mercatorPixelsY, zoom);
|
||||||
if(!lngLatBounds){ return };
|
if(!lngLatBounds){ return };
|
||||||
charity.game.map.flyTo({center: lngLatBounds, zoom: 9}) // Fly to the template's position
|
charity.game.map.flyTo({center: lngLatBounds, zoom: 9}) // Fly to the template's position
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ export const CharityJSON = z.object({
|
||||||
*/
|
*/
|
||||||
export const BlueMarbleTemplate = z.object({
|
export const BlueMarbleTemplate = z.object({
|
||||||
name: z.string().optional(), // Name of the template
|
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
|
authorID: z.number().optional(), // Numerical ID of the author, taken from wplace
|
||||||
enabled: z.boolean(),
|
enabled: z.boolean(),
|
||||||
urlLink: z.string().optional(), // Link to the template image's file data
|
urlLink: z.string().optional(), // Link to the template image's file data
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue