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

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;

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

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

    [ToScriptString]() {
        return "invalid";
    }
    [ToString]() {
        return "InkField";
    }
}