update to pc
This commit is contained in:
@@ -1,14 +1,25 @@
|
||||
<div>
|
||||
<div id = 'segment-leaf-template' class = 'segment segment-leaf'>
|
||||
<div class = 'leaf-element'></div>
|
||||
<div class='max-height'>
|
||||
<!-- Templates for segments-->
|
||||
<div id='segment-leaf-template' class='segment segment-leaf'>
|
||||
<div class='leaf-element'></div>
|
||||
</div>
|
||||
<div id = 'segment-parent-template' class = 'segment segment-parent'>
|
||||
<div class = 'child-container'></div>
|
||||
<div id='segment-parent-template' class='segment segment-parent'>
|
||||
<div class='child-container'></div>
|
||||
</div>
|
||||
<div id = 'segment-row-template' class = 'segment segment-row'>
|
||||
<div class = 'child-container'></div>
|
||||
<div id='segment-row-template' class='segment segment-row'>
|
||||
<div class='child-container'></div>
|
||||
</div>
|
||||
|
||||
<div id = 'level'>
|
||||
<!-- Site Content -->
|
||||
<div class='max-height'>
|
||||
<div class = 'show-when-won height-20 center flex-center'>
|
||||
<b data-translation="won" id = "won-text"></b>
|
||||
</div>
|
||||
<div class="flex-center height-60 overflow-hidden">
|
||||
<div id='level'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='show-when-won flex-center height-20'>
|
||||
<button class='button' id='continue-button' data-translation="continue"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -35,12 +35,12 @@ export class WordRotatorDb extends MyDb {
|
||||
return this.load(levelId, WordRotatorDb.OBJECT_STORE.LEVEL);
|
||||
}
|
||||
|
||||
async loadNextLevel() {
|
||||
async loadNextLevel(rendererTypes) {
|
||||
const levels = await this.loadMany("difficulty", IDBKeyRange.lowerBound(0), WordRotatorDb.OBJECT_STORE.LEVEL);
|
||||
|
||||
let newLevels = [];
|
||||
for (let i = 0, n = levels.length; i < n; i++) {
|
||||
if (!levels[i].deleted && !levels[i].played) {
|
||||
if (!levels[i]["deleted"] && !levels[i]["played"] && rendererTypes.indexOf(levels[i]["rendererType"]) !== -1) {
|
||||
newLevels.push(levels[i]);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,13 @@ export class WordRotatorDb extends MyDb {
|
||||
|
||||
return newLevels[Math.round(Math.random() * newLevels.length) % newLevels.length];
|
||||
}
|
||||
|
||||
async saveLevelPlayed(levelId)
|
||||
{
|
||||
const level = await this.loadLevel(levelId);
|
||||
level.played = true;
|
||||
return await this.saveObj(level, WordRotatorDb.OBJECT_STORE.LEVEL);
|
||||
}
|
||||
}
|
||||
|
||||
WordRotatorDb.OBJECT_STORE = {
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
import {AbstractSite, Helper} from "../../../../../js/lib/pwa-lib";
|
||||
import {AbstractSite, Helper, Menu, MenuAction} 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";
|
||||
|
||||
export class LevelSite extends AbstractSite {
|
||||
constructor(siteManager) {
|
||||
super(siteManager, "html/application/level.html", "level");
|
||||
}
|
||||
|
||||
createActionBarMenu(menu) {
|
||||
menu = super.createActionBarMenu(menu);
|
||||
|
||||
this.levelCounterAction = new MenuAction("", function(){}, Menu.SHOW_ALWAYS, 0);
|
||||
this.levelCounterAction.setShouldTranslate(false);
|
||||
menu.addAction(this.levelCounterAction);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
onConstruct(args) {
|
||||
this.setTitle("Level");
|
||||
|
||||
this.levelCounter = Helper.nonNull(localStorage.getItem("levelCounter"), 1);
|
||||
|
||||
return super.onConstruct(args);
|
||||
}
|
||||
|
||||
@@ -31,24 +45,43 @@ export class LevelSite extends AbstractSite {
|
||||
parentSegmentTemplate.remove();
|
||||
rowSegmentTemplate.remove();
|
||||
|
||||
let self = this;
|
||||
let continueButton = this.findBy("#continue-button");
|
||||
continueButton.addEventListener("click", ()=> {
|
||||
self.nextLevel();
|
||||
});
|
||||
|
||||
let wonText = this.findBy("#won-text");
|
||||
|
||||
let scaleHelper = new ScaleHelper();
|
||||
scaleHelper.scaleToFull(continueButton, continueButton.parentElement);
|
||||
scaleHelper.scaleToFull(wonText, wonText.parentElement);
|
||||
|
||||
this.levelCounterAction.setTitle(this.levelCounter);
|
||||
this.templateContainer = new TemplateContainer(leafSegmentTemplate, parentSegmentTemplate, rowSegmentTemplate);
|
||||
this.nextLevel();
|
||||
}
|
||||
|
||||
async nextLevel() {
|
||||
try {
|
||||
this._siteContent.classList.remove('won');
|
||||
|
||||
const db = WordRotatorDb.getInstance();
|
||||
const nextLevelJson = await db.loadNextLevel();
|
||||
const nextLevelJson = await db.loadNextLevel([20]);
|
||||
const level = LevelHelper.inflateLevel(nextLevelJson, this.templateContainer);
|
||||
|
||||
const self = this;
|
||||
level.getWonPromise().then(() => {
|
||||
self.nextLevel();
|
||||
self.levelWon(level);
|
||||
});
|
||||
|
||||
level.createSegments();
|
||||
level.getRootSegment()._updateElement();
|
||||
this.findBy("#level").appendChild(level.getRootSegment().getElement());
|
||||
|
||||
let levelSegment = this.findBy("#level");
|
||||
levelSegment.removeAllChildren().appendChild(level.getRootSegment().getElement());
|
||||
let scaleHelper = new ScaleHelper();
|
||||
scaleHelper.scaleToFull(levelSegment, levelSegment.parentElement, false, false, 2,level.words[0].length * 2);
|
||||
|
||||
this.level = level;
|
||||
}
|
||||
@@ -56,4 +89,16 @@ export class LevelSite extends AbstractSite {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async levelWon(level){
|
||||
const db = WordRotatorDb.getInstance();
|
||||
// db.saveLevelPlayed(level);
|
||||
|
||||
this.levelCounter++;
|
||||
localStorage.setItem("levelCounter", this.levelCounter);
|
||||
this.levelCounterAction.setTitle(this.levelCounter);
|
||||
this.levelCounterAction.redraw();
|
||||
|
||||
this._siteContent.classList.add('won');
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ export class Level {
|
||||
this.templateContainer = templateContainer;
|
||||
|
||||
this.hasWon = false;
|
||||
this.id = null;
|
||||
|
||||
this.wonResolver = null;
|
||||
this.giveUpResolver = null;
|
||||
@@ -20,6 +21,16 @@ export class Level {
|
||||
});
|
||||
}
|
||||
|
||||
setId(id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
getLevel()
|
||||
{
|
||||
return this;
|
||||
@@ -29,6 +40,10 @@ export class Level {
|
||||
{
|
||||
this.rootSegment = rootSegment;
|
||||
this.rootSegment.setParent(this);
|
||||
if (this.startRotations)
|
||||
{
|
||||
this.applyRotations();
|
||||
}
|
||||
}
|
||||
|
||||
setWords(words)
|
||||
@@ -44,6 +59,15 @@ export class Level {
|
||||
this.startRotations = rotations;
|
||||
}
|
||||
|
||||
applyRotations(rotations)
|
||||
{
|
||||
if (this.rootSegment)
|
||||
{
|
||||
rotations = Helper.nonNull(rotations, this.startRotations);
|
||||
this.rootSegment.applyRotations(rotations);
|
||||
}
|
||||
}
|
||||
|
||||
getHasWon()
|
||||
{
|
||||
return this.hasWon;
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
export class LevelHelper{
|
||||
static setLevelType(typeId, level)
|
||||
{
|
||||
export class LevelHelper {
|
||||
static setLevelType(typeId, level) {
|
||||
LevelHelper.types[typeId] = level;
|
||||
}
|
||||
|
||||
static getLevelClass(type)
|
||||
{
|
||||
static getLevelClass(type) {
|
||||
return LevelHelper.types[type];
|
||||
}
|
||||
|
||||
static inflateLevel(jsonLevel, templateContainer)
|
||||
{
|
||||
static inflateLevel(jsonLevel, templateContainer) {
|
||||
let level = new (LevelHelper.types[jsonLevel["rendererType"]])(templateContainer);
|
||||
level.setWords(jsonLevel["words"]);
|
||||
level.setId(jsonLevel["id"]);
|
||||
|
||||
for (let i = 0, n = jsonLevel["rotations"].length; i < n; i++) {
|
||||
if (jsonLevel["rotations"][i] <= 4) {
|
||||
jsonLevel["rotations"][i] = 90 * jsonLevel["rotations"][i];
|
||||
}
|
||||
}
|
||||
|
||||
level.setStartRotations(jsonLevel["rotations"]);
|
||||
return level;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ export class RowLevel extends Level {
|
||||
parent.addChild(leafsWordTwo[2 * i + 1]);
|
||||
rootSegment.addChild(parent);
|
||||
}
|
||||
|
||||
rootSegment.applyRotations(this.startRotations);
|
||||
|
||||
// rootSegment.applyRotations(this.startRotations);
|
||||
this.setRootSegment(rootSegment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ export class ParentSegment extends Segment {
|
||||
this.getLevel().checkHasWon(new Promise((resolve, reject)=>{
|
||||
this.element.addEventListener("animationend", resolve);
|
||||
}));
|
||||
return new DelayPromise(250);
|
||||
// return new DelayPromise(250);
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(resolve, 250);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
{
|
||||
"is-writing":"{0} schreibt...",
|
||||
"restart":"Story neustarten...",
|
||||
"should-restart-title":"Wirklich neustarten?",
|
||||
"should-restart-question":"Willst du wirklich neu starten? Dein bisheriger Fortschritt geht dabei verloren!"
|
||||
"won":"Gewonnen!",
|
||||
"continue":"Weiter"
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"is-writing":"{0} is writing..."
|
||||
"won":"Won!",
|
||||
"continue":"Continue"
|
||||
}
|
||||
Reference in New Issue
Block a user