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

Commit d067ae3

Browse files
committed
add addon creation loop, add comments
1 parent 74365d4 commit d067ae3

File tree

4 files changed

+82
-35
lines changed

4 files changed

+82
-35
lines changed

index.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ <h3>What would you like to do?</h3>
4040
</div>
4141
<div id="update_existing_addon">
4242
<div class="top">
43-
<button id="back_button_existing_addon" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#update_existing_addon">◀ Back</button>
43+
<button id="back_button_existing_addon" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#update_existing_addon" data-resize="500, 175">◀ Back</button>
4444
<h3>Your addons</h3>
4545
</div>
4646
<div id="yourAddons"></div>
4747
</div>
4848
<div id="create_new_addon">
4949
<div class="top">
50-
<button id="back_button_addon_creation" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#create_new_addon">◀ Back</button>
50+
<button id="back_button_addon_creation" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#create_new_addon" data-resize="500, 175">◀ Back</button>
5151
<h3>Addon creation</h3>
5252
</div>
5353
<div id="addon_creation">
@@ -64,7 +64,7 @@ <h3>Addon creation</h3>
6464
<p>Do you already have a addon.json?</p>
6565
<div>
6666
<button class="button_normal transition_button removeBackOption" data-divtoshow="#jsonCreator" data-divtohide="#addonjsonPrompt" data-resize="500, 350">No</button>
67-
<button class="button_normal transition_button removeBackOption" data-divtoshow="#gmaPrep" data-divtohide="#addonjsonPrompt">Yes</button>
67+
<button class="button_normal transition_button removeBackOption" data-divtoshow="#gmaPrep" data-divtohide="#addonjsonPrompt" data-resize="500, 250">Yes</button>
6868
</div>
6969
</div>
7070
<div id="jsonCreator">
@@ -77,7 +77,7 @@ <h3>Addon creation</h3>
7777
<div id="jsonType">
7878
<p class="jsonSectionHeader">Type</p>
7979
<select name="addonType" id="">
80-
<option value="">-- Select one --</option>
80+
<option value="null">-- Select one --</option>
8181
<option value="serverContent">Server Content</option>
8282
<option value="gamemode">Gamemode</option>
8383
<option value="map">Map</option>
@@ -141,7 +141,7 @@ <h3>Addon creation</h3>
141141
<div id="jsonIgnore">
142142
<p class="jsonSectionHeader">Ignore</p>
143143
<input name="addonIgnore" type="text" placeholder="*.html, README.md, etc">
144-
<p><span style="font-size: .7em; color: grey; font-weight:500;">(folder/file names seprated by a comma)</span></p>
144+
<p><span style="font-size: .7em; color: grey; font-weight:500;">(file names seprated by a comma)</span></p>
145145
</div>
146146
<div class="next_prompt">
147147
<button id="jsonAddonValidate" class="transition_button" data-divtoshow="#gmaPrep" data-divtohide="#jsonCreator" data-resize="500, 250" disabled>Next</button>
@@ -151,10 +151,12 @@ <h3>Addon creation</h3>
151151
<div id="gmaPrep">
152152
<p>Created <span style="font-weight: 700">addon.json</span>!</p>
153153
<h3>Create GMA for uploading to the Workshop?</h3>
154-
<button class="button_normal transition_button" data-divtohide="" data-divtoshow="" data-resize="">Yes</button>
155-
<button class="button_normal transition_button" data-divtohide="" data-divtoshow="" data-resize="">No</button>
154+
<button style="width: 200px;" class="button_normal transition_button" data-divtohide="" data-divtoshow="" data-resize="">Yes</button>
155+
<button style="width: 200px;" class="button_normal transition_button" id="resetAddonCreation" data-divtohide="#create_new_addon" data-divtoshow="#addon_management_prompt" data-resize="500, 175">No</button>
156156
<!-- <img src="src/img/loading.gif" style="display: block; margin-left: auto; margin-right: auto; width: 64px;" alt=""> -->
157157
</div>
158+
<div id="createGMA">
159+
</div>
158160
</div>
159161
</div>
160162
</div>

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function createWindow() {
2424
// Create the browser window.
2525
mainWindow = new BrowserWindow({
2626
width: 500,
27-
height: 175,
27+
height: 250,
2828
resizable: false,
2929
fullscreenable: false,
3030
backgroundColor: "#262626",
@@ -108,6 +108,8 @@ ipcMain.on('createJsonFile', (event, json, dir) => {
108108
})
109109
})
110110

111-
// ipcMain.on('createGmaFile', (addonDir))
111+
// ipcMain.on('createGmaFile', (addonDir) => {
112+
// // var gmaLocation = addonDir +
113+
// })
112114

113115
// function

src/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ header {
164164
text-align: center;
165165
}
166166

167-
#update_existing_addon, #directory_selection, #create_new_addon, #jsonCreator, #gmaPrep, #addonjsonPrompt {
167+
#update_existing_addon, #directory_selection, #create_new_addon, #jsonCreator, #gmaPrep, #addonjsonPrompt, #addon_management_prompt {
168168
display: none;
169169
}
170170

src/js/script.js

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ currentNewAddon = "";
1515
jsonCheckboxCount = 0;
1616
jsonChecks = [false, false];
1717
apiError = 0;
18+
var addonTitle;
19+
var addonTags;
20+
var addonType;
1821
addonToCreateData = {
1922
"title": "",
2023
"type": "",
@@ -24,22 +27,21 @@ addonToCreateData = {
2427

2528

2629

27-
// assuming $ is jQuery
30+
// Make links open in enternal browser
2831
$(document).on("click", "a[href^='http']", function(event) {
2932
event.preventDefault();
3033
shell.openExternal(this.href);
3134
});
3235

3336

3437
$(document).ready(() => {
38+
// Try and recieve data from gmpublish about user's addons
3539
ipcRenderer.on("message", (event, message) => {
36-
3740
var arrayOfAddonIds = message;
38-
3941
for (let index = 0; index < arrayOfAddonIds.length; index++) {
4042
$.ajax({
4143
type: 'POST',
42-
url: 'https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/1',
44+
url: 'https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/',
4345
data: {
4446
'itemcount': 1,
4547
'publishedfileids[0]': parseInt(arrayOfAddonIds[index])
@@ -66,8 +68,13 @@ $(document).ready(() => {
6668
$('#update_existing_addon_button').text('Update existing addon');
6769
});
6870

71+
// If user has already defined their Garrysmod directory, just skip ahead to #addon_management
6972
if (settings.get('gmodDirectory') != null) {
7073
$('#addon_management').fadeIn();
74+
$('#addon_management_prompt').fadeIn();
75+
win.setBounds({
76+
height: 175
77+
})
7178
ipcRenderer.send('getAddonInfo');
7279
} else {
7380
$('#directory_selection').fadeIn();
@@ -81,12 +88,14 @@ $(document).ready(() => {
8188
remote.getCurrentWindow().minimize();
8289
})
8390

91+
// Used to "fake click" the input[type="file"]
8492
$('.fake_select').click((event) => {
85-
var foo = event.target;
86-
var foo2 = $(foo).data('buttonclick');
87-
$(foo2).click();
93+
var fakeButton = event.target;
94+
var realButton = $(fakeButton).data('buttonclick');
95+
$(realButton).click();
8896
})
8997

98+
// Validate that we have read/write access to the users Garrysmod directory so we can use gmad & gmpublish
9099
$('#gmod_dir_folder').change(() => {
91100
var filePath = document.getElementById("gmod_dir_folder").files[0].path;
92101
var desName = filePath.substring(filePath.length - 9, filePath.length);
@@ -112,6 +121,7 @@ $(document).ready(() => {
112121
}
113122
})
114123

124+
// If directory exists (and is writable/readable) allow user to procede
115125
$('#addon_dir_folder').change(() => {
116126
currentNewAddon = document.getElementById("addon_dir_folder").files[0].path;
117127
ipcRenderer.send('checkIfDirectoryExists', currentNewAddon);
@@ -142,22 +152,25 @@ $(document).ready(() => {
142152
$('#create_new_addon_button').click(() => {
143153
$('#addon_management_prompt').fadeOut(() => {
144154
win.setBounds({height: 250})
145-
$('#create_new_addon').fadeIn()
155+
$('#create_new_addon, #addonDirPrompt').fadeIn()
146156
})
147157
})
148158

149159
$('.back_button').click((event) => {
150160
var target = event.target;
151161
var divToGoBack = $(target).data('forwards');
152162
var divToShow = $(target).data('backwards');
153-
win.setBounds({height: 175})
154-
goBack(divToGoBack, divToShow);
163+
if ($(target).data('resize') != null) {
164+
var resizeInfo = JSON.parse("[" + $(target).data('resize') + "]");
165+
}
166+
goBack(divToGoBack, divToShow, resizeInfo);
155167
})
156168

157169
$('.transition_button').click((event) => {
158170
var target = event.target;
159171
var divToGoBack = $(target).data('divtohide');
160172
var divToShow = $(target).data('divtoshow');
173+
console.log(divToGoBack, divToShow)
161174
if ($(target).data('resize') != null) {
162175
var resizeInfo = JSON.parse("[" + $(target).data('resize') + "]");
163176
}
@@ -220,44 +233,38 @@ $(document).ready(() => {
220233
}
221234
})
222235

236+
// Dyamically change boolean based on whether or not string is empty
223237
$("#jsonTitle > input[name='addonTitle']").on('keyup', () => {
224238
if ($("#jsonTitle > input[name='addonTitle']").val() != "") {
225-
var addonTitle = $("#jsonTitle > input[name='addonTitle']").val();
239+
addonTitle = $("#jsonTitle > input[name='addonTitle']").val();
226240
jsonChecks[0] = true;
227-
validateJsonForm()
241+
validateJsonForm();
228242
} else {
229243
jsonChecks[0] = false;
230-
validateJsonForm()
244+
validateJsonForm();
231245
}
232246
})
233247

234248
$("#jsonType > select[name='addonType']").change(() => {
235-
if ($('#jsonType > select[name="addonType"]').val() != "") {
236-
var addonType = $('#jsonType > select[name="addonType"]').val();
249+
if ($('#jsonType > select[name="addonType"]').val() != "null") {
250+
addonType = $('#jsonType > select[name="addonType"]').val();
237251
jsonChecks[1] = true;
238-
validateJsonForm()
252+
validateJsonForm();
239253
} else {
240254
jsonChecks[1] = false;
241-
validateJsonForm()
255+
validateJsonForm();
242256
}
243257
})
244258

245259
$('#jsonAddonValidate').click(() => {
246260
if ($(".typeCheckbox:checked").val() != null) {
247-
var addonTags = $(".typeCheckbox:checked").map(function(){
261+
addonTags = $(".typeCheckbox:checked").map(function(){
248262
return $(this).attr('name');
249263
}).get();
250264
}
251265

252266
var ignoreList = $("#jsonIgnore input[name='addonIgnore']").val().replace(/\s/g,'').split(',');
253-
254-
console.log(ignoreList)
255-
256-
// var test = ignoreList);
257-
258267

259-
// console.log(JSON.parse("[" + ignoreList + "]"));
260-
261268
if (jsonChecks[0, 1]) {
262269
addonToCreateData.title = addonTitle;
263270
addonToCreateData.type = addonType;
@@ -279,4 +286,40 @@ $(document).ready(() => {
279286
$('#jsonAddonValidate').css('background-color', "#0f0f0f")
280287
}
281288
}
289+
290+
$("#resetAddonCreation").click(() => {
291+
292+
jsonCheckboxCount = 0;
293+
294+
// Clear the old data we used to make addon.json
295+
addonToCreateData = {
296+
"title": "",
297+
"type": "",
298+
"tags": [],
299+
"ignore": []
300+
};
301+
302+
// Reset all input values & checkboxes
303+
$('#jsonTitle > input[name="addonTitle"]').val("");
304+
$('select[name="addonType"]').val("null");
305+
$('.typeCheckbox').prop('checked', false);
306+
$('#jsonIgnore > input[name="addonIgnore"]').val("");
307+
308+
// Clear the addon name on directory selection
309+
$("#addonDir b").text('');
310+
311+
// Set the input to null
312+
$("#addon_dir_folder").val(null);
313+
314+
// Reset directory validation
315+
$('#addonDirCheck').css({backgroundColor: "#0f0f0f", cursor: "not-allowed"});
316+
$('#addonDirCheck').prop('disabled', true);
317+
318+
// Reset validation checks
319+
jsonChecks = [false, false];
320+
validateJsonForm();
321+
322+
// Hide any div that may still be displayed
323+
$('#addonjsonPrompt, #jsonCreator, #gmaPrep, #createGMA').css('display', 'none');
324+
})
282325
});

0 commit comments

Comments
 (0)