@jtff/miztemplate-lib 3.0.0-rc2 → 3.0.0-rc20
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 +376 -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 +281 -355
- package/scripts/template-update.js +1 -1
- package/resources/radios/.gitkeep +0 -0
package/lib/mizlib.js
CHANGED
|
@@ -7,331 +7,423 @@ 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
|
+
'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
|
+
'lib/' + file,
|
|
130
|
+
{force: true}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
this.injectLuaFilesFromFolderIntoZipObject(zipObject, 'src');
|
|
134
|
+
this.injectLuaFilesFromFolderIntoZipObject(zipObject, 'lib');
|
|
135
|
+
zipObject = await this.injectRadioPresetsFromFolderIntoZipObject(zipObject, 'resources/radios/' + strTheatreSettings);
|
|
136
|
+
this.injectSettingsLuaFilesFromFolderIntoZipObject(zipObject, singleMission ? '' : strTheatreSettings);
|
|
137
|
+
await this.injectSoundFoldersIntoZipObject(zipObject);
|
|
138
|
+
const inputZip = await zipObject.generateAsync({
|
|
139
|
+
type: 'nodebuffer',
|
|
140
|
+
streamFiles: true,
|
|
141
|
+
compression: "DEFLATE",
|
|
142
|
+
compressionOptions: {
|
|
143
|
+
level: 9
|
|
41
144
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
actions: actionsObject,
|
|
46
|
-
predicate: 'triggerOnce',
|
|
47
|
-
colorItem: hexColor
|
|
48
|
-
};
|
|
49
|
-
return { tObject: tObject, trObject: trObject, mrObject: mrObject };
|
|
50
|
-
}
|
|
145
|
+
});
|
|
146
|
+
fs.writeFileSync(copyPath ? copyPath : mizPath, inputZip);
|
|
147
|
+
}
|
|
51
148
|
|
|
52
|
-
async
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
149
|
+
async injectMissionObjectIntoMizFile(mizPath, missionObject) {
|
|
150
|
+
const zip = this.injectMissionObjectIntoZipObject(await this.getZipObjectFromMizPath(mizPath), missionObject);
|
|
151
|
+
const inputZip = await zip.generateAsync({
|
|
152
|
+
type: 'nodebuffer',
|
|
153
|
+
streamFiles: true,
|
|
154
|
+
compression: "DEFLATE",
|
|
155
|
+
compressionOptions: {
|
|
156
|
+
level: 9
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
fs.writeFileSync(mizPath, inputZip);
|
|
160
|
+
}
|
|
57
161
|
|
|
58
|
-
async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
162
|
+
async injectLuaSettingsFromFolderPathToMizPath(mizPath, settingsFolder) {
|
|
163
|
+
const zip = await this.getZipObjectFromMizPath(mizPath);
|
|
164
|
+
await this.injectLuaSettingsFromFolderPathToZipObject(zip, settingsFolder);
|
|
165
|
+
const outputZip = await zip.generateAsync({
|
|
166
|
+
type: 'nodebuffer',
|
|
167
|
+
streamFiles: true,
|
|
168
|
+
compression: "DEFLATE",
|
|
169
|
+
compressionOptions: {
|
|
170
|
+
level: 9
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
fs.writeFileSync(mizPath, outputZip);
|
|
67
174
|
}
|
|
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
175
|
|
|
81
|
-
async
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
compression: "DEFLATE",
|
|
88
|
-
compressionOptions: {
|
|
89
|
-
level: 9
|
|
176
|
+
async injectLuaSettingsFromFolderPathToZipObject(zip, settingsFolder) {
|
|
177
|
+
for (let file of fs.readdirSync(settingsFolder).filter(file => file.endsWith(".lua"))) {
|
|
178
|
+
this.injectFileIntoZipObject(zip, [
|
|
179
|
+
settingsFolder,
|
|
180
|
+
"/",
|
|
181
|
+
file].join(""));
|
|
90
182
|
}
|
|
91
|
-
}
|
|
92
|
-
fs.writeFileSync(mizPath, inputZip);
|
|
93
|
-
}
|
|
183
|
+
}
|
|
94
184
|
|
|
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
185
|
|
|
109
|
-
async
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
186
|
+
async injectMapResourceObjectIntoMizFile(mizPath, mapResourceObject) {
|
|
187
|
+
const zip = await this.getZipObjectFromMizPath(mizPath);
|
|
188
|
+
this.injectMapResourceObjectIntoZipObject(zip, mapResourceObject);
|
|
189
|
+
const inputZip = await zip.generateAsync({
|
|
190
|
+
type: 'nodebuffer',
|
|
191
|
+
streamFiles: true,
|
|
192
|
+
compression: "DEFLATE",
|
|
193
|
+
compressionOptions: {
|
|
194
|
+
level: 9
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
fs.writeFileSync(mizPath, inputZip);
|
|
115
198
|
}
|
|
116
|
-
}
|
|
117
199
|
|
|
200
|
+
injectFileIntoZipObject(zip, filePath) {
|
|
201
|
+
zip.remove("l10n/DEFAULT/" + path.basename(filePath));
|
|
202
|
+
var stream = fs.createReadStream(filePath);
|
|
203
|
+
zip.file("l10n/DEFAULT/" + path.basename(filePath), stream);
|
|
204
|
+
}
|
|
118
205
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
fs.writeFileSync(mizPath, inputZip);
|
|
131
|
-
}
|
|
206
|
+
injectMissionObjectIntoZipObject(zip, missionObject) {
|
|
207
|
+
zip.remove("mission");
|
|
208
|
+
let missionLuaT = format(missionObject, {singleQuote: false})
|
|
209
|
+
missionLuaT = missionLuaT
|
|
210
|
+
.split('\n')
|
|
211
|
+
.slice(1, -1)
|
|
212
|
+
.join('\n')
|
|
213
|
+
.slice(0, -1)
|
|
214
|
+
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
215
|
+
zip.file("mission", missionLuaT);
|
|
216
|
+
}
|
|
132
217
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
218
|
+
injectMapResourceObjectIntoZipObject(zip, mapResourceObject) {
|
|
219
|
+
zip.remove("l10n/DEFAULT/mapResource");
|
|
220
|
+
let mapResourceLuaT = format(mapResourceObject, {singleQuote: false})
|
|
221
|
+
mapResourceLuaT = mapResourceLuaT
|
|
222
|
+
.split('\n')
|
|
223
|
+
.slice(1, -1)
|
|
224
|
+
.join('\n')
|
|
225
|
+
.slice(0, -1)
|
|
226
|
+
.replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
227
|
+
zip.file("l10n/DEFAULT/mapResource", mapResourceLuaT);
|
|
228
|
+
}
|
|
138
229
|
|
|
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
|
-
}
|
|
230
|
+
getMissionLuaStringFromZipObject(zipStream) {
|
|
231
|
+
return zipStream.file("mission").async("string");
|
|
232
|
+
}
|
|
150
233
|
|
|
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
|
-
}
|
|
234
|
+
getMapResourceLuaStringFromZipObject(zipStream) {
|
|
235
|
+
return zipStream.file("l10n/DEFAULT/mapResource").async("string");
|
|
236
|
+
}
|
|
162
237
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
238
|
+
injectLuaFilesFromFolderIntoZipObject(zip, folderPath) {
|
|
239
|
+
for (let file of fs.readdirSync(folderPath).filter(file => file.endsWith(".lua"))) {
|
|
240
|
+
console.log('injecting up2date ' + folderPath + '/' + file + ' file in archive');
|
|
241
|
+
this.injectFileIntoZipObject(zip, folderPath + "/" + file);
|
|
242
|
+
};
|
|
243
|
+
}
|
|
166
244
|
|
|
167
|
-
function getMapResourceLuaStringFromZipObject(zipStream) {
|
|
168
|
-
return zipStream.file("l10n/DEFAULT/mapResource").async("string");
|
|
169
|
-
}
|
|
170
245
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
246
|
+
async injectRadioPresetsFromFolderIntoZipObject(zip, preset_folder) {
|
|
247
|
+
// Create folder Avionics to make sure it exists then delete it to remove any old preset in the template
|
|
248
|
+
// Allows adding presets for A-10C
|
|
249
|
+
zip.folder("Avionics");
|
|
250
|
+
zip.remove("Avionics");
|
|
177
251
|
|
|
252
|
+
const mission_object = await this.getMissionObjectFromZipObject(zip);
|
|
253
|
+
for (let file of fs.readdirSync(preset_folder).filter(file => file.endsWith(".lua"))) {
|
|
254
|
+
const file_data = fs.readFileSync(preset_folder + '/' + file).toString();
|
|
255
|
+
const lua_string = file_data.substring(0, file_data.indexOf("radio_descriptor_table =") - 1);
|
|
256
|
+
const radio_descriptor_table = parse("return {" + lua_string + "}").descriptor;
|
|
178
257
|
|
|
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
|
-
|
|
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)
|
|
258
|
+
console.log('updating radio presets (aircraft: ' + radio_descriptor_table["aircraft"] + ', group_name: ' + radio_descriptor_table["group_name"] + ') with preset in ' + preset_folder + ' folder');
|
|
259
|
+
const dcs_radio_presets = file_data.substring(file_data.indexOf("radio_descriptor_table =") + 24);
|
|
260
|
+
|
|
261
|
+
for (const coalition_key in mission_object.coalition) {
|
|
262
|
+
const coalition = mission_object.coalition[coalition_key];
|
|
263
|
+
for (const country_list_key in coalition) {
|
|
264
|
+
if (country_list_key != "country") continue;
|
|
265
|
+
const country_list = coalition[country_list_key];
|
|
266
|
+
for (const country_key in country_list) {
|
|
267
|
+
const country = country_list[country_key];
|
|
268
|
+
for (const plane_key in country["plane"]) {
|
|
269
|
+
const plane = country["plane"][plane_key];
|
|
270
|
+
for (const group_key in plane) {
|
|
271
|
+
const group = plane[group_key];
|
|
272
|
+
if (group["name"].match(radio_descriptor_table["group_name"]) == null) continue;
|
|
273
|
+
for (const unit_key in group) {
|
|
274
|
+
if (unit_key != "units") continue;
|
|
275
|
+
const unit = group[unit_key];
|
|
276
|
+
for (const sub_unit_key in unit) {
|
|
277
|
+
const sub_unit = unit[sub_unit_key];
|
|
278
|
+
if (sub_unit["skill"] != "Client") continue;
|
|
279
|
+
// Aircraft is an A10CII, use A10C mode by creating files in the root with the unit id
|
|
280
|
+
// if (radio_descriptor_table["aircraft"] == 'A-10C_2') {
|
|
281
|
+
// const unit_id = sub_unit["unitId"];
|
|
282
|
+
// ["UHF_RADIO", "VHF_AM_RADIO", "VHF_FM_RADIO"].forEach(folder => {
|
|
283
|
+
// var zip_folder = zip.folder("Avionics/A-10C_2/" + unit_id + "/" + folder);
|
|
284
|
+
// var file = parse("return " + dcs_radio_presets)[folder];
|
|
285
|
+
// file = format(file, { singleQuote: false });
|
|
286
|
+
// file = file
|
|
287
|
+
// .split('\n')
|
|
288
|
+
// .slice(1, -1)
|
|
289
|
+
// .join('\n')
|
|
290
|
+
// .slice(0, -1)
|
|
291
|
+
// .replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
|
|
292
|
+
// zip_folder.file("SETTINGS.lua", file);
|
|
293
|
+
// });
|
|
294
|
+
// continue;
|
|
295
|
+
// }
|
|
296
|
+
if (sub_unit["type"] != radio_descriptor_table["aircraft"]) continue;
|
|
297
|
+
// GROUP FOUND, SET RADIOS
|
|
298
|
+
sub_unit["Radio"] = parse("return " + dcs_radio_presets)
|
|
299
|
+
}
|
|
232
300
|
}
|
|
233
301
|
}
|
|
234
302
|
}
|
|
235
303
|
}
|
|
236
304
|
}
|
|
237
305
|
}
|
|
306
|
+
};
|
|
307
|
+
this.injectMissionObjectIntoZipObject(zip, {mission: mission_object});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
injectSettingsLuaFilesFromFolderIntoZipObject(zip, strTheatre) {
|
|
311
|
+
for (let file of fs.readdirSync(['settings',strTheatre.length > 0 ? '/' + strTheatre : ''].join('')).filter(file => path.extname(file).toLowerCase()==='.lua')) {
|
|
312
|
+
console.log(['updating settings',strTheatre.length > 0 ? '/' + strTheatre : '','/',file,' file in miz file'].join(''));
|
|
313
|
+
this.injectFileIntoZipObject(zip, ['settings',strTheatre.length > 0 ? '/' + strTheatre : '','/',file].join(''));
|
|
238
314
|
}
|
|
239
|
-
}
|
|
240
|
-
mizUpdateMissionDataFile(zip, {mission: mission_object});
|
|
241
|
-
}
|
|
315
|
+
}
|
|
242
316
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
317
|
+
async injectSoundFoldersIntoZipObject(zip) {
|
|
318
|
+
if (fs.existsSync('resources/sounds') && fs.lstatSync('resources/sounds').isDirectory()) {
|
|
319
|
+
const folderArray = fs.readdirSync('resources/sounds');
|
|
320
|
+
for (const folder of folderArray) {
|
|
321
|
+
await this.injectSingleSoundFolderIntoZipObject(zip, folder);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
249
325
|
|
|
250
|
-
async
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
326
|
+
async updateWorkspaceWithSingleSoundFolder(workspacePath, folderString) {
|
|
327
|
+
if (
|
|
328
|
+
fs.existsSync(
|
|
329
|
+
[
|
|
330
|
+
workspacePath,
|
|
331
|
+
"/.workspace/resources/sounds/",
|
|
332
|
+
folderString
|
|
333
|
+
].join("")
|
|
334
|
+
) &&
|
|
335
|
+
fs.lstatSync([
|
|
336
|
+
workspacePath,
|
|
337
|
+
"/.workspace/resources/sounds/",
|
|
338
|
+
folderString
|
|
339
|
+
].join("")).isDirectory()
|
|
340
|
+
) {
|
|
341
|
+
fs.rmSync([
|
|
342
|
+
workspacePath,
|
|
343
|
+
"/.workspace/resources/sounds/",
|
|
344
|
+
folderString
|
|
345
|
+
].join(""), {recursive: true});
|
|
346
|
+
}
|
|
347
|
+
if (
|
|
348
|
+
fs.existsSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString) &&
|
|
349
|
+
fs.lstatSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString).isDirectory()) {
|
|
350
|
+
fs.mkdirSync([
|
|
351
|
+
workspacePath,
|
|
352
|
+
"/.workspace/resources/sounds/",
|
|
353
|
+
folderString
|
|
354
|
+
].join(""), {recursive: true});
|
|
355
|
+
fs.cpSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString,[
|
|
356
|
+
workspacePath,
|
|
357
|
+
"/.workspace/resources/sounds/",
|
|
358
|
+
folderString
|
|
359
|
+
].join(""), {recursive: true});
|
|
255
360
|
}
|
|
256
361
|
}
|
|
257
|
-
}
|
|
258
362
|
|
|
259
|
-
async
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
363
|
+
async injectSingleSoundFolderIntoZipObject(zip, workspacePath, folder, fromLibrary = true) {
|
|
364
|
+
if (
|
|
365
|
+
fs.existsSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder].join('')) &&
|
|
366
|
+
fs.lstatSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder].join('')).isDirectory()) {
|
|
367
|
+
console.log(['adding sound files from ',workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder,' folder...'].join(''));
|
|
368
|
+
zip = zip.remove(folder).folder(folder);
|
|
369
|
+
await this.addFilesToZip(
|
|
370
|
+
zip,
|
|
371
|
+
[workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder].join(''),
|
|
372
|
+
fs.readdirSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder].join('')));
|
|
373
|
+
}
|
|
264
374
|
}
|
|
265
|
-
}
|
|
266
375
|
|
|
267
|
-
async
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
376
|
+
async addFilesToZip(zip, directoryPath, filesToInclude) {
|
|
377
|
+
const promiseArr = await filesToInclude.map(async file => {
|
|
378
|
+
const filePath = path.join(directoryPath, file)
|
|
379
|
+
try {
|
|
380
|
+
const fileStats = await lstat(filePath)
|
|
381
|
+
const isDirectory = fileStats.isDirectory()
|
|
382
|
+
if (isDirectory) {
|
|
383
|
+
const directory = zip.remove(file).folder(file)
|
|
384
|
+
const subFiles = fs.readdirSync(filePath)
|
|
385
|
+
return this.addFilesToZip(directory, filePath, subFiles)
|
|
386
|
+
} else {
|
|
387
|
+
// console.log('added file : '+file);
|
|
388
|
+
return zip.file(file, fs.createReadStream(filePath))
|
|
389
|
+
}
|
|
390
|
+
} catch (err) {
|
|
391
|
+
console.log(err)
|
|
392
|
+
return Promise.resolve()
|
|
280
393
|
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
})
|
|
286
|
-
return Promise.all(promiseArr)
|
|
287
|
-
}
|
|
394
|
+
})
|
|
395
|
+
return Promise.all(promiseArr)
|
|
396
|
+
}
|
|
288
397
|
|
|
289
|
-
async
|
|
290
|
-
|
|
291
|
-
}
|
|
398
|
+
async copyMiz(srcMizPath, dstMizPath) {
|
|
399
|
+
await fs.createReadStream(srcMizPath).pipe(fs.createWriteStream(dstMizPath));
|
|
400
|
+
}
|
|
292
401
|
|
|
293
|
-
async
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
402
|
+
async getMissionObjectFromMizPath(MizPath) {
|
|
403
|
+
let luaTable = 'return { \n' + await this.getMissionLuaStringFromZipObject(await this.getZipObjectFromMizPath(MizPath)) + ' }';
|
|
404
|
+
return parse(luaTable).mission;
|
|
405
|
+
}
|
|
297
406
|
|
|
298
|
-
async
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
407
|
+
async getMissionObjectFromZipObject(zip) {
|
|
408
|
+
let luaTable = 'return { \n' + await this.getMissionLuaStringFromZipObject(zip) + ' }';
|
|
409
|
+
return parse(luaTable).mission;
|
|
410
|
+
}
|
|
302
411
|
|
|
303
|
-
async
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
412
|
+
async getMapResourceObjectFromMizPath(MizPath) {
|
|
413
|
+
let luaTable = 'return { \n' + await this.getMapResourceLuaStringFromZipObject(await this.getZipObjectFromMizPath(MizPath)) + ' }';
|
|
414
|
+
return parse(luaTable).mapResource;
|
|
415
|
+
}
|
|
307
416
|
|
|
308
|
-
async
|
|
309
|
-
|
|
310
|
-
|
|
417
|
+
async getMapResourceObjectFromZipObject(zip) {
|
|
418
|
+
let luaTable = 'return { \n' + await this.getMapResourceLuaStringFromZipObject(zip) + ' }';
|
|
419
|
+
let mrObject = parse(luaTable).mapResource;
|
|
420
|
+
if (Array.isArray(mrObject)) {
|
|
421
|
+
if (mrObject.length === 0) {
|
|
422
|
+
mrObject = {};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return mrObject;
|
|
426
|
+
}
|
|
311
427
|
}
|
|
312
428
|
|
|
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
|
-
};
|
|
429
|
+
module.exports = Mizlib;
|