Skip to content

Commit

Permalink
added image size checking, some polish, ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Leeous committed May 8, 2019
1 parent 012af2f commit a599f07
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Garry's Mod Addon Tool
# 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`.
32 changes: 16 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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())
Expand All @@ -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);
});
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
19 changes: 13 additions & 6 deletions src/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit a599f07

Please sign in to comment.