aboutsummaryrefslogtreecommitdiff
path: root/src/fields/InkField.ts
blob: dbe51b24a5f98f7cdac219c667412a6d3782327f (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
51
52
53
54
55
import { Deserializable } from "../client/util/SerializationHelper";
import { serializable, custom, createSimpleSchema, list, object, map } from "serializr";
import { ObjectField } from "./ObjectField";
import { Copy, ToScriptString, ToString, Update } from "./FieldSymbols";
import { Scripting } from "../client/util/Scripting";

export enum InkTool {
    None = "none",
    Pen = "pen",
    Highlighter = "highlighter",
    Eraser = "eraser",
    Stamp = "stamp"
}

export interface PointData {
    X: number;
    Y: number;
}

export type InkData = Array<PointData>;

const pointSchema = createSimpleSchema({
    X: true, Y: true
});

const strokeDataSchema = createSimpleSchema({
    pathData: list(object(pointSchema)),
    "*": true
});

@Deserializable("ink")
export class InkField extends ObjectField {
    @serializable(list(object(strokeDataSchema)))
    readonly inkData: InkData;
    // inkData: InkData;


    constructor(data: InkData) {
        super();
        this.inkData = data;
    }

    [Copy]() {
        return new InkField(this.inkData);
    }

    [ToScriptString]() {
        return "new InkField([" + this.inkData.map(i => `{X: ${i.X}, Y: ${i.Y}} `) + "])";
    }
    [ToString]() {
        return "InkField";
    }
}

Scripting.addGlobal("InkField", InkField);