mr-crocs-adventures/tilorswift/js/Tileset.js

48 lines
1.1 KiB
JavaScript

import GraphicSet from "../../js/GraphicSet.js";
import Setting from "../../js/Setting.js";
export default class Tileset
{
constructor(setId)
{
this.setId = setId;
this.image = new Image();
this.image.src = '../' + Setting.TILESET_LOCATION + GraphicSet[this.setId].tileset;
this.tiles = GraphicSet[this.setId].tiles;
this.scale = GraphicSet[this.setId].scale;
this.primaryTiles = GraphicSet[this.setId].primaryTiles;
}
getWidth()
{
return this.image.width * this.scale;
}
getHeight()
{
return this.image.height * this.scale;
}
getTileWidth()
{
return this.image.width / this.tiles * this.scale;
}
getTileHeight()
{
return this.image.height * this.scale;
}
hasExtendedTiles()
{
return GraphicSet[this.setId].tiles > GraphicSet[this.setId].primaryTiles ;
}
getTileIndexFactor(code)
{
const CODES = ['ltr', 't', 'r', 'b', 'l', 'lt', 'tr', 'ltb', 'tb', 'trb', 'lb', 'rb', 'ltrb', 'lr', 'lrb'];
return CODES.indexOf(code) + 1;
}
}