From 3f01c131c3dbb3998756e1fd94715812fa147c5c Mon Sep 17 00:00:00 2001 From: EmeraldBlock Date: Thu, 1 Apr 2021 14:56:04 -0500 Subject: [PATCH] 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. --- src/js/game/hud/parts/screenshot_exporter.js | 33 ++++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/js/game/hud/parts/screenshot_exporter.js b/src/js/game/hud/parts/screenshot_exporter.js index 7d91671b..af18216e 100644 --- a/src/js/game/hud/parts/screenshot_exporter.js +++ b/src/js/game/hud/parts/screenshot_exporter.js @@ -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);