git @ Cat's Eye Technologies ALPACA / e891e0e
Simplify testing JS by using yoob.Playfield.dump(). catseye 12 years ago
1 changed file(s) with 9 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
313313 for (x, y, c) in pf.iteritems():
314314 self.file.write("pf.putDirty(%d, %d, '%s');\n" % (x, y, c))
315315 self.file.write("pf.recalculateBounds();\n")
316 # TODO: use pf.dump()
317 self.file.write("""
318 function dump_playfield(pf) {
319 for (var y = pf.minY; y <= pf.maxY; y++) {
320 var line = '';
321 for (var x = pf.minX; x <= pf.maxX; x++) {
322 s = pf.get(x, y);
323 """)
316 self.file.write("var dumper = function(s) {\n")
324317 for (state_id, char) in pf.state_to_repr.iteritems():
325 self.file.write("""
326 if (s === '%s') line += '%s';
327 """ % (state_id, char))
328 self.file.write("""
329 }
330 console.log(line);
331 }
332 }
333 """)
334 self.file.write("""
335 new_pf = new yoob.Playfield();
336 new_pf.setDefault('%s');
337 evolve_playfield(pf, new_pf);
318 self.file.write(" if (s === '%s') return '%s';\n" %
319 (state_id, char))
320 self.file.write("};\n")
321 self.file.write(r"""
322 newPf = new yoob.Playfield();
323 newPf.setDefault('%s');
324 evolve_playfield(pf, newPf);
338325 console.log('-----');
339 dump_playfield(new_pf);
326 console.log(newPf.dump(dumper).replace(/\n$/, ""));
340327 console.log('-----');
341328 """ % pf.default)
342329 return True