mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
use rectangle instead of two vectors
This commit is contained in:
parent
470beeadb1
commit
e92c0111b4
@ -145,15 +145,10 @@ export class HUDScreenshotExporter extends BaseHUDPart {
|
|||||||
// Find extends
|
// Find extends
|
||||||
const staticEntities = this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent);
|
const staticEntities = this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent);
|
||||||
|
|
||||||
const minTile = new Vector(0, 0);
|
if (!bounds) {
|
||||||
const maxTile = new Vector(0, 0);
|
const minTile = new Vector(0, 0);
|
||||||
if (bounds) {
|
const maxTile = new Vector(0, 0);
|
||||||
minTile.x = bounds.x;
|
|
||||||
minTile.y = bounds.y;
|
|
||||||
|
|
||||||
maxTile.x = bounds.x + bounds.w;
|
|
||||||
maxTile.y = bounds.y + bounds.h;
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < staticEntities.length; ++i) {
|
for (let i = 0; i < staticEntities.length; ++i) {
|
||||||
const entityBounds = staticEntities[i].components.StaticMapEntity.getTileSpaceBounds();
|
const entityBounds = staticEntities[i].components.StaticMapEntity.getTileSpaceBounds();
|
||||||
minTile.x = Math.min(minTile.x, entityBounds.x);
|
minTile.x = Math.min(minTile.x, entityBounds.x);
|
||||||
@ -168,12 +163,13 @@ export class HUDScreenshotExporter extends BaseHUDPart {
|
|||||||
|
|
||||||
maxTile.x = Math.ceil(maxTile.x / globalConfig.mapChunkSize) * globalConfig.mapChunkSize;
|
maxTile.x = Math.ceil(maxTile.x / globalConfig.mapChunkSize) * globalConfig.mapChunkSize;
|
||||||
maxTile.y = Math.ceil(maxTile.y / globalConfig.mapChunkSize) * globalConfig.mapChunkSize;
|
maxTile.y = Math.ceil(maxTile.y / globalConfig.mapChunkSize) * globalConfig.mapChunkSize;
|
||||||
|
|
||||||
|
bounds = Rectangle.fromTwoPoints(minTile, maxTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dimensions = maxTile.sub(minTile);
|
logger.log("Bounds:", bounds);
|
||||||
logger.log("Dimensions:", dimensions);
|
|
||||||
|
|
||||||
const maxDimensions = Math.max(dimensions.x, dimensions.y);
|
const maxDimensions = Math.max(bounds.w, bounds.h);
|
||||||
|
|
||||||
const tileSizePixels = overlay
|
const tileSizePixels = overlay
|
||||||
? // we want multiple of 3 pixels per tile, since the map mode buildings are 3x3 pixels
|
? // we want multiple of 3 pixels per tile, since the map mode buildings are 3x3 pixels
|
||||||
@ -215,23 +211,14 @@ export class HUDScreenshotExporter extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.log("Allocating buffer, if the factory grew too big it will crash here");
|
logger.log("Allocating buffer, if the factory grew too big it will crash here");
|
||||||
const [canvas, context] = makeOffscreenBuffer(
|
const [canvas, context] = makeOffscreenBuffer(bounds.w * tileSizePixels, bounds.h * tileSizePixels, {
|
||||||
dimensions.x * tileSizePixels,
|
smooth: true,
|
||||||
dimensions.y * tileSizePixels,
|
reusable: false,
|
||||||
{
|
label: "export-buffer",
|
||||||
smooth: true,
|
});
|
||||||
reusable: false,
|
|
||||||
label: "export-buffer",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
logger.log("Got buffer, rendering now ...");
|
logger.log("Got buffer, rendering now ...");
|
||||||
|
|
||||||
const visibleRect = new Rectangle(
|
const visibleRect = bounds.allScaled(globalConfig.tileSize);
|
||||||
minTile.x * globalConfig.tileSize,
|
|
||||||
minTile.y * globalConfig.tileSize,
|
|
||||||
dimensions.x * globalConfig.tileSize,
|
|
||||||
dimensions.y * globalConfig.tileSize
|
|
||||||
);
|
|
||||||
const parameters = new DrawParameters({
|
const parameters = new DrawParameters({
|
||||||
context,
|
context,
|
||||||
visibleRect,
|
visibleRect,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user