tileset: Some progress.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
+6
-26
@@ -1,14 +1,16 @@
|
||||
import { fabric } from "fabric";
|
||||
|
||||
import Layer from "../board/layer";
|
||||
import TileSet from "./tileset";
|
||||
|
||||
const image = new fabric.Image();
|
||||
|
||||
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 = [];
|
||||
}
|
||||
}
|
||||
@@ -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) => {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user