@jtff/miztemplate-lib 3.0.3 → 3.0.4

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.
Files changed (2) hide show
  1. package/lib/mizlib.js +60 -0
  2. package/package.json +1 -1
package/lib/mizlib.js CHANGED
@@ -432,6 +432,66 @@ class Mizlib {
432
432
  }
433
433
  return mrObject;
434
434
  }
435
+
436
+ js2Lua(data, depth = 0) {
437
+ const indentation = _.range(0, depth + 1)
438
+ .map(() => "")
439
+ .join(" ");
440
+
441
+ if (_.isArray(data)) {
442
+ if (_.isEmpty(data)) {
443
+ return `\n${indentation}{\n${indentation}}`;
444
+ }
445
+ return `\n${indentation}{\n${data
446
+ .map((it, idx) => `${indentation} [${idx + 1}] = ${this.js2Lua(it, depth + 1)}`)
447
+ .join(",\n")},\n${indentation}}`;
448
+ }
449
+
450
+ if (_.isObject(data)) {
451
+ if (_.isEmpty(data)) {
452
+ return `\n${indentation}{\n${indentation}}`;
453
+ }
454
+ return `\n${indentation}{\n${map(
455
+ data,
456
+ (value, key) =>
457
+ `${indentation} [${!_.isNaN(key)?key:this.js2Lua(key)}] = ${this.js2Lua(value, depth + 1)}${_.isObject(value)?`, -- end of [${!_.isNaN(key)?key:this.js2Lua(key)}]`:","}`,
458
+ ).join("\n")}\n${indentation}}`;
459
+ }
460
+
461
+ if (_.isString(data)) {
462
+ return JSON.stringify(data);
463
+ }
464
+
465
+ return `${data}`;
466
+ };
467
+
468
+ generatePresetObjectFromMissionObject(missionObject, blnHidden){
469
+ const presetObject = {};
470
+ const missionDate = new Date(new Date(
471
+ missionObject.date.Year + "-" +
472
+ missionObject.date.Month + "-" +
473
+ missionObject.date.Day + " 00:00:00").getTime() + 1000 * missionObject.start_time);
474
+ presetObject.hidden = blnHidden;
475
+ presetObject.date = [String(missionDate.getFullYear()).padStart(4,'0'),String(missionDate.getMonth()+1).padStart(2,'0'),String(missionDate.getDate()).padStart(2,'0')].join("-");
476
+ presetObject.start_time = String(missionDate.getHours()).padStart(2,'0') + ":" + String(missionDate.getMinutes()).padStart(2,'0');
477
+ presetObject.temperature = missionObject.weather.season.temperature;
478
+ presetObject.clouds = missionObject.weather.clouds;
479
+ presetObject.wind = missionObject.weather.wind;
480
+ presetObject.qnh = missionObject.weather.qnh;
481
+ presetObject.groundTurbulence = missionObject.weather.groundTurbulence;
482
+ presetObject.enable_dust = missionObject.weather.enable_dust;
483
+ presetObject.dust_density = missionObject.weather.dust_density;
484
+ presetObject.enable_fog = missionObject.weather.enable_fog;
485
+ presetObject.fog = missionObject.weather.fog;
486
+ presetObject.halo = missionObject.weather.halo;
487
+ return presetObject;
488
+ }
489
+
490
+ async generatePresetObjectFromZipObject(ZipObject, blnHidden) {
491
+ const missionObject = await this.getMissionObjectFromZipObject(ZipObject);
492
+ return this.generatePresetObjectFromMissionObject(missionObject, blnHidden);
493
+ }
494
+
435
495
  }
436
496
 
437
497
  module.exports = Mizlib;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jtff/miztemplate-lib",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "JTFF mission template library",
5
5
  "main": "index.js",
6
6
  "files": [