Skip to content

Commit

Permalink
- fix packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
atomy committed Aug 3, 2024
1 parent 91ffe13 commit 03e6f54
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
3 changes: 2 additions & 1 deletion assets/weapon_classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
]
},
{
Expand Down
2 changes: 0 additions & 2 deletions doc/missing_weapons/.gitignore

This file was deleted.

12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
"files": [
"dist",
"node_modules",
"package.json"
"package.json",
"assets/weapon_classes.json"
],
"afterSign": ".erb/scripts/notarize.js",
"mac": {
Expand Down Expand Up @@ -242,14 +243,5 @@
"src/main/**"
],
"logLevel": "quiet"
},
"config": {
"forge": {
"packagerConfig": {
"extraResource": [
"./doc/weapon_classes.json"
]
}
}
}
}
5 changes: 4 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 15 additions & 9 deletions src/main/mapEntityToClass.js
Original file line number Diff line number Diff line change
@@ -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 = [];

Expand All @@ -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 };

0 comments on commit 03e6f54

Please sign in to comment.