Add a personal, configurable quest

This commit is contained in:
Pieter Vander Vennet 2020-07-31 17:11:44 +02:00
parent 7ec00a3301
commit b36b103ed3
7 changed files with 55 additions and 54 deletions

View file

@ -1,18 +1,18 @@
import {Groen} from "./Layouts/Groen";
import {GRB} from "./Layouts/GRB";
import {Artworks} from "./Layouts/Artworks";
import {Bookcases} from "./Layouts/Bookcases";
import Cyclofix from "./Layouts/Cyclofix";
import {WalkByBrussels} from "./Layouts/WalkByBrussels";
import {All} from "./Layouts/All";
import {Layout} from "./Layout";
import {MetaMap} from "./Layouts/MetaMap";
import {StreetWidth} from "./Layouts/StreetWidth";
import {Natuurpunt} from "./Layouts/Natuurpunt";
import {LayerDefinition} from "./LayerDefinition";
import {ClimbingTrees} from "./Layouts/ClimbingTrees";
import {Smoothness} from "./Layouts/Smoothness";
import {LayerDefinition} from "./LayerDefinition";
import {Natuurpunt} from "./Layouts/Natuurpunt";
import {Groen} from "./Layouts/Groen";
import Cyclofix from "./Layouts/Cyclofix";
import {Layout} from "./Layout";
import {CustomLayout} from "../Logic/CustomLayers";
import {GRB} from "./Layouts/GRB";
import {Artworks} from "./Layouts/Artworks";
import {WalkByBrussels} from "./Layouts/WalkByBrussels";
import {MetaMap} from "./Layouts/MetaMap";
import {Bookcases} from "./Layouts/Bookcases";
export class AllKnownLayouts {

View file

@ -1,15 +1,10 @@
import {UIEventSource} from "../UI/UIEventSource";
import {UIElement} from "../UI/UIElement";
export class LocalStorageSource {
static Get(key: string, defaultValue: string = undefined): UIEventSource<string> {
if (UIElement.runningFromConsole) {
// ignore when running from the console
return new UIEventSource<string>(defaultValue);
}
try {
const saved = localStorage.getItem(key);
@ -20,5 +15,8 @@ export class LocalStorageSource {
console.log("Wriging ", key, data)
});
return source;
} catch (e) {
return new UIEventSource<string>(defaultValue);
}
}
}

View file

@ -2,11 +2,13 @@
* Wraps the query parameters into UIEventSources
*/
import {UIEventSource} from "../UI/UIEventSource";
import {UIElement} from "../UI/UIElement";
export class QueryParameters {
private static order: string [] = ["layout","test","z","lat","lon"];
private static knownSources = QueryParameters.init();
private static knownSources = {};
private static initialized = false;
private static defaults = {}
private static addOrder(key){
@ -16,11 +18,13 @@ export class QueryParameters {
}
private static init() {
const knownSources = {}
if(window === undefined){
if(this.initialized){
return;
}
if (window.location.search) {
this.initialized = true;
if (window?.location?.search) {
const params = window.location.search.substr(1).split("&");
for (const param of params) {
const kv = param.split("=");
@ -29,10 +33,9 @@ export class QueryParameters {
const v = kv[1];
const source = new UIEventSource<string>(v);
source.addCallback(() => QueryParameters.Serialize())
knownSources[key] = source;
QueryParameters.knownSources[key] = source;
}
}
return knownSources;
}
private static Serialize() {
@ -51,6 +54,9 @@ export class QueryParameters {
}
public static GetQueryParameter(key: string, deflt: string): UIEventSource<string> {
if(!this.initialized){
this.init();
}
if (deflt !== undefined) {
QueryParameters.defaults[key] = deflt;
}

View file

@ -25,6 +25,7 @@ export class State {
// The singleton of the global state
public static state: State;
public static runningFromConsole: boolean = false;
/**
THe layout to use
@ -176,6 +177,10 @@ export class State {
"Beantwoorden van vragen met #MapComplete voor vragenset #" + this.layoutToUse.data.name,
this);
if(State.runningFromConsole){
console.warn("running from console - not initializing map. Assuming test.html");
return;
}
if (document.getElementById("leafletDiv") === null) {

View file

@ -1,9 +1,6 @@
import {UIEventSource} from "../UIEventSource";
import {LocalStorageSource} from "../../Logic/LocalStorageSource";
import {DropDown} from "../Input/DropDown";
import {Layout} from "../../Customizations/Layout";
import {UIElement} from "../UIElement";
import {State} from "../../State";
export default class Locale {
@ -11,10 +8,12 @@ export default class Locale {
public static language: UIEventSource<string> = Locale.setup();
private static setup() {
const source = LocalStorageSource.Get('language', "en");
if (!UIElement.runningFromConsole) {
// @ts-ignore
window.setLanguage = function (language: string) {
source.setData(language)
}
}
return source;
}

View file

@ -25,6 +25,9 @@ export class Utils {
}
static DoEvery(millis: number, f: (() => void)) {
if(State.runningFromConsole){
return;
}
window.setTimeout(
function () {
f();

View file

@ -1,25 +1,15 @@
import {Groen} from "./Customizations/Layouts/Groen";
import {Bookcases} from "./Customizations/Layouts/Bookcases";
import {GRB} from "./Customizations/Layouts/GRB";
import Cyclofix from "./Customizations/Layouts/Cyclofix";
import {WalkByBrussels} from "./Customizations/Layouts/WalkByBrussels";
import {MetaMap} from "./Customizations/Layouts/MetaMap";
import {StreetWidth} from "./Customizations/Layouts/StreetWidth";
import {Natuurpunt} from "./Customizations/Layouts/Natuurpunt";
import {UIElement} from "./UI/UIElement";
UIElement.runningFromConsole = true;
import {AllKnownLayouts} from "./Customizations/AllKnownLayouts";
import {Layout} from "./Customizations/Layout";
import {readFileSync, writeFile, writeFileSync} from "fs";
import {Utils} from "./Utils";
import svg2img from 'promise-svg2img';
import Translation from "./UI/i18n/Translation";
import Locale from "./UI/i18n/Locale";
import Translations from "./UI/i18n/Translations";
import {UIElement} from "./UI/UIElement";
import {LayerDefinition} from "./Customizations/LayerDefinition";
console.log("Building the layouts")
UIElement.runningFromConsole = true;
function enc(str: string): string {
return encodeURIComponent(str.toLowerCase());
@ -73,7 +63,6 @@ function validate(layout: Layout) {
}
const alreadyWritten = []
function createIcon(iconPath: string, size: number) {
@ -110,7 +99,7 @@ function createIcon(iconPath: string, size: number) {
}
function createManifest(layout: Layout, relativePath: string) {
const name = Utils.Upper(layout.name);
const name = layout.name;
const icons = [];
@ -151,7 +140,6 @@ function createManifest(layout: Layout, relativePath: string) {
}
const template = readFileSync("index.html", "utf8");
function createLandingPage(layout: Layout) {
Locale.language.setData(layout.supportedLanguages[0]);
@ -172,9 +160,9 @@ function createLandingPage(layout: Layout) {
`<link rel="icon" href="${layout.icon}" sizes="any" type="image/svg+xml">`)
}
const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap"]
const all = AllKnownLayouts.allSets;
/*
for (const layoutName in all) {
if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) {
console.log(`Skipping a layout with name${layoutName}, it is on the blacklist`);
@ -197,3 +185,5 @@ for (const layoutName in all) {
}
Translations.CountTranslations();
*/