mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Add originalRotation to static comp in order to fix bugs with the automatic placement
This commit is contained in:
@@ -13,12 +13,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
}
|
||||
|
||||
static getSchema() {
|
||||
return {
|
||||
origin: types.tileVector,
|
||||
tileSize: types.tileVector,
|
||||
rotationDegrees: types.uint,
|
||||
spriteKey: types.string,
|
||||
};
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,27 +21,30 @@ export class StaticMapEntityComponent extends Component {
|
||||
* @param {object} param0
|
||||
* @param {Vector=} param0.origin Origin (Top Left corner) of the entity
|
||||
* @param {Vector=} param0.tileSize Size of the entity in tiles
|
||||
* @param {number=} param0.rotationDegrees Rotation in degrees. Must be multiple of 90
|
||||
* @param {number=} param0.rotation Rotation in degrees. Must be multiple of 90
|
||||
* @param {number=} param0.originalRotation Original Rotation in degrees. Must be multiple of 90
|
||||
* @param {string=} param0.spriteKey Optional sprite
|
||||
* @param {string=} param0.silhouetteColor Optional silhouette color override
|
||||
*/
|
||||
constructor({
|
||||
origin = new Vector(),
|
||||
tileSize = new Vector(1, 1),
|
||||
rotationDegrees = 0,
|
||||
rotation = 0,
|
||||
originalRotation = 0,
|
||||
spriteKey = null,
|
||||
silhouetteColor = null,
|
||||
}) {
|
||||
super();
|
||||
assert(
|
||||
rotationDegrees % 90 === 0,
|
||||
"Rotation of static map entity must be multiple of 90 (was " + rotationDegrees + ")"
|
||||
rotation % 90 === 0,
|
||||
"Rotation of static map entity must be multiple of 90 (was " + rotation + ")"
|
||||
);
|
||||
|
||||
this.origin = origin;
|
||||
this.tileSize = tileSize;
|
||||
this.spriteKey = spriteKey;
|
||||
this.rotationDegrees = rotationDegrees;
|
||||
this.rotation = rotation;
|
||||
this.originalRotation = originalRotation;
|
||||
this.silhouetteColor = silhouetteColor;
|
||||
}
|
||||
|
||||
@@ -55,7 +53,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
* @returns {Rectangle}
|
||||
*/
|
||||
getTileSpaceBounds() {
|
||||
switch (this.rotationDegrees) {
|
||||
switch (this.rotation) {
|
||||
case 0:
|
||||
return new Rectangle(this.origin.x, this.origin.y, this.tileSize.x, this.tileSize.y);
|
||||
case 90:
|
||||
@@ -90,7 +88,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
* @returns {Vector}
|
||||
*/
|
||||
applyRotationToVector(vector) {
|
||||
return vector.rotateFastMultipleOf90(this.rotationDegrees);
|
||||
return vector.rotateFastMultipleOf90(this.rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +97,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
* @returns {Vector}
|
||||
*/
|
||||
unapplyRotationToVector(vector) {
|
||||
return vector.rotateFastMultipleOf90(360 - this.rotationDegrees);
|
||||
return vector.rotateFastMultipleOf90(360 - this.rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +106,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
* @returns {enumDirection}
|
||||
*/
|
||||
localDirectionToWorld(direction) {
|
||||
return Vector.transformDirectionFromMultipleOf90(direction, this.rotationDegrees);
|
||||
return Vector.transformDirectionFromMultipleOf90(direction, this.rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +115,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
* @returns {enumDirection}
|
||||
*/
|
||||
worldDirectionToLocal(direction) {
|
||||
return Vector.transformDirectionFromMultipleOf90(direction, 360 - this.rotationDegrees);
|
||||
return Vector.transformDirectionFromMultipleOf90(direction, 360 - this.rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +149,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
const worldX = this.origin.x * globalConfig.tileSize;
|
||||
const worldY = this.origin.y * globalConfig.tileSize;
|
||||
|
||||
if (this.rotationDegrees === 0) {
|
||||
if (this.rotation === 0) {
|
||||
// Early out, is faster
|
||||
sprite.drawCached(
|
||||
parameters,
|
||||
@@ -166,7 +164,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
const rotationCenterY = worldY + globalConfig.halfTileSize;
|
||||
|
||||
parameters.context.translate(rotationCenterX, rotationCenterY);
|
||||
parameters.context.rotate(Math_radians(this.rotationDegrees));
|
||||
parameters.context.rotate(Math_radians(this.rotation));
|
||||
|
||||
sprite.drawCached(
|
||||
parameters,
|
||||
@@ -177,7 +175,7 @@ export class StaticMapEntityComponent extends Component {
|
||||
false
|
||||
);
|
||||
|
||||
parameters.context.rotate(-Math_radians(this.rotationDegrees));
|
||||
parameters.context.rotate(-Math_radians(this.rotation));
|
||||
parameters.context.translate(-rotationCenterX, -rotationCenterY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user