mirror of
https://github.com/BlueMap-Minecraft/BlueMapWeb.git
synced 2024-11-28 12:55:53 +01:00
Update to new settings.json-s
This commit is contained in:
parent
a0f5548293
commit
889d3cf94c
@ -23,37 +23,42 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
ClampToEdgeWrapping, Color,
|
ClampToEdgeWrapping,
|
||||||
FileLoader, FrontSide, NearestFilter, NearestMipMapLinearFilter, Raycaster,
|
Color,
|
||||||
Scene, ShaderMaterial, Texture, Vector2, Vector3, VertexColors
|
FileLoader,
|
||||||
|
FrontSide,
|
||||||
|
NearestFilter,
|
||||||
|
NearestMipMapLinearFilter,
|
||||||
|
Raycaster,
|
||||||
|
Scene,
|
||||||
|
ShaderMaterial,
|
||||||
|
Texture,
|
||||||
|
Vector3,
|
||||||
|
VertexColors
|
||||||
} from "three";
|
} from "three";
|
||||||
import {alert, dispatchEvent, generateCacheHash, hashTile, stringToImage} from "../util/Utils";
|
import {alert, dispatchEvent, generateCacheHash, hashTile, stringToImage, vecArrToObj} from "../util/Utils";
|
||||||
import {TileManager} from "./TileManager";
|
import {TileManager} from "./TileManager";
|
||||||
import {TileLoader} from "./TileLoader";
|
import {TileLoader} from "./TileLoader";
|
||||||
import {MarkerFileManager} from "../markers/MarkerFileManager";
|
|
||||||
import {PlayerMarkerManager} from "../markers/PlayerMarkerManager";
|
|
||||||
|
|
||||||
export class Map {
|
export class Map {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id {string}
|
* @param id {string}
|
||||||
* @param dataUrl {string}
|
* @param dataUrl {string}
|
||||||
* @param settingsUrl {string}
|
|
||||||
* @param texturesUrl {string}
|
|
||||||
* @param events {EventTarget}
|
* @param events {EventTarget}
|
||||||
*/
|
*/
|
||||||
constructor(id, dataUrl, settingsUrl, texturesUrl, events = null) {
|
constructor(id, dataUrl, events = null) {
|
||||||
Object.defineProperty( this, 'isMap', { value: true } );
|
Object.defineProperty( this, 'isMap', { value: true } );
|
||||||
|
|
||||||
this.events = events;
|
this.events = events;
|
||||||
|
|
||||||
this.data = {
|
this.data = {
|
||||||
id: id,
|
id: id,
|
||||||
|
sorting: 0,
|
||||||
dataUrl: dataUrl,
|
dataUrl: dataUrl,
|
||||||
settingsUrl: settingsUrl,
|
settingsUrl: dataUrl + "settings.json",
|
||||||
texturesUrl: texturesUrl,
|
texturesUrl: dataUrl + "textures.json",
|
||||||
name: id,
|
name: id,
|
||||||
world: "-",
|
|
||||||
startPos: {x: 0, z: 0},
|
startPos: {x: 0, z: 0},
|
||||||
skyColor: new Color(),
|
skyColor: new Color(),
|
||||||
ambientLight: 0,
|
ambientLight: 0,
|
||||||
@ -127,28 +132,33 @@ export class Map {
|
|||||||
return this.loadSettingsFile()
|
return this.loadSettingsFile()
|
||||||
.then(worldSettings => {
|
.then(worldSettings => {
|
||||||
this.data.name = worldSettings.name ? worldSettings.name : this.data.name;
|
this.data.name = worldSettings.name ? worldSettings.name : this.data.name;
|
||||||
this.data.world = worldSettings.world ? worldSettings.world : this.data.world;
|
|
||||||
|
|
||||||
this.data.startPos = {...this.data.startPos, ...worldSettings.startPos};
|
this.data.sorting = worldSettings.sorting ? worldSettings.sorting : this.data.sorting;
|
||||||
|
|
||||||
|
this.data.startPos = {...this.data.startPos, ...vecArrToObj(worldSettings.startPos, true)};
|
||||||
|
|
||||||
|
if (worldSettings.skyColor && worldSettings.skyColor.length >= 3) {
|
||||||
this.data.skyColor.setRGB(
|
this.data.skyColor.setRGB(
|
||||||
worldSettings.skyColor.r !== undefined ? worldSettings.skyColor.r : this.data.skyColor.r,
|
worldSettings.skyColor[0],
|
||||||
worldSettings.skyColor.g !== undefined ? worldSettings.skyColor.g : this.data.skyColor.g,
|
worldSettings.skyColor[1],
|
||||||
worldSettings.skyColor.b !== undefined ? worldSettings.skyColor.b : this.data.skyColor.b
|
worldSettings.skyColor[2]
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.data.ambientLight = worldSettings.ambientLight ? worldSettings.ambientLight : this.data.ambientLight;
|
this.data.ambientLight = worldSettings.ambientLight ? worldSettings.ambientLight : this.data.ambientLight;
|
||||||
|
|
||||||
if (worldSettings.hires === undefined) worldSettings.hires = {};
|
if (worldSettings.hires === undefined) worldSettings.hires = {};
|
||||||
if (worldSettings.lowres === undefined) worldSettings.lowres = {};
|
if (worldSettings.lowres === undefined) worldSettings.lowres = {};
|
||||||
|
|
||||||
this.data.hires = {
|
this.data.hires = {
|
||||||
tileSize: {...this.data.hires.tileSize, ...worldSettings.hires.tileSize},
|
tileSize: {...this.data.hires.tileSize, ...vecArrToObj(worldSettings.hires.tileSize, true)},
|
||||||
scale: {...this.data.hires.scale, ...worldSettings.hires.scale},
|
scale: {...this.data.hires.scale, ...vecArrToObj(worldSettings.hires.scale, true)},
|
||||||
translate: {...this.data.hires.translate, ...worldSettings.hires.translate}
|
translate: {...this.data.hires.translate, ...vecArrToObj(worldSettings.hires.translate, true)}
|
||||||
};
|
};
|
||||||
this.data.lowres = {
|
this.data.lowres = {
|
||||||
tileSize: {...this.data.lowres.tileSize, ...worldSettings.lowres.tileSize},
|
tileSize: {...this.data.lowres.tileSize, ...vecArrToObj(worldSettings.lowres.tileSize, true)},
|
||||||
scale: {...this.data.lowres.scale, ...worldSettings.lowres.scale},
|
scale: {...this.data.lowres.scale, ...vecArrToObj(worldSettings.lowres.scale, true)},
|
||||||
translate: {...this.data.lowres.translate, ...worldSettings.lowres.translate}
|
translate: {...this.data.lowres.translate, ...vecArrToObj(worldSettings.lowres.translate, true)}
|
||||||
};
|
};
|
||||||
|
|
||||||
alert(this.events, `Settings for map '${this.data.id}' loaded.`, "fine");
|
alert(this.events, `Settings for map '${this.data.id}' loaded.`, "fine");
|
||||||
@ -203,13 +213,7 @@ export class Map {
|
|||||||
let loader = new FileLoader();
|
let loader = new FileLoader();
|
||||||
loader.setResponseType("json");
|
loader.setResponseType("json");
|
||||||
loader.load(this.data.settingsUrl + "?" + generateCacheHash(),
|
loader.load(this.data.settingsUrl + "?" + generateCacheHash(),
|
||||||
settings => {
|
resolve,
|
||||||
if (settings.maps && settings.maps[this.data.id]) {
|
|
||||||
resolve(settings.maps[this.data.id]);
|
|
||||||
} else {
|
|
||||||
reject(`the settings.json does not contain information for map: ${this.data.id}`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
() => {},
|
() => {},
|
||||||
() => reject(`Failed to load the settings.json for map: ${this.data.id}`)
|
() => reject(`Failed to load the settings.json for map: ${this.data.id}`)
|
||||||
)
|
)
|
||||||
|
@ -372,3 +372,11 @@ export const softMax = (value, max, stiffness) => {
|
|||||||
export const softClamp = (value, min, max, stiffness) => {
|
export const softClamp = (value, min, max, stiffness) => {
|
||||||
return softMax(softMin(value, min, stiffness), max, stiffness);
|
return softMax(softMin(value, min, stiffness), max, stiffness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const vecArrToObj = (val, useZ = false) => {
|
||||||
|
if (val.length >= 2) {
|
||||||
|
if (useZ) return {x: val[0], z: val[1]};
|
||||||
|
return {x: val[0], y: val[1]};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user