aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/nword.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/nword.js b/examples/nword.js
new file mode 100644
index 0000000..fe09a0b
--- /dev/null
+++ b/examples/nword.js
@@ -0,0 +1,50 @@
+// Replaces the n-word with "n-word"
+const Socket = require('../socket');
+const Space = require('../space');
+const Search = require('../tools/search');
+const Queue = require('../tools/queue');
+const maketiles = require('../utils/maketiles');
+const vec = require('../utils/vec');
+const wwrap = require('../utils/writewrap');
+
+var main = new Socket();
+wwrap.call(main);
+var search = new Search();
+var ids = [];
+var idcall = [];
+var wq = new Queue(1000, 200, (w,max) =>{
+ let globid = main.write(w);
+ let id;
+ while (id = ids.shift()) {
+ if (id > max) break;
+ main.on(globid, idcall.shift());
+ }
+});
+
+main.on('open',()=>{wq.enable(); console.log('here');});
+
+var expire = {};
+main.on('tileUpdate', (send, source, tiles)=>{
+ let tiledata = maketiles(tiles);
+ for (loc of tiledata.locs) {
+ let spc = tiledata.tilespaces[loc];
+ if (search.has(loc)){
+ clearTimeout(expire[loc]);
+ search.del(loc);
+ }
+ search.add(loc, spc);
+ expire[loc] = setTimeout(() => {search.del(loc); delete expire[loc];},
+ 30000);
+ }
+});
+
+search.match(new Space().adhoc('nigger'), clean);
+search.match(new Space().adhoc('Nigger'), clean);
+search.match(new Space().adhoc('NIGGER'), clean);
+
+let response = new Space().adhoc(' I am a racist ');
+function clean(coord, send){
+ response.loc = vec.add(coord,[0,-6]);
+ ids.push(wq.enqueue(response.towrite()));
+ idcall.push(() => {search.update(response);});
+}