From f26b5af8c272628da9a46d7e4bf79634fb8dbae3 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Thu, 16 Jul 2020 13:41:19 -0400 Subject: search.update passing incorrect stringy loc, improved search.js doc --- tools/search.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tools/search.js') diff --git a/tools/search.js b/tools/search.js index e365214..378f316 100644 --- a/tools/search.js +++ b/tools/search.js @@ -14,9 +14,9 @@ function getComp(index){ 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.sort = [[],[]]; // Vertically/horizontally sorted list of indexed tiles for fast addition, deletion, and searching + this.spaces = []; // if spaces[i] is detected, + this.calls = []; // calls[i](coords, send, searchspace) this.add = function(loc, space, send){ // loc should be [tileY,tileX] and space Space. this.tiles[loc] = space; @@ -77,8 +77,10 @@ function Search(){ // searchBlock should be a Space object. } this.update = function(space){ // Must be a space w/ valid loc; allows overlay of some arbitrary text (in the space) mostly for recording updates from the server without directly cataloguing them + if (space.loc.length === 0) throw "Update space must have valid loc"; let tiles = raster(space); // Returns a this.tiles-style binding: {'2,-3':Space object} - for (let tile in tiles){ + for (let tile in tiles) { + tile = tile.split(',').map(s => parseInt(s)); if (this.tiles[tile]) this.tiles[tile].comb(tiles[tile], comb.flip(comb.add)); else this.add(tile, tiles[tile]); } -- cgit