|
15 | 15 | * @param {Array} goodsDataArray: An array with one object for each goods type that |
16 | 16 | * can be bought on the market. ID will be used as property name. Some special properties: |
17 | 17 | * - 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 |
19 | 19 | * as a cost. Several resources may be present for a combined cost. |
20 | 20 | * - any: Will be interpreted as a cost that can be paid with any resource |
21 | 21 | * type. |
@@ -302,25 +302,23 @@ class Goods { |
302 | 302 | constructor(goodsData, market) { |
303 | 303 | if (!market instanceof Market) |
304 | 304 | 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); |
306 | 307 | Object.assign(this, goodsData); |
| 308 | + |
307 | 309 | if (this.id === undefined) |
308 | 310 | throw('Goods must have an id property set.'); |
309 | 311 | this.market = market; |
310 | 312 | market.goods[this.id] = this; |
311 | 313 | // 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; |
316 | 314 | this.initialQuantity = this.quantity; |
317 | 315 |
|
318 | 316 | return this; |
319 | 317 | } |
320 | 318 |
|
321 | 319 | /** |
322 | 320 | * 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 |
324 | 322 | * 'resolver' set and a corresponding method must be placed in |
325 | 323 | * modules[module].resolvers.goods. |
326 | 324 | */ |
|
0 commit comments