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 { fabric } from "fabric";
|
||||||
|
|
||||||
|
import Layer from "../board/layer";
|
||||||
import TileSet from "./tileset";
|
import TileSet from "./tileset";
|
||||||
|
|
||||||
const image = new fabric.Image();
|
export default class TileMap extends Layer {
|
||||||
|
|
||||||
export default class TileMap {
|
|
||||||
/**
|
/**
|
||||||
* @param {TileSet} tileset
|
* @param {TileSet} tileset
|
||||||
* @param {{chunkSiz:number}} opts
|
* @param {{chunkSiz:number}} opts
|
||||||
*/
|
*/
|
||||||
constructor(tileset, opts = {}) {
|
constructor(tileset, opts = {}) {
|
||||||
|
super();
|
||||||
|
|
||||||
this.tileset = tileset;
|
this.tileset = tileset;
|
||||||
|
|
||||||
this.opts = {
|
this.opts = {
|
||||||
@@ -16,28 +18,6 @@ export default class TileMap {
|
|||||||
...opts,
|
...opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.chunks = [];
|
this.rows = [];
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,8 +5,22 @@ export default class TileSet {
|
|||||||
this.opts = {
|
this.opts = {
|
||||||
tileSize: [32, 32],
|
tileSize: [32, 32],
|
||||||
tileSep: [0, 0],
|
tileSep: [0, 0],
|
||||||
|
hTiles: 2,
|
||||||
|
vTiles: 2,
|
||||||
src: "/res/tilesets/default.png",
|
src: "/res/tilesets/default.png",
|
||||||
|
metaTiles: [],
|
||||||
...opts,
|
...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