UNPKG

novaparse

Version:
105 lines 4.74 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const BaseParse_1 = require("./BaseParse"); const PictData_1 = require("novadatainterface/PictData"); const Constants_1 = require("./Constants"); // This should not be necessary! const noUnitConversion = new Set(["freeCargo", "shield", "armor", "energy", "ionization"]); const perFrameTimes1000 = new Set(["shieldRecharge", "armorRecharge"]); function OutfitParse(outf, notFoundFunction) { return __awaiter(this, void 0, void 0, function* () { var base = yield BaseParse_1.BaseParse(outf, notFoundFunction); // Unlike during parsing, these are objects instead of // lists of tuples because properties should not be repeated, // and objects enforce a "one value per key" requirement. var weapons = {}; var physics = { freeMass: outf.mass }; for (let i in outf.functions) { let func = outf.functions[i]; let fType = func[0]; let fVal = func[1]; // Unit conversions. Everything should be in units / second. // Parse weapons as well. // Refactor me with ship properties??? if (fType == "weapon") { if (typeof fVal !== "number") { throw new Error("Wrong type for weapon val. Expected number"); } let weap = outf.idSpace.wëap[fVal]; if (!weap) { notFoundFunction("Missing wëap id " + fVal + " for oütf " + base.id); continue; } var weaponGlobalID = weap.globalID; if (!(weaponGlobalID in weapons)) { weapons[weaponGlobalID] = 0; } weapons[weaponGlobalID] += 1; } else if (noUnitConversion.has(fType)) { //else if (fType === "freeCargo") { // No unit conversion needed physics[fType] = fVal; } else if (perFrameTimes1000.has(fType)) { // convert from (units * 1000) / frame to units / second if (typeof fVal !== "number") { throw new Error("Wrong type. Expected number"); } physics[fType] = fVal * Constants_1.FPS / 1000; } else if (fType == "deionize") { if (typeof fVal !== "number") { throw new Error("Wrong type. Expected number"); } physics["deionize"] = fVal * Constants_1.FPS / 100; } else if (fType == "turnRate") { if (typeof fVal !== "number") { throw new Error("Wrong type. Expected number"); } physics["deionize"] = fVal * Constants_1.TurnRateConversionFactor; } else if (fType == "energyRecharge") { if (typeof fVal !== "number") { throw new Error("Wrong type. Expected number"); } physics["energyRecharge"] = Constants_1.FPS / fVal; } else { //throw new Error("Unknown outfit function " + fType + " on outfit " + base.id); } } var pict; var pictResource = outf.idSpace.PICT[outf.pictID]; if (pictResource) { pict = pictResource.globalID; } else { notFoundFunction("No matching PICT for oütf of id " + base.id); pict = PictData_1.DefaultPictData.id; } var desc; var descResource = outf.idSpace.dësc[outf.descID]; if (descResource) { desc = descResource.text; } else { desc = "No matching dësc for oütf of id " + base.id; notFoundFunction(desc); } return Object.assign({}, base, { weapons, physics, pict, price: outf.cost, desc, displayWeight: outf.displayWeight, max: outf.max }); }); } exports.OutfitParse = OutfitParse; //# sourceMappingURL=OutfitParse.js.map