2020-02-14 00:12:24 +01:00
|
|
|
import GraphicSet from "../../js/GraphicSet.js";
|
|
|
|
import Setting from "../../js/Setting.js";
|
|
|
|
|
2020-01-29 00:21:53 +01:00
|
|
|
export default class Tileset
|
|
|
|
{
|
2020-02-14 00:12:24 +01:00
|
|
|
constructor(setId)
|
2020-01-29 00:21:53 +01:00
|
|
|
{
|
2020-02-14 00:12:24 +01:00
|
|
|
this.setId = setId;
|
|
|
|
this.image = new Image();
|
2021-09-14 20:11:01 +02:00
|
|
|
this.image.src = '../' + Setting.TILESET_LOCATION + GraphicSet[this.setId].tileset;
|
2020-02-14 00:12:24 +01:00
|
|
|
this.tiles = GraphicSet[this.setId].tiles;
|
|
|
|
this.scale = GraphicSet[this.setId].scale;
|
2023-09-24 01:48:01 +02:00
|
|
|
this.primaryTiles = GraphicSet[this.setId].primaryTiles;
|
2020-01-29 00:21:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-09-24 01:48:01 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-09-14 20:11:01 +02:00
|
|
|
}
|