Browse Source

tileset: Some progress.

master
Gisle Aune 3 years ago
parent
commit
3923179d02
  1. BIN
      dev-server/res/tilesets/simple.png
  2. 32
      src/tiles/tilemap.js
  3. 14
      src/tiles/tileset.js

BIN
dev-server/res/tilesets/simple.png

After

Width: 64  |  Height: 64  |  Size: 6.0 KiB

32
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 = [];
}
}

14
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) => {
});
}
}
Loading…
Cancel
Save