mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Reduce savegame size by not storing the tileSize in the static entity
This commit is contained in:
parent
8d329990ef
commit
bb431b8490
@ -92,13 +92,7 @@ export class Blueprint {
|
||||
parameters.context.globalAlpha = 1;
|
||||
}
|
||||
|
||||
staticComp.drawSpriteOnFullEntityBounds(
|
||||
parameters,
|
||||
staticComp.getBlueprintSprite(),
|
||||
0,
|
||||
true,
|
||||
newPos
|
||||
);
|
||||
staticComp.drawSpriteOnFullEntityBounds(parameters, staticComp.getBlueprintSprite(), 0, newPos);
|
||||
}
|
||||
parameters.context.globalAlpha = 1;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* typehints:start */
|
||||
import { MetaBuilding } from "./meta_building";
|
||||
import { AtlasSprite } from "../core/sprites";
|
||||
import { Vector } from "../core/vector";
|
||||
/* typehints:end */
|
||||
|
||||
/**
|
||||
@ -9,6 +10,7 @@ import { AtlasSprite } from "../core/sprites";
|
||||
* metaInstance?: MetaBuilding,
|
||||
* variant?: string,
|
||||
* rotationVariant?: number,
|
||||
* tileSize?: Vector,
|
||||
* sprite?: AtlasSprite,
|
||||
* blueprintSprite?: AtlasSprite,
|
||||
* silhouetteColor?: string
|
||||
@ -41,6 +43,8 @@ export function registerBuildingVariant(
|
||||
metaClass: meta,
|
||||
variant,
|
||||
rotationVariant,
|
||||
// @ts-ignore
|
||||
tileSize: new meta().getDimensions(variant),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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 {AtlasSprite}
|
||||
@ -51,7 +59,6 @@ export class StaticMapEntityComponent extends Component {
|
||||
duplicateWithoutContents() {
|
||||
return new StaticMapEntityComponent({
|
||||
origin: this.origin.copy(),
|
||||
tileSize: this.tileSize.copy(),
|
||||
rotation: this.rotation,
|
||||
originalRotation: this.originalRotation,
|
||||
code: this.code,
|
||||
@ -81,7 +88,6 @@ export class StaticMapEntityComponent extends Component {
|
||||
);
|
||||
|
||||
this.origin = origin;
|
||||
this.tileSize = tileSize;
|
||||
this.rotation = rotation;
|
||||
this.code = code;
|
||||
this.originalRotation = originalRotation;
|
||||
@ -92,30 +98,16 @@ export class StaticMapEntityComponent extends Component {
|
||||
* @returns {Rectangle}
|
||||
*/
|
||||
getTileSpaceBounds() {
|
||||
const size = this.getTileSize();
|
||||
switch (this.rotation) {
|
||||
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:
|
||||
return new Rectangle(
|
||||
this.origin.x - this.tileSize.y + 1,
|
||||
this.origin.y,
|
||||
this.tileSize.y,
|
||||
this.tileSize.x
|
||||
);
|
||||
return new Rectangle(this.origin.x - size.y + 1, this.origin.y, size.y, size.x);
|
||||
case 180:
|
||||
return new Rectangle(
|
||||
this.origin.x - this.tileSize.x + 1,
|
||||
this.origin.y - this.tileSize.y + 1,
|
||||
this.tileSize.x,
|
||||
this.tileSize.y
|
||||
);
|
||||
return new Rectangle(this.origin.x - size.x + 1, this.origin.y - size.y + 1, size.x, size.y);
|
||||
case 270:
|
||||
return new Rectangle(
|
||||
this.origin.x,
|
||||
this.origin.y - this.tileSize.x + 1,
|
||||
this.tileSize.y,
|
||||
this.tileSize.x
|
||||
);
|
||||
return new Rectangle(this.origin.x, this.origin.y - size.x + 1, size.y, size.x);
|
||||
default:
|
||||
assert(false, "Invalid rotation");
|
||||
}
|
||||
@ -186,34 +178,35 @@ export class StaticMapEntityComponent extends Component {
|
||||
let y = 0;
|
||||
let w = 0;
|
||||
let h = 0;
|
||||
const size = this.getTileSize();
|
||||
|
||||
switch (this.rotation) {
|
||||
case 0: {
|
||||
x = this.origin.x;
|
||||
y = this.origin.y;
|
||||
w = this.tileSize.x;
|
||||
h = this.tileSize.y;
|
||||
w = size.x;
|
||||
h = size.y;
|
||||
break;
|
||||
}
|
||||
case 90: {
|
||||
x = this.origin.x - this.tileSize.y + 1;
|
||||
x = this.origin.x - size.y + 1;
|
||||
y = this.origin.y;
|
||||
w = this.tileSize.y;
|
||||
h = this.tileSize.x;
|
||||
w = size.y;
|
||||
h = size.x;
|
||||
break;
|
||||
}
|
||||
case 180: {
|
||||
x = this.origin.x - this.tileSize.x + 1;
|
||||
y = this.origin.y - this.tileSize.y + 1;
|
||||
w = this.tileSize.x;
|
||||
h = this.tileSize.y;
|
||||
x = this.origin.x - size.x + 1;
|
||||
y = this.origin.y - size.y + 1;
|
||||
w = size.x;
|
||||
h = size.y;
|
||||
break;
|
||||
}
|
||||
case 270: {
|
||||
x = this.origin.x;
|
||||
y = this.origin.y - this.tileSize.x + 1;
|
||||
w = this.tileSize.y;
|
||||
h = this.tileSize.x;
|
||||
y = this.origin.y - size.x + 1;
|
||||
w = size.y;
|
||||
h = size.x;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -233,19 +226,13 @@ export class StaticMapEntityComponent extends Component {
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {AtlasSprite} 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
|
||||
*/
|
||||
drawSpriteOnFullEntityBounds(
|
||||
parameters,
|
||||
sprite,
|
||||
extrudePixels = 0,
|
||||
clipping = true,
|
||||
overridePosition = null
|
||||
) {
|
||||
drawSpriteOnFullEntityBounds(parameters, sprite, extrudePixels = 0, overridePosition = null) {
|
||||
if (!this.shouldBeDrawn(parameters) && !overridePosition) {
|
||||
return;
|
||||
}
|
||||
const size = this.getTileSize();
|
||||
let worldX = this.origin.x * globalConfig.tileSize;
|
||||
let worldY = this.origin.y * globalConfig.tileSize;
|
||||
|
||||
@ -258,10 +245,10 @@ export class StaticMapEntityComponent extends Component {
|
||||
// Early out, is faster
|
||||
sprite.drawCached(
|
||||
parameters,
|
||||
worldX - extrudePixels * this.tileSize.x,
|
||||
worldY - extrudePixels * this.tileSize.y,
|
||||
globalConfig.tileSize * this.tileSize.x + 2 * extrudePixels * this.tileSize.x,
|
||||
globalConfig.tileSize * this.tileSize.y + 2 * extrudePixels * this.tileSize.y,
|
||||
worldX - extrudePixels * size.x,
|
||||
worldY - extrudePixels * size.y,
|
||||
globalConfig.tileSize * size.x + 2 * extrudePixels * size.x,
|
||||
globalConfig.tileSize * size.y + 2 * extrudePixels * size.y,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
@ -273,10 +260,10 @@ export class StaticMapEntityComponent extends Component {
|
||||
|
||||
sprite.drawCached(
|
||||
parameters,
|
||||
-globalConfig.halfTileSize - extrudePixels * this.tileSize.x,
|
||||
-globalConfig.halfTileSize - extrudePixels * this.tileSize.y,
|
||||
globalConfig.tileSize * this.tileSize.x + 2 * extrudePixels * this.tileSize.x,
|
||||
globalConfig.tileSize * this.tileSize.y + 2 * extrudePixels * this.tileSize.y,
|
||||
-globalConfig.halfTileSize - extrudePixels * size.x,
|
||||
-globalConfig.halfTileSize - extrudePixels * size.y,
|
||||
globalConfig.tileSize * size.x + 2 * extrudePixels * size.x,
|
||||
globalConfig.tileSize * size.y + 2 * extrudePixels * size.y,
|
||||
false
|
||||
);
|
||||
|
||||
|
@ -312,7 +312,6 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
const staticComp = this.fakeEntity.components.StaticMapEntity;
|
||||
staticComp.origin = mouseTile;
|
||||
staticComp.rotation = rotation;
|
||||
staticComp.tileSize = metaBuilding.getDimensions(this.currentVariant.get());
|
||||
metaBuilding.updateVariants(this.fakeEntity, rotationVariant, this.currentVariant.get());
|
||||
staticComp.code = getCodeFromBuildingData(
|
||||
this.currentMetaBuilding.get(),
|
||||
|
@ -507,12 +507,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
const direction = entity.components.Belt.direction;
|
||||
const sprite = this.beltAnimations[direction][animationIndex % BELT_ANIM_COUNT];
|
||||
|
||||
entity.components.StaticMapEntity.drawSpriteOnFullEntityBounds(
|
||||
parameters,
|
||||
sprite,
|
||||
0,
|
||||
false
|
||||
);
|
||||
entity.components.StaticMapEntity.drawSpriteOnFullEntityBounds(parameters, sprite, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ export class StaticMapEntitySystem extends GameSystem {
|
||||
const beltComp = entity.components.Belt;
|
||||
if (beltComp) {
|
||||
const sprite = this.beltOverviewSprites[beltComp.direction];
|
||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 0, false);
|
||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 0);
|
||||
} else {
|
||||
parameters.context.fillRect(
|
||||
rect.x * globalConfig.tileSize,
|
||||
@ -59,7 +59,7 @@ export class StaticMapEntitySystem extends GameSystem {
|
||||
} else {
|
||||
const sprite = staticComp.getSprite();
|
||||
if (sprite) {
|
||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 2, false);
|
||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,7 +91,7 @@ export class StaticMapEntitySystem extends GameSystem {
|
||||
|
||||
const sprite = staticComp.getSprite();
|
||||
if (sprite) {
|
||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 2, false);
|
||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user