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

Commit c6e2c8b

Browse files
committed
add working addon creation page with wrting addon.json
1 parent 8e4de60 commit c6e2c8b

File tree

5 files changed

+125
-46
lines changed

5 files changed

+125
-46
lines changed

index.html

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,69 +71,71 @@ <h3>Addon creation</h3>
7171
<div id="jsonInfo">
7272
<div id="jsonTitle">
7373
<p class="jsonSectionHeader">Title</p>
74-
<input type="text">
74+
<input name="addonTitle" type="text" placeholder="Crazy cool addon" maxlength="128">
7575
</div>
7676
<div id="jsonType">
7777
<p class="jsonSectionHeader">Type</p>
78-
<select name="" id="">
78+
<select name="addonType" id="">
7979
<option value="">-- Select one --</option>
80-
<option value="">Server Content</option>
81-
<option value="">Gamemode</option>
82-
<option value="">Map</option>
83-
<option value="">Weapon</option>
84-
<option value="">Vehicle</option>
85-
<option value="">NPC</option>
86-
<option value="">Tool</option>
87-
<option value="">Effects</option>
88-
<option value="">Model</option>
80+
<option value="serverContent">Server Content</option>
81+
<option value="gamemode">Gamemode</option>
82+
<option value="map">Map</option>
83+
<option value="weapon">Weapon</option>
84+
<option value="vehicle">Vehicle</option>
85+
<option value="npc">NPC</option>
86+
<option value="tool">Tool</option>
87+
<option value="effects">Effects</option>
88+
<option value="model">Model</option>
8989
</select>
9090
</div>
9191
<div id="jsonTags">
9292
<div class="col">
93-
<p class="jsonSectionHeader">Tags</p>
93+
<p class="jsonSectionHeader">Tag</p>
9494
</div>
9595
<div class="col">
9696
<div class="jsonGrid">
9797
<div class="type">
98-
<input type="checkbox" name="fun">
99-
<p>Fun</p>
100-
</div>
101-
<div class="type">
102-
<input type="checkbox" name="roleplay">
98+
<input type="checkbox" name="roleplay" class="typeCheckbox">
10399
<p>Roleplay</p>
104100
</div>
105101
<div class="type">
106-
<input type="checkbox" name="scenic">
102+
<input type="checkbox" name="scenic" class="typeCheckbox">
107103
<p>Scenic</p>
108104
</div>
109105
<div class="type">
110-
<input type="checkbox" name="movie">
106+
<input type="checkbox" name="movie" class="typeCheckbox">
111107
<p>Movie</p>
112108
</div>
113109
<div class="type">
114-
<input type="checkbox" name="realism">
110+
<input type="checkbox" name="realism" class="typeCheckbox">
115111
<p>Realism</p>
116112
</div>
117113
<div class="type">
118-
<input type="checkbox" name="cartoon">
119-
<p>Cartoon</p>
114+
<input type="checkbox" name="fun" class="typeCheckbox">
115+
<p>Fun</p>
120116
</div>
121117
<div class="type">
122-
<input type="checkbox" name="water">
118+
<input type="checkbox" name="water" class="typeCheckbox">
123119
<p>Water</p>
124120
</div>
125121
<div class="type">
126-
<input type="checkbox" name="comic">
122+
<input type="checkbox" name="comic" class="typeCheckbox">
127123
<p>Comic</p>
128124
</div>
129125
<div class="type">
130-
<input type="checkbox" name="build">
126+
<input type="checkbox" name="build" class="typeCheckbox">
131127
<p>Build</p>
132128
</div>
129+
<div class="type">
130+
<input type="checkbox" name="cartoon" class="typeCheckbox">
131+
<p>Cartoon</p>
132+
</div>
133133
</div>
134134
</div>
135135
</div>
136-
<button class="transition_button" data-divtohide="#jsonCreator" data-divtoshow="#gmaPrep">Next</button>
136+
<div class="next_prompt">
137+
<button id="jsonAddonValidate" class="transition_button" style="background-color: #56bd56; color: white;" data-divtoshow="" data-divtohide="">Next</button>
138+
</div>
137139
</div>
138140
</div>
139141
<div id="gmaPrep">

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ ipcMain.on('getAddonInfo', () => {
8484

8585
var ADDON_IDS = []
8686

87-
88-
8987
// We use this to get the addon IDs from gmpublish.exe
9088

9189
function sendClientAddonInfo() {
@@ -101,4 +99,13 @@ function sendClientAddonInfo() {
10199
console.log('sent to client!')
102100
mainWindow.webContents.send('message', ADDON_IDS);
103101
});
104-
}
102+
}
103+
104+
ipcMain.on('createJsonFile', (event, json, dir) => {
105+
console.log(json, dir)
106+
fs.writeFileSync(dir + "\\addon.json", json, 'utf8', (err) => {
107+
console.log("An error occured while writing JSON Object to File.\n", err);
108+
})
109+
})
110+
111+
// function

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
},
1111
"devDependencies": {
1212
"electron": "^5.0.0",
13-
"electron-connect": "^0.6.3"
13+
"electron-connect": "^0.6.3",
14+
"electron-packager": "^13.1.1"
1415
},
1516
"scripts": {
1617
"test": "echo \"Error: no test specified\" && exit 1",

src/css/style.css

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ header {
238238

239239
#jsonInfo {
240240
text-align: left;
241-
padding: 0 10px;
242241
}
243242

244243
#jsonTitle > * {
@@ -247,16 +246,23 @@ header {
247246

248247
#jsonTitle input[type='text'] {
249248
border-radius: 5px;
249+
display: inline-block;
250+
width: 350px;
250251
border: none;
251252
padding: 5px;
252253
}
253254

255+
#jsonTags, #jsonTitle, #jsonType {
256+
padding: 0 10px;
257+
}
258+
254259
#jsonTags .type > * {
255260
display: inline-block;
256261
}
257262

258263
#jsonTags .type {
259-
margin-right: 10px;
264+
margin: 0 5px 10px 0;
265+
260266
}
261267

262268
#jsonTags .type p {
@@ -271,16 +277,21 @@ header {
271277
border-radius: 5px;
272278
border: none;
273279
padding: 5px;
280+
cursor: pointer;
274281
}
275282

276283
.jsonSectionHeader {
277284
font-weight: 700;
278-
margin-right: 10px;
285+
/* margin-top: 0; */
286+
padding-right: 15px;
287+
letter-spacing: 1px;
288+
/* white-space: nowrap; */
279289
}
280290

281291
.jsonGrid {
282292
display: grid;
283-
grid-template-columns: auto auto auto;
293+
margin-left: 7px;
294+
grid-template-columns: auto auto auto auto auto;
284295
}
285296

286297
.next_prompt {

src/js/script.js

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,32 @@ const {
33
remote,
44
ipcRenderer,
55
files
6-
} = require('electron')
7-
const settings = require('electron-settings');
8-
const shell = require('electron').shell;
6+
} = require("electron")
7+
const settings = require("electron-settings");
8+
const shell = require("electron").shell;
99
let win = remote.getCurrentWindow()
1010

1111
addon_data = []
1212
okToProcessAddonList = false
1313
donePopulatingAddonList = false
1414
currentNewAddon = "";
15+
jsonCheckboxCount = 0;
16+
addonToCreateData = {
17+
"title": "",
18+
"type": "",
19+
"tags": [],
20+
}
1521

1622

1723
// assuming $ is jQuery
18-
$(document).on('click', 'a[href^="http"]', function(event) {
24+
$(document).on("click", "a[href^='http']", function(event) {
1925
event.preventDefault();
2026
shell.openExternal(this.href);
2127
});
2228

2329

2430
$(document).ready(() => {
25-
ipcRenderer.on('message', (event, message) => {
31+
ipcRenderer.on("message", (event, message) => {
2632

2733
var arrayOfAddonIds = message;
2834

@@ -111,6 +117,9 @@ $(document).ready(() => {
111117
$('#addonDirCheck').css('background-color', '#56bd56')
112118
$('#addonDirCheck').prop('disabled', false)
113119
$('#addonDirCheck').css('cursor', 'pointer')
120+
win.setBounds({
121+
height: 300,
122+
})
114123
})
115124

116125
$('#dir_prompt_next button').click(() => {
@@ -131,9 +140,7 @@ $(document).ready(() => {
131140
$('#create_new_addon_button').click(() => {
132141
$('#addon_management_prompt').fadeOut(() => {
133142
$('#create_new_addon').fadeIn(() => {
134-
// win.setBounds({
135-
// height: 300,
136-
// })
143+
137144
})
138145
})
139146
})
@@ -156,28 +163,79 @@ $(document).ready(() => {
156163
$('#back_button_addon_creation').fadeOut();
157164
})
158165

166+
// General function for transitioning between div tags
159167
function goBack(divToFadeOut, divToFadeIn) {
160168
$(divToFadeOut).fadeOut(() => {
161169
$(divToFadeIn).fadeIn();
162170
})
163171
}
164172

173+
// Get array of addon infomation and append their names to #yourAddons
165174
function populateAddonList() {
175+
// This check is done to make sure this only gets executed once
166176
if (!donePopulatingAddonList) {
167177
for (let i = 0; i < addon_data.length; i++) {
168178
$('#yourAddons').append("<div class='addon_existing'><p>" + addon_data[i].title + "</p></div>")
169179
donePopulatingAddonList = true;
170180
}
171-
181+
// Make sure if nothing is returned to let the user know
182+
// TODO: Allow for multiple error codes such as 429 (too many requests)
172183
if (0 == addon_data.length) {
173184
$('#yourAddons').append("<p style='background-color: #0f0f0f; padding: 15px 10px; margin: 10px 15px; border-radius: 5px;'><b>No addons found!</b><br/><br/>Either you don't have Steam open or haven't uploaded anything.</p>")
174185
donePopulatingAddonList = true;
175186
}
176187
}
177188
}
178189

190+
$('.typeCheckbox').on('click', (event) => {
191+
var target = $(event.target);
192+
if (jsonCheckboxCount < 2 && target.is(":checked")) {
193+
jsonCheckboxCount++
194+
console.log(jsonCheckboxCount)
195+
} else if (jsonCheckboxCount != 0 && !target.is(":checked")) {
196+
jsonCheckboxCount--
197+
console.log(jsonCheckboxCount)
198+
} else if (jsonCheckboxCount == 2 && target.is(":checked")) {
199+
console.log(jsonCheckboxCount)
200+
event.preventDefault()
201+
}
202+
203+
if (jsonCheckboxCount == 2) {
204+
var checkboxes = $('.typeCheckbox')
205+
console.log(checkboxes.is(":checked"))
206+
if (!checkboxes.is(":checked")) {
207+
$(checkboxes).prop('disabled', true)
208+
}
209+
}
210+
})
211+
212+
$('#jsonAddonValidate').click(() => {
213+
var checks = [false, false, false]
179214

180-
// $('.type').click((event) => {
181-
// console.log(event)
182-
// })
215+
if ($("#jsonTitle > input[name='addonTitle']").val() != "") {
216+
var addonTitle = $("#jsonTitle > input[name='addonTitle']").val()
217+
checks[0] = true;
218+
}
219+
220+
if ($('#jsonType > select[name="addonType"]').val() != "") {
221+
var addonType = $('#jsonType > select[name="addonType"]').val()
222+
checks[1] = true;
223+
}
224+
225+
if ($(".typeCheckbox:checked").val() != null) {
226+
var addonTags = $(".typeCheckbox:checked").map(function(){
227+
return $(this).attr('name');
228+
}).get();
229+
checks[2] = true;
230+
}
231+
232+
if (checks[0, 1, 2]) {
233+
console.log($('.typeCheckbox:checked').attr('name'))
234+
addonToCreateData.title = addonTitle
235+
addonToCreateData.type = addonType
236+
addonToCreateData.tags = addonTags
237+
console.log(addonToCreateData)
238+
ipcRenderer.send('createJsonFile', JSON.stringify(addonToCreateData), currentNewAddon)
239+
}
240+
})
183241
});

0 commit comments

Comments
 (0)