mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 23:27:09 +00:00
Improve biome map (#246)
* Start biome map rewrite * Remove climate layers and add end biome source * Update to use RandomState * Make biome map work for past versions * Remove old biome map code * Implement multi noise presets and fix caching * Update deepslate * Fix biome hover * Fix #190 biome map diagonal lines Also increases performance by making better use of the biome cache * Add proper zoom limit
This commit is contained in:
@@ -256,8 +256,8 @@ export function deepEqual(a: any, b: any) {
|
||||
}
|
||||
|
||||
export class BiMap<A, B> {
|
||||
private readonly forward: Map<A, B>
|
||||
private readonly backward: Map<B, A>
|
||||
public readonly forward: Map<A, B>
|
||||
public readonly backward: Map<B, A>
|
||||
|
||||
constructor() {
|
||||
this.forward = new Map()
|
||||
@@ -285,6 +285,16 @@ export class BiMap<A, B> {
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
public computeIfAbsent(key: A, value: () => B) {
|
||||
const b = this.forward.get(key)
|
||||
if (b === undefined) {
|
||||
const newValue = value()
|
||||
this.set(key, newValue)
|
||||
return newValue
|
||||
}
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
export async function readZip(file: File): Promise<[string, string][]> {
|
||||
@@ -307,3 +317,23 @@ export async function writeZip(entries: [string, string][]): Promise<string> {
|
||||
}))
|
||||
return await writer.close()
|
||||
}
|
||||
|
||||
export function computeIfAbsent<K, V>(map: Map<K, V>, key: K, getter: (key: K) => V): V {
|
||||
const existing = map.get(key)
|
||||
if (existing) {
|
||||
return existing
|
||||
}
|
||||
const value = getter(key)
|
||||
map.set(key, value)
|
||||
return value
|
||||
}
|
||||
|
||||
export async function computeIfAbsentAsync<K, V>(map: Map<K, V>, key: K, getter: (key: K) => Promise<V>): Promise<V> {
|
||||
const existing = map.get(key)
|
||||
if (existing) {
|
||||
return existing
|
||||
}
|
||||
const value = await getter(key)
|
||||
map.set(key, value)
|
||||
return value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user