@jtff/miztemplate-lib 3.0.3 → 3.0.5

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