Commits

catseye  committed ae4d3e9

Don't accept ( and ) in source; implement a load indicator.

  • Participants
  • Parent commits c822e28

Comments (0)

Files changed (3)

File impl/worb.js/TODO.markdown

-* implement something for load (sound? callback?)
 * speed control
-* convert ( and ) to < and > after copying init cfg into textarea

File impl/worb.js/demo/worb.html

     width: 420px; height: 420px; overflow: scroll; border: 1px solid black;
     display: inline-block;
 }
+# load_indicator { border: 1px solid purple; }
 .initial_configuration { display: none; }
   </style>
 </head>
         <option>or_gate</option>
         <option>subtraction</option>
         <option>division</option>
+        <option>heater</option>
       </select>
     </span>
   </span>
+  <span id="load_indicator">
+    load indicator
+  </span>
 </div>
 
 <div id="canvas_viewport">
       ######
 </div>
 
+<div class="initial_configuration" id="heater"
+>     #########
+     #! ! ! !#
+###### ! ! ! ######
+#+    ! ! ! !    -#
+###### ! ! ! ######
+     #! ! ! !#
+     #########
+</div>
+
 </body>
 <script src="../src/yoob/playfield.js"></script>
 <script src="../src/worb.js"></script>
 <script>
   var canvas = document.getElementById('canvas');
+  var cfg = document.getElementById('configuration');
+  var loadIndicator = document.getElementById('load_indicator');
+
   var worb = new NoitOMnainWorb();
+  var loadLevel = 0;
+
   worb.init(canvas);
+  worb.onstep = function(underLoad) {
+      if (underLoad) loadLevel += 60;
+      loadLevel -= 10;
+      if (loadLevel < 0) loadLevel = 0;
+      if (loadLevel > 255) loadLevel = 255;
+      var l = 255-loadLevel;
+      loadIndicator.style.background = "rgba(255, " + l + "," + l + ",1.0)";
+  };
   document.getElementById('load').onclick = function() {
-      var cfg = document.getElementById('configuration');
       worb.load(cfg);
   };
   document.getElementById('start').onclick = function() {
       worb.stop();
   };
   document.getElementById('select_configuration').onchange = function() {
-      var cfg = document.getElementById('configuration');
       var initcfg = document.getElementById(this.options[this.selectedIndex].value);
-      cfg.value = initcfg.innerHTML;
+      var text = initcfg.innerHTML;
+      text = text.replace(/\(/g, '<');
+      text = text.replace(/\)/g, '>');
+      cfg.value = text;
       worb.load(cfg);
   };
 </script>

File impl/worb.js/src/worb.js

                     this.put(lx, ly, new Sink());
                 } else if (c === '!') {
                     this.put(lx, ly, new Load());
-                } else if (c === '>' || c === ')') {
+                } else if (c === '>') {
                     var g = new Diode();
                     g.init(1, 0);
                     this.put(lx, ly, g);
-                } else if (c === '<' || c === '(') {
+                } else if (c === '<') {
                     var g = new Diode();
                     g.init(-1, 0);
                     this.put(lx, ly, g);
     };
 
     this.step = function() {
+        var underLoad = false;
         var pf = this.pf;
         this.draw();
         pf.foreachBobule(function (x, y, elem) {
                 if (!(b instanceof Bobule) && Math.random() <= 0.10) {
                     pf.put(x, y, new Bobule());
                 }
+            } else if (elem instanceof Load) {
+                b = pf.get(x, y);
+                if (b instanceof Bobule) {
+                    underLoad = true;
+                }
             }
         });
+        if (this.onstep !== undefined) {
+            this.onstep(underLoad);
+        }
     };
 
     this.start = function() {