-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
134 lines (110 loc) · 2.73 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const electron = require('electron')
const fs = require('fs')
const path = require('path')
const package = require('./package.json')
const vocab = require('./src/vocab.json')
const remote = electron.remote
const app = electron.app
const BrowserWindow = electron.BrowserWindow
let win
// Creating window
function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600,
fullscreen: false,
fullscreenable: true,
title: package.productName,
icon: __dirname + "/assets/misc/icon.png",
webPreferences: {}
})
win.loadURL('file://' + __dirname + '/index.html')
// win.webContents.openDevTools()
win.on('closed', function() {
app.quit()
})
finishLoading()
}
// Finish loading process
function finishLoading() {
weapons = loadParts()
data = new Data(weapons)
win.rendererSideName = data
win.webContents.on('did-finish-load', function() {
win.webContents.executeJavaScript('initialize()')
})
}
// Data object
function Data(weapons) {
this.weapons = weapons
this.pkg = package
this.vocab = vocab
}
// Weapon object
function Weapon(name) {
this.name = name
this.nodelist = []
}
// Node object
function GunNode(name) {
params = name.split('$')
this.name = params[1]
this.noderef = name
this.zlevel = params[0]
this.partslist = []
}
// Part object
function GunPart(src) {
params = src.split('/').reverse()[0].split('.')[0].split('$')
this.id = params[0]
this.name = params[1]
this.src = src
}
// Parts loading
function loadParts() {
gunsdir = __dirname + '/assets/guns'
guns = getDirectories(gunsdir)
weapons = []
for (i = 0; i < guns.length; i++) {
weapons.push(new Weapon(guns[i]))
gunbuffer = weapons[i]
subdir = gunsdir + '/' + guns[i]
nodes = getDirectories(subdir)
for (a = 0; a < nodes.length; a++) {
gunbuffer.nodelist.push(new GunNode(nodes[a]))
nodebuffer = gunbuffer.nodelist[a]
partsdir = subdir + '/' + nodes[a]
parts = getImages(partsdir)
for (b = 0; b < parts.length; b++) {
nodebuffer.partslist.push(new GunPart(partsdir + '/' + parts[b]))
}
}
}
return weapons
}
// Get directories
function getDirectories(src) {
return fs.readdirSync(src).filter(function(file) {
return fs.statSync(path.join(src, file)).isDirectory()
})
}
// Get images
function getImages(src) {
return fs.readdirSync(src).filter(function(file) {
return file.slice(-4) === '.png'
})
}
// App event listeners
app.on('ready', function() {
createWindow()
})
app.on('window-all-closed', function() {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function() {
if (mainWindow === null) {
createWindow()
}
})