Add rewrite of 'special' clauses, various QOLimprovements on import viewer

This commit is contained in:
Pieter Vander Vennet 2022-03-29 00:20:10 +02:00
parent 8df0324572
commit c47a6d5ea7
22 changed files with 597 additions and 155 deletions

View file

@ -407,7 +407,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
*
* If a list is encountered, this is tranparently walked recursively on every object.
*
* The leaf objects are replaced by the function
* 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[] = []) {
const head = path[0]
@ -793,6 +793,12 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
}
return new Date(str)
}
public static sortedByLevenshteinDistance<T>(reference: string, ts: T[], getName: (t:T) => string): T[]{
const withDistance: [T, number][] = ts.map(t => [t, Utils.levenshteinDistance(getName(t), reference)])
withDistance.sort(([_, a], [__, b]) => a - b)
return withDistance.map(n => n[0])
}
public static levenshteinDistance(str1: string, str2: string) {
const track = Array(str2.length + 1).fill(null).map(() =>