feat(app): add character location tracking and display
This commit is contained in:
@@ -14,6 +14,45 @@ export namespace main {
|
||||
this.character_name = source["character_name"];
|
||||
}
|
||||
}
|
||||
export class CharacterLocation {
|
||||
character_id: number;
|
||||
character_name: string;
|
||||
solar_system_id: number;
|
||||
solar_system_name: string;
|
||||
// Go type: time
|
||||
retrieved_at: any;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new CharacterLocation(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.character_id = source["character_id"];
|
||||
this.character_name = source["character_name"];
|
||||
this.solar_system_id = source["solar_system_id"];
|
||||
this.solar_system_name = source["solar_system_name"];
|
||||
this.retrieved_at = this.convertValues(source["retrieved_at"], null);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user