Skip to content

Commit

Permalink
Update version to 0.11.1 and fix preview world map
Browse files Browse the repository at this point in the history
resource icons bug
  • Loading branch information
herbix committed Nov 17, 2023
1 parent 88dbf75 commit edb9eca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ All notable changes to the "hoi4modutilities" extension will be documented in th

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [0.11.0] - 2023/11/17 - Latest
## [0.11.1] - 2023/11/17 - Latest

### Fixed
* Preview world map will stuck if resource icons are not available.

## [0.11.0] - 2023/11/17

### Added
* Preview map shows X and Z from HOI4 coordinate system.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ For feature details and user manual, please refer to [HOI4 Mod Utilities Wiki](h
* Edge lines on world map not alway fit edge of colors.
* Event tree preview will duplicate events even they are same event if they are from different option.

## Release Notes - [0.11.0]
## Release Notes - [0.11.1]

### Added
* Preview map shows X and Z from HOI4 coordinate system.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hoi4modutilities",
"displayName": "%hoi4modutilities.displayName%",
"description": "Utilities for Heart of Iron IV mods developers",
"version": "0.11.0",
"version": "0.11.1",
"author": "Chaofan Yang",
"publisher": "chaofan",
"icon": "icon.png",
Expand Down
18 changes: 14 additions & 4 deletions webviewsrc/worldmap/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Renderer extends Subscriber {
private cursorX = 0;
private cursorY = 0;

private static resourceImages: Record<string, HTMLImageElement> = {};
private static resourceImages: Record<string, HTMLImageElement | undefined> = {};

constructor(private mainCanvas: HTMLCanvasElement, private viewPoint: ViewPoint, private loader: Loader, private topBar: TopBar) {
super();
Expand Down Expand Up @@ -908,6 +908,9 @@ ${worldMap.getSupplyAreaWarnings(supplyArea).map(v => '|r|' + v).join('\n')}`);
if (image) {
maxHeight = Math.max(maxHeight, image.naturalHeight * scale);
fullWidth += image.naturalWidth * scale;
} else {
maxHeight = Math.max(maxHeight, 24 * scale)
fullWidth += 24 * scale;
}
fullWidth += labelWidth;
}
Expand All @@ -924,9 +927,16 @@ ${worldMap.getSupplyAreaWarnings(supplyArea).map(v => '|r|' + v).join('\n')}`);
}

const image = Renderer.resourceImages[resource];
context.drawImage(image, x, y, image.naturalWidth * scale, image.naturalHeight * scale);
context.fillText(resourceNumber.toString(), x + (image?.naturalWidth ?? 0) * scale + labelWidth / 2, y + Math.max(0, image?.naturalHeight ?? 0) * scale / 2);
x += (image?.naturalWidth ?? 0) * scale + labelWidth;
if (image) {
context.drawImage(image, x, y, image.naturalWidth * scale, image.naturalHeight * scale);
context.fillText(resourceNumber.toString(), x + (image?.naturalWidth ?? 0) * scale + labelWidth / 2, y + Math.max(0, image?.naturalHeight ?? 0) * scale / 2);
x += (image?.naturalWidth ?? 0) * scale + labelWidth;
} else {
context.fillStyle = 'gray';
context.fillRect(x, y, 24 * scale, 24 * scale);
context.fillText(resourceNumber.toString(), x + 24 * scale + labelWidth / 2, y + 24 * scale / 2);
x += 24 * scale + labelWidth;
}
}
}
}
Expand Down

0 comments on commit edb9eca

Please sign in to comment.