Fix invalid maps
This commit is contained in:
parent
2132fc0323
commit
ea49dafea4
@ -142,6 +142,9 @@ class LocalUserStore {
|
|||||||
localStorage.getItem(lastRoomUrl) ?? window.location.protocol + "//" + window.location.host + START_ROOM_URL
|
localStorage.getItem(lastRoomUrl) ?? window.location.protocol + "//" + window.location.host + START_ROOM_URL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
removeLastRoomUrl(): void {
|
||||||
|
localStorage.removeItem(lastRoomUrl);
|
||||||
|
}
|
||||||
getLastRoomUrlCacheApi(): Promise<string | undefined> {
|
getLastRoomUrlCacheApi(): Promise<string | undefined> {
|
||||||
if (!("caches" in window)) {
|
if (!("caches" in window)) {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
|
@ -273,7 +273,7 @@ export class GameScene extends DirtyScene {
|
|||||||
const base = new URL(window.location.href);
|
const base = new URL(window.location.href);
|
||||||
base.pathname = "";
|
base.pathname = "";
|
||||||
const url = new URL(file.src, base.toString());
|
const url = new URL(file.src, base.toString());
|
||||||
const host = url.host.split(":")[0];
|
const host = url.host.split(":")[ 0 ];
|
||||||
if (
|
if (
|
||||||
window.location.protocol === "https:" &&
|
window.location.protocol === "https:" &&
|
||||||
file.src === this.MapUrlFile &&
|
file.src === this.MapUrlFile &&
|
||||||
@ -328,8 +328,8 @@ export class GameScene extends DirtyScene {
|
|||||||
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(this.load as any).rexWebFont({
|
(this.load as any).rexWebFont({
|
||||||
custom: {
|
custom: {
|
||||||
families: ["Press Start 2P"],
|
families: [ "Press Start 2P" ],
|
||||||
urls: ["/resources/fonts/fonts.css"],
|
urls: [ "/resources/fonts/fonts.css" ],
|
||||||
testString: "abcdefg",
|
testString: "abcdefg",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -375,7 +375,7 @@ export class GameScene extends DirtyScene {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [itemType, objectsOfType] of this.objectsByType) {
|
for (const [ itemType, objectsOfType ] of this.objectsByType) {
|
||||||
// FIXME: we would ideally need for the loader to WAIT for the import to be performed, which means writing our own loader plugin.
|
// FIXME: we would ideally need for the loader to WAIT for the import to be performed, which means writing our own loader plugin.
|
||||||
|
|
||||||
let itemFactory: ItemFactoryInterface;
|
let itemFactory: ItemFactoryInterface;
|
||||||
@ -406,7 +406,7 @@ export class GameScene extends DirtyScene {
|
|||||||
// TODO: we should pass here a factory to create sprites (maybe?)
|
// TODO: we should pass here a factory to create sprites (maybe?)
|
||||||
|
|
||||||
// Do we have a state for this object?
|
// Do we have a state for this object?
|
||||||
const state = roomJoinedAnswer.items[object.id];
|
const state = roomJoinedAnswer.items[ object.id ];
|
||||||
|
|
||||||
const actionableItem = itemFactory.factory(this, object, state);
|
const actionableItem = itemFactory.factory(this, object, state);
|
||||||
this.actionableItems.set(actionableItem.getId(), actionableItem);
|
this.actionableItems.set(actionableItem.getId(), actionableItem);
|
||||||
@ -429,7 +429,11 @@ export class GameScene extends DirtyScene {
|
|||||||
//hook create scene
|
//hook create scene
|
||||||
create(): void {
|
create(): void {
|
||||||
this.preloading = false;
|
this.preloading = false;
|
||||||
this.trackDirtyAnims();
|
try {
|
||||||
|
this.trackDirtyAnims();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
gameManager.gameSceneIsCreated(this);
|
gameManager.gameSceneIsCreated(this);
|
||||||
urlManager.pushRoomIdToUrl(this.room);
|
urlManager.pushRoomIdToUrl(this.room);
|
||||||
@ -455,6 +459,17 @@ export class GameScene extends DirtyScene {
|
|||||||
//initialise map
|
//initialise map
|
||||||
this.Map = this.add.tilemap(this.MapUrlFile);
|
this.Map = this.add.tilemap(this.MapUrlFile);
|
||||||
const mapDirUrl = this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf("/"));
|
const mapDirUrl = this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf("/"));
|
||||||
|
|
||||||
|
if (!this.mapFile && this.room.href == localUserStore.getLastRoomUrl()) {
|
||||||
|
localUserStore.removeLastRoomUrl();
|
||||||
|
this.scene.start(ErrorSceneName, {
|
||||||
|
title: "This map seems unaccessible.",
|
||||||
|
message:
|
||||||
|
"If you want more information, you may contact administrator or contact us at: partey@bstly.de",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.mapFile.tilesets.forEach((tileset: ITiledTileSet) => {
|
this.mapFile.tilesets.forEach((tileset: ITiledTileSet) => {
|
||||||
this.Terrains.push(
|
this.Terrains.push(
|
||||||
this.Map.addTilesetImage(
|
this.Map.addTilesetImage(
|
||||||
@ -642,7 +657,7 @@ export class GameScene extends DirtyScene {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.all([this.connectionAnswerPromise as Promise<unknown>, ...scriptPromises]).then(() => {
|
Promise.all([ this.connectionAnswerPromise as Promise<unknown>, ...scriptPromises ]).then(() => {
|
||||||
this.scene.wake();
|
this.scene.wake();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -729,8 +744,8 @@ export class GameScene extends DirtyScene {
|
|||||||
if (item === undefined) {
|
if (item === undefined) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'Received an event about object "' +
|
'Received an event about object "' +
|
||||||
message.itemId +
|
message.itemId +
|
||||||
'" but cannot find this item on the map.'
|
'" but cannot find this item on the map.'
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -975,8 +990,8 @@ export class GameScene extends DirtyScene {
|
|||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
"Error while opening a popup. Cannot find an object on the map with name '" +
|
"Error while opening a popup. Cannot find an object on the map with name '" +
|
||||||
openPopupEvent.targetObject +
|
openPopupEvent.targetObject +
|
||||||
"'. The first parameter of WA.openPopup() must be the name of a rectangle object in your map."
|
"'. The first parameter of WA.openPopup() must be the name of a rectangle object in your map."
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1241,7 +1256,7 @@ export class GameScene extends DirtyScene {
|
|||||||
const jsonTilesetDir = eventTileset.url.substr(0, eventTileset.url.lastIndexOf("/"));
|
const jsonTilesetDir = eventTileset.url.substr(0, eventTileset.url.lastIndexOf("/"));
|
||||||
//Initialise the firstgid to 1 because if there is no tileset in the tilemap, the firstgid will be 1
|
//Initialise the firstgid to 1 because if there is no tileset in the tilemap, the firstgid will be 1
|
||||||
let newFirstgid = 1;
|
let newFirstgid = 1;
|
||||||
const lastTileset = this.mapFile.tilesets[this.mapFile.tilesets.length - 1];
|
const lastTileset = this.mapFile.tilesets[ this.mapFile.tilesets.length - 1 ];
|
||||||
if (lastTileset) {
|
if (lastTileset) {
|
||||||
//If there is at least one tileset in the tilemap then calculate the firstgid of the new tileset
|
//If there is at least one tileset in the tilemap then calculate the firstgid of the new tileset
|
||||||
newFirstgid = lastTileset.firstgid + lastTileset.tilecount;
|
newFirstgid = lastTileset.firstgid + lastTileset.tilecount;
|
||||||
@ -1341,14 +1356,14 @@ export class GameScene extends DirtyScene {
|
|||||||
if (phaserLayers === []) {
|
if (phaserLayers === []) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'Could not find layer with name that contains "' +
|
'Could not find layer with name that contains "' +
|
||||||
layerName +
|
layerName +
|
||||||
'" when calling WA.hideLayer / WA.showLayer'
|
'" when calling WA.hideLayer / WA.showLayer'
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < phaserLayers.length; i++) {
|
for (let i = 0; i < phaserLayers.length; i++) {
|
||||||
phaserLayers[i].setVisible(visible);
|
phaserLayers[ i ].setVisible(visible);
|
||||||
phaserLayers[i].setCollisionByProperty({ collides: true }, visible);
|
phaserLayers[ i ].setCollisionByProperty({ collides: true }, visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
|
Loading…
Reference in New Issue
Block a user