Skip to content

Commit

Permalink
Merge pull request #40 from anno-mods/devel/1.12-fixes2
Browse files Browse the repository at this point in the history
minor fixes
  • Loading branch information
jakobharder authored Jun 8, 2023
2 parents 0726717 + a6dfe62 commit 32f924e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## 1.12 Simplified Build and Deploy

- 1.12.11: Rename bundled mods to ModID to avoid confusion
- 1.12.10: Disable xmltest for documents not starting with `<ModOps>`
- 1.12.9: Support local bundles
- 1.12.8: Treat icon LOD generation under `data/ui` differently
- 1.12.7: Updated xmltest, annodiff to GU17.1
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.9",
"version": "1.12.11",
"publisher": "JakobHarder",
"repository": {
"type": "git",
Expand Down
28 changes: 25 additions & 3 deletions src/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ export class ModBuilder {
this._downloadBundle(bundle, cache, outFolder);
}
}

this._renameModFolders(outFolder);
}

for (const sourceFolder of sourceFolders) {
Expand Down Expand Up @@ -206,15 +208,15 @@ export class ModBuilder {
return;
}

const modName = this._getModName(modinfoPath, modinfo.modinfo);
const targetFolder = path.join(outFolder, modName);
// const modName = this._getModName(modinfoPath, modinfo.modinfo);
const targetFolder = path.join(outFolder, path.basename(bundle));

await this.build(modinfoPath, targetFolder);
}

private _downloadBundle(bundle: string, cache: string, outFolder: string) {
const fileName = path.basename(bundle);
const version = path.basename(path.dirname(bundle)).replace(/[^\w\-]/g, '');
const version = path.basename(path.dirname(bundle)).replace(/[^\w\-\.]/g, '');
const targetPath = path.join(cache, 'downloads', utils.insertEnding(fileName, '-' + version));
if (!fs.existsSync(targetPath)) {
this._logger.log(` * download ${version}/${fileName}`);
Expand All @@ -227,6 +229,26 @@ export class ModBuilder {
utils.extractZip(targetPath, outFolder, this._logger);
}

private _renameModFolders(modsPath: string) {
const modinfoPaths = glob.sync("*/modinfo.json", { cwd: modsPath, nodir: true });
for (var modinfoPath of modinfoPaths) {
const namedModPath = path.join(modsPath, path.dirname(modinfoPath));
const modinfo = utils.readModinfo(namedModPath);
if (!modinfo) {
continue;
}

if (!modinfo.modinfo.ModID) {
continue;
}

const idModPath = path.join(path.dirname(namedModPath), modinfo.modinfo.ModID);
if (namedModPath != idModPath) {
fs.renameSync(namedModPath, idModPath);
}
}
}

private _getOutFolder(filePath: string, modJson: any) {
let outFolder = modJson.out ?? '${annoMods}/${modName}';
outFolder = outFolder.replace('${modName}', this._getModName(filePath, modJson.modinfo ?? modJson));
Expand Down
16 changes: 16 additions & 0 deletions src/features/assetsActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,28 @@ export function clearDiagnostics(context: vscode.ExtensionContext, doc: vscode.T
vscode.window.activeTextEditor?.setDecorations(performanceDecorationType, []);
}

function checkRootTag(doc: vscode.TextDocument, tag: string): boolean {
for (var index = 0; index < doc.lineCount; index++) {
const line = doc.lineAt(index);
const match = /<(\w+)/.exec(line.text);
if (match) {
return match[1] == tag;
}
}
return false;
}

export function refreshDiagnostics(context: vscode.ExtensionContext, doc: vscode.TextDocument, collection: vscode.DiagnosticCollection): void {
if (doc.lineCount > 10000 || !minimatch(doc.fileName, ASSETS_FILENAME_PATTERN)) {
// ignore large files and non-assets.xmls
return;
}

if (!checkRootTag(doc, "ModOps")) {
// not a ModOps document
return;
}

const config = vscode.workspace.getConfiguration('anno', doc.uri);
const checkFileNames = config.get('checkFileNames');
const annoRda: string | undefined = config.get('rdaFolder');
Expand Down
12 changes: 12 additions & 0 deletions src/other/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ export function hasGraphicsFile(modPaths: string[], filePath: string, annoRda?:
if (fs.existsSync(path.join(modPath, folderPath, path.basename(fileName, '.psd') + '.png'))) {
return [];
}

if (fs.existsSync(path.join(modPath, folderPath, path.basename(fileName, '_norm.psd') + '_rga.png'))) {
return [];
}
checked.push(path.join(folderPath, path.basename(fileName, '.psd') + '_0.dds'));
checked.push(path.join(folderPath, path.basename(fileName, '.psd') + '.png'));
}
Expand Down Expand Up @@ -330,6 +334,14 @@ export function hasGraphicsFile(modPaths: string[], filePath: string, annoRda?:
}
checked.push(path.join(folderPath, path.basename(fileName, '.png') + '_0.dds'));
}

// try .rdp.xml
if (fileName.endsWith('.rdp')) {
if (fs.existsSync(path.join(modPath, folderPath, fileName + '.xml'))) {
return [];
}
checked.push(path.join(modPath, folderPath, fileName + '.xml'));
}
}

return checked;
Expand Down

0 comments on commit 32f924e

Please sign in to comment.