aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/SchemaHeaderField.ts
diff options
context:
space:
mode:
authorSam Wilkins <abdullah_ahmed@brown.edu>2019-07-23 19:17:03 -0400
committerSam Wilkins <abdullah_ahmed@brown.edu>2019-07-23 19:17:03 -0400
commit6bf6c34a4c3643a2ee438e49e10267de15e431e7 (patch)
tree7ebe5d864cbedd07b8f73074ce5f8e140e8733e6 /src/new_fields/SchemaHeaderField.ts
parent0ef6d9b5a3f90552562f4a6392967887d8805cc3 (diff)
parent0ebcadb80a89e7fe4f8f2a8a47570b19fd2f8711 (diff)
merge
Diffstat (limited to 'src/new_fields/SchemaHeaderField.ts')
-rw-r--r--src/new_fields/SchemaHeaderField.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/new_fields/SchemaHeaderField.ts b/src/new_fields/SchemaHeaderField.ts
new file mode 100644
index 000000000..284de3023
--- /dev/null
+++ b/src/new_fields/SchemaHeaderField.ts
@@ -0,0 +1,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`;
+ }
+}
+