|
|
@ -24,6 +24,14 @@ export class StaticMapEntityComponent extends Component {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the effective tile size
|
|
|
|
|
|
|
|
* @returns {Vector}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
getTileSize() {
|
|
|
|
|
|
|
|
return getBuildingDataFromCode(this.code).tileSize;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Returns the sprite
|
|
|
|
* Returns the sprite
|
|
|
|
* @returns {AtlasSprite}
|
|
|
|
* @returns {AtlasSprite}
|
|
|
@ -51,7 +59,6 @@ export class StaticMapEntityComponent extends Component {
|
|
|
|
duplicateWithoutContents() {
|
|
|
|
duplicateWithoutContents() {
|
|
|
|
return new StaticMapEntityComponent({
|
|
|
|
return new StaticMapEntityComponent({
|
|
|
|
origin: this.origin.copy(),
|
|
|
|
origin: this.origin.copy(),
|
|
|
|
tileSize: this.tileSize.copy(),
|
|
|
|
|
|
|
|
rotation: this.rotation,
|
|
|
|
rotation: this.rotation,
|
|
|
|
originalRotation: this.originalRotation,
|
|
|
|
originalRotation: this.originalRotation,
|
|
|
|
code: this.code,
|
|
|
|
code: this.code,
|
|
|
@ -81,7 +88,6 @@ export class StaticMapEntityComponent extends Component {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
this.origin = origin;
|
|
|
|
this.origin = origin;
|
|
|
|
this.tileSize = tileSize;
|
|
|
|
|
|
|
|
this.rotation = rotation;
|
|
|
|
this.rotation = rotation;
|
|
|
|
this.code = code;
|
|
|
|
this.code = code;
|
|
|
|
this.originalRotation = originalRotation;
|
|
|
|
this.originalRotation = originalRotation;
|
|
|
@ -92,30 +98,16 @@ export class StaticMapEntityComponent extends Component {
|
|
|
|
* @returns {Rectangle}
|
|
|
|
* @returns {Rectangle}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
getTileSpaceBounds() {
|
|
|
|
getTileSpaceBounds() {
|
|
|
|
|
|
|
|
const size = this.getTileSize();
|
|
|
|
switch (this.rotation) {
|
|
|
|
switch (this.rotation) {
|
|
|
|
case 0:
|
|
|
|
case 0:
|
|
|
|
return new Rectangle(this.origin.x, this.origin.y, this.tileSize.x, this.tileSize.y);
|
|
|
|
return new Rectangle(this.origin.x, this.origin.y, size.x, size.y);
|
|
|
|
case 90:
|
|
|
|
case 90:
|
|
|
|
return new Rectangle(
|
|
|
|
return new Rectangle(this.origin.x - size.y + 1, this.origin.y, size.y, size.x);
|
|
|
|
this.origin.x - this.tileSize.y + 1,
|
|
|
|
|
|
|
|
this.origin.y,
|
|
|
|
|
|
|
|
this.tileSize.y,
|
|
|
|
|
|
|
|
this.tileSize.x
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
case 180:
|
|
|
|
case 180:
|
|
|
|
return new Rectangle(
|
|
|
|
return new Rectangle(this.origin.x - size.x + 1, this.origin.y - size.y + 1, size.x, size.y);
|
|
|
|
this.origin.x - this.tileSize.x + 1,
|
|
|
|
|
|
|
|
this.origin.y - this.tileSize.y + 1,
|
|
|
|
|
|
|
|
this.tileSize.x,
|
|
|
|
|
|
|
|
this.tileSize.y
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
case 270:
|
|
|
|
case 270:
|
|
|
|
return new Rectangle(
|
|
|
|
return new Rectangle(this.origin.x, this.origin.y - size.x + 1, size.y, size.x);
|
|
|
|
this.origin.x,
|
|
|
|
|
|
|
|
this.origin.y - this.tileSize.x + 1,
|
|
|
|
|
|
|
|
this.tileSize.y,
|
|
|
|
|
|
|
|
this.tileSize.x
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
assert(false, "Invalid rotation");
|
|
|
|
assert(false, "Invalid rotation");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -186,34 +178,35 @@ export class StaticMapEntityComponent extends Component {
|
|
|
|
let y = 0;
|
|
|
|
let y = 0;
|
|
|
|
let w = 0;
|
|
|
|
let w = 0;
|
|
|
|
let h = 0;
|
|
|
|
let h = 0;
|
|
|
|
|
|
|
|
const size = this.getTileSize();
|
|
|
|
|
|
|
|
|
|
|
|
switch (this.rotation) {
|
|
|
|
switch (this.rotation) {
|
|
|
|
case 0: {
|
|
|
|
case 0: {
|
|
|
|
x = this.origin.x;
|
|
|
|
x = this.origin.x;
|
|
|
|
y = this.origin.y;
|
|
|
|
y = this.origin.y;
|
|
|
|
w = this.tileSize.x;
|
|
|
|
w = size.x;
|
|
|
|
h = this.tileSize.y;
|
|
|
|
h = size.y;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 90: {
|
|
|
|
case 90: {
|
|
|
|
x = this.origin.x - this.tileSize.y + 1;
|
|
|
|
x = this.origin.x - size.y + 1;
|
|
|
|
y = this.origin.y;
|
|
|
|
y = this.origin.y;
|
|
|
|
w = this.tileSize.y;
|
|
|
|
w = size.y;
|
|
|
|
h = this.tileSize.x;
|
|
|
|
h = size.x;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 180: {
|
|
|
|
case 180: {
|
|
|
|
x = this.origin.x - this.tileSize.x + 1;
|
|
|
|
x = this.origin.x - size.x + 1;
|
|
|
|
y = this.origin.y - this.tileSize.y + 1;
|
|
|
|
y = this.origin.y - size.y + 1;
|
|
|
|
w = this.tileSize.x;
|
|
|
|
w = size.x;
|
|
|
|
h = this.tileSize.y;
|
|
|
|
h = size.y;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 270: {
|
|
|
|
case 270: {
|
|
|
|
x = this.origin.x;
|
|
|
|
x = this.origin.x;
|
|
|
|
y = this.origin.y - this.tileSize.x + 1;
|
|
|
|
y = this.origin.y - size.x + 1;
|
|
|
|
w = this.tileSize.y;
|
|
|
|
w = size.y;
|
|
|
|
h = this.tileSize.x;
|
|
|
|
h = size.x;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -233,19 +226,13 @@ export class StaticMapEntityComponent extends Component {
|
|
|
|
* @param {DrawParameters} parameters
|
|
|
|
* @param {DrawParameters} parameters
|
|
|
|
* @param {AtlasSprite} sprite
|
|
|
|
* @param {AtlasSprite} sprite
|
|
|
|
* @param {number=} extrudePixels How many pixels to extrude the sprite
|
|
|
|
* @param {number=} extrudePixels How many pixels to extrude the sprite
|
|
|
|
* @param {boolean=} clipping Whether to clip
|
|
|
|
|
|
|
|
* @param {Vector=} overridePosition Whether to drwa the entity at a different location
|
|
|
|
* @param {Vector=} overridePosition Whether to drwa the entity at a different location
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
drawSpriteOnFullEntityBounds(
|
|
|
|
drawSpriteOnFullEntityBounds(parameters, sprite, extrudePixels = 0, overridePosition = null) {
|
|
|
|
parameters,
|
|
|
|
|
|
|
|
sprite,
|
|
|
|
|
|
|
|
extrudePixels = 0,
|
|
|
|
|
|
|
|
clipping = true,
|
|
|
|
|
|
|
|
overridePosition = null
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (!this.shouldBeDrawn(parameters) && !overridePosition) {
|
|
|
|
if (!this.shouldBeDrawn(parameters) && !overridePosition) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const size = this.getTileSize();
|
|
|
|
let worldX = this.origin.x * globalConfig.tileSize;
|
|
|
|
let worldX = this.origin.x * globalConfig.tileSize;
|
|
|
|
let worldY = this.origin.y * globalConfig.tileSize;
|
|
|
|
let worldY = this.origin.y * globalConfig.tileSize;
|
|
|
|
|
|
|
|
|
|
|
@ -258,10 +245,10 @@ export class StaticMapEntityComponent extends Component {
|
|
|
|
// Early out, is faster
|
|
|
|
// Early out, is faster
|
|
|
|
sprite.drawCached(
|
|
|
|
sprite.drawCached(
|
|
|
|
parameters,
|
|
|
|
parameters,
|
|
|
|
worldX - extrudePixels * this.tileSize.x,
|
|
|
|
worldX - extrudePixels * size.x,
|
|
|
|
worldY - extrudePixels * this.tileSize.y,
|
|
|
|
worldY - extrudePixels * size.y,
|
|
|
|
globalConfig.tileSize * this.tileSize.x + 2 * extrudePixels * this.tileSize.x,
|
|
|
|
globalConfig.tileSize * size.x + 2 * extrudePixels * size.x,
|
|
|
|
globalConfig.tileSize * this.tileSize.y + 2 * extrudePixels * this.tileSize.y,
|
|
|
|
globalConfig.tileSize * size.y + 2 * extrudePixels * size.y,
|
|
|
|
false
|
|
|
|
false
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -273,10 +260,10 @@ export class StaticMapEntityComponent extends Component {
|
|
|
|
|
|
|
|
|
|
|
|
sprite.drawCached(
|
|
|
|
sprite.drawCached(
|
|
|
|
parameters,
|
|
|
|
parameters,
|
|
|
|
-globalConfig.halfTileSize - extrudePixels * this.tileSize.x,
|
|
|
|
-globalConfig.halfTileSize - extrudePixels * size.x,
|
|
|
|
-globalConfig.halfTileSize - extrudePixels * this.tileSize.y,
|
|
|
|
-globalConfig.halfTileSize - extrudePixels * size.y,
|
|
|
|
globalConfig.tileSize * this.tileSize.x + 2 * extrudePixels * this.tileSize.x,
|
|
|
|
globalConfig.tileSize * size.x + 2 * extrudePixels * size.x,
|
|
|
|
globalConfig.tileSize * this.tileSize.y + 2 * extrudePixels * this.tileSize.y,
|
|
|
|
globalConfig.tileSize * size.y + 2 * extrudePixels * size.y,
|
|
|
|
false
|
|
|
|
false
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|