Line data Source code
1 0 : Resources = new Resources(); 2 : 3 0 : var API3 = function(m) 4 : { 5 : 6 0 : m.Resources = function(amounts = {}, population = 0) 7 : { 8 0 : for (let key of Resources.GetCodes()) 9 0 : this[key] = amounts[key] || 0; 10 : 11 0 : this.population = population > 0 ? population : 0; 12 : }; 13 : 14 0 : m.Resources.prototype.reset = function() 15 : { 16 0 : for (let key of Resources.GetCodes()) 17 0 : this[key] = 0; 18 0 : this.population = 0; 19 : }; 20 : 21 0 : m.Resources.prototype.canAfford = function(that) 22 : { 23 0 : for (let key of Resources.GetCodes()) 24 0 : if (this[key] < that[key]) 25 0 : return false; 26 0 : return true; 27 : }; 28 : 29 0 : m.Resources.prototype.add = function(that) 30 : { 31 0 : for (let key of Resources.GetCodes()) 32 0 : this[key] += that[key]; 33 0 : this.population += that.population; 34 : }; 35 : 36 0 : m.Resources.prototype.subtract = function(that) 37 : { 38 0 : for (let key of Resources.GetCodes()) 39 0 : this[key] -= that[key]; 40 0 : this.population += that.population; 41 : }; 42 : 43 0 : m.Resources.prototype.multiply = function(n) 44 : { 45 0 : for (let key of Resources.GetCodes()) 46 0 : this[key] *= n; 47 0 : this.population *= n; 48 : }; 49 : 50 0 : m.Resources.prototype.Serialize = function() 51 : { 52 0 : let amounts = {}; 53 0 : for (let key of Resources.GetCodes()) 54 0 : amounts[key] = this[key]; 55 0 : return { "amounts": amounts, "population": this.population }; 56 : }; 57 : 58 0 : m.Resources.prototype.Deserialize = function(data) 59 : { 60 0 : for (let key in data.amounts) 61 0 : this[key] = data.amounts[key]; 62 0 : this.population = data.population; 63 : }; 64 : 65 0 : return m; 66 : 67 : }(API3);