Repository: sjbarag/brs
Pull request #414 (2020-05-13 17:17:45)

feat(stdlib): implement Poster component
# Change Summary
This implements the `<Poster>` component.


Patch:
diff --git a/src/brsTypes/components/ComponentFactory.ts b/src/brsTypes/components/ComponentFactory.ts
index 7192947..6ef9536 100644
--- a/src/brsTypes/components/ComponentFactory.ts
+++ b/src/brsTypes/components/ComponentFactory.ts
@@ -1,4 +1,4 @@
-import { RoSGNode, Group, Rectangle, Label, Font } from "..";
+import { RoSGNode, Group, Rectangle, Label, Font, Poster } from "..";
 
 export enum BrsComponentName {
     Node = "Node",
@@ -6,6 +6,7 @@ export enum BrsComponentName {
     Rectangle = "Rectangle",
     Label = "Label",
     Font = "Font",
+    Poster = "Poster",
 }
 
 // TODO: update with more components as they're implemented.
@@ -26,6 +27,8 @@ export class ComponentFactory {
                 return new Label([], name);
             case BrsComponentName.Font:
                 return new Font([], name);
+            case BrsComponentName.Poster:
+                return new Poster([], name);
             default:
                 return;
         }
diff --git a/src/brsTypes/components/Poster.ts b/src/brsTypes/components/Poster.ts
new file mode 100644
index 0000000..58a001c
--- /dev/null
+++ b/src/brsTypes/components/Poster.ts
@@ -0,0 +1,32 @@
+import { FieldModel } from "./RoSGNode";
+import { AAMember } from "./RoAssociativeArray";
+import { Group } from "./Group";
+
+export class Poster extends Group {
+    readonly defaultFields: FieldModel[] = [
+        { name: "uri", type: "string" },
+        { name: "width", type: "float", value: "0.0" },
+        { name: "height", type: "float", value: "0.0" },
+        { name: "loadSync", type: "boolean", value: "false" },
+        { name: "loadWidth", type: "float", value: "0.0" },
+        { name: "loadHeight", type: "float", value: "0.0" },
+        { name: "loadDisplayMode", type: "string", value: "noScale" },
+        { name: "loadStatus", type: "string", value: "noScale" },
+        { name: "bitmapWidth", type: "float", value: "0.0" },
+        { name: "bitmapHeight", type: "float", value: "0.0" },
+        { name: "bitmapMargins", type: "assocarray" },
+        { name: "blendColor", type: "string", value: "0xFFFFFFFF" },
+        { name: "loadingBitmapUri", type: "string" },
+        { name: "loadingBitmapOpacity", type: "float", value: "1.0" },
+        { name: "failedBitmapUri", type: "string" },
+        { name: "failedBitmapOpacity", type: "float", value: "1.0" },
+        { name: "audioGuideText", type: "string" },
+    ];
+
+    constructor(initializedFields: AAMember[] = [], readonly name: string = "Poster") {
+        super([], name);
+
+        this.registerDefaultFields(this.defaultFields);
+        this.registerInitializedFields(initializedFields);
+    }
+}
diff --git a/src/brsTypes/index.ts b/src/brsTypes/index.ts
index 60ef23a..2672726 100644
--- a/src/brsTypes/index.ts
+++ b/src/brsTypes/index.ts
@@ -46,6 +46,7 @@ export * from "./components/Group";
 export * from "./components/Rectangle";
 export * from "./components/Label";
 export * from "./components/Font";
+export * from "./components/Poster";
 
 /**
  * Determines whether or not the given value is a number.


Test patch:
diff --git a/test/brsTypes/components/Poster.test.js b/test/brsTypes/components/Poster.test.js
new file mode 100644
index 0000000..3c071fa
--- /dev/null
+++ b/test/brsTypes/components/Poster.test.js
@@ -0,0 +1,51 @@
+const brs = require("brs");
+const { Poster } = brs.types;
+
+describe("Poster", () => {
+    describe("stringification", () => {
+        it("inits a new Poster component", () => {
+            let group = new Poster();
+
+            expect(group.toString()).toEqual(
+                `<Component: roSGNode:Poster> =
+{
+    change: <UNINITIALIZED>
+    focusable: false
+    focusedchild: invalid
+    id: 
+    visible: true
+    opacity: 1
+    translation: invalid
+    rotation: 0
+    scale: invalid
+    scalerotatecenter: invalid
+    childrenderorder: renderLast
+    inheritparenttransform: true
+    inheritparentopacity: true
+    clippingrect: invalid
+    renderpass: 0
+    muteaudioguide: false
+    enablerendertracking: false
+    rendertracking: disabled
+    uri: 
+    width: 0
+    height: 0
+    loadsync: false
+    loadwidth: 0
+    loadheight: 0
+    loaddisplaymode: noScale
+    loadstatus: noScale
+    bitmapwidth: 0
+    bitmapheight: 0
+    bitmapmargins: invalid
+    blendcolor: 0xFFFFFFFF
+    loadingbitmapuri: 
+    loadingbitmapopacity: 1
+    failedbitmapuri: 
+    failedbitmapopacity: 1
+    audioguidetext: 
+}`
+            );
+        });
+    });
+});
diff --git a/test/e2e/BrsComponents.test.js b/test/e2e/BrsComponents.test.js
index 29bd100..9c0c103 100644
--- a/test/e2e/BrsComponents.test.js
+++ b/test/e2e/BrsComponents.test.js
@@ -454,4 +454,24 @@ describe("end to end brightscript functions", () => {
             "font/as/child/uri",
         ]);
     });
+
+    test("components/Poster.brs", async () => {
+        outputStreams.root = __dirname + "/resources";
+        await execute([resourceFile("components", "Poster.brs")], outputStreams);
+
+        expect(allArgs(outputStreams.stdout.write).filter(arg => arg !== "\n")).toEqual([
+            "poster node type:",
+            "Poster",
+            "poster node width:",
+            "0",
+            "poster node height:",
+            "0",
+            "poster as child audioGuideText:",
+            "fake text",
+            "poster as child uri:",
+            "/fake/uri",
+            "poster as child bitmapWidth:",
+            "10.4",
+        ]);
+    });
 });
diff --git a/test/e2e/resources/components/ComponentsAsChildren.xml b/test/e2e/resources/components/ComponentsAsChildren.xml
index 1507a11..c6d6616 100644
--- a/test/e2e/resources/components/ComponentsAsChildren.xml
+++ b/test/e2e/resources/components/ComponentsAsChildren.xml
@@ -12,6 +12,11 @@
             <Font id="font"
                 size="56"
                 uri="font/as/child/uri" />
+            <Poster id="poster"
+                audioGuideText="fake text"
+                bitmapWidth="10.4"
+                uri="/fake/uri"
+            />
         </Group>
     </children>
 </component>
diff --git a/test/e2e/resources/components/Poster.brs b/test/e2e/resources/components/Poster.brs
new file mode 100644
index 0000000..174a912
--- /dev/null
+++ b/test/e2e/resources/components/Poster.brs
@@ -0,0 +1,12 @@
+sub Main()
+    poster = createObject("roSGNode", "Poster")
+    print "poster node type:" type(poster)                                       ' => Group
+    print "poster node width:" poster.width
+    print "poster node height:" poster.height
+
+    parent = createObject("roSGNode", "ComponentsAsChildren")
+    posterAsChild = parent.findNode("poster")
+    print "poster as child audioGuideText:" posterAsChild.audioGuideText
+    print "poster as child uri:" posterAsChild.uri
+    print "poster as child bitmapWidth:" posterAsChild.bitmapWidth
+end sub