From 46d56620c3ba385bdd41bc391c975e4934b4c82d Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Fri, 24 Jan 2020 15:33:38 -0500
Subject: tools/claim now uses 'fallback' event
---
tools/claim.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'tools')
diff --git a/tools/claim.js b/tools/claim.js
index 721c5ad..b43417b 100644
--- a/tools/claim.js
+++ b/tools/claim.js
@@ -5,7 +5,7 @@ const ri = require('../utils/rectintersect');
const vec = require('../utils/vec');
const comb = require('../utils/comb');
-module.exports = function(catchall){
+module.exports = function(){
// catchall is called if tileUpdate occurs w/ no relevant claim on a part.
let claims = {};
let claimId = 0;
@@ -44,6 +44,6 @@ module.exports = function(catchall){
}
claim.call(send, diffspace, rellocs, id, claim.space, claim.area); // claim.space should not be modified by the function. it is only present to make functions easier to write
}
- catchall(send, tilespaces, locs);
+ this.emit('fallback', send, tilespaces, locs);
}
}
--
cgit
From 1cc310e20dda4a378aac76b49288e6c8e2361e5e Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Wed, 29 Jan 2020 23:42:44 -0500
Subject: generalized tools/search model
search.js now provides for a .match and .unmatch method,
so it doesn't need to be called every time (in-line with the singleton
MetaSocket object model, meaning that callbacks are used and several
spaces can be matched at a time)
---
tools/search.js | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
(limited to 'tools')
diff --git a/tools/search.js b/tools/search.js
index 7f681f0..78e0ee7 100644
--- a/tools/search.js
+++ b/tools/search.js
@@ -12,11 +12,13 @@ function getComp(index){
return (element,needle) => (element[index] - needle[index] || element[1-index] - needle[1-index])
}
-function Search(searchBlock){ // searchBlock should be a Space object.
+function Search(){ // searchBlock should be a Space object.
this.tiles = {}; // Object which stores Spaces.
this.sort = [[],[]]; // Vertically/horizontally sorted list of tiles for fast addition, deletion, and searching
+ this.spaces = [];
+ this.calls = [];
- this.add = function(loc, space){ // loc should be [tileY,tileX] and space Space.
+ this.add = function(loc, space, send){ // loc should be [tileY,tileX] and space Space.
this.tiles[loc] = space;
let inds = Array(2); // Records horizontal and vertical indices for insertion. Then actually inserts the item.
[0,1].forEach( ind => { // ind chooses y-or-x
@@ -29,8 +31,10 @@ function Search(searchBlock){ // searchBlock should be a Space object.
block.forEach( (tile) => {
searchspace.comb( this.tiles[tile], comb.add );
});
- coords = searchspace.search(searchBlock); // According to space docs, [] on failure and a character location on success
- return vec.add(coords, searchspace.loc);
+ for (let i=0; i