Comparing version 0.4.1 to 0.5.0
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _mori = require('mori'); | ||
var _mori2 = _interopRequireDefault(_mori); | ||
var _immy = require('immy'); | ||
@@ -42,3 +46,3 @@ | ||
class Frame { | ||
constructor(stateMap = new Map(), grid = new _immy2.default.Map(), collisions = new _immy2.default.Map(), updates = []) { | ||
constructor(stateMap = new Map(), grid = _mori2.default.hashMap(), collisions = _mori2.default.hashMap(), updates = []) { | ||
this.stateMap = stateMap; | ||
@@ -55,4 +59,4 @@ this.grid = grid; | ||
getIndexOfCollisionInCell(cell, line) { | ||
if (!this.grid.has(cell)) return; | ||
let cellFrames = this.grid.get(cell); | ||
let cellFrames = _mori2.default.get(this.grid, cell); | ||
if (!cellFrames) return; | ||
for (let i = 0; i < cellFrames.size(); i++) { | ||
@@ -67,3 +71,3 @@ let cellFrame = cellFrames.get(i); | ||
getIndexOfCollisionWithLine(line) { | ||
let lineCollisions = this.collisions.get(line.id); | ||
let lineCollisions = _mori2.default.get(this.collisions, line.id); | ||
if (lineCollisions) { | ||
@@ -88,3 +92,3 @@ return lineCollisions.get(0); | ||
for (let cell of cells) { | ||
let cellFrames = this.grid.get(cell); | ||
let cellFrames = _mori2.default.get(this.grid, cell); | ||
if (!cellFrames) { | ||
@@ -95,3 +99,3 @@ cellFrames = makeCellFrames(index, entity); | ||
} | ||
this.grid = this.grid.withKeySetToValue(cell, cellFrames); | ||
this.grid = _mori2.default.assoc(this.grid, cell, cellFrames); | ||
} | ||
@@ -101,3 +105,3 @@ } | ||
addToCollisions(line, index) { | ||
let lineCollisions = this.collisions.get(line.id); | ||
let lineCollisions = _mori2.default.get(this.collisions, line.id); | ||
if (!lineCollisions) { | ||
@@ -110,3 +114,3 @@ lineCollisions = new _immy2.default.List([index]); | ||
} | ||
this.collisions = this.collisions.withKeySetToValue(line.id, lineCollisions); | ||
this.collisions = _mori2.default.assoc(this.collisions, line.id, lineCollisions); | ||
} | ||
@@ -113,0 +117,0 @@ } |
{ | ||
"name": "lr-core", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Line Rider core library", | ||
@@ -35,5 +35,6 @@ "main": "index.js", | ||
"immy": "^0.4.0", | ||
"lodash": "^4.13.1" | ||
"lodash": "^4.13.1", | ||
"mori": "^0.3.2" | ||
}, | ||
"optionalDependencies": {} | ||
} |
@@ -0,1 +1,2 @@ | ||
import mori from 'mori' | ||
import Immy from 'immy' | ||
@@ -31,3 +32,3 @@ | ||
export default class Frame { | ||
constructor (stateMap = new Map(), grid = new Immy.Map(), collisions = new Immy.Map(), updates = []) { | ||
constructor (stateMap = new Map(), grid = mori.hashMap(), collisions = mori.hashMap(), updates = []) { | ||
this.stateMap = stateMap | ||
@@ -44,4 +45,4 @@ this.grid = grid | ||
getIndexOfCollisionInCell (cell, line) { | ||
if (!this.grid.has(cell)) return | ||
let cellFrames = this.grid.get(cell) | ||
let cellFrames = mori.get(this.grid, cell) | ||
if (!cellFrames) return | ||
for (let i = 0; i < cellFrames.size(); i++) { | ||
@@ -56,3 +57,3 @@ let cellFrame = cellFrames.get(i) | ||
getIndexOfCollisionWithLine (line) { | ||
let lineCollisions = this.collisions.get(line.id) | ||
let lineCollisions = mori.get(this.collisions, line.id) | ||
if (lineCollisions) { | ||
@@ -77,3 +78,3 @@ return lineCollisions.get(0) | ||
for (let cell of cells) { | ||
let cellFrames = this.grid.get(cell) | ||
let cellFrames = mori.get(this.grid, cell) | ||
if (!cellFrames) { | ||
@@ -84,3 +85,3 @@ cellFrames = makeCellFrames(index, entity) | ||
} | ||
this.grid = this.grid.withKeySetToValue(cell, cellFrames) | ||
this.grid = mori.assoc(this.grid, cell, cellFrames) | ||
} | ||
@@ -90,3 +91,3 @@ } | ||
addToCollisions (line, index) { | ||
let lineCollisions = this.collisions.get(line.id) | ||
let lineCollisions = mori.get(this.collisions, line.id) | ||
if (!lineCollisions) { | ||
@@ -99,4 +100,4 @@ lineCollisions = new Immy.List([index]) | ||
} | ||
this.collisions = this.collisions.withKeySetToValue(line.id, lineCollisions) | ||
this.collisions = mori.assoc(this.collisions, line.id, lineCollisions) | ||
} | ||
} |
@@ -143,2 +143,18 @@ import test from 'tape' | ||
t.test('does not cause stack overflow for recomputation', t => { | ||
const line = createLineFromJson({id: 2, type: 0, x1: -113.5, x2: 39.5, y1: 12.75, y2: 8.25}) | ||
const INDEX = 120 | ||
let engine = new LineRiderEngine() | ||
void engine.getRider(INDEX) | ||
try { | ||
void engine.addLine(line) | ||
} catch (e) { | ||
t.fail(e) | ||
} | ||
t.end() | ||
}) | ||
t.end() | ||
@@ -145,0 +161,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159321
5215
3
+ Addedmori@^0.3.2
+ Addedmori@0.3.2(transitive)