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