aboutsummaryrefslogtreecommitdiff
path: root/src/fields/URLField.ts
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2020-05-15 00:03:41 -0700
committerSam Wilkins <samwilkins333@gmail.com>2020-05-15 00:03:41 -0700
commit2b79008596351f6948d8de80c7887446d97b068c (patch)
tree7f393199bf780936cee1427c07c64bd2745fa3f9 /src/fields/URLField.ts
parentb9440e34d89b28acacdd6eed2cda39cd2a1d8c46 (diff)
renamed new_fields to fields
Diffstat (limited to 'src/fields/URLField.ts')
-rw-r--r--src/fields/URLField.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/fields/URLField.ts b/src/fields/URLField.ts
new file mode 100644
index 000000000..fb71160ca
--- /dev/null
+++ b/src/fields/URLField.ts
@@ -0,0 +1,53 @@
+import { Deserializable } from "../client/util/SerializationHelper";
+import { serializable, custom } from "serializr";
+import { ObjectField } from "./ObjectField";
+import { ToScriptString, ToString, Copy } from "./FieldSymbols";
+import { Scripting, scriptingGlobal } from "../client/util/Scripting";
+
+function url() {
+ return custom(
+ function (value: URL) {
+ return value.href;
+ },
+ function (jsonValue: string) {
+ return new URL(jsonValue);
+ }
+ );
+}
+
+export abstract class URLField extends ObjectField {
+ @serializable(url())
+ readonly url: URL;
+
+ constructor(url: string);
+ constructor(url: URL);
+ constructor(url: URL | string) {
+ super();
+ if (typeof url === "string") {
+ url = new URL(url);
+ }
+ this.url = url;
+ }
+
+ [ToScriptString]() {
+ return `new ${this.constructor.name}("${this.url.href}")`;
+ }
+ [ToString]() {
+ return this.url.href;
+ }
+
+ [Copy](): this {
+ return new (this.constructor as any)(this.url);
+ }
+}
+
+export const nullAudio = "https://actions.google.com/sounds/v1/alarms/beep_short.ogg";
+
+@scriptingGlobal @Deserializable("audio") export class AudioField extends URLField { }
+@scriptingGlobal @Deserializable("image") export class ImageField extends URLField { }
+@scriptingGlobal @Deserializable("video") export class VideoField extends URLField { }
+@scriptingGlobal @Deserializable("pdf") export class PdfField extends URLField { }
+@scriptingGlobal @Deserializable("web") export class WebField extends URLField { }
+@scriptingGlobal @Deserializable("youtube") export class YoutubeField extends URLField { }
+@scriptingGlobal @Deserializable("webcam") export class WebCamField extends URLField { }
+