mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Handle erroneous data better
This commit is contained in:
@@ -26,8 +26,8 @@ angular.module('app').controller('ImportController', ['lodash', '$rootScope', '$
|
||||
if (!shipData) {
|
||||
throw '"' + shipId + '" is not a valid Ship Id!';
|
||||
}
|
||||
if (typeof name != 'string' || name.length < 3) {
|
||||
throw shipData.properties.name + ' build "' + name + '" must be a string at least 3 characters long!';
|
||||
if (typeof name != 'string' || name.length == 0) {
|
||||
throw shipData.properties.name + ' build "' + name + '" must be a string at least 1 character long!';
|
||||
}
|
||||
if (typeof code != 'string' || code.length < 10) {
|
||||
throw shipData.properties.name + ' build "' + name + '" is not valid!';
|
||||
@@ -45,6 +45,10 @@ angular.module('app').controller('ImportController', ['lodash', '$rootScope', '$
|
||||
throw 'Build Name missing!';
|
||||
}
|
||||
|
||||
if (!detailedBuild.name.trim()) {
|
||||
throw 'Build Name must be a string at least 1 character long!';
|
||||
}
|
||||
|
||||
try {
|
||||
ship = Serializer.fromDetailedBuild(detailedBuild);
|
||||
} catch (e) {
|
||||
@@ -213,7 +217,7 @@ angular.module('app').controller('ImportController', ['lodash', '$rootScope', '$
|
||||
|
||||
if (importData instanceof Array) { // Must be detailed export json
|
||||
importDetailedArray(importData);
|
||||
} else if (importData.ship && importData.name) { // Using JSON from a single ship build export
|
||||
} else if (importData.ship && typeof importData.name !== undefined) { // Using JSON from a single ship build export
|
||||
importDetailedArray([importData]); // Convert to array with singleobject
|
||||
} else { // Using Backup JSON
|
||||
importBackup(importData);
|
||||
|
||||
@@ -195,7 +195,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
for (i = 0; i < cl; i++) {
|
||||
common[i].cat = 0;
|
||||
common[i].enabled = enabled ? enabled[i + 1] * 1 : true;
|
||||
common[i].priority = priorities ? priorities[i + 1] * 1 : 0;
|
||||
common[i].priority = priorities && priorities[i + 1] ? priorities[i + 1] * 1 : 0;
|
||||
common[i].type = 'SYS';
|
||||
common[i].c = common[i].id = null; // Resetting 'old' component if there was one
|
||||
common[i].discountedCost = 0;
|
||||
@@ -212,7 +212,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
for (i = 0, l = hps.length; i < l; i++) {
|
||||
hps[i].cat = 1;
|
||||
hps[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
||||
hps[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
||||
hps[i].priority = priorities && priorities[cl + i] ? priorities[cl + i] * 1 : 0;
|
||||
hps[i].type = hps[i].maxClass ? 'WEP' : 'SYS';
|
||||
hps[i].c = hps[i].id = null; // Resetting 'old' component if there was one
|
||||
hps[i].discountedCost = 0;
|
||||
@@ -227,7 +227,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
for (i = 0, l = internal.length; i < l; i++) {
|
||||
internal[i].cat = 2;
|
||||
internal[i].enabled = enabled ? enabled[cl + i] * 1 : true;
|
||||
internal[i].priority = priorities ? priorities[cl + i] * 1 : 0;
|
||||
internal[i].priority = priorities && priorities[cl + i] ? priorities[cl + i] * 1 : 0;
|
||||
internal[i].type = 'SYS';
|
||||
internal[i].id = internal[i].c = null; // Resetting 'old' component if there was one
|
||||
internal[i].discountedCost = 0;
|
||||
|
||||
Reference in New Issue
Block a user