Anonymous avatar Anonymous committed 51020e1 Draft

Use generated loadMapper() and dumpMapper().

Comments (0)

Files changed (2)

demo/circute.html

   var c = new yoob.Controller();
   var pf;
   
-  var dumper = function(state) {
-      if (state === 'Space') return ' ';
-      if (state === 'NAND') return 'N';
-      if (state === 'Wire') return '=';
-      if (state === 'Spark') return '*';
-      if (state === 'Tail') return '-';
-      return '?';
-  };
-
   c.load = function(text) {
       pf = new yoob.Playfield();
       pf.setDefault('Space');
-      pf.load(0, 0, text, function(c) {
-        if (c === ' ') return 'Space';
-        if (c === 'N') return 'NAND';
-        if (c === '=') return 'Wire';
-        if (c === '*') return 'Spark';
-        if (c === '-') return 'Tail';
-      });
-      output.innerHTML = pf.dump(dumper);
+      pf.load(0, 0, text, loadMapper);
+      output.innerHTML = pf.dump(dumpMapper);
   };
 
   c.step = function() {
       evolve_playfield(pf, newPf);
       pf = newPf;
       var output = document.getElementById('output');
-      output.innerHTML = pf.dump(dumper);
+      output.innerHTML = pf.dump(dumpMapper);
   };
 
   c.connect({

script/circute.js

 function evolve_playfield(pf, new_pf) {
   pf.map(new_pf, evalState, -1, -1, 1, 1);
 }
+function loadMapper(c) {
+  if (c === ' ') return 'Space';
+  if (c === '#') return 'Spark';
+  if (c === '-') return 'Tail';
+  if (c === '=') return 'Wire';
+  if (c === 'N') return 'NAND';
+};
+function dumpMapper(s) {
+  if (s === 'Space') return ' ';
+  if (s === 'Spark') return '#';
+  if (s === 'Tail') return '-';
+  if (s === 'Wire') return '=';
+  if (s === 'NAND') return 'N';
+};
 function eval_Space(pf, x, y) {
 var id;
 return 'Space';
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.