From a599f07fca38d173435005698615d59b82ea0b31 Mon Sep 17 00:00:00 2001 From: Leeous Date: Wed, 8 May 2019 11:38:18 -0400 Subject: [PATCH] added image size checking, some polish, ready for release --- README.md | 12 +++++++++++- index.js | 32 ++++++++++++++++---------------- package.json | 1 + src/js/script.js | 19 +++++++++++++------ 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index f5aa186..6f502ea 100644 --- a/README.md +++ b/README.md @@ -1 +1,11 @@ -# Garry's Mod Addon Tool \ No newline at end of file +# Garry's Mod Addon Tool +A light-weight application that allows you to create/update Garry's Mod addons very easily. + +Meant for the crowd who aren't good with using terminals. +Should work with any type of addon. +Creates GMAs, addon.json, and uploads it to the Workshop. + +![](https://i.imgur.com/PjWwPJP.png) + +## Instructions +Download a [release](https://github.com/Leeous/gmod-addon-tool/releases) and run `gmod-addon-tool.exe`. \ No newline at end of file diff --git a/index.js b/index.js index 601e379..4b6e8bc 100644 --- a/index.js +++ b/index.js @@ -78,12 +78,12 @@ ipcMain.on('checkIfDirectoryExists', (event, file) => { }) ipcMain.on('getAddonInfo', () => { - console.log('Trying to get addon info...') - sendClientAddonInfo() - console.log("User's Gmod Directory:" + settings.get('gmodDirectory')) + console.log('Trying to get addon info...'); + sendClientAddonInfo(); + console.log("User's Gmod Directory:" + settings.get('gmodDirectory')); }) -var ADDON_IDS = [] +var ADDON_IDS = []; // We use this to get the addon IDs from gmpublish.exe @@ -108,8 +108,8 @@ ipcMain.on('createJsonFile', (event, json, dir) => { fs.writeFileSync(dir + "\\addon.json", json, 'utf8', (err) => { console.log("An error occured while writing JSON Object to File.\n", err); mainWindow.webContents.send('error', "Error writing directory."); - }) -}) + }); +}); ipcMain.on('createGMAFile', (event, addonDir) => { console.log("Addon's Directory: " + addonDir.toString()) @@ -128,21 +128,21 @@ ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => { if (addonId != null) { const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['update', '-id', addonId, '-icon', iconDir, '-addon', gmaDir]); gmpublish.stdout.on('data', (data) => { - var arrayOfOutput = data.toString().split('\n') - var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7) - fixedArray = fixedArray[0].replace(/\D/, '') - fixedArray = fixedArray.substr(5, fixedArray.length) - console.log(fixedArray) + var arrayOfOutput = data.toString().split('\n'); + var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7); + fixedArray = fixedArray[0].replace(/\D/, ''); + fixedArray = fixedArray.substr(5, fixedArray.length); + console.log(fixedArray); mainWindow.webContents.send('currentAddonID', fixedArray); }); } else { const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['create', '-icon', iconDir, '-addon', gmaDir]); gmpublish.stdout.on('data', (data) => { - var arrayOfOutput = data.toString().split('\n') - var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7) - fixedArray = fixedArray[0].replace(/\D/, '') - fixedArray = fixedArray.substr(5, fixedArray.length) - console.log(fixedArray) + var arrayOfOutput = data.toString().split('\n'); + var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7); + fixedArray = fixedArray[0].replace(/\D/, ''); + fixedArray = fixedArray.substr(5, fixedArray.length); + console.log(fixedArray); mainWindow.webContents.send('currentAddonID', fixedArray); }); }; diff --git a/package.json b/package.json index 81b8c19..2b30f5e 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dependencies": { "cross-spawn": "^6.0.5", "electron-settings": "^3.2.0", + "image-size": "^0.7.4", "jquery": "^3.4.0" }, "devDependencies": { diff --git a/src/js/script.js b/src/js/script.js index 9897f8c..e043b9c 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -6,6 +6,7 @@ const { } = require("electron"); const settings = require("electron-settings"); const shell = require("electron").shell; +const imageSize = require("image-size"); let win = remote.getCurrentWindow(); addon_data = []; @@ -148,19 +149,25 @@ $(document).ready(() => { $('#addon_icon').change(() => { addonIcon = document.getElementById("addon_icon").files[0].path; + sizeIsOkay = true; ipcRenderer.send('checkIfDirectoryExists', addonIcon); var jpegCheck = addonIcon.substring(addonIcon.length - 4); - console.log(jpegCheck) + var sizeOf = require('image-size'); + var dimensions = sizeOf(addonIcon); if (jpegCheck == "jpeg" || jpegCheck == ".jpg") { - $('#addonIconCheck').css('background-color', '#56bd56'); - $('#addonIconCheck').prop('disabled', false); - $('#addonIconCheck').css('cursor', 'pointer'); + if (dimensions.height == 512 && dimensions.width == 512) { + $('#addonIconCheck').css('background-color', '#56bd56'); + $('#addonIconCheck').prop('disabled', false); + $('#addonIconCheck').css('cursor', 'pointer'); + } else { + alert("Image must be 512x512.") + } } else { $('#addonIconCheck').css('background-color', '#0f0f0f'); $('#addonIconCheck').prop('disabled', true); $('#addonIconCheck').css('cursor', 'not-allowed'); - alert("Doesn't seem like a JPEG image.") - } + alert("Doesn't seem like a JPEG image."); + } }) $('#dir_prompt_next button').click(() => {