diff --git a/assets/weapon_classes.json b/assets/weapon_classes.json index 3315f7c..d7eae77 100644 --- a/assets/weapon_classes.json +++ b/assets/weapon_classes.json @@ -186,7 +186,8 @@ {"weaponId": "amputator", "weaponName": "Amputator"}, {"weaponId": "blutsauger", "weaponName": "Blutsauger"}, {"weaponId": "telefrag", "weaponName": "Telefrag"}, - {"weaponId": "freedom_staff", "weaponName": "Freedom Staff"} + {"weaponId": "freedom_staff", "weaponName": "Freedom Staff"}, + {"weaponId": "syringegun_medic", "weaponName": "Syringe Gun"} ] }, { diff --git a/doc/missing_weapons/.gitignore b/doc/missing_weapons/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/doc/missing_weapons/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/package.json b/package.json index dc21d0d..08e11d7 100644 --- a/package.json +++ b/package.json @@ -176,7 +176,8 @@ "files": [ "dist", "node_modules", - "package.json" + "package.json", + "assets/weapon_classes.json" ], "afterSign": ".erb/scripts/notarize.js", "mac": { @@ -242,14 +243,5 @@ "src/main/**" ], "logLevel": "quiet" - }, - "config": { - "forge": { - "packagerConfig": { - "extraResource": [ - "./doc/weapon_classes.json" - ] - } - } } } diff --git a/src/main/main.ts b/src/main/main.ts index ca0f852..6144ea3 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -40,6 +40,9 @@ class AppUpdater { autoUpdater.checkForUpdatesAndNotify(); } } +const appPath = app.isPackaged + ? path.join(process.resourcesPath) + : path.join(__dirname, '../../'); let mainWindow: BrowserWindow | null = null; let tf2rconChild: ChildProcessWithoutNullStreams | null = null; @@ -265,7 +268,7 @@ const sendApplicationFragData = (fragMessage: RconAppFragEntry) => { const windows = BrowserWindow.getAllWindows(); // console.log(`Sending log-message: ${logMessage}`); - const tfClass = mapEntityToClass(__dirname + '/../../', fragMessage.Weapon); + const tfClass = mapEntityToClass(appPath, fragMessage.Weapon); if (tfClass == null || tfClass.length <= 0) { console.log( diff --git a/src/main/mapEntityToClass.js b/src/main/mapEntityToClass.js index ee0fe5b..45e66a2 100644 --- a/src/main/mapEntityToClass.js +++ b/src/main/mapEntityToClass.js @@ -1,22 +1,29 @@ const fs = require('fs'); const path = require('path'); -const weaponClassesPath = path.join(__dirname, '../../doc', 'weapon_classes.json'); -const missingEntitiesDir = path.join(__dirname, '../../doc/missing_weapons'); - -function addToMissing(entityName) { +function addToMissing(missingEntitiesDir, entityName) { if (!fs.existsSync(missingEntitiesDir)) { fs.mkdirSync(missingEntitiesDir); } - const missingFilePath = path.join(missingEntitiesDir, `missing_${entityName}.json`); + const missingFilePath = path.join( + missingEntitiesDir, + `missing_${entityName}.json`, + ); if (!fs.existsSync(missingFilePath)) { fs.writeFileSync(missingFilePath, JSON.stringify({ entityName }, null, 2)); } } -function mapEntityToClass(weaponId) { +function mapEntityToClass(appPath, weaponId) { + const weaponClassesPath = path.join(appPath, 'assets', 'weapon_classes.json'); + const missingEntitiesDir = path.join(appPath, 'assets', 'missing_weapons'); + + if (!fs.existsSync(weaponClassesPath)) { + throw new Error(`File not found: ${weaponClassesPath}`); + } + const weaponClasses = JSON.parse(fs.readFileSync(weaponClassesPath, 'utf-8')); const classNames = []; @@ -30,10 +37,9 @@ function mapEntityToClass(weaponId) { if (classNames.length > 0) { return classNames; - } else { - addToMissing(weaponId); - return null; } + addToMissing(missingEntitiesDir, weaponId); + return null; } module.exports = { mapEntityToClass };