mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 06:43:24 +00:00
Add/impromve find compoonent functions
This commit is contained in:
@@ -145,11 +145,11 @@ angular.module('app').controller('ImportController', ['lodash', '$rootScope', '$
|
|||||||
|
|
||||||
group = _.find(GroupMap, equalsIgnoreCase, name);
|
group = _.find(GroupMap, equalsIgnoreCase, name);
|
||||||
|
|
||||||
var hpid = Components.findHardpointId(group, cl, rating, group ? null : name, mount, missile);
|
var hp = Components.findHardpoint(group, cl, rating, group ? null : name, mount, missile);
|
||||||
|
|
||||||
if (!hpid) { throw 'Unknown component: "' + line + '"'; }
|
if (!hp) { throw 'Unknown component: "' + line + '"'; }
|
||||||
|
|
||||||
ship.use(slot, hpid, Components.hardpoints(hpid), true);
|
ship.use(slot, hp.id, hp, true);
|
||||||
|
|
||||||
} else if (typeSize == 'BH') {
|
} else if (typeSize == 'BH') {
|
||||||
var bhId = bhMap[name.toLowerCase()];
|
var bhId = bhMap[name.toLowerCase()];
|
||||||
@@ -177,11 +177,11 @@ angular.module('app').controller('ImportController', ['lodash', '$rootScope', '$
|
|||||||
|
|
||||||
group = _.find(GroupMap, equalsIgnoreCase, name);
|
group = _.find(GroupMap, equalsIgnoreCase, name);
|
||||||
|
|
||||||
var intId = Components.findInternalId(group, cl, rating, group ? null : name);
|
var intComp = Components.findInternal(group, cl, rating, group ? null : name);
|
||||||
|
|
||||||
if (!intId) { throw 'Unknown component: "' + line + '"'; }
|
if (!intComp) { throw 'Unknown component: "' + line + '"'; }
|
||||||
|
|
||||||
ship.use(slot, intId, Components.internal(intId));
|
ship.use(slot, intComp.id, intComp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,11 +143,10 @@ angular.module('app').service('Serializer', ['lodash', 'GroupMap', 'MountMap', '
|
|||||||
var internal = _.map(comps.internal, function(c) { return c ? Components.findInternalId(c.group, c.class, c.rating, c.name) : 0; });
|
var internal = _.map(comps.internal, function(c) { return c ? Components.findInternalId(c.group, c.class, c.rating, c.name) : 0; });
|
||||||
|
|
||||||
var hardpoints = _.map(comps.hardpoints, function(c) {
|
var hardpoints = _.map(comps.hardpoints, function(c) {
|
||||||
return c ? Components.findHardpointId(c.group, c.class, c.rating, c.name, MountMap[c.mount], c.missile) : 0;
|
return c ? Components.findHardpointId(c.group, c.class, c.rating, c.name, MountMap[c.mount], c.missile) : 0;
|
||||||
});
|
}).concat(_.map(comps.utility, function(c) {
|
||||||
hardpoints = hardpoints.concat(_.map(comps.utility, function(c) {
|
return c ? Components.findHardpointId(c.group, c.class, c.rating, c.name, MountMap[c.mount]) : 0;
|
||||||
return c ? Components.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
|
// The ordering of these arrays must match the order in which they are read in Ship.buildWith
|
||||||
priorities = priorities.concat(_.map(comps.hardpoints, function(c) { return (!c || c.priority === undefined) ? 0 : c.priority - 1; }),
|
priorities = priorities.concat(_.map(comps.hardpoints, function(c) { return (!c || c.priority === undefined) ? 0 : c.priority - 1; }),
|
||||||
|
|||||||
@@ -38,46 +38,85 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'Shi
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.findInternalId = function(groupName, clss, rating, name) {
|
/**
|
||||||
|
* Finds an internal Component based on Class, Rating, Group and/or name.
|
||||||
|
* At least one ofGroup name or unique component name must be provided
|
||||||
|
*
|
||||||
|
* @param {string} groupName [Optional] Full name or abbreviated name for component group
|
||||||
|
* @param {integer} clss Component Class
|
||||||
|
* @param {string} rating Component Rating
|
||||||
|
* @param {string} name [Optional] Long/unique name for component -e.g. 'Advanced Discover Scanner'
|
||||||
|
* @return {String} The id of the component if found, null if not found
|
||||||
|
*/
|
||||||
|
this.findInternal = function(groupName, clss, rating, name) {
|
||||||
var groups = {};
|
var groups = {};
|
||||||
|
|
||||||
if (groupName) {
|
if (groupName) {
|
||||||
var grpCode = GrpNameToCodeMap[groupName];
|
if (C.internal[groupName]) {
|
||||||
if (grpCode && !C.internal[grpCode]) {
|
groups[groupName] = C.internal[groupName];
|
||||||
throw 'Invalid internal group: ' + groupName;
|
} else {
|
||||||
|
var grpCode = GrpNameToCodeMap[groupName];
|
||||||
|
if (grpCode && C.internal[grpCode]) {
|
||||||
|
groups[grpCode] = C.internal[grpCode];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
groups[grpCode] = C.internal[grpCode];
|
|
||||||
} else if (name) {
|
} else if (name) {
|
||||||
groups = C.internal;
|
groups = C.internal;
|
||||||
} else {
|
|
||||||
throw 'Invalid group or name not provided';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var g in groups) {
|
for (var g in groups) {
|
||||||
var group = groups[g];
|
var group = groups[g];
|
||||||
for (var i = 0, l = group.length; i < l; i++) {
|
for (var 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)) {
|
if (group[i].class == clss && group[i].rating == rating && ((!name && !group[i].name) || group[i].name == name)) {
|
||||||
return group[i].id;
|
return group[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.findHardpointId = function(groupName, clss, rating, name, mode, missile) {
|
/**
|
||||||
|
* Finds an internal Component ID based on Class, Rating, Group and/or name.
|
||||||
|
* At least one ofGroup name or unique component name must be provided
|
||||||
|
*
|
||||||
|
* @param {string} groupName [Optional] Full name or abbreviated name for component group
|
||||||
|
* @param {integer} clss Component Class
|
||||||
|
* @param {string} rating Component Rating
|
||||||
|
* @param {string} name [Optional] Long/unique name for component -e.g. 'Advanced Discover Scanner'
|
||||||
|
* @return {String} The id of the component if found, null if not found
|
||||||
|
*/
|
||||||
|
this.findInternalId = function(groupName, clss, rating, name) {
|
||||||
|
var i = this.findInternal(groupName, clss, rating, name);
|
||||||
|
return i ? i.id : 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a hardpoint Component based on Class, Rating, Group and/or name.
|
||||||
|
* At least one ofGroup name or unique component name must be provided
|
||||||
|
*
|
||||||
|
* @param {string} groupName [Optional] Full name or abbreviated name for component group
|
||||||
|
* @param {integer} clss Component Class
|
||||||
|
* @param {string} rating Component Rating
|
||||||
|
* @param {string} name [Optional] Long/unique name for component -e.g. 'Heat Sink Launcher'
|
||||||
|
* @param {string} mode Mount mode/type - [F]ixed, [G]imballed, [T]urret
|
||||||
|
* @param {string} missile [Optional] Missile type - [D]umbfire, [S]eeker
|
||||||
|
* @return {String} The id of the component if found, null if not found
|
||||||
|
*/
|
||||||
|
this.findHardpoint = function(groupName, clss, rating, name, mode, missile) {
|
||||||
var groups = {};
|
var groups = {};
|
||||||
|
|
||||||
if (groupName) {
|
if (groupName) {
|
||||||
var grpCode = GrpNameToCodeMap[groupName];
|
if (C.hardpoints[groupName]) {
|
||||||
if (grpCode && !C.hardpoints[grpCode]) {
|
groups[groupName] = C.hardpoints[groupName];
|
||||||
throw 'Invalid internal group: ' + groupName;
|
} else {
|
||||||
|
var grpCode = GrpNameToCodeMap[groupName];
|
||||||
|
if (grpCode && C.hardpoints[grpCode]) {
|
||||||
|
groups[grpCode] = C.hardpoints[grpCode];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
groups[grpCode] = C.hardpoints[grpCode];
|
|
||||||
} else if (name) {
|
} else if (name) {
|
||||||
groups = C.hardpoints;
|
groups = C.hardpoints;
|
||||||
} else {
|
|
||||||
throw 'Invalid group or name not provided';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var g in groups) {
|
for (var g in groups) {
|
||||||
@@ -87,12 +126,29 @@ angular.module('shipyard').service('Components', ['lodash', 'ComponentsDB', 'Shi
|
|||||||
&& ((!name && !group[i].name) || group[i].name == name)
|
&& ((!name && !group[i].name) || group[i].name == name)
|
||||||
&& ((!missile && !group[i].missile) || group[i].missile == missile)
|
&& ((!missile && !group[i].missile) || group[i].missile == missile)
|
||||||
) {
|
) {
|
||||||
return group[i].id;
|
return group[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a hardpoint Component ID based on Class, Rating, Group and/or name.
|
||||||
|
* At least one of Group name or unique component name must be provided
|
||||||
|
*
|
||||||
|
* @param {string} groupName [Optional] Full name or abbreviated name for component group
|
||||||
|
* @param {integer} clss Component Class
|
||||||
|
* @param {string} rating Component Rating
|
||||||
|
* @param {string} name [Optional] Long/unique name for component -e.g. 'Heat Sink Launcher'
|
||||||
|
* @param {string} mode Mount mode/type - [F]ixed, [G]imballed, [T]urret
|
||||||
|
* @param {string} missile [Optional] Missile type - [D]umbfire, [S]eeker
|
||||||
|
* @return {String} The id of the component if found, null if not found
|
||||||
|
*/
|
||||||
|
this.findHardpointId = function(groupName, clss, rating, name, mode, missile) {
|
||||||
|
var h = this.findHardpoint(groupName, clss, rating, name, mode, missile);
|
||||||
|
return h ? h.id : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user