Skip to content

Commit

Permalink
Full code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pietervdvn committed Jan 26, 2022
1 parent 3a4a2a2 commit fa971ff
Show file tree
Hide file tree
Showing 300 changed files with 16,250 additions and 19,182 deletions.
16 changes: 9 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ Hi! Thanks for checking out how to contribute to MapComplete!

There are multiple ways to contribute:

- Translating MapComplete to your own language can be done on [this website](https://hosted.weblate.org/projects/mapcomplete/)
- Translating MapComplete to your own language can be done
on [this website](https://hosted.weblate.org/projects/mapcomplete/)
- If you encounter a bug, the [issue tracker](https://github.com/pietervdvn/MapComplete/issues) is the place to be
- If you want to improve a theme, create a new theme, spot a typo in the repo... the best way is to open a pull request.

People who stick around and contribute in a meaningful way, _might_ be granted write access to the repository. This is done on a purely subjective basis, e.g. after a few pull requests and if you are a member of the OSM community.
People who stick around and contribute in a meaningful way, _might_ be granted write access to the repository. This is
done on a purely subjective basis, e.g. after a few pull requests and if you are a member of the OSM community.

Rights of contributors
-----------------------

If you have write access to the repository, you can make a fork of an already existing branch and push this new branch to
github. This means that this branch will be _automatically built_ and be **deployed**
If you have write access to the repository, you can make a fork of an already existing branch and push this new branch
to github. This means that this branch will be _automatically built_ and be **deployed**
to `https://pietervdvn.github.io/mc/<branchname>`. You can see the deploy process
on [Github Actions](https://github.com/pietervdvn/MapComplete/actions). Don't worry about pushing too much. These
deploys are free and totally automatic. They might fail if something is wrong, but this will hinder no-one.
Expand All @@ -30,9 +32,9 @@ As a non-admin contributor, you can _not_ make changes to the `master` nor to th
soon as master is changed, this is built and deployed on `mapcomplete.osm.be`, which a lot of people use. An error there
will cause a lot of grieve.

A push on `develop` is automatically deployed to [pietervdvn.github.io/mc/develop] which is used by quite some contributors.
However, people using this version should know that this is a testing ground for new features and might contain a bug every now
and then.
A push on `develop` is automatically deployed to [pietervdvn.github.io/mc/develop] which is used by quite some
contributors. However, people using this version should know that this is a testing ground for new features and might
contain a bug every now and then.

In other words, to get your theme deployed on the main instances, you'll still have to create a pull request. The
maintainers will then doublecheck and pull it in.
Expand Down
93 changes: 45 additions & 48 deletions Customizations/AllKnownLayouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,10 @@ import Link from "../UI/Base/Link";
import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";

export class AllKnownLayouts {
// Must be below the list...
private static sharedLayers: Map<string, LayerConfig> = AllKnownLayouts.getSharedLayers();

private static getSharedLayers(): Map<string, LayerConfig> {
const sharedLayers = new Map<string, LayerConfig>();
for (const layer of known_themes.layers) {
try {
// @ts-ignore
const parsed = new LayerConfig(layer, "shared_layers")
sharedLayers.set(layer.id, parsed);
} catch (e) {
if (!Utils.runningFromConsole) {
console.error("CRITICAL: Could not parse a layer configuration!", layer.id, " due to", e)
}
}
}

return sharedLayers;
}

public static allKnownLayouts: Map<string, LayoutConfig> = AllKnownLayouts.AllLayouts();
public static layoutsList: LayoutConfig[] = AllKnownLayouts.GenerateOrderedList(AllKnownLayouts.allKnownLayouts);
// Must be below the list...
private static sharedLayers: Map<string, LayerConfig> = AllKnownLayouts.getSharedLayers();

public static AllPublicLayers() {
const allLayers: LayerConfig[] = []
Expand All @@ -54,8 +36,7 @@ export class AllKnownLayouts {
}
return allLayers
}



public static GenOverviewsForSingleLayer(callback: (layer: LayerConfig, element: BaseUIElement) => void): void {
const allLayers: LayerConfig[] = Array.from(AllKnownLayouts.sharedLayers.values())
.filter(layer => Constants.priviliged_layers.indexOf(layer.id) < 0)
Expand All @@ -82,12 +63,12 @@ export class AllKnownLayouts {


// Determine the cross-dependencies
const layerIsNeededBy : Map<string, string[]> = new Map<string, string[]>()
const layerIsNeededBy: Map<string, string[]> = new Map<string, string[]>()

for (const layer of allLayers) {
for (const dep of DependencyCalculator.getLayerDependencies(layer)) {
const dependency = dep.neededLayer
if(!layerIsNeededBy.has(dependency)){
if (!layerIsNeededBy.has(dependency)) {
layerIsNeededBy.set(dependency, [])
}
layerIsNeededBy.get(dependency).push(layer.id)
Expand All @@ -97,7 +78,7 @@ export class AllKnownLayouts {
}

allLayers.forEach((layer) => {
const element = layer.GenerateDocumentation(themesPerLayer.get(layer.id),layerIsNeededBy,DependencyCalculator.getLayerDependencies(layer))
const element = layer.GenerateDocumentation(themesPerLayer.get(layer.id), layerIsNeededBy, DependencyCalculator.getLayerDependencies(layer))
callback(layer, element)
})
}
Expand Down Expand Up @@ -131,38 +112,54 @@ export class AllKnownLayouts {


// Determine the cross-dependencies
const layerIsNeededBy : Map<string, string[]> = new Map<string, string[]>()
const layerIsNeededBy: Map<string, string[]> = new Map<string, string[]>()

for (const layer of allLayers) {
for (const dep of DependencyCalculator.getLayerDependencies(layer)) {
const dependency = dep.neededLayer
if(!layerIsNeededBy.has(dependency)){
if (!layerIsNeededBy.has(dependency)) {
layerIsNeededBy.set(dependency, [])
}
layerIsNeededBy.get(dependency).push(layer.id)
}


}





return new Combine([
new Title("Special and other useful layers", 1),
"MapComplete has a few data layers available in the theme which have special properties through builtin-hooks. Furthermore, there are some normal layers (which are built from normal Theme-config files) but are so general that they get a mention here.",
new Title("Priviliged layers", 1),
new List(Constants.priviliged_layers.map(id => "[" + id + "](#" + id + ")")),
...Constants.priviliged_layers
.map(id => AllKnownLayouts.sharedLayers.get(id))
.map((l) => l.GenerateDocumentation(themesPerLayer.get(l.id), layerIsNeededBy, DependencyCalculator.getLayerDependencies(l),Constants.added_by_default.indexOf(l.id) >= 0, Constants.no_include.indexOf(l.id) < 0)),
.map((l) => l.GenerateDocumentation(themesPerLayer.get(l.id), layerIsNeededBy, DependencyCalculator.getLayerDependencies(l), Constants.added_by_default.indexOf(l.id) >= 0, Constants.no_include.indexOf(l.id) < 0)),
new Title("Normal layers", 1),
"The following layers are included in MapComplete:",
new List(Array.from(AllKnownLayouts.sharedLayers.keys()).map(id => new Link(id, "./Layers/"+id+".md")))
new List(Array.from(AllKnownLayouts.sharedLayers.keys()).map(id => new Link(id, "./Layers/" + id + ".md")))
])


}

private static getSharedLayers(): Map<string, LayerConfig> {
const sharedLayers = new Map<string, LayerConfig>();
for (const layer of known_themes.layers) {
try {
// @ts-ignore
const parsed = new LayerConfig(layer, "shared_layers")
sharedLayers.set(layer.id, parsed);
} catch (e) {
if (!Utils.runningFromConsole) {
console.error("CRITICAL: Could not parse a layer configuration!", layer.id, " due to", e)
}
}
}

return sharedLayers;
}

private static GenerateOrderedList(allKnownLayouts: Map<string, LayoutConfig>): LayoutConfig[] {
const list = []
allKnownLayouts.forEach((layout) => {
Expand All @@ -174,20 +171,20 @@ export class AllKnownLayouts {
private static AllLayouts(): Map<string, LayoutConfig> {
const dict: Map<string, LayoutConfig> = new Map();
for (const layoutConfigJson of known_themes.themes) {
const layout = new LayoutConfig(<LayoutConfigJson> layoutConfigJson, true)
dict.set(layout.id, layout)
for (let i = 0; i < layout.layers.length; i++) {
let layer = layout.layers[i];
if (typeof (layer) === "string") {
layer = AllKnownLayouts.sharedLayers.get(layer);
layout.layers[i] = layer
if (layer === undefined) {
console.log("Defined layers are ", AllKnownLayouts.sharedLayers.keys())
throw `Layer ${layer} was not found or defined - probably a type was made`
}
}
}
const layout = new LayoutConfig(<LayoutConfigJson>layoutConfigJson, true)
dict.set(layout.id, layout)
for (let i = 0; i < layout.layers.length; i++) {
let layer = layout.layers[i];
if (typeof (layer) === "string") {
layer = AllKnownLayouts.sharedLayers.get(layer);
layout.layers[i] = layer
if (layer === undefined) {
console.log("Defined layers are ", AllKnownLayouts.sharedLayers.keys())
throw `Layer ${layer} was not found or defined - probably a type was made`
}
}

}
}
return dict;
}
Expand Down
6 changes: 3 additions & 3 deletions Customizations/SharedTagRenderings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ export default class SharedTagRenderings {

if (!iconsOnly) {
for (const key in questions) {
if(key === "id"){
if (key === "id") {
continue
}
dict.set(key, <TagRenderingConfigJson>questions[key])
}
}
for (const key in icons) {
if(key === "id"){
if (key === "id") {
continue
}
dict.set(key, <TagRenderingConfigJson>icons[key])
}

dict.forEach((value, key) => {
if(key === "id"){
if (key === "id") {
return
}
value.id = value.id ?? key;
Expand Down
Loading

0 comments on commit fa971ff

Please sign in to comment.