@dra2020/baseclient 1.0.85 → 1.0.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/baseclient.js +67 -0
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/all.d.ts +1 -0
- package/dist/geo/multiblockmapping.d.ts +21 -0
- package/lib/geo/all.ts +1 -0
- package/lib/geo/multiblockmapping.ts +72 -0
- package/package.json +1 -1
package/dist/geo/all.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare type BlockMapping = {
|
|
2
|
+
[blockid: string]: string;
|
|
3
|
+
};
|
|
4
|
+
export declare type ReverseBlockMapping = {
|
|
5
|
+
[geoid: string]: string[];
|
|
6
|
+
};
|
|
7
|
+
interface Entry {
|
|
8
|
+
tag: string;
|
|
9
|
+
bm: BlockMapping;
|
|
10
|
+
rbm?: ReverseBlockMapping;
|
|
11
|
+
}
|
|
12
|
+
export declare function reverseBlockMapping(bm: BlockMapping): ReverseBlockMapping;
|
|
13
|
+
export declare class MultiBlockMapping {
|
|
14
|
+
entries: Entry[];
|
|
15
|
+
constructor(tag?: string, bm?: BlockMapping);
|
|
16
|
+
add(tag: string, bm: BlockMapping): void;
|
|
17
|
+
remove(tag: string): void;
|
|
18
|
+
map(blockid: string): string;
|
|
19
|
+
rev(geoid: string): string[];
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/lib/geo/all.ts
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export type BlockMapping = { [blockid: string]: string };
|
|
2
|
+
export type ReverseBlockMapping = { [geoid: string]: string[] };
|
|
3
|
+
|
|
4
|
+
interface Entry
|
|
5
|
+
{
|
|
6
|
+
tag: string,
|
|
7
|
+
bm: BlockMapping,
|
|
8
|
+
rbm?: ReverseBlockMapping,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function reverseBlockMapping(bm: BlockMapping): ReverseBlockMapping
|
|
12
|
+
{
|
|
13
|
+
let rev: ReverseBlockMapping = {};
|
|
14
|
+
|
|
15
|
+
if (bm) Object.keys(bm).forEach(blockid => {
|
|
16
|
+
let geoid = bm[blockid];
|
|
17
|
+
if (! rev[geoid]) rev[geoid] = [];
|
|
18
|
+
rev[geoid].push(blockid);
|
|
19
|
+
});
|
|
20
|
+
Object.values(rev).forEach((a: string[]) => a.sort());
|
|
21
|
+
return rev;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class MultiBlockMapping
|
|
25
|
+
{
|
|
26
|
+
entries: Entry[];
|
|
27
|
+
|
|
28
|
+
constructor(tag?: string, bm?: BlockMapping)
|
|
29
|
+
{
|
|
30
|
+
this.entries = [];
|
|
31
|
+
if (tag && bm)
|
|
32
|
+
this.entries.push({ tag, bm });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
add(tag: string, bm: BlockMapping): void
|
|
36
|
+
{
|
|
37
|
+
this.entries.forEach(e => { if (e.tag === tag) { e.bm = bm; delete e.rbm; bm = null } });
|
|
38
|
+
if (bm)
|
|
39
|
+
this.entries.push({ tag, bm });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
remove(tag: string): void
|
|
43
|
+
{
|
|
44
|
+
for (let i = this.entries.length-1; i >= 0; i--)
|
|
45
|
+
if (this.entries[i].tag === tag)
|
|
46
|
+
this.entries.splice(i, 1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
map(blockid: string): string
|
|
50
|
+
{
|
|
51
|
+
for (let i = 0; i < this.entries.length; i++)
|
|
52
|
+
{
|
|
53
|
+
let e = this.entries[i];
|
|
54
|
+
if (e.bm[blockid])
|
|
55
|
+
return e.bm[blockid];
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
rev(geoid: string): string[]
|
|
61
|
+
{
|
|
62
|
+
for (let i = 0; i < this.entries.length; i++)
|
|
63
|
+
{
|
|
64
|
+
let e = this.entries[i];
|
|
65
|
+
if (! e.rbm)
|
|
66
|
+
e.rbm = reverseBlockMapping(e.bm);
|
|
67
|
+
if (e.rbm[geoid])
|
|
68
|
+
return e.rbm[geoid];
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|