Startseite und Tests geupdated
This commit is contained in:
@@ -23,6 +23,7 @@ applyPolyfills();
|
||||
import {WordRotatorSettingFragment} from "../module/Application/pwa/js/Fragment/WordRotatorSettingFragment";
|
||||
|
||||
import './settings'
|
||||
import {SoundManager} from "./lib/pwa-assets";
|
||||
|
||||
ThemeManager.addTheme(new Theme('red', ''));
|
||||
ThemeManager.addTheme(new Theme("blue", "blue"));
|
||||
@@ -57,6 +58,9 @@ LoginSite.addLoginAction = false;
|
||||
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});
|
||||
|
||||
app.start(SynchronizeSite);
|
||||
Translator.setLanguage("de");
|
||||
});
|
||||
|
||||
@@ -109,6 +109,123 @@ class ScaleHelper {
|
||||
}
|
||||
}
|
||||
|
||||
class SoundManager {
|
||||
static getInstance() {
|
||||
if (Helper.isNull(SoundManager.instance)) {
|
||||
SoundManager.instance = new SoundManager();
|
||||
}
|
||||
return SoundManager.instance;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.channels = {};
|
||||
}
|
||||
|
||||
set(options, channel) {
|
||||
channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT);
|
||||
let audioObject = Helper.nonNull(this.channels[channel], {});
|
||||
|
||||
if (typeof options === "string") {
|
||||
options = {audio: options};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
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);
|
||||
|
||||
this.channels[channel] = audioObject;
|
||||
this._update(channel);
|
||||
|
||||
return this.channels[channel];
|
||||
}
|
||||
|
||||
play(channel, audioOrOptions) {
|
||||
channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT);
|
||||
if (Helper.isNull(audioOrOptions)) {
|
||||
audioOrOptions = {};
|
||||
} else if (!(typeof audioOrOptions === "object")) {
|
||||
audioOrOptions = {
|
||||
audio: audioOrOptions
|
||||
};
|
||||
}
|
||||
audioOrOptions.timeOffset = Helper.nonNull(audioOrOptions.timeOffset, 0);
|
||||
|
||||
this.stop(channel);
|
||||
this.set(audioOrOptions, channel);
|
||||
// this._update(channel);
|
||||
|
||||
if (!this.channels[channel].muted) {
|
||||
this.channels[channel].audio.play();
|
||||
}
|
||||
return this.channels[channel];
|
||||
}
|
||||
|
||||
stop(channel) {
|
||||
channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT);
|
||||
|
||||
let oldAudio = this.channels[channel];
|
||||
if (oldAudio != null) {
|
||||
oldAudio.audio.pause();
|
||||
}
|
||||
}
|
||||
|
||||
_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];
|
||||
}
|
||||
}
|
||||
|
||||
SoundManager.CHANNELS = {
|
||||
MUSIC: "music",
|
||||
SOUND: "sound",
|
||||
DEFAULT: "default"
|
||||
};
|
||||
|
||||
class TabbedFragment extends Fragment {
|
||||
constructor(site) {
|
||||
super(site, 'pwaAssets/html/fragment/tabbedFragment.html');
|
||||
@@ -174,4 +291,4 @@ class TabbedFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
export { DelayPromise, RotateHelper, ScaleHelper, TabbedFragment };
|
||||
export { DelayPromise, RotateHelper, ScaleHelper, SoundManager, TabbedFragment };
|
||||
|
||||
@@ -872,10 +872,12 @@ class Helper {
|
||||
}
|
||||
|
||||
static nonNull(val1, val2) {
|
||||
if (Helper.isNotNull(val1)) {
|
||||
return val1;
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
if (Helper.isNotNull(arguments[i])) {
|
||||
return arguments[i];
|
||||
}
|
||||
}
|
||||
return val2;
|
||||
return null;
|
||||
}
|
||||
|
||||
static notEmpty(value) {
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {FlashMessenger, Helper, Menu, MenuAction, SystemSettings} from "../../../../../js/lib/pwa-lib";
|
||||
import {ParentSegment} from "../wordrotator/Segment/ParentSegment";
|
||||
import {LeafSegment} from "../wordrotator/Segment/LeafSegment";
|
||||
import {TemplateContainer} from "../wordrotator/Segment/TemplateContainer";
|
||||
import {SimpleLevel} from "../wordrotator/Level/SimpleLevel";
|
||||
import {LevelHelper} from "../wordrotator/Level/LevelHelper";
|
||||
import {WordRotatorDb} from "../WordRotatorDb";
|
||||
import {ScaleHelper} from "../../../../../js/lib/pwa-assets";
|
||||
import {ScaleHelper, SoundManager} from "../../../../../js/lib/pwa-assets";
|
||||
import {EndSite} from "./EndSite";
|
||||
import {WordRotatorBaseSite} from "./WordRotatorBaseSite";
|
||||
|
||||
@@ -34,16 +31,10 @@ export class LevelSite extends WordRotatorBaseSite {
|
||||
this.wonParams = {
|
||||
aborted: false,
|
||||
coinCounterTimer: null,
|
||||
audio: new Audio()
|
||||
};
|
||||
this.wonParams.audioPromise = Promise.race([new Promise(resolve => {
|
||||
this.wonParams.audio.addEventListener('loadeddata', resolve);
|
||||
}),
|
||||
new Promise(resolve => {
|
||||
this.wonParams.audio.addEventListener('error', resolve);
|
||||
})
|
||||
]);
|
||||
this.wonParams.audio.src = Helper.basePath("sound/single_coin_fall_on_concrete_.mp3");
|
||||
|
||||
let soundManager = SoundManager.getInstance();
|
||||
soundManager.set("sound/single_coin_fall_on_concrete_.mp3", SoundManager.CHANNELS.SOUND);
|
||||
|
||||
return super.onConstruct(args);
|
||||
}
|
||||
@@ -223,15 +214,17 @@ export class LevelSite extends WordRotatorBaseSite {
|
||||
let coinsBefore = parseInt(Helper.nonNull(localStorage.getItem("coins"), "0"));
|
||||
localStorage.setItem("coins", coinsBefore + parseInt(coinsPerLevel));
|
||||
|
||||
let soundManager = SoundManager.getInstance();
|
||||
let audioOptions = soundManager.get(SoundManager.CHANNELS.SOUND);
|
||||
|
||||
let coinPromise = Promise.all([new Promise((r) => {
|
||||
setTimeout(() => {
|
||||
r(continueButton.fadeIn());
|
||||
}, 500)
|
||||
}), this.wonParams.audioPromise]);
|
||||
}), audioOptions.loadedPromise.catch(e => {console.error(e)})]);
|
||||
|
||||
this.wonParams.aborted = false;
|
||||
|
||||
let audio = this.wonParams.audio;
|
||||
for (let i = 0; i < coinsPerLevel; i++) {
|
||||
let coinElem = Helper.cloneNode(this.coinTemplate);
|
||||
this.coinContainer.appendChild(coinElem);
|
||||
@@ -241,11 +234,7 @@ export class LevelSite extends WordRotatorBaseSite {
|
||||
|
||||
if (!this.wonParams.aborted) {
|
||||
coinElem.fadeIn(timeout / 1000);
|
||||
if (audio !== null) {
|
||||
audio.pause();
|
||||
audio.currentTime = 0;
|
||||
audio.play();
|
||||
}
|
||||
soundManager.play(SoundManager.CHANNELS.SOUND);
|
||||
|
||||
this.wonParams.coinCounterTimer = setTimeout(() => {
|
||||
if (!this.wonParams.aborted) {
|
||||
|
||||
@@ -52,6 +52,7 @@ export class MenuSite extends WordRotatorBaseSite {
|
||||
if (index === indexBlocked) {
|
||||
index = (index + 1) % rotationsSegments.length;
|
||||
}
|
||||
|
||||
rotationsSegments[index].rotate();
|
||||
randomRotationFunction();
|
||||
}, timeout);
|
||||
@@ -72,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.15, levelNumber.parentElement, levelNumber.parentElement.parentElement, null, null, null, 10, null, false);
|
||||
await scaleHelper.scaleTo(0.17, levelNumber.parentElement, levelNumber.parentElement.parentElement, null, null, null, 10, null, false);
|
||||
scaleHelper.scaleToFull(levelNumber, levelNumber.parentElement, false, false, 8, null, null, false);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user