@jtff/miztemplate-lib 3.0.0-rc2 → 3.0.0-rc22
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/ci/build.js +6 -0
- package/ci/clean.js +4 -0
- package/ci/ftpupload.js +6 -0
- package/ci/gdrive-upload.js +6 -0
- package/ci/get-mizfiles.js +6 -0
- package/ci/getset-version.js +10 -0
- package/ci/inject-scripts.js +5 -0
- package/ci/prepare-nextversion.js +5 -0
- package/ci/release.js +5 -0
- package/ci/template-update.js +5 -0
- package/index.js +2 -2
- package/lib/jtff-lib-ci.js +74 -2
- package/lib/mizlib.js +385 -284
- package/lua/src/199-skynet.lua +1 -1
- package/package.json +4 -2
- package/resources/radios/Caucasus/354th-caucasus.lua +124 -0
- package/resources/radios/Caucasus/494th-caucasus.lua +91 -0
- package/resources/radios/Caucasus/79th-SUFA-caucasus.lua +65 -0
- package/resources/radios/Caucasus/79th-caucasus.lua +65 -0
- package/resources/radios/Caucasus/ec25-D-caucasus.lua +65 -0
- package/resources/radios/Caucasus/ec25-caucasus.lua +65 -0
- package/resources/radios/Caucasus/vf84-a-caucasus.lua +75 -0
- package/resources/radios/Caucasus/vf84-b-caucasus.lua +75 -0
- package/resources/radios/Caucasus/vfa-131-caucasus.lua +65 -0
- package/resources/radios/Caucasus/vmfa-314-caucasus.lua +65 -0
- package/resources/radios/Mariana/354th-marianas.lua +124 -0
- package/resources/radios/Mariana/494th-marianas.lua +91 -0
- package/resources/radios/Mariana/79th-marianas.lua +65 -0
- package/resources/radios/Mariana/ec25-marianas.lua +65 -0
- package/resources/radios/Mariana/vf84-a-marianas.lua +75 -0
- package/resources/radios/Mariana/vf84-b-marianas.lua +75 -0
- package/resources/radios/Mariana/vfa-131-marianas.lua +65 -0
- package/resources/radios/Mariana/vmfa-314-marianas.lua +65 -0
- package/resources/radios/NTTR/354th-nttr.lua +124 -0
- package/resources/radios/NTTR/494th-nttr.lua +91 -0
- package/resources/radios/NTTR/79th-nttr.lua +65 -0
- package/resources/radios/NTTR/ec25-nttr.lua +65 -0
- package/resources/radios/NTTR/vf84-a-nttr.lua +75 -0
- package/resources/radios/NTTR/vf84-b-nttr.lua +75 -0
- package/resources/radios/NTTR/vfa-131-nttr.lua +65 -0
- package/resources/radios/NTTR/vmfa-314-nttr.lua +65 -0
- package/resources/radios/PersianGulf/354th-persian.lua +124 -0
- package/resources/radios/PersianGulf/3_30-persian.lua +65 -0
- package/resources/radios/PersianGulf/494th-persian.lua +91 -0
- package/resources/radios/PersianGulf/79th-persian.lua +65 -0
- package/resources/radios/PersianGulf/ec25-persian.lua +65 -0
- package/resources/radios/PersianGulf/vf84-a-persian.lua +75 -0
- package/resources/radios/PersianGulf/vf84-b-persian.lua +75 -0
- package/resources/radios/PersianGulf/vfa-131-persian.lua +65 -0
- package/resources/radios/PersianGulf/vmfa-314-persian.lua +65 -0
- package/resources/radios/SinaiMap/354th-sinai.lua +124 -0
- package/resources/radios/SinaiMap/494th-sinai.lua +91 -0
- package/resources/radios/SinaiMap/79th-SUFA-sinai.lua +65 -0
- package/resources/radios/SinaiMap/79th-sinai.lua +65 -0
- package/resources/radios/SinaiMap/ec25-D-sinai.lua +65 -0
- package/resources/radios/SinaiMap/ec25-sinai.lua +65 -0
- package/resources/radios/SinaiMap/vf84-a-sinai.lua +75 -0
- package/resources/radios/SinaiMap/vf84-b-sinai.lua +75 -0
- package/resources/radios/SinaiMap/vfa-131-sinai.lua +65 -0
- package/resources/radios/SinaiMap/vmfa-314-sinai.lua +65 -0
- package/resources/radios/Syria/354th-syria.lua +124 -0
- package/resources/radios/Syria/494th-syria.lua +91 -0
- package/resources/radios/Syria/79th-SUFA-syria.lua +65 -0
- package/resources/radios/Syria/79th-syria.lua +65 -0
- package/resources/radios/Syria/ec25-D-syria.lua +65 -0
- package/resources/radios/Syria/ec25-syria.lua +65 -0
- package/resources/radios/Syria/vf84-a-syria.lua +75 -0
- package/resources/radios/Syria/vf84-b-syria.lua +75 -0
- package/resources/radios/Syria/vfa-131-syria.lua +65 -0
- package/resources/radios/Syria/vmfa-314-syria.lua +65 -0
- package/scripts/build.js +15 -18
- package/scripts/inject-scripts.js +272 -355
- package/scripts/template-update.js +1 -1
- package/resources/radios/.gitkeep +0 -0
package/lib/mizlib.js
CHANGED
|
@@ -7,331 +7,432 @@ const {promisify} = require("util");
|
|
|
7
7
|
const fs = require("fs");
|
|
8
8
|
const lstat = promisify(fs.lstat);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
tObject['actions'] = {};
|
|
14
|
-
tObject['func'] = {};
|
|
15
|
-
tObject['conditions'] = {};
|
|
16
|
-
tObject['flag'] = {};
|
|
17
|
-
trObject = {};
|
|
10
|
+
class Mizlib {
|
|
11
|
+
constructor() {
|
|
12
|
+
// no need for initialization
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
|
|
15
|
+
async injectLuaScriptIntoZipObjectAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, zipObject, timing, colorString, fromLibrary=true) {
|
|
16
|
+
let missionObject = await this.getMissionObjectFromZipObject(zipObject);
|
|
17
|
+
let mapResourceObject = await this.getMapResourceObjectFromZipObject(zipObject);
|
|
18
|
+
let tuple = this.injectLuaScriptAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, missionObject, mapResourceObject, timing, colorString, fromLibrary);
|
|
19
|
+
for (let luaScript of luaScriptsArray) {
|
|
20
|
+
this.injectFileIntoZipObject(zipObject, [
|
|
21
|
+
workspacePath,
|
|
22
|
+
fromLibrary ? "/.workspace/" : "/",
|
|
23
|
+
folderPath,
|
|
24
|
+
"/",
|
|
25
|
+
path.basename(luaScript)
|
|
26
|
+
].join("")
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return {tuple, zipObject};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
injectLuaScriptAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, missionObject, mapResourceObject, timing, colorString ,fromLibrary=true) {
|
|
33
|
+
let tuple = this.injectLuaScriptsInMissionObject(
|
|
34
|
+
missionObject['trig'],
|
|
35
|
+
missionObject['trigrules'],
|
|
36
|
+
mapResourceObject,
|
|
37
|
+
titleString,
|
|
38
|
+
luaScriptsArray,
|
|
39
|
+
timing,
|
|
40
|
+
colorString
|
|
41
|
+
);
|
|
42
|
+
for (let luaScript of luaScriptsArray) {
|
|
43
|
+
fs.cpSync(
|
|
44
|
+
[
|
|
45
|
+
'node_modules/@jtff/miztemplate-lib/lua/',
|
|
46
|
+
folderPath,
|
|
47
|
+
'/',
|
|
48
|
+
luaScript
|
|
49
|
+
].join(""),
|
|
50
|
+
[
|
|
51
|
+
workspacePath,
|
|
52
|
+
fromLibrary ? "/.workspace/" : "/",
|
|
53
|
+
folderPath,
|
|
54
|
+
"/",
|
|
55
|
+
path.basename(luaScript)
|
|
56
|
+
].join(""),
|
|
57
|
+
{force: true}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return tuple;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
injectLuaScriptsInMissionObject(tObject, trObject, mrObject, strTitle, scriptFilesArray, timingInSeconds, hexColor) {
|
|
64
|
+
let nextIndex = Object.keys(trObject).length + 1;
|
|
65
|
+
if (nextIndex === 1) {
|
|
66
|
+
tObject['actions'] = {};
|
|
67
|
+
tObject['func'] = {};
|
|
68
|
+
tObject['conditions'] = {};
|
|
69
|
+
tObject['flag'] = {};
|
|
70
|
+
trObject = {};
|
|
71
|
+
}
|
|
72
|
+
let actionSentence = "";
|
|
73
|
+
let actionsObject = {};
|
|
74
|
+
for (const [index, scriptFile] of scriptFilesArray.entries()) {
|
|
75
|
+
actionSentence += "a_do_script_file(getValueResourceByKey(\"" + scriptFile + "\")); "
|
|
76
|
+
actionsObject[index + 1] = {
|
|
77
|
+
file: scriptFile,
|
|
78
|
+
predicate: 'a_do_script_file',
|
|
79
|
+
};
|
|
80
|
+
mrObject[scriptFile] = scriptFile;
|
|
81
|
+
}
|
|
82
|
+
actionSentence += "mission.trig.func[" + nextIndex + "]=nil;"
|
|
83
|
+
tObject['actions'][nextIndex] = actionSentence;
|
|
84
|
+
tObject['func'][nextIndex] = "if mission.trig.conditions[" + nextIndex + "]() then mission.trig.actions[" + nextIndex + "]() end";
|
|
85
|
+
tObject['conditions'][nextIndex] = "return(c_time_after(" + timingInSeconds + ") )";
|
|
86
|
+
tObject['flag'][nextIndex] = true;
|
|
87
|
+
trObject[nextIndex] = {
|
|
88
|
+
rules: {
|
|
89
|
+
1: {
|
|
90
|
+
coalitionlist: 'red',
|
|
91
|
+
seconds: timingInSeconds,
|
|
92
|
+
predicate: 'c_time_after',
|
|
93
|
+
zone: ''
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
eventlist: '',
|
|
97
|
+
comment: strTitle,
|
|
98
|
+
actions: actionsObject,
|
|
99
|
+
predicate: 'triggerOnce',
|
|
100
|
+
colorItem: hexColor
|
|
26
101
|
};
|
|
27
|
-
mrObject
|
|
102
|
+
return {tObject: tObject, trObject: trObject, mrObject: mrObject};
|
|
28
103
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
104
|
+
|
|
105
|
+
async getZipObjectFromMizPath(mizPath) {
|
|
106
|
+
var MizFile = new jszip();
|
|
107
|
+
const mizData = fs.readFileSync(mizPath);
|
|
108
|
+
return MizFile.loadAsync(mizData);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async buildMizFileFromMizTemplate(mizPath, copyPath, singleMission= true) {
|
|
112
|
+
const zipObject = await this.getZipObjectFromMizPath(mizPath);
|
|
113
|
+
const missionObject = await this.getMissionObjectFromZipObject(zipObject);
|
|
114
|
+
const strTheatreSettings = missionObject.theatre;
|
|
115
|
+
const srcFiles = fs.readdirSync("node_modules/@jtff/miztemplate-lib/lua/src",{recursive: true})
|
|
116
|
+
.filter(filename => path.extname(filename).toLowerCase()==='.lua' && !(filename.startsWith('200-')));
|
|
117
|
+
const libFiles = fs.readdirSync("node_modules/@jtff/miztemplate-lib/lua/lib",{recursive: true})
|
|
118
|
+
.filter(filename => path.extname(filename).toLowerCase()==='.lua');
|
|
119
|
+
for (let file of srcFiles) {
|
|
120
|
+
console.log('updating src/' + file + ' from the miztemplate-lib');
|
|
121
|
+
fs.cpSync('node_modules/@jtff/miztemplate-lib/lua/src/' + file,
|
|
122
|
+
'.workspace/src/' + file,
|
|
123
|
+
{force: true}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
for (let file of libFiles) {
|
|
127
|
+
console.log('updating lib/' + file + ' from the miztemplate-lib');
|
|
128
|
+
fs.cpSync('node_modules/@jtff/miztemplate-lib/lua/lib/' + file,
|
|
129
|
+
'.workspace/lib/' + file,
|
|
130
|
+
{force: true}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
this.injectLuaFilesFromFolderIntoZipObject(zipObject, '.workspace/src');
|
|
134
|
+
this.injectLuaFilesFromFolderIntoZipObject(zipObject, '.workspace/lib');
|
|
135
|
+
this.injectLuaFilesFromFolderIntoZipObject(zipObject, 'src');
|
|
136
|
+
await this.injectRadioPresetsFromFolderIntoZipObject(zipObject, 'resources/radios/' + strTheatreSettings);
|
|
137
|
+
this.injectSettingsLuaFilesFromFolderIntoZipObject(zipObject, singleMission ? '' : strTheatreSettings);
|
|
138
|
+
await this.injectSoundFoldersIntoZipObject(zipObject);
|
|
139
|
+
const inputZip = await zipObject.generateAsync({
|
|
140
|
+
type: 'nodebuffer',
|
|
141
|
+
streamFiles: true,
|
|
142
|
+
compression: "DEFLATE",
|
|
143
|
+
compressionOptions: {
|
|
144
|
+
level: 9
|
|
41
145
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
actions: actionsObject,
|
|
46
|
-
predicate: 'triggerOnce',
|
|
47
|
-
colorItem: hexColor
|
|
48
|
-
};
|
|
49
|
-
return { tObject: tObject, trObject: trObject, mrObject: mrObject };
|
|
50
|
-
}
|
|
146
|
+
});
|
|
147
|
+
fs.writeFileSync(copyPath ? copyPath : mizPath, inputZip);
|
|
148
|
+
}
|
|
51
149
|
|
|
52
|
-
async
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
150
|
+
async injectMissionObjectIntoMizFile(mizPath, missionObject) {
|
|
151
|
+
const zip = this.injectMissionObjectIntoZipObject(await this.getZipObjectFromMizPath(mizPath), missionObject);
|
|
152
|
+
const inputZip = await zip.generateAsync({
|
|
153
|
+
type: 'nodebuffer',
|
|
154
|
+
streamFiles: true,
|
|
155
|
+
compression: "DEFLATE",
|
|
156
|
+
compressionOptions: {
|
|
157
|
+
level: 9
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
fs.writeFileSync(mizPath, inputZip);
|
|
161
|
+
}
|
|
57
162
|
|
|
58
|
-
async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
163
|
+
async injectLuaSettingsFromFolderPathToMizPath(mizPath, settingsFolder) {
|
|
164
|
+
const zip = await this.getZipObjectFromMizPath(mizPath);
|
|
165
|
+
await this.injectLuaSettingsFromFolderPathToZipObject(zip, settingsFolder);
|
|
166
|
+
const outputZip = await zip.generateAsync({
|
|
167
|
+
type: 'nodebuffer',
|
|
168
|
+
streamFiles: true,
|
|
169
|
+
compression: "DEFLATE",
|
|
170
|
+
compressionOptions: {
|
|
171
|
+
level: 9
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
fs.writeFileSync(mizPath, outputZip);
|
|
67
175
|
}
|
|
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
176
|
|
|
81
|
-
async
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
compression: "DEFLATE",
|
|
88
|
-
compressionOptions: {
|
|
89
|
-
level: 9
|
|
177
|
+
async injectLuaSettingsFromFolderPathToZipObject(zip, settingsFolder) {
|
|
178
|
+
for (let file of fs.readdirSync(settingsFolder).filter(file => file.endsWith(".lua"))) {
|
|
179
|
+
this.injectFileIntoZipObject(zip, [
|
|
180
|
+
settingsFolder,
|
|
181
|
+
"/",
|
|
182
|
+
file].join(""));
|
|
90
183
|
}
|
|
91
|
-
}
|
|
92
|
-
fs.writeFileSync(mizPath, inputZip);
|
|
93
|
-
}
|
|
184
|
+
}
|
|
94
185
|
|
|
95
|
-
async function injectLuaSettingsFromFolderPathToMizPath(mizPath, settingsFolder) {
|
|
96
|
-
const zip = await getZipObjectFromMizPath(mizPath);
|
|
97
|
-
await injectLuaSettingsFromFolderPathToZipObject(zip,settingsFolder);
|
|
98
|
-
const outputZip = await zip.generateAsync({
|
|
99
|
-
type: 'nodebuffer',
|
|
100
|
-
streamFiles: true,
|
|
101
|
-
compression: "DEFLATE",
|
|
102
|
-
compressionOptions: {
|
|
103
|
-
level: 9
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
fs.writeFileSync(mizPath, outputZip);
|
|
107
|
-
}
|
|
108
186
|
|
|
109
|
-
async
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
187
|
+
async injectMapResourceObjectIntoMizFile(mizPath, mapResourceObject) {
|
|
188
|
+
const zip = await this.getZipObjectFromMizPath(mizPath);
|
|
189
|
+
this.injectMapResourceObjectIntoZipObject(zip, mapResourceObject);
|
|
190
|
+
const inputZip = await zip.generateAsync({
|
|
191
|
+
type: 'nodebuffer',
|
|
192
|
+
streamFiles: true,
|
|
193
|
+
compression: "DEFLATE",
|
|
194
|
+
compressionOptions: {
|
|
195
|
+
level: 9
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
fs.writeFileSync(mizPath, inputZip);
|
|
115
199
|
}
|
|
116
|
-
}
|
|
117
200
|
|
|
201
|
+
injectFileIntoZipObject(zip, filePath) {
|
|
202
|
+
zip.remove("l10n/DEFAULT/" + path.basename(filePath));
|
|
203
|
+
var stream = fs.createReadStream(filePath);
|
|
204
|
+
zip.file("l10n/DEFAULT/" + path.basename(filePath), stream);
|
|
205
|
+
}
|
|
118
206
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
fs.writeFileSync(mizPath, inputZip);
|
|
131
|
-
}
|
|
207
|
+
injectMissionObjectIntoZipObject(zip, missionObject) {
|
|
208
|
+
zip.remove("mission");
|
|
209
|
+
let missionLuaT = format(missionObject, {singleQuote: false})
|
|
210
|
+
missionLuaT = missionLuaT
|
|
211
|
+
.split('\n')
|
|
212
|
+
.slice(1, -1)
|
|
213
|
+
.join('\n')
|
|
214
|
+
.slice(0, -1)
|
|
215
|
+
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
216
|
+
zip.file("mission", missionLuaT);
|
|
217
|
+
}
|
|
132
218
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
219
|
+
injectMapResourceObjectIntoZipObject(zip, mapResourceObject) {
|
|
220
|
+
zip.remove("l10n/DEFAULT/mapResource");
|
|
221
|
+
let mapResourceLuaT = format(mapResourceObject, {singleQuote: false})
|
|
222
|
+
mapResourceLuaT = mapResourceLuaT
|
|
223
|
+
.split('\n')
|
|
224
|
+
.slice(1, -1)
|
|
225
|
+
.join('\n')
|
|
226
|
+
.slice(0, -1)
|
|
227
|
+
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
228
|
+
zip.file("l10n/DEFAULT/mapResource", mapResourceLuaT);
|
|
229
|
+
}
|
|
138
230
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
missionLuaT = missionLuaT
|
|
143
|
-
.split('\n')
|
|
144
|
-
.slice(1, -1)
|
|
145
|
-
.join('\n')
|
|
146
|
-
.slice(0, -1)
|
|
147
|
-
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
148
|
-
zip.file("mission", missionLuaT);
|
|
149
|
-
}
|
|
231
|
+
getMissionLuaStringFromZipObject(zipStream) {
|
|
232
|
+
return zipStream.file("mission").async("string");
|
|
233
|
+
}
|
|
150
234
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
mapResourceLuaT = mapResourceLuaT
|
|
155
|
-
.split('\n')
|
|
156
|
-
.slice(1, -1)
|
|
157
|
-
.join('\n')
|
|
158
|
-
.slice(0, -1)
|
|
159
|
-
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
160
|
-
zip.file("l10n/DEFAULT/mapResource", mapResourceLuaT);
|
|
161
|
-
}
|
|
235
|
+
getMapResourceLuaStringFromZipObject(zipStream) {
|
|
236
|
+
return zipStream.file("l10n/DEFAULT/mapResource").async("string");
|
|
237
|
+
}
|
|
162
238
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
239
|
+
injectLuaFilesFromFolderIntoZipObject(zip, folderPath) {
|
|
240
|
+
for (let file of fs.readdirSync(folderPath).filter(file => file.endsWith(".lua"))) {
|
|
241
|
+
console.log('injecting up2date ' + folderPath + '/' + file + ' file in archive');
|
|
242
|
+
this.injectFileIntoZipObject(zip, folderPath + "/" + file);
|
|
243
|
+
};
|
|
244
|
+
}
|
|
166
245
|
|
|
167
|
-
function getMapResourceLuaStringFromZipObject(zipStream) {
|
|
168
|
-
return zipStream.file("l10n/DEFAULT/mapResource").async("string");
|
|
169
|
-
}
|
|
170
246
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
247
|
+
async injectRadioPresetsFromFolderIntoZipObject(zip, preset_folder) {
|
|
248
|
+
// Create folder Avionics to make sure it exists then delete it to remove any old preset in the template
|
|
249
|
+
// Allows adding presets for A-10C
|
|
250
|
+
zip.folder("Avionics");
|
|
251
|
+
zip.remove("Avionics");
|
|
252
|
+
|
|
253
|
+
const mission_object = await this.getMissionObjectFromZipObject(zip);
|
|
254
|
+
for (let file of fs.readdirSync(preset_folder).filter(file => file.endsWith(".lua"))) {
|
|
255
|
+
const file_data = fs.readFileSync(preset_folder + '/' + file).toString();
|
|
256
|
+
const lua_string = file_data.substring(0, file_data.indexOf("radio_descriptor_table =") - 1);
|
|
257
|
+
const radio_descriptor_table = parse("return {" + lua_string + "}").descriptor;
|
|
177
258
|
|
|
259
|
+
console.log('updating radio presets (aircraft: ' + radio_descriptor_table["aircraft"] + ', group_name: ' + radio_descriptor_table["group_name"] + ') with preset in ' + preset_folder + ' folder');
|
|
260
|
+
const dcs_radio_presets = file_data.substring(file_data.indexOf("radio_descriptor_table =") + 24);
|
|
178
261
|
|
|
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
|
-
// file = format(file, { singleQuote: false });
|
|
219
|
-
// file = file
|
|
220
|
-
// .split('\n')
|
|
221
|
-
// .slice(1, -1)
|
|
222
|
-
// .join('\n')
|
|
223
|
-
// .slice(0, -1)
|
|
224
|
-
// .replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
225
|
-
// zip_folder.file("SETTINGS.lua", file);
|
|
226
|
-
// });
|
|
227
|
-
// continue;
|
|
228
|
-
// }
|
|
229
|
-
if (sub_unit["type"] != radio_descriptor_table["aircraft"]) continue;
|
|
230
|
-
// GROUP FOUND, SET RADIOS
|
|
231
|
-
sub_unit["Radio"] = parse("return " + dcs_radio_presets)
|
|
262
|
+
for (const coalition_key in mission_object.coalition) {
|
|
263
|
+
const coalition = mission_object.coalition[coalition_key];
|
|
264
|
+
for (const country_list_key in coalition) {
|
|
265
|
+
if (country_list_key != "country") continue;
|
|
266
|
+
const country_list = coalition[country_list_key];
|
|
267
|
+
for (const country_key in country_list) {
|
|
268
|
+
const country = country_list[country_key];
|
|
269
|
+
for (const plane_key in country["plane"]) {
|
|
270
|
+
const plane = country["plane"][plane_key];
|
|
271
|
+
for (const group_key in plane) {
|
|
272
|
+
const group = plane[group_key];
|
|
273
|
+
if (group["name"].match(radio_descriptor_table["group_name"]) == null) continue;
|
|
274
|
+
for (const unit_key in group) {
|
|
275
|
+
if (unit_key != "units") continue;
|
|
276
|
+
const unit = group[unit_key];
|
|
277
|
+
for (const sub_unit_key in unit) {
|
|
278
|
+
const sub_unit = unit[sub_unit_key];
|
|
279
|
+
if (sub_unit["skill"] != "Client") continue;
|
|
280
|
+
// Aircraft is an A10CII, use A10C mode by creating files in the root with the unit id
|
|
281
|
+
// if (radio_descriptor_table["aircraft"] == 'A-10C_2') {
|
|
282
|
+
// const unit_id = sub_unit["unitId"];
|
|
283
|
+
// ["UHF_RADIO", "VHF_AM_RADIO", "VHF_FM_RADIO"].forEach(folder => {
|
|
284
|
+
// var zip_folder = zip.folder("Avionics/A-10C_2/" + unit_id + "/" + folder);
|
|
285
|
+
// var file = parse("return " + dcs_radio_presets)[folder];
|
|
286
|
+
// file = format(file, { singleQuote: false });
|
|
287
|
+
// file = file
|
|
288
|
+
// .split('\n')
|
|
289
|
+
// .slice(1, -1)
|
|
290
|
+
// .join('\n')
|
|
291
|
+
// .slice(0, -1)
|
|
292
|
+
// .replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
293
|
+
// zip_folder.file("SETTINGS.lua", file);
|
|
294
|
+
// });
|
|
295
|
+
// continue;
|
|
296
|
+
// }
|
|
297
|
+
if (sub_unit["type"] != radio_descriptor_table["aircraft"]) continue;
|
|
298
|
+
// GROUP FOUND, SET RADIOS
|
|
299
|
+
sub_unit["Radio"] = parse("return " + dcs_radio_presets)
|
|
300
|
+
}
|
|
232
301
|
}
|
|
233
302
|
}
|
|
234
303
|
}
|
|
235
304
|
}
|
|
236
305
|
}
|
|
237
306
|
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
307
|
+
};
|
|
308
|
+
this.injectMissionObjectIntoZipObject(zip, {mission: mission_object});
|
|
309
|
+
}
|
|
242
310
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
311
|
+
injectSettingsLuaFilesFromFolderIntoZipObject(zip, strTheatre) {
|
|
312
|
+
for (let file of fs.readdirSync(['settings',strTheatre.length > 0 ? '/' + strTheatre : ''].join('')).filter(file => path.extname(file).toLowerCase()==='.lua')) {
|
|
313
|
+
console.log(['updating settings',strTheatre.length > 0 ? '/' + strTheatre : '','/',file,' file in miz file'].join(''));
|
|
314
|
+
this.injectFileIntoZipObject(zip, ['settings',strTheatre.length > 0 ? '/' + strTheatre : '','/',file].join(''));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
249
317
|
|
|
250
|
-
async
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
318
|
+
async injectSoundFoldersIntoZipObject(zip) {
|
|
319
|
+
if (fs.existsSync('resources/sounds') && fs.lstatSync('resources/sounds').isDirectory()) {
|
|
320
|
+
const folderArray = fs.readdirSync('resources/sounds');
|
|
321
|
+
for (const folder of folderArray) {
|
|
322
|
+
await this.injectSingleSoundFolderIntoZipObject(zip, '.', folder, false);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (fs.existsSync('.workspace/resources/sounds') && fs.lstatSync('.workspace/resources/sounds').isDirectory()) {
|
|
326
|
+
const folderArray = fs.readdirSync('.workspace/resources/sounds');
|
|
327
|
+
for (const folder of folderArray) {
|
|
328
|
+
await this.injectSingleSoundFolderIntoZipObject(zip, '.', folder, true);
|
|
329
|
+
}
|
|
255
330
|
}
|
|
256
331
|
}
|
|
257
|
-
}
|
|
258
332
|
|
|
259
|
-
async
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
333
|
+
async updateWorkspaceWithSingleSoundFolder(workspacePath, folderString) {
|
|
334
|
+
if (
|
|
335
|
+
fs.existsSync(
|
|
336
|
+
[
|
|
337
|
+
workspacePath,
|
|
338
|
+
"/.workspace/resources/sounds/",
|
|
339
|
+
folderString
|
|
340
|
+
].join("")
|
|
341
|
+
) &&
|
|
342
|
+
fs.lstatSync([
|
|
343
|
+
workspacePath,
|
|
344
|
+
"/.workspace/resources/sounds/",
|
|
345
|
+
folderString
|
|
346
|
+
].join("")).isDirectory()
|
|
347
|
+
) {
|
|
348
|
+
fs.rmSync([
|
|
349
|
+
workspacePath,
|
|
350
|
+
"/.workspace/resources/sounds/",
|
|
351
|
+
folderString
|
|
352
|
+
].join(""), {recursive: true});
|
|
353
|
+
}
|
|
354
|
+
if (
|
|
355
|
+
fs.existsSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString) &&
|
|
356
|
+
fs.lstatSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString).isDirectory()) {
|
|
357
|
+
fs.mkdirSync([
|
|
358
|
+
workspacePath,
|
|
359
|
+
"/.workspace/resources/sounds/",
|
|
360
|
+
folderString
|
|
361
|
+
].join(""), {recursive: true});
|
|
362
|
+
fs.cpSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString,[
|
|
363
|
+
workspacePath,
|
|
364
|
+
"/.workspace/resources/sounds/",
|
|
365
|
+
folderString
|
|
366
|
+
].join(""), {recursive: true});
|
|
367
|
+
}
|
|
264
368
|
}
|
|
265
|
-
}
|
|
266
369
|
|
|
267
|
-
async
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const directory = zip.remove(file).folder(file)
|
|
275
|
-
const subFiles = fs.readdirSync(filePath)
|
|
276
|
-
return addFilesToZip(directory, filePath, subFiles)
|
|
277
|
-
} else {
|
|
278
|
-
// console.log('added file : '+file);
|
|
279
|
-
return zip.file(file, fs.createReadStream(filePath))
|
|
370
|
+
async injectSingleSoundFolderIntoZipObject(zip, workspacePath, folder, fromLibrary = true) {
|
|
371
|
+
if (
|
|
372
|
+
fs.existsSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/'+folder : '/resources/sounds'].join('')) &&
|
|
373
|
+
fs.lstatSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/'+folder : '/resources/sounds'].join('')).isDirectory()) {
|
|
374
|
+
console.log(['adding sound files from ',workspacePath,fromLibrary? '/.workspace/resources/sounds/'+folder : '/resources/sounds',' folder...'].join(''));
|
|
375
|
+
if (fromLibrary) {
|
|
376
|
+
zip = zip.remove(folder).folder(folder);
|
|
280
377
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
378
|
+
await this.addFilesToZip(
|
|
379
|
+
zip,
|
|
380
|
+
[workspacePath,fromLibrary? '/.workspace/resources/sounds/'+folder : '/resources/sounds'].join(''),
|
|
381
|
+
fs.readdirSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/'+folder : '/resources/sounds'].join('')));
|
|
284
382
|
}
|
|
285
|
-
}
|
|
286
|
-
return Promise.all(promiseArr)
|
|
287
|
-
}
|
|
383
|
+
}
|
|
288
384
|
|
|
289
|
-
async
|
|
290
|
-
|
|
291
|
-
|
|
385
|
+
async addFilesToZip(zip, directoryPath, filesToInclude) {
|
|
386
|
+
const promiseArr = await filesToInclude.map(async file => {
|
|
387
|
+
const filePath = path.join(directoryPath, file)
|
|
388
|
+
try {
|
|
389
|
+
const fileStats = await lstat(filePath)
|
|
390
|
+
const isDirectory = fileStats.isDirectory()
|
|
391
|
+
if (isDirectory) {
|
|
392
|
+
const directory = zip.remove(file).folder(file)
|
|
393
|
+
const subFiles = fs.readdirSync(filePath)
|
|
394
|
+
return this.addFilesToZip(directory, filePath, subFiles)
|
|
395
|
+
} else {
|
|
396
|
+
// console.log('added file : '+file);
|
|
397
|
+
return zip.file(file, fs.createReadStream(filePath))
|
|
398
|
+
}
|
|
399
|
+
} catch (err) {
|
|
400
|
+
console.log(err)
|
|
401
|
+
return Promise.resolve()
|
|
402
|
+
}
|
|
403
|
+
})
|
|
404
|
+
return Promise.all(promiseArr)
|
|
405
|
+
}
|
|
292
406
|
|
|
293
|
-
async
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
407
|
+
async copyMiz(srcMizPath, dstMizPath) {
|
|
408
|
+
await fs.createReadStream(srcMizPath).pipe(fs.createWriteStream(dstMizPath));
|
|
409
|
+
}
|
|
297
410
|
|
|
298
|
-
async
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
411
|
+
async getMissionObjectFromMizPath(MizPath) {
|
|
412
|
+
let luaTable = 'return { \n' + await this.getMissionLuaStringFromZipObject(await this.getZipObjectFromMizPath(MizPath)) + ' }';
|
|
413
|
+
return parse(luaTable).mission;
|
|
414
|
+
}
|
|
302
415
|
|
|
303
|
-
async
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
416
|
+
async getMissionObjectFromZipObject(zip) {
|
|
417
|
+
let luaTable = 'return { \n' + await this.getMissionLuaStringFromZipObject(zip) + ' }';
|
|
418
|
+
return parse(luaTable).mission;
|
|
419
|
+
}
|
|
307
420
|
|
|
308
|
-
async
|
|
309
|
-
|
|
310
|
-
|
|
421
|
+
async getMapResourceObjectFromMizPath(MizPath) {
|
|
422
|
+
let luaTable = 'return { \n' + await this.getMapResourceLuaStringFromZipObject(await this.getZipObjectFromMizPath(MizPath)) + ' }';
|
|
423
|
+
return parse(luaTable).mapResource;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
async getMapResourceObjectFromZipObject(zip) {
|
|
427
|
+
let luaTable = 'return { \n' + await this.getMapResourceLuaStringFromZipObject(zip) + ' }';
|
|
428
|
+
let mrObject = parse(luaTable).mapResource;
|
|
429
|
+
if (Array.isArray(mrObject)) {
|
|
430
|
+
if (mrObject.length === 0) {
|
|
431
|
+
mrObject = {};
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return mrObject;
|
|
435
|
+
}
|
|
311
436
|
}
|
|
312
437
|
|
|
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
|
-
};
|
|
438
|
+
module.exports = Mizlib;
|