update to pc
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
<div class = 'row'>
|
||||
<div class = 'small-12 smedium-6 columns' data-translation="current-time">Current time:</div>
|
||||
<div class = 'small-12 smedium-6 columns' id = 'current-time'>???</div>
|
||||
</div>
|
||||
3
src/module/Application/pwa/html/application/sync.html
Normal file
3
src/module/Application/pwa/html/application/sync.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
Sync
|
||||
</div>
|
||||
38
src/module/Application/pwa/js/WordRotatorDb.js
Normal file
38
src/module/Application/pwa/js/WordRotatorDb.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import {Helper, MyDb} from "../../../../js/lib/pwa-lib";
|
||||
|
||||
export class WordRotatorDb extends MyDb {
|
||||
|
||||
static getInstance() {
|
||||
if (Helper.isNull(WordRotatorDb.instance)) {
|
||||
WordRotatorDb.instance = new WordRotatorDb();
|
||||
}
|
||||
return WordRotatorDb.instance;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super("wordRotator", 2);
|
||||
}
|
||||
|
||||
upgrade(db, oldVersion, newVersion, e) {
|
||||
if (Helper.isNull(oldVersion) || oldVersion < 1 && newVersion >= 1) {
|
||||
let levelObjectStore = db.createObjectStore(WordRotatorDb.OBJECT_STORE.LEVEL, {"keyPath": "id"});
|
||||
}
|
||||
if (Helper.isNull(oldVersion) || oldVersion < 2 && newVersion >= 2) {
|
||||
let levelObjectStore = e.target.transaction.objectStore(WordRotatorDb.OBJECT_STORE.LEVEL);
|
||||
levelObjectStore.createIndex("played", ["played", "difficulty", "id"], {"unique": false});
|
||||
}
|
||||
};
|
||||
|
||||
async saveManyLevels(levels) {
|
||||
return this.saveMany(levels, WordRotatorDb.OBJECT_STORE.LEVEL);
|
||||
}
|
||||
|
||||
async loadLevel(levelId) {
|
||||
return this.load(levelId, WordRotatorDb.OBJECT_STORE.LEVEL);
|
||||
}
|
||||
}
|
||||
|
||||
WordRotatorDb.OBJECT_STORE = {
|
||||
LEVEL: "level",
|
||||
};
|
||||
WordRotatorDb.instance = null;
|
||||
@@ -1,21 +0,0 @@
|
||||
import {DataManager} from "../../../../../js/lib/pwa-core";
|
||||
import {AbstractSite} from "../../../../../js/lib/pwa-lib";
|
||||
|
||||
export class ClockSite extends AbstractSite
|
||||
{
|
||||
constructor(siteManager) {
|
||||
super(siteManager, "html/application/clock.html");
|
||||
}
|
||||
|
||||
|
||||
onConstruct(args) {
|
||||
this.setTitle("clock");
|
||||
return super.onConstruct(args);
|
||||
}
|
||||
|
||||
onFirstStart(){
|
||||
DataManager.load("clock").then(function(data){
|
||||
document.getElementById("current-time").innerText = data.result.date;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ export class LevelSite extends AbstractSite{
|
||||
|
||||
let templateContainer = new TemplateContainer(leafSegmentTemplate, parentSegmentTemplate, rowSegmentTemplate);
|
||||
|
||||
|
||||
let level = new SimpleLevel(templateContainer);
|
||||
level.setWords([
|
||||
"Dynamo",
|
||||
@@ -39,8 +38,17 @@ export class LevelSite extends AbstractSite{
|
||||
]);
|
||||
level.setStartRotations([0,90,180]);
|
||||
|
||||
level.getWonPromise().then(()=>{
|
||||
console.log("has won");
|
||||
});
|
||||
|
||||
level.createSegments();
|
||||
level.getRootSegment()._updateElement();
|
||||
this.findBy("#level").appendChild(level.getRootSegment().getElement());
|
||||
}
|
||||
|
||||
async nextLevel()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
58
src/module/Application/pwa/js/site/SynchronizeSite.js
Normal file
58
src/module/Application/pwa/js/site/SynchronizeSite.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import {AbstractSite, Helper} from "../../../../../js/lib/pwa-lib";
|
||||
import {DataManager} from "../../../../../js/lib/pwa-core";
|
||||
import {WordRotatorDb} from "../WordRotatorDb";
|
||||
import {LevelSite} from "./LevelSite";
|
||||
|
||||
export class SynchronizeSite extends AbstractSite {
|
||||
|
||||
constructor(siteManager) {
|
||||
super(siteManager, "html/application/sync.html");
|
||||
}
|
||||
|
||||
|
||||
async onConstruct(args) {
|
||||
let res = await super.onConstruct(args);
|
||||
await this.loadLevels();
|
||||
return res;
|
||||
}
|
||||
|
||||
onFirstStart() {
|
||||
super.onFirstStart();
|
||||
this.startSite(LevelSite);
|
||||
}
|
||||
|
||||
async loadLevels() {
|
||||
|
||||
const dateLastSync = Helper.nonNull(localStorage.getItem("date-last-sync"), 0);
|
||||
const db = WordRotatorDb.getInstance();
|
||||
|
||||
let newLastSync = null;
|
||||
let maxRuns = 1;
|
||||
let levelPromises = [];
|
||||
for (let run = 0; run < maxRuns; run++) {
|
||||
let res = await DataManager.load("wordRotator/levels" + DataManager.buildQuery({
|
||||
"currentRun": run,
|
||||
"dateLastSync": dateLastSync
|
||||
}));
|
||||
if (!res["success"]) {
|
||||
break;
|
||||
}
|
||||
res = res["result"];
|
||||
newLastSync = Helper.nonNull(newLastSync, res["currentSyncDate"]);
|
||||
maxRuns = res["maxRuns"];
|
||||
|
||||
let levels = res["levels"];
|
||||
for (let i = 0, n = levels.length; i < n; i++) {
|
||||
let currentLevel = levels[i];
|
||||
levelPromises.push(db.loadLevel(levels[i]["id"]).then(level => {
|
||||
currentLevel["played"] = (Helper.nonNull(Helper.nonNull(level, {}).played, false));
|
||||
return currentLevel;
|
||||
}));
|
||||
}
|
||||
}
|
||||
let levels = await Promise.all(levelPromises);
|
||||
await db.saveManyLevels(levels);
|
||||
|
||||
localStorage.setItem("date-last-sync", newLastSync);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,28 @@ export class Level {
|
||||
this.words = [];
|
||||
this.startRotations = [];
|
||||
this.templateContainer = templateContainer;
|
||||
|
||||
this.hasWon = false;
|
||||
|
||||
this.wonResolver = null;
|
||||
this.giveUpResolver = null;
|
||||
|
||||
const self = this;
|
||||
this.wonPromise = new Promise((resolve, reject) => {
|
||||
self.wonResolver = resolve;
|
||||
self.giveUpResolver = reject;
|
||||
});
|
||||
}
|
||||
|
||||
getLevel()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
setRootSegment(rootSegment)
|
||||
{
|
||||
this.rootSegment = rootSegment;
|
||||
this.rootSegment.setParent(this);
|
||||
}
|
||||
|
||||
setWords(words)
|
||||
@@ -22,8 +44,25 @@ export class Level {
|
||||
this.startRotations = rotations;
|
||||
}
|
||||
|
||||
hasWon() {
|
||||
return this.rootSegment.isSolved();
|
||||
getHasWon()
|
||||
{
|
||||
return this.hasWon;
|
||||
}
|
||||
|
||||
checkHasWon(delayPromise) {
|
||||
if (this.rootSegment.isSolved()){
|
||||
this.hasWon = true;
|
||||
const self = this;
|
||||
delayPromise.then(()=>{
|
||||
self.wonResolver(true);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getWonPromise(){
|
||||
return this.wonPromise;
|
||||
}
|
||||
|
||||
getRootSegment(){
|
||||
|
||||
31
src/module/Application/pwa/js/wordrotator/Level/RowLevel.js
Normal file
31
src/module/Application/pwa/js/wordrotator/Level/RowLevel.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import {Level} from "./Level";
|
||||
import {RowSegment} from "../Segment/RowSegment";
|
||||
import {ParentSegment} from "../Segment/ParentSegment";
|
||||
|
||||
export class RowLevel extends Level {
|
||||
constructor(container, wordLength) {
|
||||
super(container);
|
||||
this.wordLength = wordLength;
|
||||
}
|
||||
|
||||
createSegments() {
|
||||
if (this.words.length >= 2 && this.words[0].length >= this.wordLength && this.words[1].length >= this.wordLength) {
|
||||
let leafsWordOne = Level._createLeafsForWord(this.words[0], this.templateContainer.copyLeafTemplate());
|
||||
let leafsWordTwo = Level._createLeafsForWord(this.words[1], this.templateContainer.copyLeafTemplate());
|
||||
|
||||
let rootSegment = new RowSegment(this.templateContainer.copyRowTemplate());
|
||||
for (let i = 0, n = this.wordLength / 2; i < n; i++) {
|
||||
let parent = new ParentSegment(this.templateContainer.copyParentTemplate());
|
||||
parent.addChild(leafsWordOne[2 * i]);
|
||||
parent.addChild(leafsWordOne[2 * i + 1]);
|
||||
parent.addChild(leafsWordTwo[2 * i]);
|
||||
parent.addChild(leafsWordTwo[2 * i + 1]);
|
||||
rootSegment.addChild(parent);
|
||||
}
|
||||
|
||||
rootSegment.applyRotations(this.startRotations);
|
||||
|
||||
this.setRootSegment(rootSegment)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,8 @@
|
||||
import {Level} from "./Level";
|
||||
import {ParentSegment} from "../Segment/ParentSegment";
|
||||
import {RowSegment} from "../Segment/RowSegment";
|
||||
import {RowLevel} from "./RowLevel";
|
||||
|
||||
export class SimpleLevel extends Level{
|
||||
export class SimpleLevel extends RowLevel{
|
||||
|
||||
createSegments() {
|
||||
if (this.words.length >= 2 && this.words[0].length >= 6 &&this.words[1].length >= 6){
|
||||
|
||||
let leafsWordOne = Level._createLeafsForWord(this.words[0], this.templateContainer.copyLeafTemplate());
|
||||
let leafsWordTwo = Level._createLeafsForWord(this.words[1], this.templateContainer.copyLeafTemplate());
|
||||
|
||||
let segmentOne = new ParentSegment(this.templateContainer.copyParentTemplate());
|
||||
let segmentTwo = new ParentSegment(this.templateContainer.copyParentTemplate());
|
||||
let segmentThree = new ParentSegment(this.templateContainer.copyParentTemplate());
|
||||
|
||||
segmentOne.addChild(leafsWordOne[0]);
|
||||
segmentOne.addChild(leafsWordOne[1]);
|
||||
segmentOne.addChild(leafsWordTwo[0]);
|
||||
segmentOne.addChild(leafsWordTwo[1]);
|
||||
|
||||
segmentTwo.addChild(leafsWordOne[2]);
|
||||
segmentTwo.addChild(leafsWordOne[3]);
|
||||
segmentTwo.addChild(leafsWordTwo[2]);
|
||||
segmentTwo.addChild(leafsWordTwo[3]);
|
||||
|
||||
segmentThree.addChild(leafsWordOne[4]);
|
||||
segmentThree.addChild(leafsWordOne[5]);
|
||||
segmentThree.addChild(leafsWordTwo[4]);
|
||||
segmentThree.addChild(leafsWordTwo[5]);
|
||||
|
||||
this.rootSegment = new RowSegment(this.templateContainer.copyRowTemplate());
|
||||
this.rootSegment.addChild(segmentOne);
|
||||
this.rootSegment.addChild(segmentTwo);
|
||||
this.rootSegment.addChild(segmentThree);
|
||||
|
||||
this.rootSegment.applyRotations(this.startRotations);
|
||||
}
|
||||
constructor(container) {
|
||||
super(container, 6);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import {Segment} from "./Segment";
|
||||
import {DelayPromise} from "../../../../../../js/lib/pwa-assets";
|
||||
|
||||
export class ParentSegment extends Segment {
|
||||
constructor(element) {
|
||||
@@ -7,11 +8,17 @@ export class ParentSegment extends Segment {
|
||||
this.class = "rotate-0";
|
||||
}
|
||||
|
||||
rotate() {
|
||||
this.rotation += 90;
|
||||
this.rotation %= 360;
|
||||
async rotate() {
|
||||
if (!this.getLevel().getHasWon()) {
|
||||
this.rotation += 90;
|
||||
this.rotation %= 360;
|
||||
|
||||
this._updateRotationClass()
|
||||
this._updateRotationClass();
|
||||
this.getLevel().checkHasWon(new Promise((resolve, reject)=>{
|
||||
this.element.addEventListener("animationend", resolve);
|
||||
}));
|
||||
return new DelayPromise(250);
|
||||
}
|
||||
}
|
||||
|
||||
applyRotations(rotations) {
|
||||
@@ -42,6 +49,7 @@ export class ParentSegment extends Segment {
|
||||
|
||||
addChild(child) {
|
||||
this.children.push(child);
|
||||
child.setParent(this);
|
||||
this._updateElement();
|
||||
}
|
||||
|
||||
@@ -49,26 +57,10 @@ export class ParentSegment extends Segment {
|
||||
// this.style.transform = "rotate("+this.rotation+"deg)";
|
||||
this.element.classList.remove(this.class);
|
||||
this.class = "rotate-" + this.rotation;
|
||||
if (this.class === "rotate-0")
|
||||
{
|
||||
if (this.class === "rotate-0") {
|
||||
this.class = "rotate-360";
|
||||
}
|
||||
this.element.classList.add(this.class);
|
||||
|
||||
// if (this.rotation === 0) {
|
||||
// const self = this;
|
||||
// self.element.classList.add("no-transition");
|
||||
//
|
||||
// setTimeout(() => {
|
||||
// if (self.class === "rotate-0") {
|
||||
// requestAnimationFrame(()=>{
|
||||
//
|
||||
// self.element.classList.remove("rotate-0");
|
||||
// self.element.classList.remove("no-transition");
|
||||
// });
|
||||
// }
|
||||
// }, 250);
|
||||
// }
|
||||
}
|
||||
|
||||
_updateElement() {
|
||||
|
||||
@@ -4,13 +4,29 @@ export class Segment{
|
||||
constructor(element){
|
||||
this.rotation = 0;
|
||||
this.element = element;
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
setParent(parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
getLevel()
|
||||
{
|
||||
if (this.parent!==null)
|
||||
{
|
||||
return this.parent.getLevel();
|
||||
}
|
||||
}
|
||||
|
||||
isSolved(){
|
||||
return (this.rotation === 0);
|
||||
}
|
||||
|
||||
rotate(){};
|
||||
async rotate(){
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
_updateElement(){};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user