mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Merge branch 'master' of https://github.com/cmmcleod/coriolis into cmmcleod-master
This commit is contained in:
@@ -46,6 +46,7 @@ angular.module('app', ['ui.router', 'ct.ui.router.extras.sticky', 'ui.sortable',
|
||||
$rootScope.fRound = function(d) { return d3.round(d, 2); };
|
||||
$rootScope.fRound4 = function(d) { return d3.round(d, 4); };
|
||||
$rootScope.fPct = d3.format('.2%');
|
||||
$rootScope.f1Pct = d3.format('.1%');
|
||||
$rootScope.fRPct = d3.format('%');
|
||||
$rootScope.fTime = function(d) { return Math.floor(d/60) + ":" + ("00" + Math.floor(d%60)).substr(-2,2); };
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ angular.module('app').controller('OutfitController', ['$window','$rootScope','$s
|
||||
$scope.canSave = Persist.isEnabled();
|
||||
$scope.fuel = 0;
|
||||
$scope.pwrDesc = false;
|
||||
$scope.pwrPredicate = null;
|
||||
$scope.pwrPredicate = 'type';
|
||||
$scope.costDesc = true;
|
||||
$scope.costPredicate = 'c.cost';
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
||||
// Create Y Axis SVG Elements
|
||||
vis.append('g').attr('class', 'watt axis');
|
||||
vis.append('g').attr('class', 'pct axis');
|
||||
vis.append("text").attr('x', -35).attr('y', 15).attr('class','primary').text('RET');
|
||||
vis.append("text").attr('x', -35).attr('y', barHeight + 17).attr('class','primary').text('DEP');
|
||||
vis.append("text").attr('x', -35).attr('y', 16).attr('class','primary').text('RET');
|
||||
vis.append("text").attr('x', -35).attr('y', barHeight + 18).attr('class','primary').text('DEP');
|
||||
|
||||
var retLbl = vis.append("text").attr('y', 15);
|
||||
var depLbl = vis.append("text").attr('y', barHeight + 17);
|
||||
var retLbl = vis.append("text").attr('y', 16);
|
||||
var depLbl = vis.append("text").attr('y', barHeight + 18);
|
||||
|
||||
// Watch for changes to data and events
|
||||
scope.$watchCollection('available', render);
|
||||
@@ -53,24 +53,24 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
||||
deployed.selectAll('text').remove();
|
||||
|
||||
// Update X & Y Axis
|
||||
wattScale.range([0, w]).domain([0, maxPwr]);
|
||||
pctScale.range([0, w]).domain([0, maxPwr / available]);
|
||||
wattScale.range([0, w]).domain([0, maxPwr]).clamp(true);
|
||||
pctScale.range([0, w]).domain([0, maxPwr / available]).clamp(true);
|
||||
|
||||
vis.selectAll('.watt.axis').call(wattAxis);
|
||||
vis.selectAll('.pct.axis').attr('transform', 'translate(0,' + innerHeight + ')').call(pctAxis);
|
||||
|
||||
retLbl
|
||||
.attr('x', wattScale(maxBand.retractedSum) + 5 )
|
||||
.attr('x', w + 5 )
|
||||
.attr('class',maxBand.retractedSum > available? 'warning': 'primary')
|
||||
.text(wattFmt(maxBand.retractedSum) + ' (' + pctFmt(maxBand.retractedSum / available) + ')');
|
||||
.text(wattFmt(Math.max(0,maxBand.retractedSum)) + ' (' + pctFmt(Math.max(0,maxBand.retractedSum / available)) + ')');
|
||||
depLbl
|
||||
.attr('x', wattScale(maxBand.deployedSum) + 5 )
|
||||
.attr('x', w + 5 )
|
||||
.attr('class',maxBand.deployedSum > available? 'warning': 'primary')
|
||||
.text(wattFmt(maxBand.deployedSum) + ' (' + pctFmt(maxBand.deployedSum / available) + ')');
|
||||
.text(wattFmt(Math.max(0,maxBand.deployedSum)) + ' (' + pctFmt(Math.max(0,maxBand.deployedSum / available)) + ')');
|
||||
|
||||
retracted.selectAll("rect").data(bands).enter().append("rect")
|
||||
.attr("height", barHeight)
|
||||
.attr("width", function(d) { return d.retracted? (wattScale(d.retracted) - 1) : 0; })
|
||||
.attr("width", function(d) { return Math.max(wattScale(d.retracted) - 1, 0); })
|
||||
.attr("x", function(d) { return wattScale(d.retractedSum) - wattScale(d.retracted); })
|
||||
.attr('y', 1)
|
||||
.attr('class',function(d){ return (d.retractedSum > available)? 'warning' :'primary'; });
|
||||
@@ -84,7 +84,7 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
||||
|
||||
deployed.selectAll("rect").data(bands).enter().append("rect")
|
||||
.attr("height", barHeight)
|
||||
.attr("width", function(d) { return (d.deployed || d.retracted)? (wattScale(d.deployed + d.retracted) - 1) : 0; })
|
||||
.attr("width", function(d) { return Math.max(wattScale(d.deployed + d.retracted) - 1, 0); })
|
||||
.attr("x", function(d) { return wattScale(d.deployedSum) - wattScale(d.retracted) - wattScale(d.deployed); })
|
||||
.attr('y', barHeight + 2)
|
||||
.attr('class',function(d){ return (d.deployedSum > available)? 'warning' :'primary'; });
|
||||
@@ -99,13 +99,8 @@ angular.module('app').directive('powerBands', ['$window', function ($window) {
|
||||
}
|
||||
|
||||
function bandText(val, index) {
|
||||
if (val > 0) {
|
||||
if( wattScale(val) > 100) {
|
||||
return (index + 1) + ' (' + wattFmt(val) + ' MW)';
|
||||
}
|
||||
if( wattScale(val) > 10) {
|
||||
return index + 1;
|
||||
}
|
||||
if (val > 0 && wattScale(val) > 13) {
|
||||
return index + 1;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -9,11 +9,20 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
||||
* @return {string} Encoded string of components
|
||||
*/
|
||||
this.fromShip = function(ship) {
|
||||
var power = {
|
||||
enabled: [ship.cargoScoop.enabled? 1 : 0],
|
||||
priorities: [ship.cargoScoop.priority]
|
||||
};
|
||||
|
||||
var data = [
|
||||
ship.bulkheads.id,
|
||||
_.map(ship.common, idToStr),
|
||||
_.map(ship.hardpoints, idToStr),
|
||||
_.map(ship.internal, idToStr),
|
||||
_.map(ship.common, mapGroup, power),
|
||||
_.map(ship.hardpoints, mapGroup, power),
|
||||
_.map(ship.internal, mapGroup, power),
|
||||
'.',
|
||||
LZString.compressToBase64(power.enabled.join('')).replace(/\//g,'-'),
|
||||
'.',
|
||||
LZString.compressToBase64(power.priorities.join('')).replace(/\//g,'-')
|
||||
];
|
||||
|
||||
return _.flatten(data).join('');
|
||||
@@ -26,32 +35,38 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
||||
* @param {Ship} ship The ship instance to be updated
|
||||
* @param {string} code The string to deserialize
|
||||
*/
|
||||
this.toShip = function (ship, code) {
|
||||
var commonCount = ship.common.length;
|
||||
var hpCount = commonCount + ship.hardpoints.length;
|
||||
var comps = {
|
||||
bulkheads: code.charAt(0) * 1,
|
||||
common: new Array(ship.common.length),
|
||||
hardpoints: new Array(ship.hardpoints.length),
|
||||
internal: new Array(ship.internal.length)
|
||||
};
|
||||
this.toShip = function (ship, dataString) {
|
||||
var commonCount = ship.common.length,
|
||||
hpCount = commonCount + ship.hardpoints.length,
|
||||
totalCount = hpCount + ship.internal.length,
|
||||
common = new Array(ship.common.length),
|
||||
hardpoints = new Array(ship.hardpoints.length),
|
||||
internal = new Array(ship.internal.length),
|
||||
parts = dataString.split('.'),
|
||||
priorities = null,
|
||||
enabled = null,
|
||||
code = parts[0];
|
||||
|
||||
// TODO: improve...
|
||||
for (var i = 1, c = 0, l = code.length; i < l; i++) {
|
||||
var empty = code.charAt(i) == '-';
|
||||
if (c < commonCount) {
|
||||
comps.common[c] = empty? 0 : code.substring(i, i + 2);
|
||||
} else if (c < hpCount) {
|
||||
comps.hardpoints[c - commonCount] = empty? 0 : code.substring(i, i + 2);
|
||||
} else {
|
||||
comps.internal[c - hpCount] = empty? 0 : code.substring(i, i + 2);
|
||||
}
|
||||
if (!empty) {
|
||||
i++;
|
||||
}
|
||||
c++;
|
||||
if(parts[1]) {
|
||||
enabled = LZString.decompressFromBase64(parts[1].replace(/-/g,'/')).split('');
|
||||
}
|
||||
ship.buildWith(comps);
|
||||
|
||||
if(parts[2]) {
|
||||
priorities = LZString.decompressFromBase64(parts[2].replace(/-/g,'/')).split('');
|
||||
}
|
||||
|
||||
decodeToArray(code, internal, decodeToArray(code, hardpoints, decodeToArray(code, common, 1)));
|
||||
|
||||
// get the remaining substring / split into parts for
|
||||
// - priorities
|
||||
// - enabled/disabled
|
||||
|
||||
ship.buildWith({
|
||||
bulkheads: code.charAt(0) * 1,
|
||||
common: common,
|
||||
hardpoints: hardpoints,
|
||||
internal: internal,
|
||||
}, priorities, enabled);
|
||||
};
|
||||
|
||||
this.fromComparison = function (name, builds, facets, predicate, desc) {
|
||||
@@ -82,8 +97,24 @@ angular.module('app').service('Serializer', ['lodash', function (_) {
|
||||
* @param {object} slot The slot object.
|
||||
* @return {string} The id of the selected component or '-' if none selected
|
||||
*/
|
||||
function idToStr(slot) {
|
||||
function mapGroup(slot) {
|
||||
this.enabled.push(slot.enabled? 1 : 0);
|
||||
this.priorities.push(slot.priority);
|
||||
|
||||
return (slot.id === null)? '-' : slot.id;
|
||||
}
|
||||
|
||||
function decodeToArray(code, arr, codePos) {
|
||||
for (i = 0; i < arr.length; i++) {
|
||||
if (code.charAt(codePos) == '-') {
|
||||
arr[i] = 0;
|
||||
codePos++;
|
||||
} else {
|
||||
arr[i] = code.substring(codePos, codePos + 2);
|
||||
codePos += 2;
|
||||
}
|
||||
}
|
||||
return codePos;
|
||||
}
|
||||
|
||||
}]);
|
||||
|
||||
@@ -9,7 +9,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
*/
|
||||
function Ship(id, properties, slots) {
|
||||
this.id = id;
|
||||
this.cargoScoop = { enabled: true, c: Components.cargoScoop(), type: 'SYS' };
|
||||
this.cargoScoop = { c: Components.cargoScoop(), type: 'SYS' };
|
||||
this.bulkheads = { incCost: true, maxClass: 8 };
|
||||
|
||||
for (var p in properties) { this[p] = properties[p]; } // Copy all base properties from shipData
|
||||
@@ -18,7 +18,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
var slotGroup = slots[slotType];
|
||||
var group = this[slotType] = []; // Initialize Slot group (Common, Hardpoints, Internal)
|
||||
for(var i = 0; i < slotGroup.length; i++){
|
||||
group.push({id: null, c: null, enabled: true, incCost: true, maxClass: slotGroup[i]});
|
||||
group.push({id: null, c: null, incCost: true, maxClass: slotGroup[i]});
|
||||
}
|
||||
}
|
||||
this.c = { incCost: true, c: { name: this.name, cost: this.cost } }; // Make a 'Ship' component similar to other components
|
||||
@@ -35,6 +35,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
this.powerList.unshift(this.common[3]); // Add Life Support
|
||||
this.powerList.unshift(this.common[2]); // Add FSD
|
||||
this.powerList.unshift(this.common[0]); // Add Power Plant
|
||||
|
||||
this.priorityBands = [
|
||||
{deployed: 0, retracted: 0},
|
||||
{deployed: 0, retracted: 0},
|
||||
@@ -43,7 +44,7 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
{deployed: 0, retracted: 0}
|
||||
];
|
||||
|
||||
// Reset cumulative and aggragate stats
|
||||
// Cumulative and aggragate stats
|
||||
this.fuelCapacity = 0;
|
||||
this.cargoCapacity = 0;
|
||||
this.ladenMass = 0;
|
||||
@@ -58,31 +59,38 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
* Builds/Updates the ship instance with the components[comps] passed in.
|
||||
* @param {object} comps Collection of components used to build the ship
|
||||
*/
|
||||
Ship.prototype.buildWith = function(comps) {
|
||||
var internal = this.internal;
|
||||
var common = this.common;
|
||||
var hps = this.hardpoints;
|
||||
var bands = this.priorityBands;
|
||||
var i,l;
|
||||
Ship.prototype.buildWith = function(comps, priorities, enabled) {
|
||||
var internal = this.internal,
|
||||
common = this.common,
|
||||
hps = this.hardpoints,
|
||||
bands = this.priorityBands,
|
||||
cl = common.length, hl = hps.length, il = internal.length,
|
||||
i,l;
|
||||
|
||||
this.useBulkhead(comps.bulkheads || 0, true);
|
||||
this.cargoScoop.priority = 0; // TODO set from comps
|
||||
bands[this.cargoScoop.priority].retracted += this.cargoScoop.c.power;
|
||||
this.cargoScoop.priority = priorities? priorities[0] * 1 : 0;
|
||||
this.cargoScoop.enabled = enabled? enabled[0] * 1 : true;
|
||||
|
||||
for(i = 0, l = comps.common.length; i < l; i++) {
|
||||
common[i].enabled = true; // TODO set enabled from comps
|
||||
common[i].priority = 0; // TODO set from comps
|
||||
if (this.cargoScoop.enabled) {
|
||||
bands[this.cargoScoop.priority].retracted += this.cargoScoop.c.power;
|
||||
}
|
||||
|
||||
for(i = 0; i < cl; i++) {
|
||||
common[i].enabled = enabled? enabled[i + 1] * 1 : true;
|
||||
common[i].priority = priorities? priorities[i + 1] * 1 : 0;
|
||||
common[i].type = 'SYS';
|
||||
this.use(common[i], comps.common[i], Components.common(i, comps.common[i]), true);
|
||||
}
|
||||
|
||||
common[1].type = 'ENG'; // Thrusters
|
||||
common[2].type = 'ENG'; // FSD
|
||||
cl++; // Increase accounting for Cargo Scoop
|
||||
|
||||
for(i = 0, l = comps.hardpoints.length; i < l; i++) {
|
||||
hps[i].enabled = true; // TODO set enabled from comps
|
||||
hps[i].priority = 0; // TODO set from comps
|
||||
hps[i].enabled = enabled? enabled[cl + i] * 1 : true;
|
||||
hps[i].priority = priorities? priorities[cl + i] * 1 : 0;
|
||||
hps[i].type = hps[i].maxClass? 'WEP' : 'SYS';
|
||||
|
||||
if (comps.hardpoints[i] !== 0) {
|
||||
this.use(hps[i], comps.hardpoints[i], Components.hardpoints(comps.hardpoints[i]), true);
|
||||
} else {
|
||||
@@ -91,9 +99,10 @@ angular.module('shipyard').factory('Ship', ['Components', 'calcShieldStrength',
|
||||
}
|
||||
|
||||
for(i = 0, l = comps.internal.length; i < l; i++) {
|
||||
internal[i].enabled = true; // TODO set enabled from comps
|
||||
internal[i].priority = 0; // TODO set from comps
|
||||
internal[i].enabled = enabled? enabled[hl + cl + i] * 1 : true;
|
||||
internal[i].priority = priorities? priorities[hl + cl + i] * 1 : 0;
|
||||
internal[i].type = 'SYS';
|
||||
|
||||
if (comps.internal[i] !== 0) {
|
||||
this.use(internal[i], comps.internal[i], Components.internal(comps.internal[i]), true);
|
||||
} else {
|
||||
|
||||
@@ -110,6 +110,7 @@ header {
|
||||
}
|
||||
|
||||
ul {
|
||||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
margin: 0 0 0.5em;
|
||||
padding: 0;
|
||||
|
||||
@@ -155,6 +155,7 @@ table.total {
|
||||
|
||||
.smallTablet({
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
width: 100% !important;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
<div class="r menu">
|
||||
<div class="menu-header" ng-class="{selected: openedMenu=='settings'}" ng-click="openMenu($event,'settings')">
|
||||
<svg class="icon xl warning"><use xlink:href="#cogs"></use></svg>
|
||||
<svg class="icon xl warning"><use xlink:href="#cogs"></use></svg><span class="menu-item-label"> Settings</span>
|
||||
</div>
|
||||
<div class="menu-list no-wrap" ng-if="openedMenu=='settings'" ng-click="$event.stopPropagation();">
|
||||
<ul>
|
||||
|
||||
@@ -194,7 +194,7 @@
|
||||
</div>
|
||||
|
||||
<div class="group dbl">
|
||||
<table style="width:100%">
|
||||
<table style="min-width:500px;width:100%">
|
||||
<thead>
|
||||
<tr class="main">
|
||||
<th colspan="2" class="sortable le" ng-click="sortPwr(cName)">Component</th>
|
||||
@@ -223,14 +223,14 @@
|
||||
<td ng-click="togglePwr(c)"><u ng-bind="c.type"></u></td>
|
||||
<td><span ng-click="decPriority(c)">◀</span> {{c.priority + 1}} <span ng-click="incPriority(c)">▶</span></td>
|
||||
<td class="ri" style="width:3.25em;">{{fPwr(c.c.power)}}</td>
|
||||
<td class="ri" style="width:2em;"><u>{{fRPct(c.c.power/ship.powerAvailable)}}</u></td>
|
||||
<td class="ri" style="width:3em;"><u>{{f1Pct(c.c.power/ship.powerAvailable)}}</u></td>
|
||||
<td ng-if="!c.enabled" class="disabled" colspan="2">DISABLED</td>
|
||||
<td ng-if="c.enabled" ng-class="STATUS_CLASS[statusRetracted(c)]">{{STATUS[statusRetracted(c)]}}</td>
|
||||
<td ng-if="c.enabled" ng-class="STATUS_CLASS[statusDeployed(c)]">{{STATUS[statusDeployed(c)]}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div style="margin-top: 1em" power-bands bands="priorityBands" available="ship.powerAvailable"></div>
|
||||
<div style="min-width: 500px; margin-top: 1em" power-bands bands="priorityBands" available="ship.powerAvailable"></div>
|
||||
</div>
|
||||
|
||||
<div class="group dbl">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "coriolis_shipyard",
|
||||
"version": "0.10.1",
|
||||
"version": "0.11.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cmmcleod/coriolis"
|
||||
|
||||
Reference in New Issue
Block a user