@jtff/miztemplate-lib 3.0.0-rc16 → 3.0.0-rc18

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.
@@ -59,7 +59,7 @@ class MizTemplateCI{
59
59
  return newVersionObject;
60
60
  }
61
61
 
62
- getDestinationMizFilePaths() {
62
+ getDestinationMizFilePathArrayFromConfig() {
63
63
  const returnArray = this.config.missionTemplates.map(missionTemplate => {
64
64
  return this.config.general.missionFolder + '/'
65
65
  + this.config.general.missionPrefix + '_'
@@ -70,6 +70,16 @@ class MizTemplateCI{
70
70
  return returnArray;
71
71
  }
72
72
 
73
+ getDestinationMizFilePathFromConfigMissionTemplate(missionTemplate) {
74
+ const destinationMizPath = [this.config.general.missionFolder + '/',
75
+ this.config.general.missionPrefix + '_',
76
+ missionTemplate.theatre + '_',
77
+ this.config.general.missionSuffix.length > 0 ? this.config.general.missionSuffix + '_' : '',
78
+ this.config.general.missionVersion + '.miz'].join('')
79
+ ;
80
+ return destinationMizPath;
81
+ }
82
+
73
83
  getGeneratedMizFilePaths() {
74
84
  return fs.readdirSync(this.config.general.missionFolder + '/')
75
85
  .filter(file => file.endsWith((".miz")))
@@ -239,7 +249,7 @@ class MizTemplateCI{
239
249
  }
240
250
 
241
251
  async InjectCiScriptsIntoWorkspace(workspacePath) {
242
- fs.cpSync('node_modules/@jtff/miztemplate-lib/ci',workspacePath + '/src/nodejs',{recursive: true});
252
+ fs.cpSync('node_modules/@jtff/miztemplate-lib/ci',workspacePath + '/.workspace/src/nodejs',{recursive: true});
243
253
  }
244
254
 
245
255
  async deployCIScriptsFromZipObjectIntoWorkspace(workspacePath, mizObject, mizFilePath) {
package/lib/mizlib.js CHANGED
@@ -12,10 +12,10 @@ class Mizlib {
12
12
  // no need for initialization
13
13
  }
14
14
 
15
- async injectLuaScriptIntoZipObjectAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, zipObject, timing, colorString) {
15
+ async injectLuaScriptIntoZipObjectAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, zipObject, timing, colorString, fromLibrary=true) {
16
16
  let missionObject = await this.getMissionObjectFromZipObject(zipObject);
17
17
  let mapResourceObject = await this.getMapResourceObjectFromZipObject(zipObject);
18
- let tuple = this.injectLuaScriptAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, missionObject, mapResourceObject, timing, colorString);
18
+ let tuple = this.injectLuaScriptAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, missionObject, mapResourceObject, timing, colorString, fromLibrary);
19
19
  for (let luaScript of luaScriptsArray) {
20
20
  this.injectFileIntoZipObject(zipObject, [
21
21
  workspacePath,
@@ -29,7 +29,7 @@ class Mizlib {
29
29
  return {tuple, zipObject};
30
30
  }
31
31
 
32
- injectLuaScriptAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, missionObject, mapResourceObject, timing, colorString) {
32
+ injectLuaScriptAndUpdateWorkspace(workspacePath, folderPath, luaScriptsArray, titleString, missionObject, mapResourceObject, timing, colorString ,fromLibrary=true) {
33
33
  let tuple = this.injectLuaScriptsInMissionObject(
34
34
  missionObject['trig'],
35
35
  missionObject['trigrules'],
@@ -40,7 +40,7 @@ class Mizlib {
40
40
  colorString
41
41
  );
42
42
  for (let luaScript of luaScriptsArray) {
43
- fs.copyFileSync(
43
+ fs.cpSync(
44
44
  [
45
45
  'node_modules/@jtff/miztemplate-lib/lua/',
46
46
  folderPath,
@@ -49,11 +49,12 @@ class Mizlib {
49
49
  ].join(""),
50
50
  [
51
51
  workspacePath,
52
- "/",
52
+ fromLibrary ? "/.workspace/" : "/",
53
53
  folderPath,
54
54
  "/",
55
55
  path.basename(luaScript)
56
- ].join("")
56
+ ].join(""),
57
+ {force: true}
57
58
  );
58
59
  }
59
60
  return tuple;
@@ -111,12 +112,29 @@ class Mizlib {
111
112
  const zipObject = await this.getZipObjectFromMizPath(mizPath);
112
113
  const missionObject = await this.getMissionObjectFromZipObject(zipObject);
113
114
  const strTheatreSettings = missionObject.theatre;
114
- // TODO: D'abord mettre à jour les fichiers src et lib depuis la miztemplate sauf 200-mission.lua
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
+ }
115
133
  this.injectLuaFilesFromFolderIntoZipObject(zipObject, 'src');
116
134
  this.injectLuaFilesFromFolderIntoZipObject(zipObject, 'lib');
117
- await this.injectRadioPresetsFromFolderIntoZipObject(zipObject, 'resources/radios/' + strTheatreSettings);
118
- this.mizUpdateSettingsLuaFiles(zipObject, singleMission ? '' : strTheatreSettings);
119
- await this.mizUpdateSoundFolders(zipObject);
135
+ zipObject = await this.injectRadioPresetsFromFolderIntoZipObject(zipObject, 'resources/radios/' + strTheatreSettings);
136
+ this.injectSettingsLuaFilesFromFolderIntoZipObject(zipObject, singleMission ? '' : strTheatreSettings);
137
+ await this.injectSoundFoldersIntoZipObject(zipObject);
120
138
  const inputZip = await zipObject.generateAsync({
121
139
  type: 'nodebuffer',
122
140
  streamFiles: true,
@@ -128,9 +146,8 @@ class Mizlib {
128
146
  fs.writeFileSync(copyPath ? copyPath : mizPath, inputZip);
129
147
  }
130
148
 
131
- async mizInjectMissionDataFile(mizPath, missionObject) {
132
- const zip = await this.getZipObjectFromMizPath(mizPath);
133
- this.mizUpdateMissionDataFile(zip, missionObject);
149
+ async injectMissionObjectIntoMizFile(mizPath, missionObject) {
150
+ const zip = this.injectMissionObjectIntoZipObject(await this.getZipObjectFromMizPath(mizPath), missionObject);
134
151
  const inputZip = await zip.generateAsync({
135
152
  type: 'nodebuffer',
136
153
  streamFiles: true,
@@ -166,9 +183,8 @@ class Mizlib {
166
183
  }
167
184
 
168
185
 
169
- async mizInjectMapResourceFile(mizPath, mapResourceObject) {
170
- const zip = await this.getZipObjectFromMizPath(mizPath);
171
- this.mizUpdateMapResourceFile(zip, mapResourceObject);
186
+ async injectMapResourceObjectIntoMizFile(mizPath, mapResourceObject) {
187
+ const zip = this.injectMapResourceObjectIntoZipObject(await this.getZipObjectFromMizPath(mizPath), mapResourceObject);
172
188
  const inputZip = await zip.generateAsync({
173
189
  type: 'nodebuffer',
174
190
  streamFiles: true,
@@ -186,7 +202,7 @@ class Mizlib {
186
202
  zip.file("l10n/DEFAULT/" + path.basename(filePath), stream);
187
203
  }
188
204
 
189
- mizUpdateMissionDataFile(zip, missionObject) {
205
+ injectMissionObjectIntoZipObject(zip, missionObject) {
190
206
  zip.remove("mission");
191
207
  let missionLuaT = format(missionObject, {singleQuote: false})
192
208
  missionLuaT = missionLuaT
@@ -196,9 +212,10 @@ class Mizlib {
196
212
  .slice(0, -1)
197
213
  .replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
198
214
  zip.file("mission", missionLuaT);
215
+ return zip;
199
216
  }
200
217
 
201
- mizUpdateMapResourceFile(zip, mapResourceObject) {
218
+ injectMapResourceObjectIntoZipObject(zip, mapResourceObject) {
202
219
  zip.remove("l10n/DEFAULT/mapResource");
203
220
  let mapResourceLuaT = format(mapResourceObject, {singleQuote: false})
204
221
  mapResourceLuaT = mapResourceLuaT
@@ -208,6 +225,7 @@ class Mizlib {
208
225
  .slice(0, -1)
209
226
  .replace(/\[\"(\d+)\"\] = /g, "[$1] = ");
210
227
  zip.file("l10n/DEFAULT/mapResource", mapResourceLuaT);
228
+ return zip;
211
229
  }
212
230
 
213
231
  getMissionLuaStringFromZipObject(zipStream) {
@@ -287,17 +305,17 @@ class Mizlib {
287
305
  }
288
306
  }
289
307
  };
290
- this.mizUpdateMissionDataFile(zip, {mission: mission_object});
308
+ return this.injectMissionObjectIntoZipObject(zip, {mission: mission_object});
291
309
  }
292
310
 
293
- mizUpdateSettingsLuaFiles(zip, strTheatre) {
294
- for (let file of fs.readdirSync(['settings',strTheatre].join('/')).filter(file => file.endsWith(".lua"))) {
295
- console.log('updating ' + ['settings',strTheatre,file].join('/') + ' file in miz file');
296
- this.injectFileIntoZipObject(zip, ['settings',strTheatre,file].join('/'));
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(''));
297
315
  }
298
316
  }
299
317
 
300
- async mizUpdateSoundFolders(zip) {
318
+ async injectSoundFoldersIntoZipObject(zip) {
301
319
  if (fs.existsSync('resources/sounds') && fs.lstatSync('resources/sounds').isDirectory()) {
302
320
  const folderArray = fs.readdirSync('resources/sounds');
303
321
  for (const folder of folderArray) {
@@ -311,41 +329,48 @@ class Mizlib {
311
329
  fs.existsSync(
312
330
  [
313
331
  workspacePath,
314
- "/resources/sounds/",
332
+ "/.workspace/resources/sounds/",
315
333
  folderString
316
334
  ].join("")
317
335
  ) &&
318
336
  fs.lstatSync([
319
337
  workspacePath,
320
- "/resources/sounds/",
338
+ "/.workspace/resources/sounds/",
321
339
  folderString
322
340
  ].join("")).isDirectory()
323
341
  ) {
324
342
  fs.rmSync([
325
343
  workspacePath,
326
- "/resources/sounds/",
344
+ "/.workspace/resources/sounds/",
327
345
  folderString
328
346
  ].join(""), {recursive: true});
329
347
  }
330
- if (fs.existsSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString) && fs.lstatSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString).isDirectory()) {
348
+ if (
349
+ fs.existsSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString) &&
350
+ fs.lstatSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString).isDirectory()) {
331
351
  fs.mkdirSync([
332
352
  workspacePath,
333
- "/resources/sounds/",
353
+ "/.workspace/resources/sounds/",
334
354
  folderString
335
355
  ].join(""), {recursive: true});
336
356
  fs.cpSync('node_modules/@jtff/miztemplate-lib/resources/sounds/' + folderString,[
337
357
  workspacePath,
338
- "/resources/sounds/",
358
+ "/.workspace/resources/sounds/",
339
359
  folderString
340
360
  ].join(""), {recursive: true});
341
361
  }
342
362
  }
343
363
 
344
- async injectSingleSoundFolderIntoZipObject(zip, workspacePath, folder) {
345
- if (fs.existsSync(workspacePath + '/resources/sounds/' + folder) && fs.lstatSync(workspacePath + '/resources/sounds/' + folder).isDirectory()) {
346
- console.log('adding sound files from '+workspacePath+'/resources/sounds/' + folder + ' folder...');
364
+ async injectSingleSoundFolderIntoZipObject(zip, workspacePath, folder, fromLibrary = true) {
365
+ if (
366
+ fs.existsSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder].join('')) &&
367
+ fs.lstatSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder].join('')).isDirectory()) {
368
+ console.log(['adding sound files from ',workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder,' folder...'].join(''));
347
369
  zip = zip.remove(folder).folder(folder);
348
- await this.addFilesToZip(zip, workspacePath + '/resources/sounds/' + folder, fs.readdirSync(workspacePath + '/resources/sounds/' + folder));
370
+ await this.addFilesToZip(
371
+ zip,
372
+ [workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder].join(''),
373
+ fs.readdirSync([workspacePath,fromLibrary? '/.workspace/resources/sounds/' : '/resources/sounds/',folder].join('')));
349
374
  }
350
375
  }
351
376
 
@@ -392,7 +417,13 @@ class Mizlib {
392
417
 
393
418
  async getMapResourceObjectFromZipObject(zip) {
394
419
  let luaTable = 'return { \n' + await this.getMapResourceLuaStringFromZipObject(zip) + ' }';
395
- return parse(luaTable).mapResource;
420
+ let mrObject = parse(luaTable).mapResource;
421
+ if (Array.isArray(mrObject)) {
422
+ if (mrObject.length === 0) {
423
+ mrObject = {};
424
+ }
425
+ }
426
+ return mrObject;
396
427
  }
397
428
  }
398
429
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jtff/miztemplate-lib",
3
- "version": "3.0.0-rc16",
3
+ "version": "3.0.0-rc18",
4
4
  "description": "JTFF mission template library",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -34,6 +34,7 @@
34
34
  "ftp": "^0.3.10",
35
35
  "googleapis": "^92.0.0",
36
36
  "jszip": "^3.10.1",
37
+ "loadash": "^1.0.0",
37
38
  "lua-json": "^1.0.1",
38
39
  "path": "^0.12.7",
39
40
  "prompt": "^1.3.0",
package/scripts/build.js CHANGED
@@ -6,25 +6,16 @@ function build(jtffci) {
6
6
  if (missionTemplate.filename) {
7
7
  await jtffci.mizlib.buildMizFileFromMizTemplate(
8
8
  missionTemplate.filename,
9
- [
10
- [[jtffci.config.general.missionFolder, jtffci.config.general.missionPrefix].join('/'),
11
- missionTemplate.theatre,
12
- jtffci.config.general.missionSuffix,
13
- jtffci.displayVersion(jtffci.getVersion())].join('_'),
14
- ".miz"
15
- ].join(""),(jtffci.config.missionTemplates.length > 1) ? false : true);
9
+ jtffci.getDestinationMizFilePathFromConfigMissionTemplate(missionTemplate),
10
+ (jtffci.config.missionTemplates.length > 1) ? false : true);
16
11
  } else {
17
12
  await jtffci.mizlib.buildMizFileFromMizTemplate([
18
- [missionTemplate.prefix,
19
- missionTemplate.theatre].join('_'),
20
- ".miz"
21
- ].join(""), [
22
- [[jtffci.config.general.missionFolder, jtffci.config.general.missionPrefix].join('/'),
23
- missionTemplate.theatre,
24
- jtffci.config.general.missionSuffix,
25
- jtffci.displayVersion(jtffci.getVersion())].join('_'),
26
- ".miz"
27
- ].join(""), false);
13
+ [missionTemplate.prefix,
14
+ missionTemplate.theatre].join('_'),
15
+ ".miz"
16
+ ].join(""),
17
+ jtffci.getDestinationMizFilePathFromConfigMissionTemplate(missionTemplate),
18
+ false);
28
19
  }
29
20
  let publicationConfig = {
30
21
  theatre: missionTemplate.theatre,
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require("path");
3
3
  const prompt = require('prompt');
4
+ var _ = require('lodash');
4
5
 
5
6
  function injectScripts(jtffci, env_mission) {
6
7
  const workspacePath = [
@@ -29,21 +30,33 @@ function injectScripts(jtffci, env_mission) {
29
30
  // create a src folder
30
31
  fs.mkdirSync([
31
32
  workspacePath,
32
- "/src"
33
+ "/.workspace/src"
33
34
  ].join(""),
34
35
  { recursive: true }
35
36
  );
36
37
  // create a lib folder
37
38
  fs.mkdirSync([
38
39
  workspacePath,
39
- "/lib"
40
+ "/.workspace/lib"
40
41
  ].join(""),
41
42
  { recursive: true }
42
43
  );
43
44
  // create a resources folder
44
45
  fs.mkdirSync([
45
46
  workspacePath,
46
- "/resources"
47
+ "/.workspace/resources/sounds"
48
+ ].join(""),
49
+ { recursive: true }
50
+ );
51
+ fs.mkdirSync([
52
+ workspacePath,
53
+ "/resources/radios"
54
+ ].join(""),
55
+ { recursive: true }
56
+ );
57
+ fs.mkdirSync([
58
+ workspacePath,
59
+ "/resources/sounds"
47
60
  ].join(""),
48
61
  { recursive: true }
49
62
  );
@@ -138,11 +151,6 @@ function injectScripts(jtffci, env_mission) {
138
151
  let settingsArray = [];
139
152
  let scriptsArray = [];
140
153
  let libsArray = [];
141
- if (Array.isArray(mapResourceObject)) {
142
- if (mapResourceObject.length === 0) {
143
- mapResourceObject = {};
144
- }
145
- }
146
154
  // insertion des librairies externes dans la file d'attente
147
155
  libsArray.push({
148
156
  folder: 'lib',
@@ -181,10 +189,10 @@ function injectScripts(jtffci, env_mission) {
181
189
  });
182
190
  // injection des fichiers son Généraux si repertoire resources/sounds/General present
183
191
  await jtffci.mizlib.updateWorkspaceWithSingleSoundFolder(workspacePath, 'General');
184
- await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'General');
192
+ await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'General', true);
185
193
  // injection des fichiers son Misc si repertoire resources/sounds/Misc present
186
194
  await jtffci.mizlib.updateWorkspaceWithSingleSoundFolder(workspacePath, 'Misc');
187
- await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'Misc');
195
+ await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'Misc', true);
188
196
  // insertion des Librairies JTFF dans la file d'attente
189
197
  settingsArray.push(
190
198
  {
@@ -209,20 +217,21 @@ function injectScripts(jtffci, env_mission) {
209
217
  color: '0xffff00ff'
210
218
  });
211
219
  // traitement de la file d'attente des librairies (injection des triggers et des fichiers lua)
212
- for ( script of libsArray) {
213
- console.log(['adding library',script.scripts.join(' and '),'from',workspacePath + '/' + script.folder, 'folder...'].join(' '));
220
+ for ( libscript of libsArray) {
221
+ console.log(['adding library',libscript.scripts.join(' and '),'from',workspacePath + '/.workspace/' + libscript.folder, 'folder...'].join(' '));
214
222
  let {tuple, zipObject} = await jtffci.mizlib.injectLuaScriptIntoZipObjectAndUpdateWorkspace(
215
223
  workspacePath,
216
- script.folder,
217
- script.scripts,
218
- script.scriptTitle + ' Load',
224
+ libscript.folder,
225
+ libscript.scripts,
226
+ libscript.scriptTitle + ' Load',
219
227
  mizObject,
220
- script.timing,
221
- script.color
228
+ libscript.timing,
229
+ libscript.color,
230
+ true
222
231
  );
223
232
  missionObject['trig'] = tuple.tObject;
224
233
  missionObject['trigrules'] = tuple.trObject;
225
- mapResourceObject = tuple.mrObject;
234
+ mapResourceObject = _.merge(mapResourceObject,tuple.mrObject);
226
235
  mizObject = zipObject;
227
236
  }
228
237
  // injection de la gestion des Set_Clients dans la file d'attente
@@ -231,7 +240,8 @@ function injectScripts(jtffci, env_mission) {
231
240
  scriptTitle: 'Set clients',
232
241
  scripts: ['110-set_clients.lua'],
233
242
  timing: 21,
234
- color: '0xff0000ff'
243
+ color: '0xff0000ff',
244
+ fromLibrary: true
235
245
  });
236
246
  // injection des Tankers et OndemandTankers dans la file d'attente
237
247
  if ((/^y\b|o\b|yes\b|oui\b/i).test(prompt_result.inject_tankers)) {
@@ -250,14 +260,15 @@ function injectScripts(jtffci, env_mission) {
250
260
  scriptTitle: 'Tankers',
251
261
  scripts: ['120-tankers.lua'],
252
262
  timing: 22,
253
- color: '0xff0000ff'
263
+ color: '0xff0000ff',
264
+ fromLibrary: true
254
265
  });
255
266
  }
256
267
  // injection des Airboss et Pedros dans la file d'attente
257
268
  if ((/^y\b|o\b|yes\b|oui\b/i).test(prompt_result.inject_airboss)) {
258
269
  // injection des fichiers son Airboss
259
270
  await jtffci.mizlib.updateWorkspaceWithSingleSoundFolder(workspacePath, 'AIRBOSS');
260
- await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'AIRBOSS');
271
+ await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'AIRBOSS', true);
261
272
  settingsArray.push(
262
273
  {
263
274
  file: "settings-airboss.lua",
@@ -273,7 +284,8 @@ function injectScripts(jtffci, env_mission) {
273
284
  scriptTitle: 'Airboss',
274
285
  scripts: ['130-airboss.lua', '135-pedro.lua'],
275
286
  timing: 23,
276
- color: '0xff0000ff'
287
+ color: '0xff0000ff',
288
+ fromLibrary: true
277
289
  });
278
290
  }
279
291
  // injection des Beacons dans la file d'attente
@@ -289,7 +301,8 @@ function injectScripts(jtffci, env_mission) {
289
301
  scriptTitle: 'Beacons',
290
302
  scripts: ['140-beacons.lua'],
291
303
  timing: 24,
292
- color: '0xff0000ff'
304
+ color: '0xff0000ff',
305
+ fromLibrary: true
293
306
  });
294
307
  }
295
308
  // injection des AWACS et OnDemandAwacs dans la file d'attente
@@ -309,14 +322,15 @@ function injectScripts(jtffci, env_mission) {
309
322
  scriptTitle: 'Awacs',
310
323
  scripts: ['150-awacs.lua'],
311
324
  timing: 25,
312
- color: '0xff0000ff'
325
+ color: '0xff0000ff',
326
+ fromLibrary: true
313
327
  });
314
328
  }
315
329
  // injection des ATIS dans la file d'attente
316
330
  if ((/^y\b|o\b|yes\b|oui\b/i).test(prompt_result.inject_atis)) {
317
331
  // injection des fichiers son ATIS
318
332
  await jtffci.mizlib.updateWorkspaceWithSingleSoundFolder(workspacePath, 'ATIS');
319
- await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'ATIS');
333
+ await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'ATIS', true);
320
334
  settingsArray.push(
321
335
  {
322
336
  file: "settings-atis.lua",
@@ -328,7 +342,8 @@ function injectScripts(jtffci, env_mission) {
328
342
  scriptTitle: 'ATIS',
329
343
  scripts: ['160-atis.lua'],
330
344
  timing: 26,
331
- color: '0xff0000ff'
345
+ color: '0xff0000ff',
346
+ fromLibrary: true
332
347
  });
333
348
  }
334
349
  // injection des scripts A2A dans la file d'attente
@@ -360,14 +375,15 @@ function injectScripts(jtffci, env_mission) {
360
375
  scriptTitle: 'Air To Air',
361
376
  scripts: ['170-cap_zone_training.lua', '172-cap_zone_war.lua', '173-fox_zone_training.lua', '176-random_air_traffic.lua', '178-training-intercept.lua'],
362
377
  timing: 27,
363
- color: '0xff0000ff'
378
+ color: '0xff0000ff',
379
+ fromLibrary: true
364
380
  });
365
381
  }
366
382
  // injection des CTLD dans la file d'attente
367
383
  if ((/^y\b|o\b|yes\b|oui\b/i).test(prompt_result.inject_Logistics)) {
368
384
  // injection des fichiers son CTLD
369
385
  await jtffci.mizlib.updateWorkspaceWithSingleSoundFolder(workspacePath, 'CTLD');
370
- await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'CTLD');
386
+ await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'CTLD', true);
371
387
  settingsArray.push(
372
388
  {
373
389
  file: "settings-logistics.lua",
@@ -379,14 +395,15 @@ function injectScripts(jtffci, env_mission) {
379
395
  scriptTitle: 'Logistics',
380
396
  scripts: ['180-logistics.lua'],
381
397
  timing: 28,
382
- color: '0xff0000ff'
398
+ color: '0xff0000ff',
399
+ fromLibrary: true
383
400
  });
384
401
  }
385
402
  // injection des scripts A2G dans la file d'attente
386
403
  if ((/^y\b|o\b|yes\b|oui\b/i).test(prompt_result.inject_A2G)) {
387
404
  // injection des fichiers son Range
388
405
  await jtffci.mizlib.updateWorkspaceWithSingleSoundFolder(workspacePath, 'RANGE');
389
- await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'RANGE');
406
+ await jtffci.mizlib.injectSingleSoundFolderIntoZipObject(mizObject,workspacePath, 'RANGE', true);
390
407
  settingsArray.push(
391
408
  {
392
409
  file: "settings-ranges.lua",
@@ -418,7 +435,8 @@ function injectScripts(jtffci, env_mission) {
418
435
  scriptTitle: 'Air To Ground',
419
436
  scripts: ['190-ranges.lua', '191-sams.lua', '193-training_ranges.lua', '195-reaper-ondemand.lua', '196-fac_ranges.lua', '199-skynet.lua'],
420
437
  timing: 29,
421
- color: '0xff0000ff'
438
+ color: '0xff0000ff',
439
+ fromLibrary: true
422
440
  });
423
441
  }
424
442
  // injection du script spécifique de mission dans la file d'attente
@@ -428,7 +446,8 @@ function injectScripts(jtffci, env_mission) {
428
446
  scriptTitle: 'Mission specific',
429
447
  scripts: ['200-mission.lua'],
430
448
  timing: 30,
431
- color: '0xff0000ff'
449
+ color: '0xff0000ff',
450
+ fromLibrary: false
432
451
  });
433
452
  }
434
453
  // traitement de la file d'attente des scripts (injection des triggers et des fichiers lua)
@@ -441,11 +460,12 @@ function injectScripts(jtffci, env_mission) {
441
460
  script.scriptTitle,
442
461
  mizObject,
443
462
  script.timing,
444
- script.color
463
+ script.color,
464
+ script.fromLibrary
445
465
  );
446
466
  missionObject['trig'] = tuple.tObject;
447
467
  missionObject['trigrules'] = tuple.trObject;
448
- mapResourceObject = tuple.mrObject;
468
+ mapResourceObject = _.merge(mapResourceObject,tuple.mrObject);
449
469
  mizObject = zipObject;
450
470
  }
451
471
  // injection des preset radio dans les avions humains
@@ -454,7 +474,7 @@ function injectScripts(jtffci, env_mission) {
454
474
  fs.mkdirSync(workspacePath + '/resources/radios/' + missionObject.theatre,{recursive: true});
455
475
  fs.cpSync('node_modules/@jtff/miztemplate-lib/resources/radios/' + missionObject.theatre,workspacePath + '/resources/radios/' + missionObject.theatre,{recursive: true})
456
476
  console.log(destinationMizFilePath + ": injecting radio presets declared in resources/radios/" + missionObject.theatre);
457
- await jtffci.mizlib.injectRadioPresetsFromFolderIntoZipObject(mizObject, workspacePath + '/resources/radios/' + missionObject.theatre);
477
+ mizObject = await jtffci.mizlib.injectRadioPresetsFromFolderIntoZipObject(mizObject, workspacePath + '/resources/radios/' + missionObject.theatre);
458
478
  }
459
479
  // traitement de la file d'attente des settings (injection des triggers et des fichiers lua)
460
480
  if (settingsArray.length > 0) {
@@ -466,36 +486,35 @@ function injectScripts(jtffci, env_mission) {
466
486
  'Mission Settings',
467
487
  mizObject,
468
488
  15,
469
- '0xffff00ff'
489
+ '0xffff00ff',
490
+ false
470
491
  );
471
492
  missionObject['trig'] = tuple.tObject;
472
493
  missionObject['trigrules'] = tuple.trObject;
473
- mapResourceObject = tuple.mrObject;
494
+ mapResourceObject = _.merge(mapResourceObject,tuple.mrObject);
474
495
  mizObject = zipObject;
475
496
  }
476
- // creation du cichier miz dans l'espace de travail
477
- await fs.closeSync(fs.openSync(destinationMizFilePath, 'a'));
478
- // On fait une sauvegarde dans le folder de destination
479
- fs.writeFileSync(
480
- destinationMizFilePath,
481
- await mizObject.generateAsync({
482
- type: 'nodebuffer',
483
- streamFiles: true,
484
- compression: "DEFLATE",
485
- compressionOptions: {
486
- level: 9
487
- }
488
- })
489
- );
490
- // Sauvegarde de la mission avec scripts injectés
491
- await jtffci.mizlib.mizInjectMissionDataFile(
492
- destinationMizFilePath,
497
+ // réintégration du fichier mission dans l'archive
498
+ mizObject = await jtffci.mizlib.injectMissionObjectIntoZipObject(
499
+ mizObject,
493
500
  { mission: missionObject }
494
501
  );
495
- await jtffci.mizlib.mizInjectMapResourceFile(
496
- destinationMizFilePath,
502
+ mizObject = await jtffci.mizlib.injectMapResourceObjectIntoZipObject(
503
+ mizObject,
497
504
  { mapResource: mapResourceObject }
498
505
  );
506
+ // creation du fichier miz dans l'espace de travail
507
+ await fs.closeSync(fs.openSync(destinationMizFilePath, 'a'));
508
+ // On fait une sauvegarde dans le folder de destination
509
+ const inputZip = await mizObject.generateAsync({
510
+ type: 'nodebuffer',
511
+ streamFiles: true,
512
+ compression: "DEFLATE",
513
+ compressionOptions: {
514
+ level: 9
515
+ }
516
+ });
517
+ fs.writeFileSync(destinationMizFilePath, inputZip);
499
518
  // generation des outils CI JTFF
500
519
  await jtffci.deployCIScriptsFromZipObjectIntoWorkspace(workspacePath, mizObject, env_mission);
501
520
  console.log('...Done...');