@slithy/prim-lib 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -349,6 +349,16 @@ var Shape = class {
|
|
|
349
349
|
}
|
|
350
350
|
static create(cfg) {
|
|
351
351
|
const ctors = cfg.shapeTypes;
|
|
352
|
+
const weights = cfg.shapeWeights;
|
|
353
|
+
if (weights && weights.length === ctors.length) {
|
|
354
|
+
const total = weights.reduce((sum, w) => sum + w, 0);
|
|
355
|
+
let r = Math.random() * total;
|
|
356
|
+
for (let i = 0; i < weights.length; i++) {
|
|
357
|
+
r -= weights[i];
|
|
358
|
+
if (r <= 0) return new ctors[i](cfg.width, cfg.height);
|
|
359
|
+
}
|
|
360
|
+
return new ctors[ctors.length - 1](cfg.width, cfg.height);
|
|
361
|
+
}
|
|
352
362
|
const index = Math.floor(Math.random() * ctors.length);
|
|
353
363
|
const ctor = ctors[index];
|
|
354
364
|
return new ctor(cfg.width, cfg.height);
|