Skip to content

Commit

Permalink
Merge pull request #33 from anno-mods/devel/icon-handling
Browse files Browse the repository at this point in the history
add icon lod handling
  • Loading branch information
jakobharder authored May 1, 2023
2 parents 2c32e7e + 00b3d7b commit 1352f3b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## 1.12 Simplified Build and Deploy

- 1.12.6: Use same resolution for icon LODs not placed in data/ui/2kimages
- 1.12.5: Don't create `maps/` folder if texture is already in maps
- 1.12.4: Fixed issue with texture cache
- 1.12.4: Include tag in downloaded bundle mods
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": "anno-modding-tools",
"displayName": "Anno Modding Tools",
"description": "Modding tools for Anno 1800",
"version": "1.12.5",
"version": "1.12.6",
"publisher": "JakobHarder",
"repository": {
"type": "git",
Expand Down
22 changes: 19 additions & 3 deletions src/builder/converter/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class TextureConverter extends Converter {
}) {
const cache = options.modCache;

// enable icon handling to avoid icon LODs
let iconHandling = options.converterOptions.icon ? true : false;

for (const file of files) {
this._logger.log(` => ${file}`);
const lodLevels = Math.max(0, Math.min(9, options.converterOptions.lods === undefined ? 3 : options.converterOptions.lods));
Expand All @@ -27,9 +30,13 @@ export class TextureConverter extends Converter {
try {
const dirname = path.dirname(file);
const basename = path.basename(file, '.png');
const mapsPath = (path.basename(dirname) === changePath) ? dirname : path.join(dirname, changePath);
const mapsPath = ((path.basename(dirname) === changePath) ? dirname : path.join(dirname, changePath)).replace(/\\/g, '/');
if (mapsPath.startsWith('data/ui/2kimages/main')) {
// vanilla icon path does not need special handling
iconHandling = false;
}

const lodFilePaths = [];
const lodFilePaths: string[] = [];
if (lodLevels === 0) {
// lods disabled, don't change file name
lodFilePaths.push(path.join(outFolder, mapsPath, basename + '.dds'));
Expand All @@ -49,10 +56,19 @@ export class TextureConverter extends Converter {
utils.ensureDir(path.join(outFolder, mapsPath));
utils.ensureDir(path.join(options.cache, dirname));

const textures = dds.convertToTexture(sourceFile, targetFolder, dds.TextureFormat.unknown, lodLevels);
let textures = dds.convertToTexture(sourceFile, targetFolder, dds.TextureFormat.unknown, iconHandling ? 1 : lodLevels);
if (!textures) {
return false;
}
if (iconHandling) {
// copy lod0 for icons to avoid blurry icons
textures = [...Array(lodLevels).keys()].map((index: number) => {
if (index !== 0) {
fs.copyFileSync(lodFilePaths[0], lodFilePaths[index]);
}
return path.basename(lodFilePaths[index]);
});
}
for (var [index, texture] of textures.entries()) {
this._logger.log(` <= ${lodLevels ? `LOD ${index}: ` : ''}${path.relative(path.dirname(file), path.relative(outFolder, path.join(targetFolder, texture)))}`);
cache.output(path.join(targetFolder, texture));
Expand Down
3 changes: 2 additions & 1 deletion src/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export class ModBuilder {
{
"action": "texture",
"pattern": "{data,products,shared}/**/icon*.png",
"lods": 3
"lods": 3,
"icon": true
},
{
"action": "assets"
Expand Down

0 comments on commit 1352f3b

Please sign in to comment.