Skip to content

Commit f3122ae

Browse files
committed
Added default values to goods
1 parent e17c0c9 commit f3122ae

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

000-simulation.gs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ var global = {
3030
market: {
3131
restockOnlyIncreases: true,
3232
},
33+
goods: {
34+
quantity: Number.POSITIVE_INFINITY,
35+
maxQuantity: Number.POSITIVE_INFINITY,
36+
},
3337
diceRoll: {
3438
quantity: 3,
3539
numberOfSides: 6,

classes/130-Market.gs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @param {Array} goodsDataArray: An array with one object for each goods type that
1616
* can be bought on the market. ID will be used as property name. Some special properties:
1717
* - id: The unique id for the goods type. Will be used as property name under market.goods.
18-
* - [resource]: Any property matching a resource ID will be interpreted
18+
* - <resource>: Any property matching a resource ID will be interpreted
1919
* as a cost. Several resources may be present for a combined cost.
2020
* - any: Will be interpreted as a cost that can be paid with any resource
2121
* type.
@@ -302,25 +302,23 @@ class Goods {
302302
constructor(goodsData, market) {
303303
if (!market instanceof Market)
304304
throw('Goods must be added to a proper market.');
305-
305+
// Add default settings, overwrite with provided data.
306+
Object.assign(this, global.defaults.goods);
306307
Object.assign(this, goodsData);
308+
307309
if (this.id === undefined)
308310
throw('Goods must have an id property set.');
309311
this.market = market;
310312
market.goods[this.id] = this;
311313
// Set quantity restrictions, if any.
312-
if (!this.quantity && this.quantity !== 0)
313-
this.quantity = Number.POSITIVE_INFINITY;
314-
if (!this.maxQuantity)
315-
this.maxQuantity = Number.POSITIVE_INFINITY;
316314
this.initialQuantity = this.quantity;
317315

318316
return this;
319317
}
320318

321319
/**
322320
* Passes on work to any resolver function declared for the goods,
323-
* along with any parameters. The space needs to have a the property
321+
* along with any parameters. The goods needs to have a the property
324322
* 'resolver' set and a corresponding method must be placed in
325323
* modules[module].resolvers.goods.
326324
*/

0 commit comments

Comments
 (0)