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() { |
export default function Grid() { |
||||||
this.points = {}; |
this.points = {}; |
||||||
this.gridSize = 5; |
this.gridSize = 5; |
||||||
}; |
}; |
||||||
|
|
||||||
Grid.prototype.setPoint = function({ x, y, type }, detail) { |
Grid.prototype.getKey = function({ x, y, type }) { |
||||||
this.points[getKey({ x, y, type })] = detail; |
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 }) { |
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 }) { |
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 }) {
|
Grid.prototype.setArea = function({ x, y, w, h, type }, container) { |
||||||
// for (let i = x; i <= (x + w); i += this.gridSize) {
|
for (let i = x; i <= (x + w); i += this.gridSize) { |
||||||
// for (let j = y; j <= (y + h); j += this.gridSize) {
|
for (let j = y; j <= (y + h); j += this.gridSize) { |
||||||
// this.setPoint({ x: i, y: j, type });
|
this.setPoint({ x: i, y: j, type }, true); |
||||||
// }
|
} |
||||||
// }
|
} |
||||||
// };
|
|
||||||
|
const div = document.createElement('div'); |
||||||
// const Store = function(initialProps) {
|
div.className = 'hazard'; |
||||||
// this.state = Object.freeze(initialProps);
|
div.style.left = `${x}px`; |
||||||
// }
|
div.style.top = `${y}px`; |
||||||
//
|
div.style.height = `${h}px`; |
||||||
// Store.prototype.set = function(props) {
|
div.style.width = `${w}px`; |
||||||
// this.state = Object.freeze(Object.assign({}, this.state, props));
|
container.appendChild(div); |
||||||
// return this.state;
|
|
||||||
// };
|
for (let i = x; i <= (x + w); i += this.gridSize) { |
||||||
//
|
for (let j = y; j <= (y + h); j += this.gridSize) { |
||||||
// Store.prototype.get = function() {
|
const dot = document.createElement('dot'); |
||||||
// return this.state;
|
dot.className = 'hazard-dot'; |
||||||
// }
|
dot.style.left = `${i - x}px`; |
||||||
//
|
dot.style.top = `${j - y}px`; |
||||||
// export default Store;
|
div.appendChild(dot); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
Loading…
Reference in new issue