parent
779afc5aa6
commit
529db9b626
12 changed files with 218 additions and 269 deletions
File diff suppressed because one or more lines are too long
@ -1,46 +1,49 @@ |
||||
function getKey({ x, y, type }) { |
||||
const gridX = x - x % 5; |
||||
const gridY = y - y % 5; |
||||
|
||||
return `${gridX}-${gridY}`; |
||||
} |
||||
|
||||
export default function Grid() { |
||||
this.points = {}; |
||||
this.gridSize = 5; |
||||
}; |
||||
|
||||
Grid.prototype.setPoint = function({ x, y, type }, detail) { |
||||
this.points[getKey({ x, y, type })] = detail; |
||||
Grid.prototype.getKey = function({ x, y, type }) { |
||||
const gridX = x - x % this.gridSize; |
||||
const gridY = y - y % this.gridSize; |
||||
|
||||
return `${gridX}-${gridY}-${type}`; |
||||
} |
||||
|
||||
Grid.prototype.setPoint = function({ x, y, type }, value) { |
||||
this.points[this.getKey({ x, y, type })] = value; |
||||
}; |
||||
|
||||
Grid.prototype.getPoint = function({ x, y, type }) { |
||||
return this.points[getKey({ x, y, type })]; |
||||
return this.points[this.getKey({ x, y, type })]; |
||||
} |
||||
|
||||
Grid.prototype.deletePoint = function({ x, y, type }) { |
||||
delete this.points[getKey({ x, y, type })]; |
||||
delete this.points[this.getKey({ x, y, type })]; |
||||
}; |
||||
|
||||
// Grid.prototype.setArea = function({ x, y, w, h, type }) {
|
||||
// for (let i = x; i <= (x + w); i += this.gridSize) {
|
||||
// for (let j = y; j <= (y + h); j += this.gridSize) {
|
||||
// this.setPoint({ x: i, y: j, type });
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// const Store = function(initialProps) {
|
||||
// this.state = Object.freeze(initialProps);
|
||||
// }
|
||||
//
|
||||
// Store.prototype.set = function(props) {
|
||||
// this.state = Object.freeze(Object.assign({}, this.state, props));
|
||||
// return this.state;
|
||||
// };
|
||||
//
|
||||
// Store.prototype.get = function() {
|
||||
// return this.state;
|
||||
// }
|
||||
//
|
||||
// export default Store;
|
||||
Grid.prototype.setArea = function({ x, y, w, h, type }, container) { |
||||
for (let i = x; i <= (x + w); i += this.gridSize) { |
||||
for (let j = y; j <= (y + h); j += this.gridSize) { |
||||
this.setPoint({ x: i, y: j, type }, true); |
||||
} |
||||
} |
||||
|
||||
const div = document.createElement('div'); |
||||
div.className = 'hazard'; |
||||
div.style.left = `${x}px`; |
||||
div.style.top = `${y}px`; |
||||
div.style.height = `${h}px`; |
||||
div.style.width = `${w}px`; |
||||
container.appendChild(div); |
||||
|
||||
for (let i = x; i <= (x + w); i += this.gridSize) { |
||||
for (let j = y; j <= (y + h); j += this.gridSize) { |
||||
const dot = document.createElement('dot'); |
||||
dot.className = 'hazard-dot'; |
||||
dot.style.left = `${i - x}px`; |
||||
dot.style.top = `${j - y}px`; |
||||
div.appendChild(dot); |
||||
} |
||||
} |
||||
}; |
||||
|
Loading…
Reference in new issue