novaparse
Version:
An EV Nova file parser for NovaJS
201 lines • 9.13 kB
JavaScript
"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 WeaponData_1 = require("novadatainterface/WeaponData");
const Constants_1 = require("./Constants");
const Animation_1 = require("novadatainterface/Animation");
const ShipData_1 = require("novadatainterface/ShipData");
function BaseWeaponParse(weap, _notFoundFunction, base) {
return __awaiter(this, void 0, void 0, function* () {
// TODO: Implement ammo
return Object.assign({}, base, { accuracy: weap.accuracy, ammoType: "unlimited", burstCount: weap.burstCount, burstReload: weap.burstReload, destroyShipWhenFiring: weap.ammoType === -999, exitType: weap.exitType, fireGroup: weap.fireGroup, fireRate: Constants_1.FPS / weap.reload, fireSimultaneously: weap.fireSimultaneously, shotSpeed: weap.speed, useFiringAnimation: weap.useFiringAnimation });
});
}
function NotBayWeaponParse(weap, notFoundFunction, baseWeapon) {
return __awaiter(this, void 0, void 0, function* () {
let primaryExplosion = null;
if (weap.explosion !== null) {
let primaryExplosionResource = weap.idSpace.bööm[weap.explosion];
if (primaryExplosionResource) {
primaryExplosion = primaryExplosionResource.globalID;
}
else {
notFoundFunction("Missing primary explosion " + weap.explosion + " for wëap id " + baseWeapon.id);
}
}
let secondaryExplosion = null;
if (weap.explosion128sparks) {
let secondaryExplosionResource = weap.idSpace.bööm[128];
if (secondaryExplosionResource) {
secondaryExplosion = secondaryExplosionResource.globalID;
}
else {
notFoundFunction("Missing secondary explosion 128 for wëap id " + baseWeapon.id);
}
}
let damageType;
if (weap.fireGroup == "pointDefense") {
damageType = "pointDefense";
}
else {
damageType = "normal";
}
return Object.assign({}, baseWeapon, { oneAmmoPerBurst: weap.oneAmmoPerBurst, ionizationColor: weap.ionizeColor, shotDuration: weap.duration, primaryExplosion,
secondaryExplosion, knockback: weap.impact, damageType });
});
}
function ProjectileWeaponParse(weap, notFoundFunction, baseWeapon) {
return __awaiter(this, void 0, void 0, function* () {
var notBayBase = yield NotBayWeaponParse(weap, notFoundFunction, baseWeapon);
// Parse Submunition if it exists
var submunitions = [];
if (weap.submunition) {
var subResource = weap.idSpace.wëap[weap.submunition.id];
if (subResource) {
submunitions.push({
count: weap.submunition.count,
fireAtNearest: weap.submunition.fireAtNearest,
id: subResource.globalID,
limit: weap.submunition.limit,
subIfExpire: weap.submunition.subIfExpire,
theta: weap.submunition.theta
});
}
else {
notFoundFunction("Missing submunition id " + weap.submunition.id + " for wëap " + notBayBase.id);
}
}
if (!weap.graphic) {
throw new Error("ProjectileWeapon " + baseWeapon.id + " had no graphic listed");
}
// Parse the weapon's animation (the projectile it fires)
var animation;
let spinResource = weap.idSpace.spïn[weap.graphic];
if (spinResource) {
let rledResource = spinResource.idSpace.rlëD[spinResource.spriteID];
if (rledResource) {
// There should be an animationFromSpin function
// because spins will eventually allow picts to be used
// instead of rleds
animation = {
exitPoints: Animation_1.DefaultExitPoints,
id: baseWeapon.id,
name: baseWeapon.name,
prefix: baseWeapon.prefix,
images: {
baseImage: {
id: rledResource.globalID,
imagePurposes: {
normal: { start: 0, length: rledResource.numberOfFrames }
}
}
}
};
}
else {
notFoundFunction("Missing rlëD id " + spinResource.spriteID + " for spïn " + weap.graphic);
animation = Animation_1.DefaultAnimation;
}
}
else {
notFoundFunction("Missing spïn id " + weap.graphic + " for wëap " + notBayBase.id);
animation = Animation_1.DefaultAnimation;
}
// Verify that guidance is correct for a projectile-type weapon
var guidance;
if (!WeaponData_1.ProjectileGuidanceSet.has(weap.guidance)) {
throw new Error("Wrong guidance type " + weap.guidance + " for ProjectileWeapon");
}
else {
guidance = weap.guidance;
}
// Get if the weapon is vulnerable to Point Defense
var vulnerableTo;
if (weap.vulnerableToPD && guidance === "guided") {
vulnerableTo = ["pointDefense"];
}
else {
vulnerableTo = [];
}
return Object.assign({}, notBayBase, { type: "ProjectileWeaponData", guidance,
submunitions, proxRadius: weap.proxRadius, proxSafety: weap.proxSafety / Constants_1.FPS, trailParticles: weap.trailParticles, hitParticles: weap.hitParticles, animation,
vulnerableTo, physics: {
acceleration: 0,
armorRecharge: 0,
deionize: 0,
energy: 0,
energyRecharge: 0,
ionization: 0,
mass: 0,
shieldRecharge: 0,
speed: weap.speed,
turnRate: weap.turnRate * Constants_1.TurnRateConversionFactor,
shield: 0,
armor: weap.durability
} });
});
}
function BeamWeaponParse(weap, notFoundFunction, baseWeapon) {
return __awaiter(this, void 0, void 0, function* () {
var notBayBase = yield NotBayWeaponParse(weap, notFoundFunction, baseWeapon);
var guidance;
if (!WeaponData_1.BeamGuidanceSet.has(weap.guidance)) {
throw new Error("Wrong guidance type " + weap.guidance + " for BeamWeapon");
}
else {
guidance = weap.guidance;
}
return Object.assign({}, notBayBase, { type: "BeamWeaponData", guidance, beamAnimation: {
beamColor: weap.beamColor,
coronaColor: weap.coronaColor,
coronaFalloff: weap.coronaFalloff,
length: weap.beamLength,
width: weap.beamWidth
} });
});
}
function BayWeaponParse(weap, notFoundFunction, baseWeapon) {
return __awaiter(this, void 0, void 0, function* () {
var ship = weap.idSpace.shïp[weap.ammoType];
var shipID;
if (ship) {
shipID = ship.globalID;
}
else {
notFoundFunction("Missing shïp " + weap.ammoType + " for bay weapon " + baseWeapon.id);
shipID = ShipData_1.DefaultShipData.id;
}
return Object.assign({}, baseWeapon, { type: "BayWeaponData", shipID });
});
}
function WeaponParse(weap, notFoundFunction) {
return __awaiter(this, void 0, void 0, function* () {
var base = yield BaseParse_1.BaseParse(weap, notFoundFunction);
var baseWeapon = yield BaseWeaponParse(weap, notFoundFunction, base);
var guidanceType = weap.guidance;
var parseFunc;
if (WeaponData_1.ProjectileGuidanceSet.has(weap.guidance)) {
parseFunc = ProjectileWeaponParse;
}
else if (WeaponData_1.BeamGuidanceSet.has(weap.guidance)) {
parseFunc = BeamWeaponParse;
}
else if (WeaponData_1.BayGuidanceSet.has(weap.guidance)) {
parseFunc = BayWeaponParse;
}
else {
throw new Error("Unknown guidance type " + weap.guidance + " for wëap id " + weap.globalID);
}
return yield parseFunc(weap, notFoundFunction, baseWeapon);
});
}
exports.WeaponParse = WeaponParse;
//# sourceMappingURL=WeaponParse.js.map