Startseite und Tests geupdated

This commit is contained in:
silas
2018-09-24 19:58:37 +02:00
parent 11fe3628a2
commit c8c5ccf737
15 changed files with 403 additions and 39601 deletions

View File

@@ -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) {
@@ -4663,6 +4665,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 Code {
constructor(args) {
if (typeof args === "string") {
@@ -4792,6 +4911,35 @@ WordRotatorDb.OBJECT_STORE = {
};
WordRotatorDb.instance = null;
class TemplateContainer{
constructor(leafTemplate, parentTemplate, rowTemplate, triangleTemplate){
this.leafTemplate = leafTemplate;
this.parentTemplate = parentTemplate;
this.rowTemplate = rowTemplate;
this.triangleTemplate = triangleTemplate;
}
copyLeafTemplate()
{
return Helper.cloneNode(this.leafTemplate);
}
copyParentTemplate()
{
return Helper.cloneNode(this.parentTemplate);
}
copyRowTemplate()
{
return Helper.cloneNode(this.rowTemplate);
}
copyTriangleTemplate()
{
return Helper.cloneNode(this.triangleTemplate);
}
}
class Segment{
constructor(element){
this.rotation = 0;
@@ -4853,6 +5001,29 @@ class Segment{
}
}
class LeafSegment extends Segment {
constructor(element, leaf) {
super(element);
this.leaf = 'A';
if (Helper.isNotNull(leaf)) {
this.setLeaf(leaf);
}
}
sameAs(otherSegment) {
return (otherSegment instanceof LeafSegment && otherSegment.leaf === this.leaf);
}
setLeaf(leaf) {
this.leaf = leaf;
}
_updateElement() {
this.element.querySelector(".leaf-element").removeAllChildren().appendChild(document.createTextNode(this.leaf));
}
}
class ParentSegment extends Segment {
static initListener() {
window.addEventListener("mousedown", (e) => {
@@ -5056,58 +5227,6 @@ class ParentSegment extends Segment {
ParentSegment.initListener();
class LeafSegment extends Segment {
constructor(element, leaf) {
super(element);
this.leaf = 'A';
if (Helper.isNotNull(leaf)) {
this.setLeaf(leaf);
}
}
sameAs(otherSegment) {
return (otherSegment instanceof LeafSegment && otherSegment.leaf === this.leaf);
}
setLeaf(leaf) {
this.leaf = leaf;
}
_updateElement() {
this.element.querySelector(".leaf-element").removeAllChildren().appendChild(document.createTextNode(this.leaf));
}
}
class TemplateContainer{
constructor(leafTemplate, parentTemplate, rowTemplate, triangleTemplate){
this.leafTemplate = leafTemplate;
this.parentTemplate = parentTemplate;
this.rowTemplate = rowTemplate;
this.triangleTemplate = triangleTemplate;
}
copyLeafTemplate()
{
return Helper.cloneNode(this.leafTemplate);
}
copyParentTemplate()
{
return Helper.cloneNode(this.parentTemplate);
}
copyRowTemplate()
{
return Helper.cloneNode(this.rowTemplate);
}
copyTriangleTemplate()
{
return Helper.cloneNode(this.triangleTemplate);
}
}
class Level {
constructor(templateContainer) {
this.rootSegment = null;
@@ -5636,16 +5755,10 @@ 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);
}
@@ -5825,15 +5938,17 @@ 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);
@@ -5843,11 +5958,7 @@ 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) {
@@ -5931,7 +6042,6 @@ class MenuSite extends WordRotatorBaseSite {
level.createSegments();
level.getWonPromise().then(() => {
console.log("won!");
this.startSite(LevelSite);
});
@@ -5964,6 +6074,7 @@ class MenuSite extends WordRotatorBaseSite {
if (index === indexBlocked) {
index = (index + 1) % rotationsSegments.length;
}
rotationsSegments[index].rotate();
randomRotationFunction();
}, timeout);
@@ -5984,7 +6095,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.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);
};
@@ -6173,6 +6284,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");
});

Binary file not shown.