aboutsummaryrefslogtreecommitdiff
path: root/src/fields/InkField.ts
diff options
context:
space:
mode:
authorFawn <fangrui_tong@brown.edu>2019-03-06 18:58:00 -0500
committerFawn <fangrui_tong@brown.edu>2019-03-06 18:58:00 -0500
commitc6781458648c4265f2f995be526529be54312f54 (patch)
tree7cbdb01df793a6709a614c89268b887181c6b677 /src/fields/InkField.ts
parent3e7e715a235db4da57ba22b5cce1ee3c873f5a40 (diff)
all inking code
Diffstat (limited to 'src/fields/InkField.ts')
-rw-r--r--src/fields/InkField.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/fields/InkField.ts b/src/fields/InkField.ts
new file mode 100644
index 000000000..0af72a8ea
--- /dev/null
+++ b/src/fields/InkField.ts
@@ -0,0 +1,47 @@
+import { BasicField } from "./BasicField";
+import { Types } from "../server/Message";
+import { FieldId } from "./Field";
+
+export enum InkTool {
+ None,
+ Pen,
+ Highlighter,
+ Eraser
+}
+export interface StrokeData {
+ pathData: Array<{ x: number, y: number }>;
+ color: string;
+ width: string;
+ tool: InkTool;
+}
+export type StrokeMap = Map<number, StrokeData>;
+
+export class InkField extends BasicField<StrokeMap> {
+ constructor(data: StrokeMap = new Map, id?: FieldId, save: boolean = true) {
+ super(data, save, id);
+ }
+
+ ToScriptString(): string {
+ return `new InkField("${this.Data}")`;
+ }
+
+ Copy() {
+ return new InkField(this.Data);
+ }
+
+ ToJson(): { _id: string; type: Types; data: any; } {
+ return {
+ type: Types.Ink,
+ data: this.Data,
+ _id: this.Id,
+ }
+ }
+
+ static FromJson(id: string, data: any): InkField {
+ let map = new Map<number, StrokeData>();
+ Object.keys(data).forEach(key => {
+ map.set(parseInt(key), data[key]);
+ });
+ return new InkField(map, id, false);
+ }
+} \ No newline at end of file