aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Key.ts
blob: 57e2dadf082511b9148dce0dd9d6d66124c57f7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Field, FieldId } from "./Field";
import { Utils } from "../Utils";
import { observable } from "mobx";
import { Types } from "../server/Message";
import { Server } from "../client/Server";

export class Key extends Field {
    private name: string;

    get Name(): string {
        return this.name;
    }

    constructor(name: string, id?: string, save: boolean = true) {
        super(id || Utils.GenerateDeterministicGuid(name));

        this.name = name;
        if (save) {
            Server.UpdateField(this);
        }
    }

    UpdateFromServer(data: string) {
        this.name = data;
    }

    TrySetValue(value: any): boolean {
        throw new Error("Method not implemented.");
    }

    GetValue() {
        return this.Name;
    }

    Copy(): Field {
        return this;
    }

    ToScriptString(): string {
        return name;
    }

    ToJson() {
        return {
            type: Types.Key,
            data: this.name,
            id: this.Id
        };
    }
}