mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-11 00:33:03 +00:00
Show specials; handle import of specials
This commit is contained in:
@@ -105,6 +105,59 @@ export function internal(id) {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds a standard module based on Class, Rating, Group and/or name.
|
||||
* At least one of Group name or unique module name must be provided
|
||||
*
|
||||
* @param {String} groupName [Optional] Full name or abbreviated name for module group
|
||||
* @param {integer} clss module Class
|
||||
* @param {String} rating module Rating
|
||||
* @param {String} name [Optional] Long/unique name for module -e.g. 'Advanced Discover Scanner'
|
||||
* @return {Object} The module if found, null if not found
|
||||
*/
|
||||
export function findStandard(groupName, clss, rating, name) {
|
||||
let groups = {};
|
||||
|
||||
if (groupName) {
|
||||
if (Modules.standard[groupName]) {
|
||||
groups[groupName] = Modules.standard[groupName];
|
||||
} else {
|
||||
let grpCode = ModuleNameToGroup[groupName.toLowerCase()];
|
||||
if (grpCode && Modules.standard[grpCode]) {
|
||||
groups[grpCode] = Modules.standard[grpCode];
|
||||
}
|
||||
}
|
||||
} else if (name) {
|
||||
groups = Modules.standard;
|
||||
}
|
||||
|
||||
for (let g in groups) {
|
||||
let group = groups[g];
|
||||
for (let i = 0, l = group.length; i < l; i++) {
|
||||
if (group[i].class == clss && group[i].rating == rating && ((!name && !group[i].name) || group[i].name == name)) {
|
||||
return group[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a standard Module ID based on Class, Rating, Group and/or name.
|
||||
* At least one of Group name or unique module name must be provided
|
||||
*
|
||||
* @param {String} groupName [Optional] Full name or abbreviated name for module group
|
||||
* @param {integer} clss module Class
|
||||
* @param {String} rating Module Rating
|
||||
* @param {String} name [Optional] Long/unique name for module -e.g. 'Advanced Discover Scanner'
|
||||
* @return {String} The id of the module if found, null if not found
|
||||
*/
|
||||
export function findStandardId(groupName, clss, rating, name) {
|
||||
let i = this.findStandard(groupName, clss, rating, name);
|
||||
return i ? i.id : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an internal module based on Class, Rating, Group and/or name.
|
||||
* At least one ofGroup name or unique module name must be provided
|
||||
|
||||
@@ -8,6 +8,8 @@ import { outfitURL } from '../utils/UrlGenerators';
|
||||
|
||||
const STANDARD = ['powerPlant', 'thrusters', 'frameShiftDrive', 'lifeSupport', 'powerDistributor', 'sensors', 'fuelTank'];
|
||||
|
||||
const STANDARD_GROUPS = {'powerPlant': 'pp', 'thrusters': 't', 'frameShiftDrive': 'fsd', 'lifeSupport': 'ls', 'powerDistributor': 'pd', 'sensors': 's', 'fuelTank': 'ft'};
|
||||
|
||||
/**
|
||||
* Generates ship-loadout JSON Schema standard object
|
||||
* @param {Object} standard model
|
||||
@@ -159,13 +161,12 @@ export function fromDetailedBuild(detailedBuild) {
|
||||
enabled.push(stn[c].enabled === undefined ? true : stn[c].enabled);
|
||||
modifications.push(stn[c].modifications);
|
||||
blueprints.push(stn[c].blueprint);
|
||||
return stn[c].class + stn[c].rating;
|
||||
return ModuleUtils.findStandardId(STANDARD_GROUPS[c], stn[c].class, stn[c].rating, stn[c].name);
|
||||
});
|
||||
|
||||
let internal = comps.internal.map(c => c ? ModuleUtils.findInternalId(c.group, c.class, c.rating, c.name) : 0);
|
||||
|
||||
let hardpoints = comps.hardpoints
|
||||
.map(c => c ? ModuleUtils.findHardpointId(c.group, c.class, c.rating, c.name, MountMap[c.mount], c.missile) : 0)
|
||||
let hardpoints = comps.hardpoints.map(c => c ? ModuleUtils.findHardpointId(c.group, c.class, c.rating, c.name, MountMap[c.mount], c.missile) : 0)
|
||||
.concat(comps.utility.map(c => c ? ModuleUtils.findHardpointId(c.group, c.class, c.rating, c.name, MountMap[c.mount]) : 0));
|
||||
|
||||
// The ordering of these arrays must match the order in which they are read in Ship.buildWith
|
||||
@@ -180,14 +181,14 @@ export function fromDetailedBuild(detailedBuild) {
|
||||
comps.internal.map(c => (!c || c.enabled === undefined) ? true : c.enabled * 1)
|
||||
);
|
||||
modifications = modifications.concat(
|
||||
comps.hardpoints.map(c => (c && c.m ? c.m.modifications : null)),
|
||||
comps.utility.map(c => (c && c.m ? c.m.modifications : null)),
|
||||
comps.internal.map(c => (c && c.m ? c.m.modifications : null))
|
||||
comps.hardpoints.map(c => (c ? c.modifications : null)),
|
||||
comps.utility.map(c => (c ? c.modifications : null)),
|
||||
comps.internal.map(c => (c ? c.modifications : null))
|
||||
);
|
||||
blueprints = blueprints.concat(
|
||||
comps.hardpoints.map(c => (c && c.m ? c.m.blueprint : null)),
|
||||
comps.utility.map(c => (c && c.m ? c.m.blueprint : null)),
|
||||
comps.internal.map(c => (c && c.m ? c.m.blueprint : null))
|
||||
comps.hardpoints.map(c => (c ? c.blueprint : null)),
|
||||
comps.utility.map(c => (c ? c.blueprint : null)),
|
||||
comps.internal.map(c => (c ? c.blueprint : null))
|
||||
);
|
||||
|
||||
ship.buildWith({ bulkheads, standard, hardpoints, internal }, priorities, enabled, modifications, blueprints);
|
||||
|
||||
@@ -480,7 +480,7 @@ export default class Ship {
|
||||
* @param {array} priorities Slot priorities
|
||||
* @param {Array} enabled Slot active/inactive
|
||||
* @param {Array} mods Modifications
|
||||
* @param {Array} blueprints Blueprints
|
||||
* @param {Array} blueprints Blueprints for modifications
|
||||
* @return {this} The current ship instance for chaining
|
||||
*/
|
||||
buildWith(comps, priorities, enabled, mods, blueprints) {
|
||||
@@ -1282,10 +1282,11 @@ export default class Ship {
|
||||
// Start off by gathering the information that we need
|
||||
let slots = new Array();
|
||||
let blueprints = new Array();
|
||||
let specials = new Array();
|
||||
|
||||
let bulkheadMods = new Array();
|
||||
let bulkheadBlueprint = undefined;
|
||||
let bulkheadBlueprintGrade = undefined;
|
||||
let bulkheadBlueprint = null;
|
||||
let bulkheadBlueprintGrade = null;
|
||||
if (this.bulkheads.m && this.bulkheads.m.mods) {
|
||||
for (let modKey in this.bulkheads.m.mods) {
|
||||
// Filter out invalid modifications
|
||||
@@ -1297,6 +1298,7 @@ export default class Ship {
|
||||
}
|
||||
slots.push(bulkheadMods);
|
||||
blueprints.push(bulkheadBlueprint)
|
||||
specials.push(bulkheadBlueprint ? bulkheadBlueprint.special : null);
|
||||
|
||||
for (let slot of this.standard) {
|
||||
let slotMods = new Array();
|
||||
@@ -1309,7 +1311,8 @@ export default class Ship {
|
||||
}
|
||||
}
|
||||
slots.push(slotMods);
|
||||
blueprints.push(slot.m ? slot.m.blueprint : undefined);
|
||||
blueprints.push(slot.m ? slot.m.blueprint : null);
|
||||
specials.push(slot.m && slot.m.blueprint ? slot.m.blueprint.special : null);
|
||||
}
|
||||
|
||||
for (let slot of this.hardpoints) {
|
||||
@@ -1323,7 +1326,8 @@ export default class Ship {
|
||||
}
|
||||
}
|
||||
slots.push(slotMods);
|
||||
blueprints.push(slot.m ? slot.m.blueprint : undefined);
|
||||
blueprints.push(slot.m ? slot.m.blueprint : null);
|
||||
specials.push(slot.m && slot.m.blueprint ? slot.m.blueprint.special : null);
|
||||
}
|
||||
|
||||
for (let slot of this.internal) {
|
||||
@@ -1337,7 +1341,8 @@ export default class Ship {
|
||||
}
|
||||
}
|
||||
slots.push(slotMods);
|
||||
blueprints.push(slot.m ? slot.m.blueprint : undefined);
|
||||
blueprints.push(slot.m ? slot.m.blueprint : null);
|
||||
specials.push(slot.m && slot.m.blueprint ? slot.m.blueprint.special : null);
|
||||
}
|
||||
|
||||
// Now work out the size of the binary buffer from our modifications array
|
||||
@@ -1348,6 +1353,12 @@ export default class Ship {
|
||||
bufsize = bufsize + 1 + 10 + (5 * slot.length) + 1;
|
||||
}
|
||||
}
|
||||
for (let special of specials) {
|
||||
if (special) {
|
||||
// Length is 5 for each special
|
||||
bufsize += 5;
|
||||
}
|
||||
}
|
||||
|
||||
if (bufsize > 0) {
|
||||
bufsize = bufsize + 1; // For end marker
|
||||
@@ -1366,6 +1377,11 @@ export default class Ship {
|
||||
buffer.writeInt32LE(blueprints[i].grade, curpos);
|
||||
curpos += 4;
|
||||
}
|
||||
if (specials[i]) {
|
||||
buffer.writeInt8(MODIFICATION_ID_SPECIAL, curpos++);
|
||||
buffer.writeInt32LE(specials[i].id, curpos);
|
||||
curpos += 4;
|
||||
}
|
||||
for (let slotMod of slot) {
|
||||
buffer.writeInt8(slotMod.id, curpos++);
|
||||
if (isNaN(slotMod.value)) {
|
||||
@@ -1421,6 +1437,8 @@ export default class Ship {
|
||||
blueprint = Object.assign(blueprint, _.find(Modifications.blueprints, function(o) { return o.id === modificationValue; }));
|
||||
} else if (modificationId === MODIFICATION_ID_GRADE) {
|
||||
blueprint.grade = modificationValue;
|
||||
} else if (modificationId === MODIFICATION_ID_SPECIAL) {
|
||||
blueprint.special = _.find(Modifications.specials, function(o) { return o.id === modificationValue; });
|
||||
} else {
|
||||
const modification = _.find(Modifications.modifications, function(o) { return o.id === modificationId; });
|
||||
// console.log('DECODE Slot ' + slot + ': ' + modification.name + ' = ' + modificationValue);
|
||||
|
||||
Reference in New Issue
Block a user