@jtff/miztemplate-lib 3.0.0-rc1 → 3.0.0-rc11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -2
- package/lib/jtff-lib-ci.js +3 -1
- package/lib/mizlib.js +334 -285
- package/package.json +1 -1
- package/scripts/build.js +1 -2
- package/scripts/inject-scripts.js +215 -208
- package/scripts/template-update.js +1 -1
package/lib/mizlib.js
CHANGED
|
@@ -1,336 +1,385 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const jszip = require("jszip");
|
|
4
|
-
const lstat = promisify(fs.lstat);
|
|
5
4
|
const path = require("path");
|
|
6
5
|
const {format, parse} = require("lua-json");
|
|
7
6
|
const {promisify} = require("util");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const lstat = promisify(fs.lstat);
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
class Mizlib {
|
|
11
|
+
constructor() {
|
|
12
|
+
// no need for initialization
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
injectLuaScriptAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, missionObject, mapResourceObject, timing, colorString) {
|
|
16
|
+
let tuple = this.injectLuaScriptsInMissionObject(
|
|
17
|
+
missionObject['trig'],
|
|
18
|
+
missionObject['trigrules'],
|
|
19
|
+
mapResourceObject,
|
|
20
|
+
titleString,
|
|
21
|
+
luaScriptsArray,
|
|
22
|
+
timing,
|
|
23
|
+
colorString
|
|
24
|
+
);
|
|
25
|
+
for (let luaScript of luaScriptsArray) {
|
|
26
|
+
fs.copyFileSync(
|
|
27
|
+
[
|
|
28
|
+
'node_modules/@jtff/miztemplate-lib/lua/',
|
|
29
|
+
folderPath,
|
|
30
|
+
'/',
|
|
31
|
+
luaScript
|
|
32
|
+
].join(""),
|
|
33
|
+
[
|
|
34
|
+
workspacePath,
|
|
35
|
+
"/",
|
|
36
|
+
folderPath,
|
|
37
|
+
"/",
|
|
38
|
+
path.basename(luaScript)
|
|
39
|
+
].join("")
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return tuple;
|
|
17
43
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
|
|
45
|
+
injectLuaScriptsInMissionObject(tObject, trObject, mrObject, strTitle, scriptFilesArray, timingInSeconds, hexColor) {
|
|
46
|
+
let nextIndex = Object.keys(trObject).length + 1;
|
|
47
|
+
if (nextIndex === 1) {
|
|
48
|
+
tObject['actions'] = {};
|
|
49
|
+
tObject['func'] = {};
|
|
50
|
+
tObject['conditions'] = {};
|
|
51
|
+
tObject['flag'] = {};
|
|
52
|
+
trObject = {};
|
|
53
|
+
}
|
|
54
|
+
let actionSentence = "";
|
|
55
|
+
let actionsObject = {};
|
|
56
|
+
for (const [index, scriptFile] of scriptFilesArray.entries()) {
|
|
57
|
+
actionSentence += "a_do_script_file(getValueResourceByKey(\"" + scriptFile + "\")); "
|
|
58
|
+
actionsObject[index + 1] = {
|
|
59
|
+
file: scriptFile,
|
|
60
|
+
predicate: 'a_do_script_file',
|
|
61
|
+
};
|
|
62
|
+
mrObject[scriptFile] = scriptFile;
|
|
63
|
+
}
|
|
64
|
+
actionSentence += "mission.trig.func[" + nextIndex + "]=nil;"
|
|
65
|
+
tObject['actions'][nextIndex] = actionSentence;
|
|
66
|
+
tObject['func'][nextIndex] = "if mission.trig.conditions[" + nextIndex + "]() then mission.trig.actions[" + nextIndex + "]() end";
|
|
67
|
+
tObject['conditions'][nextIndex] = "return(c_time_after(" + timingInSeconds + ") )";
|
|
68
|
+
tObject['flag'][nextIndex] = true;
|
|
69
|
+
trObject[nextIndex] = {
|
|
70
|
+
rules: {
|
|
71
|
+
1: {
|
|
72
|
+
coalitionlist: 'red',
|
|
73
|
+
seconds: timingInSeconds,
|
|
74
|
+
predicate: 'c_time_after',
|
|
75
|
+
zone: ''
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
eventlist: '',
|
|
79
|
+
comment: strTitle,
|
|
80
|
+
actions: actionsObject,
|
|
81
|
+
predicate: 'triggerOnce',
|
|
82
|
+
colorItem: hexColor
|
|
25
83
|
};
|
|
26
|
-
mrObject
|
|
84
|
+
return {tObject: tObject, trObject: trObject, mrObject: mrObject};
|
|
27
85
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
86
|
+
|
|
87
|
+
async getZipObjectFromMizPath(mizPath) {
|
|
88
|
+
var MizFile = new jszip();
|
|
89
|
+
const mizData = fs.readFileSync(mizPath);
|
|
90
|
+
return MizFile.loadAsync(mizData);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async mizUpdate(mizPath, copyPath, strTheatreSettings) {
|
|
94
|
+
const zip = await this.getZipObjectFromMizPath(mizPath);
|
|
95
|
+
this.injectLuaFilesFromFolderIntoZipObject(zip, 'src');
|
|
96
|
+
this.injectLuaFilesFromFolderIntoZipObject(zip, 'lib');
|
|
97
|
+
if (strTheatreSettings === null) {
|
|
98
|
+
// TODO: Inject fake data
|
|
99
|
+
console.log("NO THEATRE SPECIFIED. RADIO PRESETS WILL NOT BE AVAILABLE !");
|
|
100
|
+
} else {
|
|
101
|
+
await this.mizUpdateRadioPresets(zip, 'resources/radios/' + strTheatreSettings);
|
|
102
|
+
}
|
|
103
|
+
this.mizUpdateSettingsLuaFiles(zip, strTheatreSettings);
|
|
104
|
+
await this.mizUpdateSoundFolders(zip);
|
|
105
|
+
const inputZip = await zip.generateAsync({
|
|
106
|
+
type: 'nodebuffer',
|
|
107
|
+
streamFiles: true,
|
|
108
|
+
compression: "DEFLATE",
|
|
109
|
+
compressionOptions: {
|
|
110
|
+
level: 9
|
|
40
111
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
actions: actionsObject,
|
|
45
|
-
predicate: 'triggerOnce',
|
|
46
|
-
colorItem: hexColor
|
|
47
|
-
};
|
|
48
|
-
return { tObject: tObject, trObject: trObject, mrObject: mrObject };
|
|
49
|
-
}
|
|
112
|
+
});
|
|
113
|
+
fs.writeFileSync(copyPath ? copyPath : mizPath, inputZip);
|
|
114
|
+
}
|
|
50
115
|
|
|
51
|
-
async
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
116
|
+
async mizInjectMissionDataFile(mizPath, missionObject) {
|
|
117
|
+
const zip = await this.getZipObjectFromMizPath(mizPath);
|
|
118
|
+
this.mizUpdateMissionDataFile(zip, missionObject);
|
|
119
|
+
const inputZip = await zip.generateAsync({
|
|
120
|
+
type: 'nodebuffer',
|
|
121
|
+
streamFiles: true,
|
|
122
|
+
compression: "DEFLATE",
|
|
123
|
+
compressionOptions: {
|
|
124
|
+
level: 9
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
fs.writeFileSync(mizPath, inputZip);
|
|
128
|
+
}
|
|
56
129
|
|
|
57
|
-
async
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
130
|
+
async injectLuaSettingsFromFolderPathToMizPath(mizPath, settingsFolder) {
|
|
131
|
+
const zip = await this.getZipObjectFromMizPath(mizPath);
|
|
132
|
+
await this.injectLuaSettingsFromFolderPathToZipObject(zip, settingsFolder);
|
|
133
|
+
const outputZip = await zip.generateAsync({
|
|
134
|
+
type: 'nodebuffer',
|
|
135
|
+
streamFiles: true,
|
|
136
|
+
compression: "DEFLATE",
|
|
137
|
+
compressionOptions: {
|
|
138
|
+
level: 9
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
fs.writeFileSync(mizPath, outputZip);
|
|
66
142
|
}
|
|
67
|
-
mizUpdateSettingsLuaFiles(zip, strTheatreSettings);
|
|
68
|
-
await mizUpdateSoundFolders(zip);
|
|
69
|
-
const inputZip = await zip.generateAsync({
|
|
70
|
-
type: 'nodebuffer',
|
|
71
|
-
streamFiles: true,
|
|
72
|
-
compression: "DEFLATE",
|
|
73
|
-
compressionOptions: {
|
|
74
|
-
level: 9
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
fs.writeFileSync(copyPath ? copyPath : mizPath, inputZip);
|
|
78
|
-
}
|
|
79
143
|
|
|
80
|
-
async
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
compression: "DEFLATE",
|
|
87
|
-
compressionOptions: {
|
|
88
|
-
level: 9
|
|
144
|
+
async injectLuaSettingsFromFolderPathToZipObject(zip, settingsFolder) {
|
|
145
|
+
for (let file of fs.readdirSync(settingsFolder).filter(file => file.endsWith(".lua"))) {
|
|
146
|
+
this.injectFileIntoZipObject(zip, [
|
|
147
|
+
settingsFolder,
|
|
148
|
+
"/",
|
|
149
|
+
file].join(""));
|
|
89
150
|
}
|
|
90
|
-
}
|
|
91
|
-
fs.writeFileSync(mizPath, inputZip);
|
|
92
|
-
}
|
|
151
|
+
}
|
|
93
152
|
|
|
94
|
-
async function injectLuaSettingsFromFolderPathToMizPath(mizPath, settingsFolder) {
|
|
95
|
-
const zip = await getZipObjectFromMizPath(mizPath);
|
|
96
|
-
await injectLuaSettingsFromFolderPathToZipObject(zip,settingsFolder);
|
|
97
|
-
const outputZip = await zip.generateAsync({
|
|
98
|
-
type: 'nodebuffer',
|
|
99
|
-
streamFiles: true,
|
|
100
|
-
compression: "DEFLATE",
|
|
101
|
-
compressionOptions: {
|
|
102
|
-
level: 9
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
fs.writeFileSync(mizPath, outputZip);
|
|
106
|
-
}
|
|
107
153
|
|
|
108
|
-
async
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
154
|
+
async mizInjectMapResourceFile(mizPath, mapResourceObject) {
|
|
155
|
+
const zip = await this.getZipObjectFromMizPath(mizPath);
|
|
156
|
+
this.mizUpdateMapResourceFile(zip, mapResourceObject);
|
|
157
|
+
const inputZip = await zip.generateAsync({
|
|
158
|
+
type: 'nodebuffer',
|
|
159
|
+
streamFiles: true,
|
|
160
|
+
compression: "DEFLATE",
|
|
161
|
+
compressionOptions: {
|
|
162
|
+
level: 9
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
fs.writeFileSync(mizPath, inputZip);
|
|
114
166
|
}
|
|
115
|
-
}
|
|
116
167
|
|
|
168
|
+
injectFileIntoZipObject(zip, filePath) {
|
|
169
|
+
zip.remove("l10n/DEFAULT/" + path.basename(filePath));
|
|
170
|
+
var stream = fs.createReadStream(filePath);
|
|
171
|
+
zip.file("l10n/DEFAULT/" + path.basename(filePath), stream);
|
|
172
|
+
}
|
|
117
173
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
fs.writeFileSync(mizPath, inputZip);
|
|
130
|
-
}
|
|
174
|
+
mizUpdateMissionDataFile(zip, missionObject) {
|
|
175
|
+
zip.remove("mission");
|
|
176
|
+
let missionLuaT = format(missionObject, {singleQuote: false})
|
|
177
|
+
missionLuaT = missionLuaT
|
|
178
|
+
.split('\n')
|
|
179
|
+
.slice(1, -1)
|
|
180
|
+
.join('\n')
|
|
181
|
+
.slice(0, -1)
|
|
182
|
+
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
183
|
+
zip.file("mission", missionLuaT);
|
|
184
|
+
}
|
|
131
185
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
186
|
+
mizUpdateMapResourceFile(zip, mapResourceObject) {
|
|
187
|
+
zip.remove("l10n/DEFAULT/mapResource");
|
|
188
|
+
let mapResourceLuaT = format(mapResourceObject, {singleQuote: false})
|
|
189
|
+
mapResourceLuaT = mapResourceLuaT
|
|
190
|
+
.split('\n')
|
|
191
|
+
.slice(1, -1)
|
|
192
|
+
.join('\n')
|
|
193
|
+
.slice(0, -1)
|
|
194
|
+
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
195
|
+
zip.file("l10n/DEFAULT/mapResource", mapResourceLuaT);
|
|
196
|
+
}
|
|
137
197
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
missionLuaT = missionLuaT
|
|
142
|
-
.split('\n')
|
|
143
|
-
.slice(1, -1)
|
|
144
|
-
.join('\n')
|
|
145
|
-
.slice(0, -1)
|
|
146
|
-
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
147
|
-
zip.file("mission", missionLuaT);
|
|
148
|
-
}
|
|
198
|
+
getMissionLuaStringFromZipObject(zipStream) {
|
|
199
|
+
return zipStream.file("mission").async("string");
|
|
200
|
+
}
|
|
149
201
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
mapResourceLuaT = mapResourceLuaT
|
|
154
|
-
.split('\n')
|
|
155
|
-
.slice(1, -1)
|
|
156
|
-
.join('\n')
|
|
157
|
-
.slice(0, -1)
|
|
158
|
-
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
159
|
-
zip.file("l10n/DEFAULT/mapResource", mapResourceLuaT);
|
|
160
|
-
}
|
|
202
|
+
getMapResourceLuaStringFromZipObject(zipStream) {
|
|
203
|
+
return zipStream.file("l10n/DEFAULT/mapResource").async("string");
|
|
204
|
+
}
|
|
161
205
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
206
|
+
injectLuaFilesFromFolderIntoZipObject(zip, folderPath) {
|
|
207
|
+
for (let file of fs.readdirSync(folderPath).filter(file => file.endsWith(".lua"))) {
|
|
208
|
+
console.log('injecting up2date ' + folderPath + '/' + file + ' file in archive');
|
|
209
|
+
this.injectFileIntoZipObject(zip, folderPath + "/" + file);
|
|
210
|
+
};
|
|
211
|
+
}
|
|
165
212
|
|
|
166
|
-
function getMapResourceLuaStringFromZipObject(zipStream) {
|
|
167
|
-
return zipStream.file("l10n/DEFAULT/mapResource").async("string");
|
|
168
|
-
}
|
|
169
213
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
214
|
+
async mizUpdateRadioPresets(zip, preset_folder) {
|
|
215
|
+
// Create folder Avionics to make sure it exists then delete it to remove any old preset in the template
|
|
216
|
+
// Allows adding presets for A-10C
|
|
217
|
+
zip.folder("Avionics");
|
|
218
|
+
zip.remove("Avionics");
|
|
176
219
|
|
|
220
|
+
const mission_object = await this.getMissionObjectFromZipObject(zip);
|
|
221
|
+
for (let file of fs.readdirSync(preset_folder).filter(file => file.endsWith(".lua"))) {
|
|
222
|
+
const file_data = fs.readFileSync(preset_folder + '/' + file).toString();
|
|
223
|
+
const lua_string = file_data.substring(0, file_data.indexOf("radio_descriptor_table =") - 1);
|
|
224
|
+
const radio_descriptor_table = parse("return {" + lua_string + "}").descriptor;
|
|
177
225
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
// .slice(1, -1)
|
|
221
|
-
// .join('\n')
|
|
222
|
-
// .slice(0, -1)
|
|
223
|
-
// .replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
224
|
-
// zip_folder.file("SETTINGS.lua", file);
|
|
225
|
-
// });
|
|
226
|
-
// continue;
|
|
227
|
-
// }
|
|
228
|
-
if (sub_unit["type"] != radio_descriptor_table["aircraft"]) continue;
|
|
229
|
-
// GROUP FOUND, SET RADIOS
|
|
230
|
-
sub_unit["Radio"] = parse("return " + dcs_radio_presets)
|
|
226
|
+
console.log('updating radio presets (aircraft: ' + radio_descriptor_table["aircraft"] + ', group_name: ' + radio_descriptor_table["group_name"] + ') with preset in ' + preset_folder + ' folder');
|
|
227
|
+
const dcs_radio_presets = file_data.substring(file_data.indexOf("radio_descriptor_table =") + 24);
|
|
228
|
+
|
|
229
|
+
for (const coalition_key in mission_object.coalition) {
|
|
230
|
+
const coalition = mission_object.coalition[coalition_key];
|
|
231
|
+
for (const country_list_key in coalition) {
|
|
232
|
+
if (country_list_key != "country") continue;
|
|
233
|
+
const country_list = coalition[country_list_key];
|
|
234
|
+
for (const country_key in country_list) {
|
|
235
|
+
const country = country_list[country_key];
|
|
236
|
+
for (const plane_key in country["plane"]) {
|
|
237
|
+
const plane = country["plane"][plane_key];
|
|
238
|
+
for (const group_key in plane) {
|
|
239
|
+
const group = plane[group_key];
|
|
240
|
+
if (group["name"].match(radio_descriptor_table["group_name"]) == null) continue;
|
|
241
|
+
for (const unit_key in group) {
|
|
242
|
+
if (unit_key != "units") continue;
|
|
243
|
+
const unit = group[unit_key];
|
|
244
|
+
for (const sub_unit_key in unit) {
|
|
245
|
+
const sub_unit = unit[sub_unit_key];
|
|
246
|
+
if (sub_unit["skill"] != "Client") continue;
|
|
247
|
+
// Aircraft is an A10CII, use A10C mode by creating files in the root with the unit id
|
|
248
|
+
// if (radio_descriptor_table["aircraft"] == 'A-10C_2') {
|
|
249
|
+
// const unit_id = sub_unit["unitId"];
|
|
250
|
+
// ["UHF_RADIO", "VHF_AM_RADIO", "VHF_FM_RADIO"].forEach(folder => {
|
|
251
|
+
// var zip_folder = zip.folder("Avionics/A-10C_2/" + unit_id + "/" + folder);
|
|
252
|
+
// var file = parse("return " + dcs_radio_presets)[folder];
|
|
253
|
+
// file = format(file, { singleQuote: false });
|
|
254
|
+
// file = file
|
|
255
|
+
// .split('\n')
|
|
256
|
+
// .slice(1, -1)
|
|
257
|
+
// .join('\n')
|
|
258
|
+
// .slice(0, -1)
|
|
259
|
+
// .replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
260
|
+
// zip_folder.file("SETTINGS.lua", file);
|
|
261
|
+
// });
|
|
262
|
+
// continue;
|
|
263
|
+
// }
|
|
264
|
+
if (sub_unit["type"] != radio_descriptor_table["aircraft"]) continue;
|
|
265
|
+
// GROUP FOUND, SET RADIOS
|
|
266
|
+
sub_unit["Radio"] = parse("return " + dcs_radio_presets)
|
|
267
|
+
}
|
|
231
268
|
}
|
|
232
269
|
}
|
|
233
270
|
}
|
|
234
271
|
}
|
|
235
272
|
}
|
|
236
273
|
}
|
|
274
|
+
};
|
|
275
|
+
this.mizUpdateMissionDataFile(zip, {mission: mission_object});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
mizUpdateSettingsLuaFiles(zip, strTheatre) {
|
|
279
|
+
for (let file of fs.readdirSync('settings/' + strTheatre).filter(file => file.endsWith(".lua"))) {
|
|
280
|
+
console.log('updating settings/' + strTheatre + '/' + file + ' file in miz file');
|
|
281
|
+
this.injectFileIntoZipObject(zip, 'settings/' + strTheatre + '/' + file);
|
|
237
282
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
283
|
+
;
|
|
284
|
+
}
|
|
241
285
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
286
|
+
async mizUpdateSoundFolders(zip) {
|
|
287
|
+
if (fs.existsSync('resources/sounds') && fs.lstatSync('resources/sounds').isDirectory()) {
|
|
288
|
+
const folderArray = fs.readdirSync('resources/sounds');
|
|
289
|
+
for (const folder of folderArray) {
|
|
290
|
+
await this.injectSingleSoundFolderIntoZipObject(zip, folder);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
248
294
|
|
|
249
|
-
async
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
295
|
+
async updateWorkspaceWithSingleSoundFolder(workspacePath, folderString) {
|
|
296
|
+
if (
|
|
297
|
+
fs.existsSync(
|
|
298
|
+
[
|
|
299
|
+
workspacePath,
|
|
300
|
+
"/resources/sounds/",
|
|
301
|
+
folderString
|
|
302
|
+
].join("")
|
|
303
|
+
) &&
|
|
304
|
+
fs.lstatSync([
|
|
305
|
+
workspacePath,
|
|
306
|
+
"/resources/sounds/",
|
|
307
|
+
folderString
|
|
308
|
+
].join("")).isDirectory()
|
|
309
|
+
) {
|
|
310
|
+
fs.rmSync([
|
|
311
|
+
workspacePath,
|
|
312
|
+
"/resources/sounds/",
|
|
313
|
+
folderString
|
|
314
|
+
].join(""), {recursive: true});
|
|
315
|
+
}
|
|
316
|
+
if (fs.existsSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString) && fs.lstatSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString).isDirectory()) {
|
|
317
|
+
fs.mkdirSync([
|
|
318
|
+
workspacePath,
|
|
319
|
+
"/resources/sounds/",
|
|
320
|
+
folderString
|
|
321
|
+
].join(""), {recursive: true});
|
|
322
|
+
fs.cpSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString,[
|
|
323
|
+
workspacePath,
|
|
324
|
+
"/resources/sounds/",
|
|
325
|
+
folderString
|
|
326
|
+
].join(""), {recursive: true});
|
|
254
327
|
}
|
|
255
328
|
}
|
|
256
|
-
}
|
|
257
329
|
|
|
258
|
-
async
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
330
|
+
async injectSingleSoundFolderIntoZipObject(zip, folder) {
|
|
331
|
+
if (fs.existsSync('resources/sounds/' + folder) && fs.lstatSync('resources/sounds/' + folder).isDirectory()) {
|
|
332
|
+
console.log('adding sound files from resources/sounds/' + folder + ' folder...');
|
|
333
|
+
zip = zip.remove(folder).folder(folder);
|
|
334
|
+
await this.addFilesToZip(zip, 'resources/sounds/' + folder, fs.readdirSync('resources/sounds/' + folder));
|
|
335
|
+
}
|
|
263
336
|
}
|
|
264
|
-
}
|
|
265
337
|
|
|
266
|
-
async
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
338
|
+
async addFilesToZip(zip, directoryPath, filesToInclude) {
|
|
339
|
+
const promiseArr = await filesToInclude.map(async file => {
|
|
340
|
+
const filePath = path.join(directoryPath, file)
|
|
341
|
+
try {
|
|
342
|
+
const fileStats = await lstat(filePath)
|
|
343
|
+
const isDirectory = fileStats.isDirectory()
|
|
344
|
+
if (isDirectory) {
|
|
345
|
+
const directory = zip.remove(file).folder(file)
|
|
346
|
+
const subFiles = fs.readdirSync(filePath)
|
|
347
|
+
return this.addFilesToZip(directory, filePath, subFiles)
|
|
348
|
+
} else {
|
|
349
|
+
// console.log('added file : '+file);
|
|
350
|
+
return zip.file(file, fs.createReadStream(filePath))
|
|
351
|
+
}
|
|
352
|
+
} catch (err) {
|
|
353
|
+
console.log(err)
|
|
354
|
+
return Promise.resolve()
|
|
279
355
|
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
})
|
|
285
|
-
return Promise.all(promiseArr)
|
|
286
|
-
}
|
|
356
|
+
})
|
|
357
|
+
return Promise.all(promiseArr)
|
|
358
|
+
}
|
|
287
359
|
|
|
288
|
-
async
|
|
289
|
-
|
|
290
|
-
}
|
|
360
|
+
async copyMiz(srcMizPath, dstMizPath) {
|
|
361
|
+
await fs.createReadStream(srcMizPath).pipe(fs.createWriteStream(dstMizPath));
|
|
362
|
+
}
|
|
291
363
|
|
|
292
|
-
async
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
364
|
+
async getMissionObjectFromMizPath(MizPath) {
|
|
365
|
+
let luaTable = 'return { \n' + await this.getMissionLuaStringFromZipObject(await this.getZipObjectFromMizPath(MizPath)) + ' }';
|
|
366
|
+
return parse(luaTable).mission;
|
|
367
|
+
}
|
|
296
368
|
|
|
297
|
-
async
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
369
|
+
async getMissionObjectFromZipObject(zip) {
|
|
370
|
+
let luaTable = 'return { \n' + await this.getMissionLuaStringFromZipObject(zip) + ' }';
|
|
371
|
+
return parse(luaTable).mission;
|
|
372
|
+
}
|
|
301
373
|
|
|
302
|
-
async
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
374
|
+
async getMapResourceObjectFromMizPath(MizPath) {
|
|
375
|
+
let luaTable = 'return { \n' + await this.getMapResourceLuaStringFromZipObject(await this.getZipObjectFromMizPath(MizPath)) + ' }';
|
|
376
|
+
return parse(luaTable).mapResource;
|
|
377
|
+
}
|
|
306
378
|
|
|
307
|
-
async
|
|
308
|
-
|
|
309
|
-
|
|
379
|
+
async getMapResourceObjectFromZipObject(zip) {
|
|
380
|
+
let luaTable = 'return { \n' + await this.getMapResourceLuaStringFromZipObject(zip) + ' }';
|
|
381
|
+
return parse(luaTable).mapResource;
|
|
382
|
+
}
|
|
310
383
|
}
|
|
311
384
|
|
|
312
|
-
module.exports =
|
|
313
|
-
injectLuaScriptsInMissionObject: injectLuaScriptsInMissionObject,
|
|
314
|
-
getZipObjectFromMizPath: getZipObjectFromMizPath,
|
|
315
|
-
mizUpdate: mizUpdate,
|
|
316
|
-
mizInjectMissionDataFile: mizInjectMissionDataFile,
|
|
317
|
-
injectLuaSettingsFromFolderPathToMizPath: injectLuaSettingsFromFolderPathToMizPath,
|
|
318
|
-
injectLuaSettingsFromFolderPathToZipObject: injectLuaSettingsFromFolderPathToZipObject,
|
|
319
|
-
mizInjectMapResourceFile: mizInjectMapResourceFile,
|
|
320
|
-
injectFileIntoZipObject: injectFileIntoZipObject,
|
|
321
|
-
mizUpdateMissionDataFile: mizUpdateMissionDataFile,
|
|
322
|
-
mizUpdateMapResourceFile: mizUpdateMapResourceFile,
|
|
323
|
-
getMissionLuaStringFromZipObject: getMissionLuaStringFromZipObject,
|
|
324
|
-
getMapResourceLuaStringFromZipObject: getMapResourceLuaStringFromZipObject,
|
|
325
|
-
mizUpdateRadioPresets: mizUpdateRadioPresets,
|
|
326
|
-
mizUpdateSettingsLuaFiles: mizUpdateSettingsLuaFiles,
|
|
327
|
-
mizUpdateSoundFolders: mizUpdateSoundFolders,
|
|
328
|
-
mizUpdateSingleSoundFolder: mizUpdateSingleSoundFolder,
|
|
329
|
-
addFilesToZip: addFilesToZip,
|
|
330
|
-
copyMiz: copyMiz,
|
|
331
|
-
getMissionObjectFromMizPath: getMissionObjectFromMizPath,
|
|
332
|
-
getMissionObjectFromZipObject: getMissionObjectFromZipObject,
|
|
333
|
-
getMapResourceObjectFromMizPath: getMapResourceObjectFromMizPath,
|
|
334
|
-
getMapResourceObjectFromZipObject: getMapResourceObjectFromZipObject,
|
|
335
|
-
injectLuaFilesFromFolderIntoZipObject: injectLuaFilesFromFolderIntoZipObject
|
|
336
|
-
};
|
|
385
|
+
module.exports = Mizlib
|