Merge: develop

This commit is contained in:
Pieter Vander Vennet 2023-06-11 02:32:14 +02:00
commit 9cffe6814e
154 changed files with 1199 additions and 41754 deletions

View file

@ -1,16 +1,26 @@
import {Concat, Conversion, DesugaringContext, DesugaringStep, Each, FirstOf, Fuse, On, SetDefault,} from "./Conversion"
import {LayerConfigJson} from "../Json/LayerConfigJson"
import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson"
import {Utils} from "../../../Utils"
import {
Concat,
Conversion,
DesugaringContext,
DesugaringStep,
Each,
FirstOf,
Fuse,
On,
SetDefault,
} from "./Conversion"
import { LayerConfigJson } from "../Json/LayerConfigJson"
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
import { Utils } from "../../../Utils"
import RewritableConfigJson from "../Json/RewritableConfigJson"
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
import Translations from "../../../UI/i18n/Translations"
import {Translation} from "../../../UI/i18n/Translation"
import { Translation } from "../../../UI/i18n/Translation"
import tagrenderingconfigmeta from "../../../assets/tagrenderingconfigmeta.json"
import {AddContextToTranslations} from "./AddContextToTranslations"
import { AddContextToTranslations } from "./AddContextToTranslations"
import FilterConfigJson from "../Json/FilterConfigJson"
import predifined_filters from "../../../assets/layers/filters/filters.json"
import {TagConfigJson} from "../Json/TagConfigJson"
import { TagConfigJson } from "../Json/TagConfigJson"
import PointRenderingConfigJson from "../Json/PointRenderingConfigJson"
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"
import ValidationUtils from "./ValidationUtils"
@ -43,11 +53,11 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
context: string
): { result: LayerConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } {
if (json.filter === undefined || json.filter === null) {
return {result: json} // Nothing to change here
return { result: json } // Nothing to change here
}
if (json.filter["sameAs"] !== undefined) {
return {result: json} // Nothing to change here
return { result: json } // Nothing to change here
}
const newFilters: FilterConfigJson[] = []
@ -63,9 +73,9 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
if (split.length > 2) {
errors.push(
context +
": invalid filter name: " +
filter +
", expected `layername.filterid`"
": invalid filter name: " +
filter +
", expected `layername.filterid`"
)
}
const layer = this._state.sharedLayers.get(split[0])
@ -164,7 +174,6 @@ class ExpandTagRendering extends Conversion<
}
private lookup(name: string): TagRenderingConfigJson[] | undefined {
const direct = this.directLookup(name)
if (direct === undefined) {
@ -243,7 +252,7 @@ class ExpandTagRendering extends Conversion<
if (found.condition === undefined) {
found.condition = layer.source["osmTags"]
} else {
found.condition = {and: [found.condition, layer.source["osmTags"]]}
found.condition = { and: [found.condition, layer.source["osmTags"]] }
}
}
}
@ -274,18 +283,18 @@ class ExpandTagRendering extends Conversion<
warnings.push(
`${ctx}: A literal rendering was detected: ${tr}
Did you perhaps forgot to add a layer name as 'layername.${tr}'? ` +
Array.from(state.sharedLayers.keys()).join(", ")
Array.from(state.sharedLayers.keys()).join(", ")
)
}
if (this._options?.noHardcodedStrings && this._state.sharedLayers.size > 0) {
errors.push(
ctx +
"Detected an invocation to a builtin tagRendering, but this tagrendering was not found: " +
tr +
" \n Did you perhaps forget to add the layer as prefix, such as `icons." +
tr +
"`? "
"Detected an invocation to a builtin tagRendering, but this tagrendering was not found: " +
tr +
" \n Did you perhaps forget to add the layer as prefix, such as `icons." +
tr +
"`? "
)
}
@ -316,11 +325,11 @@ class ExpandTagRendering extends Conversion<
}
errors.push(
"At " +
ctx +
": an object calling a builtin can only have keys `builtin` or `override`, but a key with name `" +
key +
"` was found. This won't be picked up! The full object is: " +
JSON.stringify(tr)
ctx +
": an object calling a builtin can only have keys `builtin` or `override`, but a key with name `" +
key +
"` was found. This won't be picked up! The full object is: " +
JSON.stringify(tr)
)
}
@ -344,22 +353,22 @@ class ExpandTagRendering extends Conversion<
if (state.sharedLayers.size === 0) {
warnings.push(
ctx +
": BOOTSTRAPPING. Rerun generate layeroverview. While reusing tagrendering: " +
name +
": layer " +
layerName +
" not found. Maybe you meant on of " +
candidates.slice(0, 3).join(", ")
": BOOTSTRAPPING. Rerun generate layeroverview. While reusing tagrendering: " +
name +
": layer " +
layerName +
" not found. Maybe you meant on of " +
candidates.slice(0, 3).join(", ")
)
} else {
errors.push(
ctx +
": While reusing tagrendering: " +
name +
": layer " +
layerName +
" not found. Maybe you meant on of " +
candidates.slice(0, 3).join(", ")
": While reusing tagrendering: " +
name +
": layer " +
layerName +
" not found. Maybe you meant on of " +
candidates.slice(0, 3).join(", ")
)
}
continue
@ -371,11 +380,11 @@ class ExpandTagRendering extends Conversion<
candidates = Utils.sortedByLevenshteinDistance(name, candidates, (i) => i)
errors.push(
ctx +
": The tagRendering with identifier " +
name +
" was not found.\n\tDid you mean one of " +
candidates.join(", ") +
"?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first"
": The tagRendering with identifier " +
name +
" was not found.\n\tDid you mean one of " +
candidates.join(", ") +
"?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first"
)
continue
}
@ -701,7 +710,7 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
}
if (typeof obj === "object") {
obj = {...obj}
obj = { ...obj }
const isTr = targetIsTranslation && Translations.isProbablyATranslation(obj)
@ -764,12 +773,12 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
context: string
): { result: T[]; errors?: string[]; warnings?: string[]; information?: string[] } {
if (json === null || json === undefined) {
return {result: []}
return { result: [] }
}
if (json["rewrite"] === undefined) {
// not a rewrite
return {result: [<T>json]}
return { result: [<T>json] }
}
const rewrite = <RewritableConfigJson<T>>json
@ -809,7 +818,7 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
ts.push(t)
}
return {result: ts}
return { result: ts }
}
}
@ -1099,7 +1108,7 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson | LineRen
information?: string[]
} {
if (!json["iconBadges"]) {
return {result: json}
return { result: json }
}
const badgesJson = (<PointRenderingConfigJson>json).iconBadges
@ -1110,7 +1119,7 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson | LineRen
for (let i = 0; i < badgesJson.length; i++) {
const iconBadge: { if: TagConfigJson; then: string | TagRenderingConfigJson } =
badgesJson[i]
const {errors, result, warnings} = this._expand.convert(
const { errors, result, warnings } = this._expand.convert(
iconBadge.then,
context + ".iconBadges[" + i + "]"
)
@ -1130,7 +1139,7 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson | LineRen
}
return {
result: {...json, iconBadges},
result: { ...json, iconBadges },
errors: errs,
warnings: warns,
}
@ -1143,7 +1152,7 @@ class PreparePointRendering extends Fuse<PointRenderingConfigJson | LineRenderin
"Prepares point renderings by expanding 'icon' and 'iconBadges'",
new On(
"icon",
new FirstOf(new ExpandTagRendering(state, layer, {applyCondition: false}))
new FirstOf(new ExpandTagRendering(state, layer, { applyCondition: false }))
),
new ExpandIconBadges(state, layer)
)
@ -1238,7 +1247,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
new On(
"titleIcons",
(layer) =>
new Concat(new ExpandTagRendering(state, layer, {noHardcodedStrings: true}))
new Concat(new ExpandTagRendering(state, layer, { noHardcodedStrings: true }))
),
new ExpandFilter(state)
)

View file

@ -56,8 +56,9 @@ export default class SourceConfig {
"Error at " +
context +
": the specified tags are conflicting with each other: they will never match anything at all.\n" +
"\tThe offending tags are: "+params.osmTags.asHumanString(false, false, {})+
"\tThey optmize into 'false' "
"\tThe offending tags are: " +
params.osmTags.asHumanString(false, false, {}) +
"\tThey optmize into 'false' "
)
}
if (optimized === true) {

View file

@ -122,6 +122,10 @@ export class Unit {
`${ctx}.units[${i}]`
)
)
if(json.defaultInput && !applicable.some(denom => denom.canonical.trim() === json.defaultInput)){
throw `${ctx}: no denomination has the specified default denomination. The default denomination is '${json.defaultInput}', but the available denominations are ${applicable.map(denom => denom.canonical).join(", ")}`
}
return new Unit(appliesTo, applicable, json.eraseInvalidValues ?? false)
}