Total Complexity | 8 |
Complexity/F | 2.67 |
Lines of Code | 42 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /** |
||
7 | 'use strict'; |
||
8 | |||
9 | angular |
||
10 | .module('game') |
||
11 | .service('format', ['util', |
||
12 | 'state', |
||
13 | function(util) { |
||
14 | /* |
||
15 | * Formats in HTML a compound i.e. a collection of resources of |
||
16 | * the form x + y + z |
||
17 | */ |
||
18 | this.compoundFormat = function(number, compound, player) { |
||
19 | let compoundHTML = ''; |
||
20 | let keys = Object.keys(compound); |
||
21 | for (let i = 0; i < keys.length; i++) { |
||
22 | if (Number.isInteger(number) && number > 1) { |
||
23 | compoundHTML += util.prettifyNumber(number * compound[keys[i]], player) + |
||
24 | ' '; |
||
25 | } else if (compound[keys[i]] !== 1) { |
||
26 | compoundHTML += util.prettifyNumber(compound[keys[i]], player) + ' '; |
||
27 | } |
||
28 | compoundHTML += util.getHTML(keys[i]) + ' '; |
||
29 | if (i < keys.length - 1) { |
||
30 | compoundHTML += '+ '; |
||
31 | } |
||
32 | } |
||
33 | return compoundHTML.trim(); |
||
34 | }; |
||
35 | |||
36 | /* |
||
37 | * Formats a reaction i.e. a transformation from one compound to |
||
38 | * another |
||
39 | */ |
||
40 | this.reactionFormat = function(number, reaction, player) { |
||
41 | let reactionHTML = ''; |
||
42 | reactionHTML += this.compoundFormat(number, reaction.reactant, player); |
||
43 | reactionHTML += ' <span class=\'icon\'>→</span> '; |
||
44 | reactionHTML += this.compoundFormat(number, reaction.product, player); |
||
45 | return reactionHTML; |
||
46 | }; |
||
47 | } |
||
48 | ]); |
||
49 |