novaparse
Version:
An EV Nova file parser for NovaJS
152 lines • 6.79 kB
JavaScript
;
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 PictData_1 = require("novadatainterface/PictData");
const BaseParse_1 = require("./BaseParse");
const Animation_1 = require("novadatainterface/Animation");
const ShanParse_1 = require("./ShanParse");
const Constants_1 = require("./Constants");
function ShipParseClosure(shipPictMap, weaponOutfitMap, globalIDSpacePromise) {
// Returns the function ShipParse with shipPictMap already assigned
return function (ship, notFoundFunction) {
return ShipParse(ship, notFoundFunction, shipPictMap, weaponOutfitMap, globalIDSpacePromise);
};
}
exports.ShipParseClosure = ShipParseClosure;
function ShipParse(ship, notFoundFunction, shipPictMap, weaponOutfitMap, globalIDSpacePromise) {
return __awaiter(this, void 0, void 0, function* () {
var globalIDSpace = yield globalIDSpacePromise;
if (globalIDSpace instanceof Error) {
throw globalIDSpace;
}
var base = yield BaseParse_1.BaseParse(ship, notFoundFunction);
var desc;
var descResource = ship.idSpace.dësc[ship.descID];
if (descResource) {
desc = descResource.text;
}
else {
desc = "No matching dësc for shïp of id " + base.id;
notFoundFunction(desc);
}
// TODO: Parse Explosions
var initialExplosionID = null;
var finalExplosionID = null;
// Refactor into a function? Eh, there's only 2 of them.
if (ship.initialExplosion !== null) {
let boom = ship.idSpace.bööm[ship.initialExplosion];
if (boom) {
initialExplosionID = boom.globalID;
}
else {
notFoundFunction("shïp id " + base.id + " missing bööm of id " + ship.initialExplosion);
}
}
if (ship.finalExplosion !== null) {
let boom = ship.idSpace.bööm[ship.finalExplosion];
if (boom) {
finalExplosionID = boom.globalID;
}
else {
notFoundFunction("shïp id " + base.id + " missing bööm of id " + ship.finalExplosion);
}
}
var shanResource = ship.idSpace.shän[ship.id];
var animation;
if (shanResource) {
animation = yield ShanParse_1.ShanParse(shanResource, notFoundFunction);
}
else {
notFoundFunction("No matching shän for shïp of id " + base.id);
animation = Animation_1.DefaultAnimation;
}
var pictID;
var pict = ship.idSpace.PICT[ship.pictID];
if (pict) {
pictID = pict.globalID;
}
else {
pictID = (yield shipPictMap)[base.id];
if (!pictID) {
notFoundFunction("No matching PICT for ship of id " + base.id);
pictID = PictData_1.DefaultPictData.id;
}
}
// Outfits and weapons are included on the ship. Weapons need to be
// turned into their corresponding outfits.
var outfits = {}; // globalID : count
// Parse Outfits
// Refactor with parse weapons?
for (let i in ship.outfits) {
var o = ship.outfits[i];
var localID = o.id;
var count = o.count;
let outfit = ship.idSpace.oütf[localID];
if (!outfit) {
notFoundFunction("No matching oütf of id " + localID + " for ship of id " + base.id);
continue; // Outfit not found so don't add it
}
var globalID = outfit.globalID;
if (!outfits[globalID]) {
outfits[globalID] = 0;
}
outfits[globalID] += count;
}
// Parse weapons, turning them into their corresponding outfits.
for (let i in ship.weapons) {
var w = ship.weapons[i];
var localID = w.id;
var count = w.count;
var weapon = ship.idSpace.wëap[localID];
if (!weapon) {
notFoundFunction("No matching wëap of id " + localID + " for ship of id " + base.id);
continue;
}
var globalID = weapon.globalID;
var outfitID = (yield weaponOutfitMap)[globalID];
if (!outfitID) {
notFoundFunction("No matching oütf for weapon of id " + weapon.globalID);
continue;
}
if (!outfits[outfitID]) {
outfits[outfitID] = 0;
}
outfits[outfitID] += count;
}
// The ship's free mass is mass on top of the mass of preinstalled outfits,
// so to find it's actual free mass, we add in the masses of all the outfits.
// (this is done while outfits are parsed).
var freeMass = ship.freeSpace;
for (let outfitID in outfits) {
let outfit = globalIDSpace.oütf[outfitID];
freeMass += outfit.mass * outfits[outfitID];
}
var physics = {
shield: ship.shield,
shieldRecharge: ship.shieldRecharge * Constants_1.FPS / 1000,
armor: ship.armor,
armorRecharge: ship.armorRecharge * Constants_1.FPS / 1000,
energy: ship.energy,
energyRecharge: Constants_1.FPS / ship.energyRecharge,
ionization: ship.ionization,
deionize: ship.deionize / 100 * Constants_1.FPS,
speed: ship.speed,
acceleration: ship.acceleration,
turnRate: ship.turnRate * Constants_1.TurnRateConversionFactor,
mass: ship.mass,
freeMass,
freeCargo: ship.cargoSpace
};
return Object.assign({ physics, pict: pictID, desc: desc, outfits, initialExplosion: initialExplosionID, finalExplosion: finalExplosionID, deathDelay: ship.deathDelay / Constants_1.FPS, largeExplosion: ship.deathDelay >= 60, displayWeight: ship.id, // TODO: Fix this once displayweight is implemented
animation, vulnerableTo: ["normal"] }, base);
});
}
exports.ShipParse = ShipParse;
//# sourceMappingURL=ShipParse.js.map