Merge branch 'develop' of github.com:thecodingmachine/workadventure into menuInSvelte

This commit is contained in:
GRL 2021-08-20 16:18:45 +02:00
commit edfe440c6e
4 changed files with 32 additions and 26 deletions

View file

@ -1,4 +1,4 @@
let CACHE_NAME = 'workavdenture-cache-v1.4.14'; let CACHE_NAME = 'workavdenture-cache';
let urlsToCache = [ let urlsToCache = [
'/' '/'
]; ];
@ -14,7 +14,8 @@ self.addEventListener('install', function(event) {
}); });
self.addEventListener('fetch', function(event) { self.addEventListener('fetch', function(event) {
event.respondWith( //TODO mamnage fetch data and cache management
/*event.respondWith(
caches.match(event.request) caches.match(event.request)
.then(function(response) { .then(function(response) {
// Cache hit - return response // Cache hit - return response
@ -44,7 +45,7 @@ self.addEventListener('fetch', function(event) {
} }
); );
}) })
); );*/
}); });
self.addEventListener('activate', function(event) { self.addEventListener('activate', function(event) {

View file

@ -1,38 +1,35 @@
import {sendToWorkadventure} from "../IframeApiContribution"; import { sendToWorkadventure } from "../IframeApiContribution";
import type {LoadSoundEvent} from "../../Events/LoadSoundEvent"; import type { LoadSoundEvent } from "../../Events/LoadSoundEvent";
import type {PlaySoundEvent} from "../../Events/PlaySoundEvent"; import type { PlaySoundEvent } from "../../Events/PlaySoundEvent";
import type {StopSoundEvent} from "../../Events/StopSoundEvent"; import type { StopSoundEvent } from "../../Events/StopSoundEvent";
import SoundConfig = Phaser.Types.Sound.SoundConfig; import SoundConfig = Phaser.Types.Sound.SoundConfig;
export class Sound { export class Sound {
constructor(private url: string) { constructor(private url: string) {
sendToWorkadventure({ sendToWorkadventure({
"type": 'loadSound', type: "loadSound",
"data": { data: {
url: this.url, url: this.url,
} as LoadSoundEvent } as LoadSoundEvent,
}); });
} }
public play(config: SoundConfig) { public play(config: SoundConfig | undefined) {
sendToWorkadventure({ sendToWorkadventure({
"type": 'playSound', type: "playSound",
"data": { data: {
url: this.url, url: this.url,
config config,
} as PlaySoundEvent } as PlaySoundEvent,
}); });
return this.url; return this.url;
} }
public stop() { public stop() {
sendToWorkadventure({ sendToWorkadventure({
"type": 'stopSound', type: "stopSound",
"data": { data: {
url: this.url, url: this.url,
} as StopSoundEvent } as StopSoundEvent,
}); });
return this.url; return this.url;
} }

View file

@ -18,7 +18,7 @@ const state = "state";
const nonce = "nonce"; const nonce = "nonce";
const notification = "notificationPermission"; const notification = "notificationPermission";
const cacheAPIIndex = "workavdenture-cache-v1"; const cacheAPIIndex = "workavdenture-cache";
class LocalUserStore { class LocalUserStore {
saveUser(localUser: LocalUser) { saveUser(localUser: LocalUser) {

View file

@ -926,9 +926,10 @@ export class GameScene extends DirtyScene {
}); });
this.gameMap.onPropertyChange("zone", (newValue, oldValue) => { this.gameMap.onPropertyChange("zone", (newValue, oldValue) => {
if (newValue === undefined || newValue === false || newValue === "") { if (oldValue) {
iframeListener.sendLeaveEvent(oldValue as string); iframeListener.sendLeaveEvent(oldValue as string);
} else { }
if (newValue) {
iframeListener.sendEnterEvent(newValue as string); iframeListener.sendEnterEvent(newValue as string);
} }
}); });
@ -951,9 +952,13 @@ export class GameScene extends DirtyScene {
return; return;
} }
const escapedMessage = HtmlUtils.escapeHtml(openPopupEvent.message); const escapedMessage = HtmlUtils.escapeHtml(openPopupEvent.message);
let html = `<div id="container" hidden><div class="nes-container with-title is-centered"> let html = '<div id="container" hidden>';
if (escapedMessage) {
html += `<div class="nes-container with-title is-centered">
${escapedMessage} ${escapedMessage}
</div> `; </div> `;
}
const buttonContainer = '<div class="buttonContainer"</div>'; const buttonContainer = '<div class="buttonContainer"</div>';
html += buttonContainer; html += buttonContainer;
let id = 0; let id = 0;
@ -983,7 +988,11 @@ ${escapedMessage}
const btnId = id; const btnId = id;
button.onclick = () => { button.onclick = () => {
iframeListener.sendButtonClickedEvent(openPopupEvent.popupId, btnId); iframeListener.sendButtonClickedEvent(openPopupEvent.popupId, btnId);
// Disable for a short amount of time to let time to the script to remove the popup
button.disabled = true; button.disabled = true;
setTimeout(() => {
button.disabled = false;
}, 100);
}; };
id++; id++;
} }
@ -1364,7 +1373,6 @@ ${escapedMessage}
iframeListener.unregisterAnswerer("getState"); iframeListener.unregisterAnswerer("getState");
iframeListener.unregisterAnswerer("loadTileset"); iframeListener.unregisterAnswerer("loadTileset");
iframeListener.unregisterAnswerer("getMapData"); iframeListener.unregisterAnswerer("getMapData");
iframeListener.unregisterAnswerer("getState");
iframeListener.unregisterAnswerer("triggerActionMessage"); iframeListener.unregisterAnswerer("triggerActionMessage");
iframeListener.unregisterAnswerer("removeActionMessage"); iframeListener.unregisterAnswerer("removeActionMessage");
this.sharedVariablesManager?.close(); this.sharedVariablesManager?.close();