diff --git a/dev-server/res/tilesets/simple.png b/dev-server/res/tilesets/simple.png new file mode 100644 index 0000000..a677781 Binary files /dev/null and b/dev-server/res/tilesets/simple.png differ diff --git a/src/tiles/tilemap.js b/src/tiles/tilemap.js index 8a4e450..fd332e5 100644 --- a/src/tiles/tilemap.js +++ b/src/tiles/tilemap.js @@ -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 = []; } } \ No newline at end of file diff --git a/src/tiles/tileset.js b/src/tiles/tileset.js index a1279c3..5c445c9 100644 --- a/src/tiles/tileset.js +++ b/src/tiles/tileset.js @@ -5,8 +5,22 @@ export default class TileSet { this.opts = { tileSize: [32, 32], tileSep: [0, 0], + hTiles: 2, + vTiles: 2, src: "/res/tilesets/default.png", + metaTiles: [], ...opts, } } + + getTile(index) { + const max = this.opts.hTiles * this.opts.vTiles; + if (index > max) { + return Promise.reject(new Error("index out of bounds.")); + } + + return new Promise((resolve, reject) => { + + }); + } } \ No newline at end of file