aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/SchemaHeaderField.ts
blob: 284de3023d44cdf545e4a2be2f600832da6676c1 (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
import { Deserializable } from "../client/util/SerializationHelper";
import { serializable, createSimpleSchema, primitive } from "serializr";
import { ObjectField } from "./ObjectField";
import { Copy, ToScriptString, OnUpdate } from "./FieldSymbols";
import { scriptingGlobal, Scripting } from "../client/util/Scripting";

export const PastelSchemaPalette = new Map<string, string>([
    ["purple", "#f5b5fc"],
    ["green", "#96F7D2"],
    ["yellow", "#F0F696"],
    ["red", "#FCB1B1"]
])

@scriptingGlobal
@Deserializable("schemaheader")
export class SchemaHeaderField extends ObjectField {
    @serializable(primitive())
    heading: string;
    color: string;

    constructor(heading: string = "", color: string = Array.from(PastelSchemaPalette.values())[Math.floor(Math.random() * 4)]) {
        super();

        this.heading = heading;
        this.color = color;
    }

    setHeading(heading: string) {
        this.heading = heading;
        this[OnUpdate]();
    }

    setColor(color: string) {
        this.color = color;
        this[OnUpdate]();
    }

    [Copy]() {
        return new SchemaHeaderField(this.heading, this.color);
    }

    [ToScriptString]() {
        return `invalid`;
    }
}