boilerplate-sim
Advanced tools
Comparing version 1.0.3 to 1.1.0
{ | ||
"name": "boilerplate-sim", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "", | ||
"main": "simulator.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"test": "mocha --compilers coffee:coffee-script/register --reporter spec test.coffee", | ||
"prepublish": "coffee -cm simulator.coffee" | ||
@@ -29,4 +29,5 @@ }, | ||
"devDependencies": { | ||
"coffee-script": "^1.7.1" | ||
"coffee-script": "^1.7.1", | ||
"mocha": "^1.21.3" | ||
} | ||
} |
177
simulator.js
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Simulator, cardinal_dirs, fill, parseXY, sign; | ||
var Simulator, cardinal_dirs, fill, parseXY, sign, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -54,22 +55,6 @@ cardinal_dirs = [[0, 1], [0, -1], [1, 0], [-1, 0]]; | ||
Simulator = (function() { | ||
var colors, darkColors; | ||
function Simulator(grid) { | ||
var k, v, x, y, _ref, _ref1; | ||
this.grid = grid; | ||
this.grid || (this.grid = {}); | ||
this.engines = {}; | ||
_ref = this.grid; | ||
for (k in _ref) { | ||
v = _ref[k]; | ||
if (v === 'positive' || v === 'negative') { | ||
_ref1 = parseXY(k), x = _ref1.x, y = _ref1.y; | ||
this.engines[k] = { | ||
x: x, | ||
y: y | ||
}; | ||
} | ||
} | ||
this.delta = { | ||
changed: {}, | ||
sound: {} | ||
}; | ||
this.setGrid(grid); | ||
} | ||
@@ -107,4 +92,27 @@ | ||
Simulator.prototype.setGrid = function(grid) { | ||
var k, v, x, y, _ref, _ref1; | ||
this.grid = grid || {}; | ||
delete this.grid.tw; | ||
delete this.grid.th; | ||
this.engines = {}; | ||
_ref = this.grid; | ||
for (k in _ref) { | ||
v = _ref[k]; | ||
if (v === 'positive' || v === 'negative') { | ||
_ref1 = parseXY(k), x = _ref1.x, y = _ref1.y; | ||
this.engines[k] = { | ||
x: x, | ||
y: y | ||
}; | ||
} | ||
} | ||
return this.delta = { | ||
changed: {}, | ||
sound: {} | ||
}; | ||
}; | ||
Simulator.prototype.tryMove = function(points, dx, dy) { | ||
var isMe, shuttle, x, y, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; | ||
var isMe, shuttle, x, y, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3; | ||
dx = dx < 0 ? -1 : dx > 0 ? 1 : 0; | ||
@@ -128,4 +136,12 @@ dy = dy < 0 ? -1 : dy > 0 ? 1 : 0; | ||
}; | ||
for (_i = 0, _len = points.length; _i < _len; _i++) { | ||
_ref = points[_i], x = _ref.x, y = _ref.y; | ||
if (this.held) { | ||
for (_i = 0, _len = points.length; _i < _len; _i++) { | ||
_ref = points[_i], x = _ref.x, y = _ref.y; | ||
if (this.held.x === x && this.held.y === y) { | ||
return false; | ||
} | ||
} | ||
} | ||
for (_j = 0, _len1 = points.length; _j < _len1; _j++) { | ||
_ref1 = points[_j], x = _ref1.x, y = _ref1.y; | ||
if (!isMe(x + dx, y + dy)) { | ||
@@ -138,9 +154,9 @@ if (this.get(x + dx, y + dy) !== 'nothing') { | ||
shuttle = {}; | ||
for (_j = 0, _len1 = points.length; _j < _len1; _j++) { | ||
_ref1 = points[_j], x = _ref1.x, y = _ref1.y; | ||
for (_k = 0, _len2 = points.length; _k < _len2; _k++) { | ||
_ref2 = points[_k], x = _ref2.x, y = _ref2.y; | ||
shuttle["" + x + "," + y] = this.get(x, y); | ||
this.set(x, y, 'nothing'); | ||
} | ||
for (_k = 0, _len2 = points.length; _k < _len2; _k++) { | ||
_ref2 = points[_k], x = _ref2.x, y = _ref2.y; | ||
for (_l = 0, _len3 = points.length; _l < _len3; _l++) { | ||
_ref3 = points[_l], x = _ref3.x, y = _ref3.y; | ||
this.set(x + dx, y + dy, shuttle["" + x + "," + y]); | ||
@@ -165,3 +181,3 @@ } | ||
} | ||
if (cell === 'nothing' || cell === 'thinshuttle' || cell === 'thinsolid') { | ||
if (cell === 'nothing' || cell === 'thinshuttle' || cell === 'thinsolid' || cell === 'buttondown') { | ||
pressure["" + x + "," + y] = ((_ref1 = pressure["" + x + "," + y]) != null ? _ref1 : 0) + direction; | ||
@@ -178,3 +194,3 @@ for (_i = 0, _len = cardinal_dirs.length; _i < _len; _i++) { | ||
} | ||
if (c === 'nothing' || c === 'thinshuttle' || c === 'thinsolid') { | ||
if (c === 'nothing' || c === 'thinshuttle' || c === 'thinsolid' || c === 'buttondown') { | ||
hmm(_x, _y); | ||
@@ -248,2 +264,3 @@ } | ||
case 'thinsolid': | ||
case 'buttondown': | ||
for (_i = 0, _len = cardinal_dirs.length; _i < _len; _i++) { | ||
@@ -266,3 +283,3 @@ _ref1 = cardinal_dirs[_i], dx = _ref1[0], dy = _ref1[1]; | ||
s.force.y += dy * direction; | ||
} else if (c === 'nothing' || c === 'thinshuttle' || c === 'thinsolid') { | ||
} else if (c === 'nothing' || c === 'thinshuttle' || c === 'thinsolid' || c === 'buttondown') { | ||
hmm(_x, _y); | ||
@@ -306,2 +323,102 @@ } | ||
Simulator.prototype.holdShuttle = function(_arg) { | ||
var x, y; | ||
x = _arg.x, y = _arg.y; | ||
return this.held = { | ||
x: x, | ||
y: y | ||
}; | ||
}; | ||
Simulator.prototype.releaseShuttle = function() { | ||
return this.held = null; | ||
}; | ||
Simulator.prototype.boundingBox = function() { | ||
var bottom, k, left, right, top, v, x, y, _ref, _ref1; | ||
top = left = bottom = right = null; | ||
_ref = this.grid; | ||
for (k in _ref) { | ||
v = _ref[k]; | ||
_ref1 = parseXY(k), x = _ref1.x, y = _ref1.y; | ||
if (left === null || x < left) { | ||
left = x; | ||
} | ||
if (right === null || x >= right) { | ||
right = x + 1; | ||
} | ||
if (top === null || y < top) { | ||
top = y; | ||
} | ||
if (bottom === null || y >= bottom) { | ||
bottom = y + 1; | ||
} | ||
} | ||
return { | ||
top: top, | ||
left: left, | ||
bottom: bottom, | ||
right: right | ||
}; | ||
}; | ||
colors = { | ||
bridge: '#2E96D6', | ||
negative: '#D65729', | ||
nothing: '#FFFFFF', | ||
positive: '#5CCC5C', | ||
shuttle: '#9328BD', | ||
solid: '#09191B', | ||
thinshuttle: '#D887F8', | ||
thinsolid: '#B5B5B5', | ||
buttondown: '#FFA93D', | ||
buttonup: '#CC7B00' | ||
}; | ||
darkColors = { | ||
bridge: '#487693', | ||
negative: '#814B37', | ||
nothing: '#7D7D7D', | ||
positive: '#4D8F4D', | ||
shuttle: '#604068', | ||
solid: '#706F76', | ||
thinshuttle: '#8E56A4', | ||
thinsolid: '#7D7D7D', | ||
buttondown: 'rgb(255,169,61)', | ||
buttonup: 'rgb(171,99,18)' | ||
}; | ||
Simulator.prototype.drawCanvas = function(ctx, size, worldToScreen) { | ||
var downCells, k, p, pressure, px, py, tx, ty, v, v2, _ref, _ref1, _ref2, _results; | ||
worldToScreen || (worldToScreen = function(tx, ty) { | ||
return { | ||
px: tx * size, | ||
py: ty * size | ||
}; | ||
}); | ||
pressure = this.getPressure(); | ||
_ref = this.grid; | ||
_results = []; | ||
for (k in _ref) { | ||
v = _ref[k]; | ||
_ref1 = parseXY(k), tx = _ref1.x, ty = _ref1.y; | ||
_ref2 = worldToScreen(tx, ty), px = _ref2.px, py = _ref2.py; | ||
ctx.fillStyle = colors[v]; | ||
ctx.fillRect(px, py, size, size); | ||
downCells = ['nothing', 'buttondown']; | ||
v2 = this.get(tx, ty - 1); | ||
if (__indexOf.call(downCells, v) >= 0 && v !== v2) { | ||
ctx.fillStyle = darkColors[v2 != null ? v2 : 'solid']; | ||
ctx.fillRect(px, py, size, size * 0.3); | ||
} | ||
if ((p = pressure[k]) && p !== 0) { | ||
ctx.fillStyle = p < 0 ? 'rgba(255,0,0,0.2)' : 'rgba(0,255,0,0.15)'; | ||
_results.push(ctx.fillRect(px, py, size, size)); | ||
} else { | ||
_results.push(void 0); | ||
} | ||
} | ||
return _results; | ||
}; | ||
return Simulator; | ||
@@ -308,0 +425,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
230760
17
1200
0
2
1