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;
|
parameters.context.globalAlpha = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticComp.drawSpriteOnFullEntityBounds(
|
staticComp.drawSpriteOnFullEntityBounds(parameters, staticComp.getBlueprintSprite(), 0, newPos);
|
||||||
parameters,
|
|
||||||
staticComp.getBlueprintSprite(),
|
|
||||||
0,
|
|
||||||
true,
|
|
||||||
newPos
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
parameters.context.globalAlpha = 1;
|
parameters.context.globalAlpha = 1;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* typehints:start */
|
/* typehints:start */
|
||||||
import { MetaBuilding } from "./meta_building";
|
import { MetaBuilding } from "./meta_building";
|
||||||
import { AtlasSprite } from "../core/sprites";
|
import { AtlasSprite } from "../core/sprites";
|
||||||
|
import { Vector } from "../core/vector";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,6 +10,7 @@ import { AtlasSprite } from "../core/sprites";
|
|||||||
* metaInstance?: MetaBuilding,
|
* metaInstance?: MetaBuilding,
|
||||||
* variant?: string,
|
* variant?: string,
|
||||||
* rotationVariant?: number,
|
* rotationVariant?: number,
|
||||||
|
* tileSize?: Vector,
|
||||||
* sprite?: AtlasSprite,
|
* sprite?: AtlasSprite,
|
||||||
* blueprintSprite?: AtlasSprite,
|
* blueprintSprite?: AtlasSprite,
|
||||||
* silhouetteColor?: string
|
* silhouetteColor?: string
|
||||||
@ -41,6 +43,8 @@ export function registerBuildingVariant(
|
|||||||
metaClass: meta,
|
metaClass: meta,
|
||||||
variant,
|
variant,
|
||||||
rotationVariant,
|
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 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
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -312,7 +312,6 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
const staticComp = this.fakeEntity.components.StaticMapEntity;
|
const staticComp = this.fakeEntity.components.StaticMapEntity;
|
||||||
staticComp.origin = mouseTile;
|
staticComp.origin = mouseTile;
|
||||||
staticComp.rotation = rotation;
|
staticComp.rotation = rotation;
|
||||||
staticComp.tileSize = metaBuilding.getDimensions(this.currentVariant.get());
|
|
||||||
metaBuilding.updateVariants(this.fakeEntity, rotationVariant, this.currentVariant.get());
|
metaBuilding.updateVariants(this.fakeEntity, rotationVariant, this.currentVariant.get());
|
||||||
staticComp.code = getCodeFromBuildingData(
|
staticComp.code = getCodeFromBuildingData(
|
||||||
this.currentMetaBuilding.get(),
|
this.currentMetaBuilding.get(),
|
||||||
|
@ -507,12 +507,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
const direction = entity.components.Belt.direction;
|
const direction = entity.components.Belt.direction;
|
||||||
const sprite = this.beltAnimations[direction][animationIndex % BELT_ANIM_COUNT];
|
const sprite = this.beltAnimations[direction][animationIndex % BELT_ANIM_COUNT];
|
||||||
|
|
||||||
entity.components.StaticMapEntity.drawSpriteOnFullEntityBounds(
|
entity.components.StaticMapEntity.drawSpriteOnFullEntityBounds(parameters, sprite, 0);
|
||||||
parameters,
|
|
||||||
sprite,
|
|
||||||
0,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ export class StaticMapEntitySystem extends GameSystem {
|
|||||||
const beltComp = entity.components.Belt;
|
const beltComp = entity.components.Belt;
|
||||||
if (beltComp) {
|
if (beltComp) {
|
||||||
const sprite = this.beltOverviewSprites[beltComp.direction];
|
const sprite = this.beltOverviewSprites[beltComp.direction];
|
||||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 0, false);
|
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 0);
|
||||||
} else {
|
} else {
|
||||||
parameters.context.fillRect(
|
parameters.context.fillRect(
|
||||||
rect.x * globalConfig.tileSize,
|
rect.x * globalConfig.tileSize,
|
||||||
@ -59,7 +59,7 @@ export class StaticMapEntitySystem extends GameSystem {
|
|||||||
} else {
|
} else {
|
||||||
const sprite = staticComp.getSprite();
|
const sprite = staticComp.getSprite();
|
||||||
if (sprite) {
|
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();
|
const sprite = staticComp.getSprite();
|
||||||
if (sprite) {
|
if (sprite) {
|
||||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 2, false);
|
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user