Move definition of Scribe glyphs to an array of objects
authorCarl Worth <cworth@cworth.org>
Sat, 20 Jun 2020 18:01:33 +0000 (11:01 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 20 Jun 2020 18:01:33 +0000 (11:01 -0700)
And loop over this with map() to generate a list of React elements.

This is instead of the previous list of literal React elements we had
before.

This doesn't have any immediate impact, but makes the glyph data
available if other code wants to access it in the future, (such as
code that is scoring a mini grid).

scribe/scribe.jsx

index 3caf03c87d313ab3e582bfc68bb0da020143c6dd..548a0edc826c44258bf05af1e2cdc73325d7da18 100644 (file)
@@ -79,6 +79,123 @@ events.addEventListener("game-state", event => {
  * Game and supporting classes                           *
  *********************************************************/
 
+const scribe_glyphs = [
+  {
+    name: "Single",
+    squares: [1,0,0,
+              0,0,0,
+              0,0,0]
+  },
+  {
+    name: "Double",
+    squares: [1,1,0,
+              0,0,0,
+              0,0,0]
+  },
+  {
+    name: "Line",
+    squares: [1,1,1,
+              0,0,0,
+              0,0,0]
+  },
+  {
+    name: "Pipe",
+    squares: [0,0,1,
+              1,1,1,
+              0,0,0]
+  },
+  {
+    name: "Squat-T",
+    squares: [1,1,1,
+              0,1,0,
+              0,0,0]
+  },
+  {
+    name: "4-block",
+    squares: [1,1,0,
+              1,1,0,
+              0,0,0]
+  },
+  {
+    name: "T",
+    squares: [1,1,1,
+              0,1,0,
+              0,1,0]
+  },
+  {
+    name: "Cross",
+    squares: [0,1,0,
+              1,1,1,
+              0,1,0]
+  },
+  {
+    name: "6-block",
+    squares: [1,1,1,
+              1,1,1,
+              0,0,0]
+  },
+  {
+    name: "Bomber",
+    squares: [1,1,1,
+              0,1,1,
+              0,0,1]
+  },
+  {
+    name: "Chair",
+    squares: [0,0,1,
+              1,1,1,
+              1,0,1]
+  },
+  {
+    name: "J",
+    squares: [0,0,1,
+              1,0,1,
+              1,1,1]
+  },
+  {
+    name: "Earring",
+    squares: [0,1,1,
+              1,0,1,
+              1,1,1]
+  },
+  {
+    name: "House",
+    squares: [0,1,0,
+              1,1,1,
+              1,1,1]
+  },
+  {
+    name: "H",
+    squares: [1,0,1,
+              1,1,1,
+              1,0,1]
+  },
+  {
+    name: "U",
+    squares: [1,0,1,
+              1,0,1,
+              1,1,1]
+  },
+  {
+    name: "Ottoman",
+    squares: [1,1,1,
+              1,1,1,
+              1,0,1]
+  },
+  {
+    name: "O",
+    squares: [1,1,1,
+              1,0,1,
+              1,1,1]
+  },
+  {
+    name: "9-block",
+    squares: [1,1,1,
+              1,1,1,
+              1,1,1]
+  }
+];
+
 function copy_to_clipboard(id)
 {
   const tmp = document.createElement("input");
@@ -461,120 +578,17 @@ class Game extends React.Component {
         </div>
       </div>,
       <div key="glyphs" className="glyphs">
-        <Glyph
-          name="Single"
-          squares={[1,0,0,
-                    0,0,0,
-                    0,0,0]}
-        />
-        <Glyph
-          name="Double"
-          squares={[1,1,0,
-                    0,0,0,
-                    0,0,0]}
-        />
-        <Glyph
-          name="Line"
-          squares={[1,1,1,
-                    0,0,0,
-                    0,0,0]}
-        />
-        <Glyph
-          name="Pipe"
-          squares={[0,0,1,
-                    1,1,1,
-                    0,0,0]}
-        />
-        <Glyph
-          name="Squat-T"
-          squares={[1,1,1,
-                    0,1,0,
-                    0,0,0]}
-        />
-        <Glyph
-          name="4-block"
-          squares={[1,1,0,
-                    1,1,0,
-                    0,0,0]}
-        />
-        <Glyph
-          name="T"
-          squares={[1,1,1,
-                    0,1,0,
-                    0,1,0]}
-                />
-        <Glyph
-          name="Cross"
-          squares={[0,1,0,
-                    1,1,1,
-                    0,1,0]}
-        />
-        <Glyph
-          name="6-block"
-          squares={[1,1,1,
-                    1,1,1,
-                    0,0,0]}
-        />
-        <Glyph
-          name="Bomber"
-          squares={[1,1,1,
-                    0,1,1,
-                    0,0,1]}
-        />
-        <Glyph
-          name="Chair"
-          squares={[0,0,1,
-                    1,1,1,
-                    1,0,1]}
-        />
-        <Glyph
-          name="J"
-          squares={[0,0,1,
-                    1,0,1,
-                    1,1,1]}
-        />
-        <Glyph
-          name="Earring"
-          squares={[0,1,1,
-                    1,0,1,
-                    1,1,1]}
-        />
-        <Glyph
-          name="House"
-          squares={[0,1,0,
-                    1,1,1,
-                    1,1,1]}
-        />
-        <Glyph
-          name="H"
-          squares={[1,0,1,
-                    1,1,1,
-                    1,0,1]}
-        />
-        <Glyph
-          name="U"
-          squares={[1,0,1,
-                    1,0,1,
-                    1,1,1]}
-        />
-        <Glyph
-          name="Ottoman"
-          squares={[1,1,1,
-                    1,1,1,
-                    1,0,1]}
-        />
-        <Glyph
-          name="O"
-          squares={[1,1,1,
-                    1,0,1,
-                    1,1,1]}
-        />
-        <Glyph
-          name="9-block"
-          squares={[1,1,1,
-                    1,1,1,
-                    1,1,1]}
-        />
+        {
+          scribe_glyphs.map(glyph => {
+            return (
+              <Glyph
+                key={glyph.name}
+                name={glyph.name}
+                squares={glyph.squares}
+              />
+            );
+          })
+        }
       </div>
     ];
   }