forked from MapComplete/MapComplete
Merge develop
This commit is contained in:
commit
cac87a5467
727 changed files with 27522 additions and 15764 deletions
|
@ -37,8 +37,12 @@ import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable"
|
|||
import { ValidateThemeAndLayers } from "../src/Models/ThemeConfig/Conversion/ValidateThemeAndLayers"
|
||||
import { ExtractImages } from "../src/Models/ThemeConfig/Conversion/FixImages"
|
||||
import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import { LayerConfigDependencyGraph, LevelInfo } from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
import {
|
||||
LayerConfigDependencyGraph,
|
||||
LevelInfo,
|
||||
} from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
|
||||
import { AddContextToTranslations } from "../src/Models/ThemeConfig/Conversion/AddContextToTranslations"
|
||||
|
||||
// This scripts scans 'src/assets/layers/*.json' for layer definition files and 'src/assets/themes/*.json' for theme definition files.
|
||||
// It spits out an overview of those to be used to load them
|
||||
|
@ -113,7 +117,10 @@ class AddIconSummary extends DesugaringStep<{ raw: LayerConfigJson; parsed: Laye
|
|||
static singleton = new AddIconSummary()
|
||||
|
||||
constructor() {
|
||||
super("AddIconSummary", "Adds an icon summary for quick reference")
|
||||
super(
|
||||
"AddIconSummary",
|
||||
"Adds an icon summary ('_layerIcon') for quick reference. This previews how the layer should be shown in e.g. the filter menu"
|
||||
)
|
||||
}
|
||||
|
||||
convert(json: { raw: LayerConfigJson; parsed: LayerConfig }) {
|
||||
|
@ -124,18 +131,20 @@ class AddIconSummary extends DesugaringStep<{ raw: LayerConfigJson; parsed: Laye
|
|||
pr.location.has("point")
|
||||
)
|
||||
const defaultTags = layerConfig.baseTags
|
||||
fixed["_layerIcon"] = Lists.noNull((pointRendering?.marker ?? []).map((i) => {
|
||||
const icon = i.icon?.GetRenderValue(defaultTags)?.txt
|
||||
if (!icon) {
|
||||
return undefined
|
||||
}
|
||||
const result = { icon }
|
||||
const c = i.color?.GetRenderValue(defaultTags)?.txt
|
||||
if (c) {
|
||||
result["color"] = c
|
||||
}
|
||||
return result
|
||||
}))
|
||||
fixed["_layerIcon"] = Lists.noNull(
|
||||
(pointRendering?.marker ?? []).map((i) => {
|
||||
const icon = i.icon?.GetRenderValue(defaultTags)?.txt
|
||||
if (!icon) {
|
||||
return undefined
|
||||
}
|
||||
const result = { icon }
|
||||
const c = i.color?.GetRenderValue(defaultTags)?.txt
|
||||
if (c) {
|
||||
result["color"] = c
|
||||
}
|
||||
return result
|
||||
})
|
||||
)
|
||||
return { raw: fixed, parsed: layerConfig }
|
||||
}
|
||||
}
|
||||
|
@ -229,9 +238,13 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> {
|
|||
context.err("Invalid ID: expected", id, "but got", id)
|
||||
}
|
||||
const prepped = this.prepareLayer.convert(config, context)
|
||||
const withContext = new AddContextToTranslations<LayerConfigJson>("layers:").convertStrict(
|
||||
prepped,
|
||||
ConversionContext.construct([prepped.id], ["AddContextToTranslations"])
|
||||
)
|
||||
this._loadedIds.add(id)
|
||||
this._desugaringState.sharedLayers.set(id, prepped)
|
||||
return prepped
|
||||
this._desugaringState.sharedLayers.set(id, withContext)
|
||||
return withContext
|
||||
}
|
||||
|
||||
private buildLooping(ids: string[], context: ConversionContext) {
|
||||
|
@ -641,10 +654,16 @@ class LayerOverviewUtils extends Script {
|
|||
|
||||
writeFileSync(
|
||||
"./src/assets/generated/theme_overview.json",
|
||||
JSON.stringify({
|
||||
"#":"Generated by generateLayerOverview",
|
||||
"#version": new Date().toISOString(),
|
||||
layers: layerKeywords, themes: sorted }, null, " "),
|
||||
JSON.stringify(
|
||||
{
|
||||
"#": "Generated by generateLayerOverview",
|
||||
"#version": new Date().toISOString(),
|
||||
layers: layerKeywords,
|
||||
themes: sorted,
|
||||
},
|
||||
null,
|
||||
" "
|
||||
),
|
||||
{ encoding: "utf8" }
|
||||
)
|
||||
}
|
||||
|
@ -695,8 +714,14 @@ class LayerOverviewUtils extends Script {
|
|||
)
|
||||
|
||||
const path = "assets/layers/questions/questions.json"
|
||||
const sharedQuestions = this.parseLayer(doesImageExist, prepareLayer, path).raw
|
||||
|
||||
const sharedQuestionsRaw: LayerConfigJson = this.parseLayer(
|
||||
doesImageExist,
|
||||
prepareLayer,
|
||||
path
|
||||
).raw
|
||||
const sharedQuestions: LayerConfigJson = new AddContextToTranslations<LayerConfigJson>(
|
||||
""
|
||||
).convertStrict(sharedQuestionsRaw, ConversionContext.construct(["layers:questions"], []))
|
||||
const dict = new Map<string, QuestionableTagRenderingConfigJson>()
|
||||
|
||||
for (const tr of sharedQuestions.tagRenderings) {
|
||||
|
@ -779,7 +804,7 @@ class LayerOverviewUtils extends Script {
|
|||
)
|
||||
|
||||
const forceReload = args.some((a) => a == "--force") || labelBlacklist.size > 0
|
||||
const printAssets = args.some(a => a === "--print-needed-assets")
|
||||
const printAssets = args.some((a) => a === "--print-needed-assets")
|
||||
console.log("Arguments are:", { labelBlacklist, themeWhitelist, forceReload })
|
||||
const doesImageExist = DoesImageExist.constructWithLicenses(existsSync)
|
||||
const sharedLayers = this.buildLayerIndex(doesImageExist, labelBlacklist)
|
||||
|
@ -868,8 +893,10 @@ class LayerOverviewUtils extends Script {
|
|||
(l) => Constants.added_by_default.indexOf(l["id"]) < 0
|
||||
)
|
||||
}
|
||||
if(printAssets){
|
||||
const images = Lists.dedup(Array.from(sharedThemes.values()).flatMap(th => th._usedImages ?? []))
|
||||
if (printAssets) {
|
||||
const images = Lists.dedup(
|
||||
Array.from(sharedThemes.values()).flatMap((th) => th._usedImages ?? [])
|
||||
)
|
||||
writeFileSync("needed_assets.csv", images.join("\n"))
|
||||
console.log("Written needed_assets.csv")
|
||||
}
|
||||
|
@ -1283,9 +1310,11 @@ class LayerOverviewUtils extends Script {
|
|||
}
|
||||
}
|
||||
|
||||
const usedImages = Lists.dedup(new ExtractImages(true, knownTagRenderings)
|
||||
.convertStrict(themeFile)
|
||||
.map((x) => x.path))
|
||||
const usedImages = Lists.dedup(
|
||||
new ExtractImages(true, knownTagRenderings)
|
||||
.convertStrict(themeFile)
|
||||
.map((x) => x.path)
|
||||
)
|
||||
usedImages.sort()
|
||||
|
||||
themeFile["_usedImages"] = usedImages
|
||||
|
@ -1307,7 +1336,8 @@ class LayerOverviewUtils extends Script {
|
|||
...t,
|
||||
hideFromOverview: t.hideFromOverview ?? false,
|
||||
shortDescription:
|
||||
t.shortDescription ?? new Translation(t.description).FirstSentence(true),
|
||||
t.shortDescription ??
|
||||
new Translation(t.description).FirstSentence(true),
|
||||
mustHaveLanguage: t.mustHaveLanguage?.length > 0,
|
||||
}
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue