mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-10 15:15:34 +00:00
Allow for SE prefixes when formating module stats
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import * as ModuleUtils from './ModuleUtils';
|
import * as ModuleUtils from './ModuleUtils';
|
||||||
import { Modifications } from 'coriolis-data/dist';
|
import { Modifications } from 'coriolis-data/dist';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import StatsFormating from './StatsFormating';
|
import { STATS_FORMATING, SI_PREFIXES } from './StatsFormating';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module - active module in a ship's buildout
|
* Module - active module in a ship's buildout
|
||||||
@@ -45,8 +45,8 @@ export default class Module {
|
|||||||
let result = this.mods && this.mods[name] ? this.mods[name] : null;
|
let result = this.mods && this.mods[name] ? this.mods[name] : null;
|
||||||
|
|
||||||
// Calculate the percentage change for a synthetic value
|
// Calculate the percentage change for a synthetic value
|
||||||
if (StatsFormating[name] && StatsFormating[name].synthetic) {
|
if (STATS_FORMATING[name] && STATS_FORMATING[name].synthetic) {
|
||||||
const statGetter = this[StatsFormating[name].synthetic];
|
const statGetter = this[STATS_FORMATING[name].synthetic];
|
||||||
let unmodifiedStat = statGetter.call(this, false);
|
let unmodifiedStat = statGetter.call(this, false);
|
||||||
let modifiedStat = statGetter.call(this, true);
|
let modifiedStat = statGetter.call(this, true);
|
||||||
result = (modifiedStat / unmodifiedStat - 1) * 10000;
|
result = (modifiedStat / unmodifiedStat - 1) * 10000;
|
||||||
@@ -201,12 +201,15 @@ export default class Module {
|
|||||||
* Creates a react element that pretty-prints the queried module value
|
* Creates a react element that pretty-prints the queried module value
|
||||||
* @param {String} name The name of the value
|
* @param {String} name The name of the value
|
||||||
* @param {object} language Language object holding formats and util functions
|
* @param {object} language Language object holding formats and util functions
|
||||||
|
* @param {String} [unit] If unit is given not the stat's default formating
|
||||||
|
* unit will be applied but the given one taking into
|
||||||
|
* account SI-prefixes such as kilo, milli, etc.
|
||||||
* @param {Number} [val] If val is given, not the modules value but given
|
* @param {Number} [val] If val is given, not the modules value but given
|
||||||
* one will be formated
|
* one will be formated
|
||||||
* @returns {React.Component} The formated value as component
|
* @returns {React.Component} The formated value as component
|
||||||
*/
|
*/
|
||||||
formatModifiedValue(name, language, val) {
|
formatModifiedValue(name, language, unit, val) {
|
||||||
const formatingOptions = StatsFormating[name];
|
const formatingOptions = STATS_FORMATING[name];
|
||||||
if (val === undefined) {
|
if (val === undefined) {
|
||||||
if (formatingOptions && formatingOptions.synthetic) {
|
if (formatingOptions && formatingOptions.synthetic) {
|
||||||
val = (this[formatingOptions.synthetic]).call(this, true);
|
val = (this[formatingOptions.synthetic]).call(this, true);
|
||||||
@@ -223,8 +226,27 @@ export default class Module {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formatingOptions.format && language.formats[formatingOptions.format]) {
|
let { format } = formatingOptions;
|
||||||
val = (language.formats[formatingOptions.format])(val);
|
unit = unit || formatingOptions.unit;
|
||||||
|
let storedUnit = formatingOptions.storedUnit || formatingOptions.unit;
|
||||||
|
let factor = 1;
|
||||||
|
if (storedUnit && storedUnit !== unit) {
|
||||||
|
// Find out si prefix of storedUnit and unit as si prefixes can only take
|
||||||
|
// on charactere it suffices to compare the first character of each string
|
||||||
|
let prefixUnit = unit[0];
|
||||||
|
let prefixStored = unit[0];
|
||||||
|
if (unit.length > storedUnit.length) {
|
||||||
|
factor /= SI_PREFIXES[prefixUnit];
|
||||||
|
} else if (storedUnit.length > unit.length) {
|
||||||
|
factor *= SI_PREFIXES[prefixStored];
|
||||||
|
} else if (prefixUnit !== prefixStored) {
|
||||||
|
factor *= SI_PREFIXES[prefixStored];
|
||||||
|
factor /= SI_PREFIXES[prefixUnit];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format && language.formats[format]) {
|
||||||
|
val = (language.formats[format])(val * factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,28 @@
|
|||||||
export default {
|
export const SI_PREFIXES = {
|
||||||
|
'Y': 1e+24, // Yotta
|
||||||
|
'Z': 1e+21, // Zetta
|
||||||
|
'E': 1e+18, // Peta
|
||||||
|
'P': 1e+15, // Peta
|
||||||
|
'T': 1e+12, // Tera
|
||||||
|
'G': 1e+9, // Giga
|
||||||
|
'M': 1e+6, // Mega
|
||||||
|
'k': 1e+3, // Kilo
|
||||||
|
'h': 1e+2, // Hekto
|
||||||
|
'da': 1e+1, // Deka
|
||||||
|
'': 1,
|
||||||
|
'd': 1e-1, // Dezi
|
||||||
|
'c': 1e-2, // Zenti
|
||||||
|
'm': 1e-3, // Milli
|
||||||
|
'μ': 1e-6, // mikro not supported due to charset
|
||||||
|
'n': 10e-9, // Nano
|
||||||
|
'p': 1e-12, // Nano
|
||||||
|
'f': 1e-15, // Femto
|
||||||
|
'a': 1e-18, // Atto
|
||||||
|
'z': 1e-21, // Zepto
|
||||||
|
'y': 1e-24 // Yokto
|
||||||
|
};
|
||||||
|
|
||||||
|
export const STATS_FORMATING = {
|
||||||
'ammo': { 'format': 'int', },
|
'ammo': { 'format': 'int', },
|
||||||
'boot': { 'format': 'int', 'unit': 'secs' },
|
'boot': { 'format': 'int', 'unit': 'secs' },
|
||||||
'brokenregen': { 'format': 'round1', 'unit': 'ps' },
|
'brokenregen': { 'format': 'round1', 'unit': 'ps' },
|
||||||
@@ -17,8 +41,8 @@ export default {
|
|||||||
'eps': { 'format': 'round', 'units': 'ps', 'synthetic': 'getEps' },
|
'eps': { 'format': 'round', 'units': 'ps', 'synthetic': 'getEps' },
|
||||||
'explres': { 'format': 'pct' },
|
'explres': { 'format': 'pct' },
|
||||||
'facinglimit': { 'format': 'round1', 'unit': 'ang' },
|
'facinglimit': { 'format': 'round1', 'unit': 'ang' },
|
||||||
'falloff': { 'format': 'round1', 'unit': 'm' },
|
'falloff': { 'format': 'round1', 'unit': 'km', 'storedUnit': 'm' },
|
||||||
'fallofffromrange': { 'format': 'round1', 'unit': 'm', 'synthetic': 'getFalloff' },
|
'fallofffromrange': { 'format': 'round1', 'unit': 'km', 'storedUnit': 'm', 'synthetic': 'getFalloff' },
|
||||||
'hps': { 'format': 'round', 'units': 'ps', 'synthetic': 'getHps' },
|
'hps': { 'format': 'round', 'units': 'ps', 'synthetic': 'getHps' },
|
||||||
'hullboost': { 'format': 'pct1' },
|
'hullboost': { 'format': 'pct1' },
|
||||||
'hullreinforcement': { 'format': 'int' },
|
'hullreinforcement': { 'format': 'int' },
|
||||||
@@ -33,7 +57,7 @@ export default {
|
|||||||
'piercing': { 'format': 'int' },
|
'piercing': { 'format': 'int' },
|
||||||
'power': { 'format': 'round', 'unit': 'MW' },
|
'power': { 'format': 'round', 'unit': 'MW' },
|
||||||
'protection': { 'format': 'pct' },
|
'protection': { 'format': 'pct' },
|
||||||
'range': { 'format': 'round1', 'unit': 'm' },
|
'range': { 'format': 'round1', 'unit': 'km', 'storedUnit': 'm' },
|
||||||
'ranget': { 'format': 'round1', 'unit': 's' },
|
'ranget': { 'format': 'round1', 'unit': 's' },
|
||||||
'regen': { 'format': 'round1', 'unit': 'ps' },
|
'regen': { 'format': 'round1', 'unit': 'ps' },
|
||||||
'reload': { 'format': 'int', 'unit': 's' },
|
'reload': { 'format': 'int', 'unit': 's' },
|
||||||
|
|||||||
Reference in New Issue
Block a user