diff --git a/public/index.html b/public/index.html index cde4f37..bebc301 100755 --- a/public/index.html +++ b/public/index.html @@ -250,7 +250,6 @@ var error = "There was an Error:\n" + e.message + "\n\nMaybe your Browser is too old."; alert(error); document.body.innerHTML = error; - } diff --git a/public/js/app.js b/public/js/app.js index 62ee8b7..d6e85e9 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -1373,6 +1373,12 @@ ThemeManager.themes = []; ThemeManager.changeListeners = []; class CookieCompliance { + + static async showIfNeeded(cookieContainer) { + let cookieCompliance = new CookieCompliance(cookieContainer); + return cookieCompliance.showIfNeeded(); + } + constructor(cookieContainerId) { this.cookieContainerId = cookieContainerId; this.dropCookie = true; @@ -1381,11 +1387,11 @@ class CookieCompliance { this.cookieValue = 'true'; } - showIfNeeded() - { + async showIfNeeded() { if (CookieCompliance.checkCookie(this.cookieName) !== this.cookieValue) { - this.show(); + return this.show(); } + return Promise.resolve(); } removeMe() { @@ -1429,12 +1435,14 @@ class CookieCompliance { show() { let cookieCompliance = this; const cookieMessage = document.getElementById(this.cookieContainerId); - cookieMessage.style.display='block'; - cookieMessage.querySelector("#close-cookie-msg").onclick = function(){ - cookieCompliance.removeMe(); - cookieMessage.remove(); - }; - + cookieMessage.style.display = 'block'; + return new Promise(r => { + cookieMessage.querySelector("#close-cookie-msg").onclick = function () { + cookieCompliance.removeMe(); + cookieMessage.remove(); + r(); + }; + }); } } @@ -2343,7 +2351,7 @@ class App { if (this._showCookieCompliance) { - new CookieCompliance('cookie-compliance').showIfNeeded(); + this._cookieClosePromise = CookieCompliance.showIfNeeded('cookie-compliance'); } } @@ -4675,6 +4683,7 @@ class SoundManager { constructor() { this.channels = {}; + this.context = new AudioContext(); } set(options, channel) { @@ -4687,49 +4696,24 @@ class SoundManager { let audio = options.audio; if (Helper.isNotNull(audio)) { - let src = null; - if (typeof audio === "string") { - src = audio; - audio = new Audio(); - audioObject.loadedPromise = new Promise((resolve, reject) => { - audio.addEventListener("loadeddata", () => { - resolve(); - }); - audio.addEventListener("error", (e) => { - console.warn(e); - reject(e); - }); - }); - audio.src = Helper.basePath(src); - } - else { - audioObject.loadedPromise = Promise.resolve(); - } + audioObject.loadedPromise = fetch(audio).then(res => res.arrayBuffer()).then(arrayBuffer => this.context.decodeAudioData(arrayBuffer)); this.stop(channel); - audioObject.audio = audio; - // audio.addEventListener('timeupdate', () => { - // let buffer = 10; - // if (this.channels[channel].audio === audio && this.channels[channel].loop) { - // if (audio.currentTime > audio.duration - buffer) { - // console.log("reset"); - // audio.currentTime = 0; - // audio.play(); - // } - // } - // }, false); } audioObject.muted = Helper.nonNull(options.muted, audioObject.muted, false); audioObject.volume = Helper.nonNull(options.volume, audioObject.volume, 1); audioObject.loop = Helper.nonNull(options.loop, audioObject.loop, false); audioObject.timeOffset = Helper.nonNull(options.timeOffset, audioObject.timeOffset, 0); + if (audioObject.muted){ + this.stop(channel); + } + this.channels[channel] = audioObject; - this._update(channel); return this.channels[channel]; } - play(channel, audioOrOptions) { + async play(channel, audioOrOptions) { channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT); if (Helper.isNull(audioOrOptions)) { audioOrOptions = {}; @@ -4742,10 +4726,17 @@ class SoundManager { this.stop(channel); this.set(audioOrOptions, channel); - // this._update(channel); if (!this.channels[channel].muted) { - this.channels[channel].audio.play(); + let buffer = await this.channels[channel].loadedPromise; + let source = this.context.createBufferSource(); + source.buffer = buffer; + source.connect(this.context.destination); + // source.loopStart = 5; + // source.loopEnd = 5; + source.loop = this.channels[channel].loop; + source.start(0); + this.channels[channel].source = source; } return this.channels[channel]; } @@ -4754,22 +4745,10 @@ class SoundManager { channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT); let oldAudio = this.channels[channel]; - if (oldAudio != null) { - oldAudio.audio.pause(); + if (Helper.nonNull(oldAudio) && Helper.nonNull(oldAudio.source)) { + oldAudio.source.stop(); } } - - _update(channel) { - let audioObject = this.channels[channel]; - - audioObject.audio.currentTime = Helper.nonNull(audioObject.timeOffset, audioObject.audio.currentTime); - audioObject.audio.loop = Helper.nonNull(audioObject.loop, audioObject.audio.loop); - audioObject.audio.volume = Helper.nonNull(audioObject.volume, audioObject.audio.volume); - if (audioObject.muted) { - this.stop(channel); - } - } - get(channel) { channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT); return this.channels[channel]; @@ -5028,20 +5007,17 @@ class ParentSegment extends Segment { static initListener() { window.addEventListener("mousedown", (e) => { ParentSegment.mouseDownTarget = e.target; - // ParentSegment.mouseDownTarget = e.originalTarget; }); window.addEventListener("mouseup", (e) => { ParentSegment.mouseDownTarget = null; }); window.addEventListener("touchstart", (e) => { - console.log("start", e); if (e.targetTouches.length === 1) { ParentSegment.mouseDownTarget = e.targetTouches[0].target; } }); window.addEventListener("touchend", (e) => { - console.log("end", e); ParentSegment.mouseDownTarget = null; }); } @@ -5070,6 +5046,7 @@ class ParentSegment extends Segment { self.rotate(); e.stopPropagation(); e.preventDefault(); + console.log("mouseup", e); } }; } @@ -6095,7 +6072,7 @@ class MenuSite extends WordRotatorBaseSite { playButton.style.width = levelStyle.getPropertyValue("width"); scaleHelper.scaleToFull(playButton.children[0], playButton, null, null, null, null, null, false); - await scaleHelper.scaleTo(0.17, levelNumber.parentElement, levelNumber.parentElement.parentElement, null, null, null, 10, null, false); + await scaleHelper.scaleTo(0.2, levelNumber.parentElement, levelNumber.parentElement.parentElement, null, null, null, 10, null, false); scaleHelper.scaleToFull(levelNumber, levelNumber.parentElement, false, false, 8, null, null, false); }; @@ -6129,6 +6106,14 @@ class MenuSite extends WordRotatorBaseSite { triangleTemplate.remove(); this.templateContainer = new TemplateContainer(leafSegmentTemplate, parentSegmentTemplate, rowSegmentTemplate, triangleTemplate); + + if (Helper.nonNull(MenuSite.app._cookieClosePromise)) { + MenuSite.app._cookieClosePromise.then(() => { + if (this.listener) { + this.listener(); + } + }); + } } onPause(args) { @@ -6137,6 +6122,11 @@ class MenuSite extends WordRotatorBaseSite { } } +MenuSite.app = null; +InitPromise.addPromise(app => { + MenuSite.app = app; +}); + class SynchronizeSite extends WordRotatorBaseSite { constructor(siteManager) { @@ -6285,7 +6275,7 @@ InitPromise.resolve(app).then(function(){ SettingsSite.settingsAction.showFor = MenuAction.SHOW_ALWAYS; let soundManager = SoundManager.getInstance(); - soundManager.play(SoundManager.CHANNELS.MUSIC, {audio: "sound/brightAndBeautifull__.mp3", loop: true, volume: 0.3}); + soundManager.play(SoundManager.CHANNELS.MUSIC, {audio: "sound/brightAndBeautifull__.wav", loop: true, volume: 0.3}); app.start(SynchronizeSite); Translator.setLanguage("de"); diff --git a/public/sound/brightAndBeautifull__.mp3 b/public/sound/brightAndBeautifull__.mp3 index 65c490f..8fc39ac 100644 Binary files a/public/sound/brightAndBeautifull__.mp3 and b/public/sound/brightAndBeautifull__.mp3 differ diff --git a/public/sound/brightAndBeautifull__.wav b/public/sound/brightAndBeautifull__.wav new file mode 100644 index 0000000..2bf2f4a Binary files /dev/null and b/public/sound/brightAndBeautifull__.wav differ diff --git a/src/js/init.js b/src/js/init.js index 72dd202..1c76190 100755 --- a/src/js/init.js +++ b/src/js/init.js @@ -59,7 +59,7 @@ InitPromise.resolve(app).then(function(){ SettingsSite.settingsAction.showFor = MenuAction.SHOW_ALWAYS; let soundManager = SoundManager.getInstance(); - soundManager.play(SoundManager.CHANNELS.MUSIC, {audio: "sound/brightAndBeautifull__.mp3", loop: true, volume: 0.3}); + soundManager.play(SoundManager.CHANNELS.MUSIC, {audio: "sound/brightAndBeautifull__.wav", loop: true, volume: 0.3}); app.start(SynchronizeSite); Translator.setLanguage("de"); diff --git a/src/js/lib/pwa-assets.js b/src/js/lib/pwa-assets.js index fb9c860..61ae644 100755 --- a/src/js/lib/pwa-assets.js +++ b/src/js/lib/pwa-assets.js @@ -119,6 +119,7 @@ class SoundManager { constructor() { this.channels = {}; + this.context = new AudioContext(); } set(options, channel) { @@ -131,49 +132,24 @@ class SoundManager { let audio = options.audio; if (Helper.isNotNull(audio)) { - let src = null; - if (typeof audio === "string") { - src = audio; - audio = new Audio(); - audioObject.loadedPromise = new Promise((resolve, reject) => { - audio.addEventListener("loadeddata", () => { - resolve(); - }); - audio.addEventListener("error", (e) => { - console.warn(e); - reject(e); - }); - }); - audio.src = Helper.basePath(src); - } - else { - audioObject.loadedPromise = Promise.resolve(); - } + audioObject.loadedPromise = fetch(audio).then(res => res.arrayBuffer()).then(arrayBuffer => this.context.decodeAudioData(arrayBuffer)); this.stop(channel); - audioObject.audio = audio; - // audio.addEventListener('timeupdate', () => { - // let buffer = 10; - // if (this.channels[channel].audio === audio && this.channels[channel].loop) { - // if (audio.currentTime > audio.duration - buffer) { - // console.log("reset"); - // audio.currentTime = 0; - // audio.play(); - // } - // } - // }, false); } audioObject.muted = Helper.nonNull(options.muted, audioObject.muted, false); audioObject.volume = Helper.nonNull(options.volume, audioObject.volume, 1); audioObject.loop = Helper.nonNull(options.loop, audioObject.loop, false); audioObject.timeOffset = Helper.nonNull(options.timeOffset, audioObject.timeOffset, 0); + if (audioObject.muted){ + this.stop(channel); + } + this.channels[channel] = audioObject; - this._update(channel); return this.channels[channel]; } - play(channel, audioOrOptions) { + async play(channel, audioOrOptions) { channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT); if (Helper.isNull(audioOrOptions)) { audioOrOptions = {}; @@ -186,10 +162,17 @@ class SoundManager { this.stop(channel); this.set(audioOrOptions, channel); - // this._update(channel); if (!this.channels[channel].muted) { - this.channels[channel].audio.play(); + let buffer = await this.channels[channel].loadedPromise; + let source = this.context.createBufferSource(); + source.buffer = buffer; + source.connect(this.context.destination); + // source.loopStart = 5; + // source.loopEnd = 5; + source.loop = this.channels[channel].loop; + source.start(0); + this.channels[channel].source = source; } return this.channels[channel]; } @@ -198,22 +181,10 @@ class SoundManager { channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT); let oldAudio = this.channels[channel]; - if (oldAudio != null) { - oldAudio.audio.pause(); + if (Helper.nonNull(oldAudio) && Helper.nonNull(oldAudio.source)) { + oldAudio.source.stop(); } } - - _update(channel) { - let audioObject = this.channels[channel]; - - audioObject.audio.currentTime = Helper.nonNull(audioObject.timeOffset, audioObject.audio.currentTime); - audioObject.audio.loop = Helper.nonNull(audioObject.loop, audioObject.audio.loop); - audioObject.audio.volume = Helper.nonNull(audioObject.volume, audioObject.audio.volume); - if (audioObject.muted) { - this.stop(channel); - } - } - get(channel) { channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT); return this.channels[channel]; diff --git a/src/js/lib/pwa-lib.js b/src/js/lib/pwa-lib.js index aa5d31c..295f792 100755 --- a/src/js/lib/pwa-lib.js +++ b/src/js/lib/pwa-lib.js @@ -1373,6 +1373,12 @@ ThemeManager.themes = []; ThemeManager.changeListeners = []; class CookieCompliance { + + static async showIfNeeded(cookieContainer) { + let cookieCompliance = new CookieCompliance(cookieContainer); + return cookieCompliance.showIfNeeded(); + } + constructor(cookieContainerId) { this.cookieContainerId = cookieContainerId; this.dropCookie = true; @@ -1381,11 +1387,11 @@ class CookieCompliance { this.cookieValue = 'true'; } - showIfNeeded() - { + async showIfNeeded() { if (CookieCompliance.checkCookie(this.cookieName) !== this.cookieValue) { - this.show(); + return this.show(); } + return Promise.resolve(); } removeMe() { @@ -1429,12 +1435,14 @@ class CookieCompliance { show() { let cookieCompliance = this; const cookieMessage = document.getElementById(this.cookieContainerId); - cookieMessage.style.display='block'; - cookieMessage.querySelector("#close-cookie-msg").onclick = function(){ - cookieCompliance.removeMe(); - cookieMessage.remove(); - }; - + cookieMessage.style.display = 'block'; + return new Promise(r => { + cookieMessage.querySelector("#close-cookie-msg").onclick = function () { + cookieCompliance.removeMe(); + cookieMessage.remove(); + r(); + }; + }); } } @@ -2343,7 +2351,7 @@ class App { if (this._showCookieCompliance) { - new CookieCompliance('cookie-compliance').showIfNeeded(); + this._cookieClosePromise = CookieCompliance.showIfNeeded('cookie-compliance'); } } diff --git a/src/module/Application/pwa/js/site/MenuSite.js b/src/module/Application/pwa/js/site/MenuSite.js index e2c794c..f13b676 100644 --- a/src/module/Application/pwa/js/site/MenuSite.js +++ b/src/module/Application/pwa/js/site/MenuSite.js @@ -3,7 +3,7 @@ import {LevelSite} from "./LevelSite"; import {ScaleHelper} from "../../../../../js/lib/pwa-assets"; import {TemplateContainer} from "../wordrotator/Segment/TemplateContainer"; import {MainMenuLevel} from "../wordrotator/Level/MainMenuLevel"; -import {Helper} from "../../../../../js/lib/pwa-lib"; +import {Helper, InitPromise} from "../../../../../js/lib/pwa-lib"; export class MenuSite extends WordRotatorBaseSite { constructor(siteManager) { @@ -73,7 +73,7 @@ export class MenuSite extends WordRotatorBaseSite { playButton.style.width = levelStyle.getPropertyValue("width"); scaleHelper.scaleToFull(playButton.children[0], playButton, null, null, null, null, null, false); - await scaleHelper.scaleTo(0.17, levelNumber.parentElement, levelNumber.parentElement.parentElement, null, null, null, 10, null, false); + await scaleHelper.scaleTo(0.2, levelNumber.parentElement, levelNumber.parentElement.parentElement, null, null, null, 10, null, false); scaleHelper.scaleToFull(levelNumber, levelNumber.parentElement, false, false, 8, null, null, false); }; @@ -107,10 +107,23 @@ export class MenuSite extends WordRotatorBaseSite { triangleTemplate.remove(); this.templateContainer = new TemplateContainer(leafSegmentTemplate, parentSegmentTemplate, rowSegmentTemplate, triangleTemplate); + + if (Helper.nonNull(MenuSite.app._cookieClosePromise)) { + MenuSite.app._cookieClosePromise.then(() => { + if (this.listener) { + this.listener(); + } + }); + } } onPause(args) { window.removeEventListener("resize", this.listener); super.onPause(args); } -} \ No newline at end of file +} + +MenuSite.app = null; +InitPromise.addPromise(app => { + MenuSite.app = app; +}); \ No newline at end of file diff --git a/src/module/Application/pwa/js/wordrotator/Segment/ParentSegment.js b/src/module/Application/pwa/js/wordrotator/Segment/ParentSegment.js index 4471933..1894402 100755 --- a/src/module/Application/pwa/js/wordrotator/Segment/ParentSegment.js +++ b/src/module/Application/pwa/js/wordrotator/Segment/ParentSegment.js @@ -4,20 +4,19 @@ export class ParentSegment extends Segment { static initListener() { window.addEventListener("mousedown", (e) => { ParentSegment.mouseDownTarget = e.target; - // ParentSegment.mouseDownTarget = e.originalTarget; + ParentSegment.clickPosition = {x: e.clientX, y: e.clientY}; }); window.addEventListener("mouseup", (e) => { ParentSegment.mouseDownTarget = null; }); window.addEventListener("touchstart", (e) => { - console.log("start", e); if (e.targetTouches.length === 1) { ParentSegment.mouseDownTarget = e.targetTouches[0].target; + ParentSegment.clickPosition = {x: e.targetTouches[0].clientX, y: e.targetTouches[0].clientY}; } }); window.addEventListener("touchend", (e) => { - console.log("end", e); ParentSegment.mouseDownTarget = null; }); } @@ -46,6 +45,7 @@ export class ParentSegment extends Segment { self.rotate(); e.stopPropagation(); e.preventDefault(); + console.log("mouseup", e); } }; }