summaryrefslogtreecommitdiff
path: root/src/Api/entityDecoder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Api/entityDecoder.ts')
-rw-r--r--src/Api/entityDecoder.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/Api/entityDecoder.ts b/src/Api/entityDecoder.ts
new file mode 100644
index 0000000..96d2247
--- /dev/null
+++ b/src/Api/entityDecoder.ts
@@ -0,0 +1,55 @@
+import { Portal, Link, Field } from "./types";
+
+export const decodeEntity = (entity: any[]): Portal | Link | Field | null => {
+ switch (entity[2][0]) {
+ case 'r':
+ // Field
+ return decodeField(entity[2])
+ case 'p':
+ //Portal
+ return decodePortal(entity[2])
+ case 'e':
+ // Link
+ return decodeLink(entity[2])
+ default:
+ return null
+ }
+}
+
+export const decodePortal = (e: any[]): Portal => {
+ return new Portal(
+ e[8],
+ e[7],
+ e[1],
+ { latitude: e[2] / 1E6, longitude: e[3] / 1E6, guid: e[8] },
+ e[4],
+ e[6],
+ e[10],
+ e[5],
+ e[13],
+ e[15],
+ e[14],
+ e[16],
+ )
+}
+
+export const decodeField = (e: any[]): Field => {
+ return new Field(
+ e[1],
+ [
+ { latitude: e[2][0][1] / 1E6, longitude: e[2][0][2] / 1E6, guid: e[2][0][0] },
+ { latitude: e[2][1][1] / 1E6, longitude: e[2][1][2] / 1E6, guid: e[2][1][0] },
+ { latitude: e[2][2][1] / 1E6, longitude: e[2][2][2] / 1E6, guid: e[2][2][0] }
+ ]
+ )
+}
+
+export const decodeLink = (e: any[]): Link => {
+ return new Link(
+ e[1],
+ [
+ { latitude: e[3] / 1E6, longitude: e[4] / 1E6, guid: e[2] },
+ { latitude: e[6] / 1E6, longitude: e[7] / 1E6, guid: e[5] }
+ ]
+ )
+} \ No newline at end of file