1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Increase minimum screenshot scale

The pixels-per-tile for screenshots must now be an odd integer of at least 3.
A screenshot will not be made if the canvas size is too large, and an info dialog will be shown.

An additional quality setting that uses the minimum scale is added.
The resolutions are now calculated in terms of the maximum canvas dimensions.
This commit is contained in:
EmeraldBlock 2021-04-01 14:56:04 -05:00
parent 4ceb15051a
commit 3f01c131c3

View File

@ -15,22 +15,28 @@ import { getDeviceDPI } from "../../../core/dpi_manager";
const logger = createLogger("screenshot_exporter");
const MAX_CANVAS_DIMS = 16384;
const screenshotQualities = [
{
id: "high",
resolution: 16384,
resolution: MAX_CANVAS_DIMS,
},
{
id: "medium",
resolution: 4096,
resolution: MAX_CANVAS_DIMS / 4,
},
{
id: "low",
resolution: 1024,
resolution: MAX_CANVAS_DIMS / 16,
},
{
id: "pixels",
resolution: 0,
},
];
// @TODO: translation (T.dialogs.exportScreenshotWarning.qualities)
const qualityNames = { high: "High", medium: "Medium", low: "Low" };
const qualityNames = { high: "High", medium: "Medium", low: "Low", pixels: "Pixels" };
export class HUDScreenshotExporter extends BaseHUDPart {
createElements() {}
@ -111,15 +117,22 @@ export class HUDScreenshotExporter extends BaseHUDPart {
const maxDimensions = Math.max(dimensions.x, dimensions.y);
// we want integer pixels per tile
// if resolution too low, we want integer pixels per chunk
// we want odd integer pixels per tile, so that center of tile is rendered
// at least 3 pixels per tile, for bearable quality
const chunkSizePixels =
maxDimensions * globalConfig.mapChunkSize > resolution
? Math.max(1, Math.floor(resolution / maxDimensions))
: Math.floor(resolution / (maxDimensions * globalConfig.mapChunkSize)) *
globalConfig.mapChunkSize;
Math.max(
3,
Math.floor((resolution / (maxDimensions * globalConfig.mapChunkSize) + 1) / 2) * 2 - 1
) * globalConfig.mapChunkSize;
logger.log("ChunkSizePixels:", chunkSizePixels);
if (chunkSizePixels * maxDimensions > MAX_CANVAS_DIMS) {
logger.error("Maximum canvas size exceeded, aborting");
//@TODO: translation (T.dialogs.exportScreenshotFail.title) (T.dialogs.exportScreenshotFail.text)
this.root.hud.parts.dialogs.showInfo("Too large", "The base is too large to render, sorry!");
return;
}
// equivalent to zoomLevel
const chunkScale = chunkSizePixels / globalConfig.mapChunkWorldSize;
logger.log("Scale:", chunkScale);