In 2.0, icon_size is optional with a default of 64 - fixes #699

This commit is contained in:
Danielv123 authored and Daniel committed 2024-12-09 15:23:45 -08:00
1 parent 485504d885
commit c0d33d5852
1 file changed
+7 -7
+7 -7
View File
@@ -15,12 +15,12 @@ interface Prototype {
} }
interface SimpleIconSpecification { interface SimpleIconSpecification {
icon: string; icon: string;
icon_size: number; icon_size?: number;
icon_mipmaps?: number; icon_mipmaps?: number;
} }
interface IconLayer { interface IconLayer {
icon: string; icon: string;
icon_size: number; icon_size?: number;
tint?: lib.FactorioColor, tint?: lib.FactorioColor,
shift?: [number, number], shift?: [number, number],
scale?: number, scale?: number,
@@ -28,7 +28,7 @@ interface IconLayer {
} }
interface LayeredIconSpecification { interface LayeredIconSpecification {
icons: IconLayer[]; icons: IconLayer[];
icon_size: number; icon_size?: number;
icon_mipmaps?: number; icon_mipmaps?: number;
} }
type IconSpecification = LayeredIconSpecification | SimpleIconSpecification; type IconSpecification = LayeredIconSpecification | SimpleIconSpecification;
@@ -165,9 +165,9 @@ async function loadSimpleIcon(
size: number, size: number,
iconCache: IconCache, iconCache: IconCache,
) { ) {
let icon = await loadIcon(server, modVersions, item.icon, item.icon_size, 0, iconCache); let icon = await loadIcon(server, modVersions, item.icon, item.icon_size ?? 64, 0, iconCache);
if (icon) { if (icon) {
let iconScale = size / item.icon_size; let iconScale = size / (item.icon_size ?? 64);
if (iconScale !== 1) { if (iconScale !== 1) {
icon = icon.clone(); icon = icon.clone();
icon.scale(iconScale); icon.scale(iconScale);
@@ -183,7 +183,7 @@ async function loadLayeredIcon(
size: number, size: number,
iconCache: IconCache, iconCache: IconCache,
) { ) {
let baseLayerSize = item.icons[0].icon_size || item.icon_size; let baseLayerSize = (item.icons[0].icon_size || item.icon_size) ?? 64;
let icon = await Jimp.create(size, size); let icon = await Jimp.create(size, size);
// The scaling factor of the base layer // The scaling factor of the base layer
@@ -193,7 +193,7 @@ async function loadLayeredIcon(
let baseUnit = size / (baseLayerSize * baseLayerScale); let baseUnit = size / (baseLayerSize * baseLayerScale);
for (let layer of item.icons) { for (let layer of item.icons) {
let layerSize = layer.icon_size || item.icon_size; let layerSize = (layer.icon_size || item.icon_size) ?? 64;
let iconLayer = await loadIcon(server, modVersions, layer.icon, layerSize, layer.icon_mipmaps || 0, iconCache); let iconLayer = await loadIcon(server, modVersions, layer.icon, layerSize, layer.icon_mipmaps || 0, iconCache);
if (!iconLayer) { if (!iconLayer) {