|
|
@ -1,14 +1,16 @@ |
|
|
|
import { fabric } from "fabric"; |
|
|
|
import TileSet from "./tileset"; |
|
|
|
|
|
|
|
const image = new fabric.Image(); |
|
|
|
import Layer from "../board/layer"; |
|
|
|
import TileSet from "./tileset"; |
|
|
|
|
|
|
|
export default class TileMap { |
|
|
|
export default class TileMap extends Layer { |
|
|
|
/** |
|
|
|
* @param {TileSet} tileset |
|
|
|
* @param {{chunkSiz:number}} opts |
|
|
|
*/ |
|
|
|
constructor(tileset, opts = {}) { |
|
|
|
super(); |
|
|
|
|
|
|
|
this.tileset = tileset; |
|
|
|
|
|
|
|
this.opts = { |
|
|
@ -16,28 +18,6 @@ export default class TileMap { |
|
|
|
...opts, |
|
|
|
} |
|
|
|
|
|
|
|
this.chunks = []; |
|
|
|
} |
|
|
|
|
|
|
|
getChunk(x, y) { |
|
|
|
const cs = this.opts.chunkSize; |
|
|
|
const cx = x > 0 ? Math.floor(x / cs) : Math.ceil(x / cs); |
|
|
|
const cy = y > 0 ? Math.floor(y / cs) : Math.ceil(y / cs); |
|
|
|
|
|
|
|
let chunk = this.chunks.find(c => c.x === cx && c.y === cy); |
|
|
|
if (chunk == null) { |
|
|
|
chunk = new Chunk(x, y, cs); |
|
|
|
this.chunks.push(chunk); |
|
|
|
} |
|
|
|
|
|
|
|
return chunk; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class Chunk { |
|
|
|
constructor(x, y, size) { |
|
|
|
this.x = x; |
|
|
|
this.y = y; |
|
|
|
this.size = size; |
|
|
|
this.rows = []; |
|
|
|
} |
|
|
|
} |