Small fixes to improve local loading

This commit is contained in:
pietervdvn 2022-06-21 16:47:54 +02:00
parent 9392731e46
commit c5a6b803ec
4 changed files with 19 additions and 5 deletions

View file

@ -126,7 +126,7 @@ export default class DetermineLayout {
.AttachTo("centermessage");
}
private static prepCustomTheme(json: any, sourceUrl?: string): LayoutConfig {
private static prepCustomTheme(json: any, sourceUrl?: string, forceId?: string): LayoutConfig {
if(json.layers === undefined && json.tagRenderings !== undefined){
const iconTr = json.mapRendering.map(mr => mr.icon).find(icon => icon !== undefined)
@ -161,6 +161,7 @@ export default class DetermineLayout {
json = new PrepareTheme(converState).convertStrict(json, "While preparing a dynamic theme")
console.log("The layoutconfig is ", json)
json.id = forceId ?? json.id
return new LayoutConfig(json, false, {
definitionRaw: JSON.stringify(raw, null, " "),
@ -178,9 +179,13 @@ export default class DetermineLayout {
let parsed = await Utils.downloadJson(link)
try {
parsed.id = link;
let forcedId = parsed.id
const url = new URL(link)
if(!(url.hostname === "localhost" || url.hostname === "127.0.0.1")){
forcedId = link;
}
console.log("Loaded remote link:", link)
return DetermineLayout.prepCustomTheme(parsed, link)
return DetermineLayout.prepCustomTheme(parsed, link, forcedId);
} catch (e) {
console.error(e)
DetermineLayout.ShowErrorOnCustomTheme(

View file

@ -205,6 +205,11 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
let relative = url.protocol + "//" + url.host + url.pathname
relative = relative.substring(0, relative.lastIndexOf("/"))
const self = this;
if(relative.endsWith("assets/generated/themes")){
warnings.push("Detected 'assets/generated/themes' as relative URL. I'm assuming that you are loading your file for the MC-repository, so I'm rewriting all image links as if they were absolute instead of relative")
relative = absolute
}
function replaceString(leaf: string) {
if (self._knownImages.has(leaf)) {

View file

@ -100,7 +100,7 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string |
delete config["wayHandling"]
delete config["hideUnderlayingFeaturesMinPercentage"]
for (const mapRenderingElement of config.mapRendering) {
for (const mapRenderingElement of (config.mapRendering ?? [])) {
if (mapRenderingElement["iconOverlays"] !== undefined) {
mapRenderingElement["iconBadges"] = mapRenderingElement["iconOverlays"]
}

View file

@ -442,7 +442,11 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
*
* The leaf objects are replaced in the object itself by the specified function
*/
public static WalkPath(path: string[], object: any, replaceLeaf: ((leaf: any, travelledPath: string[]) => any), travelledPath: string[] = []) {
public static WalkPath(path: string[], object: any, replaceLeaf: ((leaf: any, travelledPath: string[]) => any), travelledPath: string[] = []) : void {
if(object == null){
return;
}
const head = path[0]
if (path.length === 1) {
// We have reached the leaf