Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit a599f07

Browse files
committed
added image size checking, some polish, ready for release
1 parent 012af2f commit a599f07

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
# Garry's Mod Addon Tool
1+
# Garry's Mod Addon Tool
2+
A light-weight application that allows you to create/update Garry's Mod addons very easily.
3+
4+
Meant for the crowd who aren't good with using terminals.
5+
Should work with any type of addon.
6+
Creates GMAs, addon.json, and uploads it to the Workshop.
7+
8+
![](https://i.imgur.com/PjWwPJP.png)
9+
10+
## Instructions
11+
Download a [release](https://github.com/Leeous/gmod-addon-tool/releases) and run `gmod-addon-tool.exe`.

index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ ipcMain.on('checkIfDirectoryExists', (event, file) => {
7878
})
7979

8080
ipcMain.on('getAddonInfo', () => {
81-
console.log('Trying to get addon info...')
82-
sendClientAddonInfo()
83-
console.log("User's Gmod Directory:" + settings.get('gmodDirectory'))
81+
console.log('Trying to get addon info...');
82+
sendClientAddonInfo();
83+
console.log("User's Gmod Directory:" + settings.get('gmodDirectory'));
8484
})
8585

86-
var ADDON_IDS = []
86+
var ADDON_IDS = [];
8787

8888
// We use this to get the addon IDs from gmpublish.exe
8989

@@ -108,8 +108,8 @@ ipcMain.on('createJsonFile', (event, json, dir) => {
108108
fs.writeFileSync(dir + "\\addon.json", json, 'utf8', (err) => {
109109
console.log("An error occured while writing JSON Object to File.\n", err);
110110
mainWindow.webContents.send('error', "Error writing directory.");
111-
})
112-
})
111+
});
112+
});
113113

114114
ipcMain.on('createGMAFile', (event, addonDir) => {
115115
console.log("Addon's Directory: " + addonDir.toString())
@@ -128,21 +128,21 @@ ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => {
128128
if (addonId != null) {
129129
const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['update', '-id', addonId, '-icon', iconDir, '-addon', gmaDir]);
130130
gmpublish.stdout.on('data', (data) => {
131-
var arrayOfOutput = data.toString().split('\n')
132-
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7)
133-
fixedArray = fixedArray[0].replace(/\D/, '')
134-
fixedArray = fixedArray.substr(5, fixedArray.length)
135-
console.log(fixedArray)
131+
var arrayOfOutput = data.toString().split('\n');
132+
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7);
133+
fixedArray = fixedArray[0].replace(/\D/, '');
134+
fixedArray = fixedArray.substr(5, fixedArray.length);
135+
console.log(fixedArray);
136136
mainWindow.webContents.send('currentAddonID', fixedArray);
137137
});
138138
} else {
139139
const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['create', '-icon', iconDir, '-addon', gmaDir]);
140140
gmpublish.stdout.on('data', (data) => {
141-
var arrayOfOutput = data.toString().split('\n')
142-
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7)
143-
fixedArray = fixedArray[0].replace(/\D/, '')
144-
fixedArray = fixedArray.substr(5, fixedArray.length)
145-
console.log(fixedArray)
141+
var arrayOfOutput = data.toString().split('\n');
142+
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7);
143+
fixedArray = fixedArray[0].replace(/\D/, '');
144+
fixedArray = fixedArray.substr(5, fixedArray.length);
145+
console.log(fixedArray);
146146
mainWindow.webContents.send('currentAddonID', fixedArray);
147147
});
148148
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dependencies": {
77
"cross-spawn": "^6.0.5",
88
"electron-settings": "^3.2.0",
9+
"image-size": "^0.7.4",
910
"jquery": "^3.4.0"
1011
},
1112
"devDependencies": {

src/js/script.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
} = require("electron");
77
const settings = require("electron-settings");
88
const shell = require("electron").shell;
9+
const imageSize = require("image-size");
910
let win = remote.getCurrentWindow();
1011

1112
addon_data = [];
@@ -148,19 +149,25 @@ $(document).ready(() => {
148149

149150
$('#addon_icon').change(() => {
150151
addonIcon = document.getElementById("addon_icon").files[0].path;
152+
sizeIsOkay = true;
151153
ipcRenderer.send('checkIfDirectoryExists', addonIcon);
152154
var jpegCheck = addonIcon.substring(addonIcon.length - 4);
153-
console.log(jpegCheck)
155+
var sizeOf = require('image-size');
156+
var dimensions = sizeOf(addonIcon);
154157
if (jpegCheck == "jpeg" || jpegCheck == ".jpg") {
155-
$('#addonIconCheck').css('background-color', '#56bd56');
156-
$('#addonIconCheck').prop('disabled', false);
157-
$('#addonIconCheck').css('cursor', 'pointer');
158+
if (dimensions.height == 512 && dimensions.width == 512) {
159+
$('#addonIconCheck').css('background-color', '#56bd56');
160+
$('#addonIconCheck').prop('disabled', false);
161+
$('#addonIconCheck').css('cursor', 'pointer');
162+
} else {
163+
alert("Image must be 512x512.")
164+
}
158165
} else {
159166
$('#addonIconCheck').css('background-color', '#0f0f0f');
160167
$('#addonIconCheck').prop('disabled', true);
161168
$('#addonIconCheck').css('cursor', 'not-allowed');
162-
alert("Doesn't seem like a JPEG image.")
163-
}
169+
alert("Doesn't seem like a JPEG image.");
170+
}
164171
})
165172

166173
$('#dir_prompt_next button').click(() => {

0 commit comments

Comments
 (0)