toosoon-prng 1.4.0 → 2.0.0
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/README.md +10 -164
- package/package.json +2 -6
- package/src/index.ts +1 -20
- package/src/prng.ts +38 -50
- package/src/types.ts +1 -3
- package/src/utils.ts +119 -0
- package/.prettierrc +0 -7
- package/LICENSE +0 -21
- package/lib/controllers.d.ts +0 -158
- package/lib/controllers.js +0 -363
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -2
- package/lib/prng.d.ts +0 -114
- package/lib/prng.js +0 -184
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types.d.ts +0 -8
- package/lib/types.js +0 -8
- package/lib/utils.d.ts +0 -45
- package/lib/utils.js +0 -115
- package/src/controllers.ts +0 -409
package/lib/controllers.d.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { Gui, GuiController } from 'toosoon-gui';
|
|
2
|
-
export interface PRNGController<T = unknown> {
|
|
3
|
-
seed: string;
|
|
4
|
-
value: T;
|
|
5
|
-
addGUI(gui: Gui, min?: number, max?: number, step?: number): GuiController;
|
|
6
|
-
getValue(): T;
|
|
7
|
-
dispose(): void;
|
|
8
|
-
}
|
|
9
|
-
export interface PRNGGroupController<T = unknown> {
|
|
10
|
-
seed: string;
|
|
11
|
-
addGUI(gui: Gui, min?: number, max?: number, step?: number): Gui;
|
|
12
|
-
createController(index: number): PRNGController<T>;
|
|
13
|
-
getValueAt(index: number): T;
|
|
14
|
-
dispose(): void;
|
|
15
|
-
}
|
|
16
|
-
declare abstract class BasePRNGController<T> implements PRNGController<T> {
|
|
17
|
-
seed: string;
|
|
18
|
-
abstract value: T;
|
|
19
|
-
gui: GuiController;
|
|
20
|
-
constructor(seed: string);
|
|
21
|
-
abstract addGUI(gui: Gui, min?: number, max?: number, step?: number): GuiController;
|
|
22
|
-
abstract getValue(): T;
|
|
23
|
-
dispose(): void;
|
|
24
|
-
}
|
|
25
|
-
declare abstract class BasePRNGGroupController<T> implements PRNGGroupController<T> {
|
|
26
|
-
seed: string;
|
|
27
|
-
controllers: PRNGController<T>[];
|
|
28
|
-
gui: Gui;
|
|
29
|
-
guiArgs: {
|
|
30
|
-
min?: number;
|
|
31
|
-
max?: number;
|
|
32
|
-
step?: number;
|
|
33
|
-
};
|
|
34
|
-
constructor(seed: string);
|
|
35
|
-
addGUI(gui: Gui, min?: number, max?: number, step?: number): Gui;
|
|
36
|
-
abstract createController(index: number): PRNGController<T>;
|
|
37
|
-
getValueAt(index: number): T;
|
|
38
|
-
dispose(): void;
|
|
39
|
-
}
|
|
40
|
-
export declare class BooleanController extends BasePRNGController<boolean> {
|
|
41
|
-
value: boolean;
|
|
42
|
-
probability: number;
|
|
43
|
-
constructor(seed: string, probability?: number);
|
|
44
|
-
addGUI(gui: Gui): GuiController;
|
|
45
|
-
getValue(): boolean;
|
|
46
|
-
}
|
|
47
|
-
export declare class SignController extends BasePRNGController<number> {
|
|
48
|
-
value: number;
|
|
49
|
-
probability: number;
|
|
50
|
-
constructor(seed: string, probability?: number);
|
|
51
|
-
addGUI(gui: Gui): GuiController;
|
|
52
|
-
getValue(): number;
|
|
53
|
-
}
|
|
54
|
-
export declare class FloatController extends BasePRNGController<number> {
|
|
55
|
-
value: number;
|
|
56
|
-
min: number;
|
|
57
|
-
max: number;
|
|
58
|
-
constructor(seed: string, min?: number, max?: number);
|
|
59
|
-
addGUI(gui: Gui, min: number, max: number, step?: number): GuiController;
|
|
60
|
-
getValue(): number;
|
|
61
|
-
}
|
|
62
|
-
export declare class IntController extends BasePRNGController<number> {
|
|
63
|
-
value: number;
|
|
64
|
-
min: number;
|
|
65
|
-
max: number;
|
|
66
|
-
constructor(seed: string, min: number, max: number);
|
|
67
|
-
addGUI(gui: Gui, min: number, max: number, step?: number): GuiController;
|
|
68
|
-
getValue(): number;
|
|
69
|
-
}
|
|
70
|
-
export declare class HexColorController extends BasePRNGController<string> {
|
|
71
|
-
value: string;
|
|
72
|
-
constructor(seed: string);
|
|
73
|
-
addGUI(gui: Gui): GuiController;
|
|
74
|
-
getValue(): string;
|
|
75
|
-
}
|
|
76
|
-
export declare class ItemController<T = unknown> extends BasePRNGController<T> {
|
|
77
|
-
value: T;
|
|
78
|
-
items: T[];
|
|
79
|
-
constructor(seed: string, items: T[]);
|
|
80
|
-
addGUI(gui: Gui): GuiController;
|
|
81
|
-
getValue(): T;
|
|
82
|
-
}
|
|
83
|
-
export declare class ObjectPropertyController<T = unknown> extends BasePRNGController<T> {
|
|
84
|
-
value: T;
|
|
85
|
-
object: {
|
|
86
|
-
[key: string]: T;
|
|
87
|
-
};
|
|
88
|
-
constructor(seed: string, object: {
|
|
89
|
-
[key: string]: T;
|
|
90
|
-
});
|
|
91
|
-
addGUI(gui: Gui): GuiController;
|
|
92
|
-
getValue(): T;
|
|
93
|
-
}
|
|
94
|
-
type WeightsItems<T> = Array<{
|
|
95
|
-
weight: number;
|
|
96
|
-
value: T;
|
|
97
|
-
}>;
|
|
98
|
-
export declare class WeightsController<T = unknown> extends BasePRNGController<T> {
|
|
99
|
-
value: T;
|
|
100
|
-
items: WeightsItems<T>;
|
|
101
|
-
weights: number[];
|
|
102
|
-
constructor(seed: string, items: WeightsItems<T>);
|
|
103
|
-
addGUI(gui: Gui): GuiController;
|
|
104
|
-
getValue(): T;
|
|
105
|
-
}
|
|
106
|
-
export declare class BooleanGroupController extends BasePRNGGroupController<boolean> {
|
|
107
|
-
probability: number;
|
|
108
|
-
controllers: BooleanController[];
|
|
109
|
-
constructor(seed: string, probability: number);
|
|
110
|
-
createController(index: number): BooleanController;
|
|
111
|
-
}
|
|
112
|
-
export declare class SignGroupController extends BasePRNGGroupController<number> {
|
|
113
|
-
probability: number;
|
|
114
|
-
controllers: SignController[];
|
|
115
|
-
constructor(seed: string, probability: number);
|
|
116
|
-
createController(index: number): SignController;
|
|
117
|
-
}
|
|
118
|
-
export declare class FloatGroupController extends BasePRNGGroupController<number> {
|
|
119
|
-
min: number;
|
|
120
|
-
max: number;
|
|
121
|
-
controllers: FloatController[];
|
|
122
|
-
constructor(seed: string, min: number, max: number);
|
|
123
|
-
createController(index: number): FloatController;
|
|
124
|
-
}
|
|
125
|
-
export declare class IntGroupController extends BasePRNGGroupController<number> {
|
|
126
|
-
min: number;
|
|
127
|
-
max: number;
|
|
128
|
-
controllers: IntController[];
|
|
129
|
-
constructor(seed: string, min: number, max: number);
|
|
130
|
-
createController(index: number): IntController;
|
|
131
|
-
}
|
|
132
|
-
export declare class HexColorGroupController extends BasePRNGGroupController<string> {
|
|
133
|
-
controllers: HexColorController[];
|
|
134
|
-
createController(index: number): HexColorController;
|
|
135
|
-
}
|
|
136
|
-
export declare class ItemGroupController<T = unknown> extends BasePRNGGroupController<T> {
|
|
137
|
-
items: T[];
|
|
138
|
-
controllers: ItemController<T>[];
|
|
139
|
-
constructor(seed: string, items: T[]);
|
|
140
|
-
createController(index: number): ItemController<T>;
|
|
141
|
-
}
|
|
142
|
-
export declare class ObjectPropertyGroupController<T = unknown> extends BasePRNGGroupController<T> {
|
|
143
|
-
object: {
|
|
144
|
-
[key: string]: T;
|
|
145
|
-
};
|
|
146
|
-
controllers: ObjectPropertyController<T>[];
|
|
147
|
-
constructor(seed: string, object: {
|
|
148
|
-
[key: string]: T;
|
|
149
|
-
});
|
|
150
|
-
createController(index: number): ObjectPropertyController<T>;
|
|
151
|
-
}
|
|
152
|
-
export declare class WeightsGroupController<T = unknown> extends BasePRNGGroupController<T> {
|
|
153
|
-
items: WeightsItems<T>;
|
|
154
|
-
controllers: WeightsController<T>[];
|
|
155
|
-
constructor(seed: string, items: WeightsItems<T>);
|
|
156
|
-
createController(index: number): WeightsController<T>;
|
|
157
|
-
}
|
|
158
|
-
export {};
|
package/lib/controllers.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
import prng from './prng';
|
|
17
|
-
// *********************
|
|
18
|
-
// Abstract controllers
|
|
19
|
-
// *********************
|
|
20
|
-
var BasePRNGController = /** @class */ (function () {
|
|
21
|
-
function BasePRNGController(seed) {
|
|
22
|
-
this.seed = seed;
|
|
23
|
-
prng.addController(this);
|
|
24
|
-
}
|
|
25
|
-
BasePRNGController.prototype.dispose = function () {
|
|
26
|
-
var _a;
|
|
27
|
-
prng.removeController(this);
|
|
28
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
29
|
-
};
|
|
30
|
-
return BasePRNGController;
|
|
31
|
-
}());
|
|
32
|
-
var BasePRNGGroupController = /** @class */ (function () {
|
|
33
|
-
function BasePRNGGroupController(seed) {
|
|
34
|
-
this.controllers = [];
|
|
35
|
-
this.seed = seed;
|
|
36
|
-
}
|
|
37
|
-
BasePRNGGroupController.prototype.addGUI = function (gui, min, max, step) {
|
|
38
|
-
this.gui = gui.addFolder(this.seed).close();
|
|
39
|
-
this.guiArgs = { min: min, max: max, step: step };
|
|
40
|
-
return this.gui;
|
|
41
|
-
};
|
|
42
|
-
BasePRNGGroupController.prototype.getValueAt = function (index) {
|
|
43
|
-
var controller = this.controllers[index];
|
|
44
|
-
if (!controller) {
|
|
45
|
-
controller = this.createController(index);
|
|
46
|
-
if (this.gui) {
|
|
47
|
-
controller
|
|
48
|
-
.addGUI(this.gui, this.guiArgs.min, this.guiArgs.max, this.guiArgs.step)
|
|
49
|
-
.name("".concat(this.seed, "-").concat(index));
|
|
50
|
-
}
|
|
51
|
-
this.controllers[index] = controller;
|
|
52
|
-
}
|
|
53
|
-
return controller.value;
|
|
54
|
-
};
|
|
55
|
-
BasePRNGGroupController.prototype.dispose = function () {
|
|
56
|
-
var _a;
|
|
57
|
-
this.controllers.forEach(function (controller) { return controller.dispose(); });
|
|
58
|
-
this.controllers = [];
|
|
59
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
60
|
-
};
|
|
61
|
-
return BasePRNGGroupController;
|
|
62
|
-
}());
|
|
63
|
-
// *********************
|
|
64
|
-
// Controllers
|
|
65
|
-
// *********************
|
|
66
|
-
var BooleanController = /** @class */ (function (_super) {
|
|
67
|
-
__extends(BooleanController, _super);
|
|
68
|
-
function BooleanController(seed, probability) {
|
|
69
|
-
if (probability === void 0) { probability = 0.5; }
|
|
70
|
-
var _this = _super.call(this, seed) || this;
|
|
71
|
-
_this.probability = probability;
|
|
72
|
-
_this.value = _this.getValue();
|
|
73
|
-
return _this;
|
|
74
|
-
}
|
|
75
|
-
BooleanController.prototype.addGUI = function (gui) {
|
|
76
|
-
this.gui = gui.add(this, 'value').name(this.seed);
|
|
77
|
-
return this.gui;
|
|
78
|
-
};
|
|
79
|
-
BooleanController.prototype.getValue = function () {
|
|
80
|
-
var _a;
|
|
81
|
-
this.value = prng.randomBoolean(this.seed, this.probability);
|
|
82
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
83
|
-
return this.value;
|
|
84
|
-
};
|
|
85
|
-
return BooleanController;
|
|
86
|
-
}(BasePRNGController));
|
|
87
|
-
export { BooleanController };
|
|
88
|
-
var SignController = /** @class */ (function (_super) {
|
|
89
|
-
__extends(SignController, _super);
|
|
90
|
-
function SignController(seed, probability) {
|
|
91
|
-
if (probability === void 0) { probability = 0.5; }
|
|
92
|
-
var _this = _super.call(this, seed) || this;
|
|
93
|
-
_this.probability = probability;
|
|
94
|
-
_this.value = _this.getValue();
|
|
95
|
-
return _this;
|
|
96
|
-
}
|
|
97
|
-
SignController.prototype.addGUI = function (gui) {
|
|
98
|
-
this.gui = gui.add(this, 'value', [-1, 1]).name(this.seed);
|
|
99
|
-
return this.gui;
|
|
100
|
-
};
|
|
101
|
-
SignController.prototype.getValue = function () {
|
|
102
|
-
var _a;
|
|
103
|
-
this.value = prng.randomSign(this.seed, this.probability);
|
|
104
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
105
|
-
return this.value;
|
|
106
|
-
};
|
|
107
|
-
return SignController;
|
|
108
|
-
}(BasePRNGController));
|
|
109
|
-
export { SignController };
|
|
110
|
-
var FloatController = /** @class */ (function (_super) {
|
|
111
|
-
__extends(FloatController, _super);
|
|
112
|
-
function FloatController(seed, min, max) {
|
|
113
|
-
if (min === void 0) { min = 0; }
|
|
114
|
-
if (max === void 0) { max = 1; }
|
|
115
|
-
var _this = _super.call(this, seed) || this;
|
|
116
|
-
_this.min = min;
|
|
117
|
-
_this.max = max;
|
|
118
|
-
_this.value = _this.getValue();
|
|
119
|
-
return _this;
|
|
120
|
-
}
|
|
121
|
-
FloatController.prototype.addGUI = function (gui, min, max, step) {
|
|
122
|
-
if (step === void 0) { step = 0.01; }
|
|
123
|
-
this.gui = gui.add(this, 'value', min, max, step).name(this.seed);
|
|
124
|
-
return this.gui;
|
|
125
|
-
};
|
|
126
|
-
FloatController.prototype.getValue = function () {
|
|
127
|
-
var _a;
|
|
128
|
-
this.value = prng.randomFloat(this.seed, this.min, this.max);
|
|
129
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
130
|
-
return this.value;
|
|
131
|
-
};
|
|
132
|
-
return FloatController;
|
|
133
|
-
}(BasePRNGController));
|
|
134
|
-
export { FloatController };
|
|
135
|
-
var IntController = /** @class */ (function (_super) {
|
|
136
|
-
__extends(IntController, _super);
|
|
137
|
-
function IntController(seed, min, max) {
|
|
138
|
-
var _this = _super.call(this, seed) || this;
|
|
139
|
-
_this.min = min;
|
|
140
|
-
_this.max = max;
|
|
141
|
-
_this.value = prng.randomInt(_this.seed, min, max);
|
|
142
|
-
return _this;
|
|
143
|
-
}
|
|
144
|
-
IntController.prototype.addGUI = function (gui, min, max, step) {
|
|
145
|
-
if (step === void 0) { step = 1; }
|
|
146
|
-
this.gui = gui.add(this, 'value', min, max, step).name(this.seed);
|
|
147
|
-
return this.gui;
|
|
148
|
-
};
|
|
149
|
-
IntController.prototype.getValue = function () {
|
|
150
|
-
var _a;
|
|
151
|
-
this.value = prng.randomInt(this.seed, this.min, this.max);
|
|
152
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
153
|
-
return this.value;
|
|
154
|
-
};
|
|
155
|
-
return IntController;
|
|
156
|
-
}(BasePRNGController));
|
|
157
|
-
export { IntController };
|
|
158
|
-
var HexColorController = /** @class */ (function (_super) {
|
|
159
|
-
__extends(HexColorController, _super);
|
|
160
|
-
function HexColorController(seed) {
|
|
161
|
-
var _this = _super.call(this, seed) || this;
|
|
162
|
-
_this.value = _this.getValue();
|
|
163
|
-
return _this;
|
|
164
|
-
}
|
|
165
|
-
HexColorController.prototype.addGUI = function (gui) {
|
|
166
|
-
this.gui = gui.addColor(this, 'value').name(this.seed);
|
|
167
|
-
return this.gui;
|
|
168
|
-
};
|
|
169
|
-
HexColorController.prototype.getValue = function () {
|
|
170
|
-
var _a;
|
|
171
|
-
this.value = prng.randomHexColor(this.seed);
|
|
172
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
173
|
-
return this.value;
|
|
174
|
-
};
|
|
175
|
-
return HexColorController;
|
|
176
|
-
}(BasePRNGController));
|
|
177
|
-
export { HexColorController };
|
|
178
|
-
var ItemController = /** @class */ (function (_super) {
|
|
179
|
-
__extends(ItemController, _super);
|
|
180
|
-
function ItemController(seed, items) {
|
|
181
|
-
var _this = _super.call(this, seed) || this;
|
|
182
|
-
_this.items = items;
|
|
183
|
-
_this.value = _this.getValue();
|
|
184
|
-
return _this;
|
|
185
|
-
}
|
|
186
|
-
ItemController.prototype.addGUI = function (gui) {
|
|
187
|
-
this.gui = gui.add(this, 'value', this.items).name(this.seed);
|
|
188
|
-
return this.gui;
|
|
189
|
-
};
|
|
190
|
-
ItemController.prototype.getValue = function () {
|
|
191
|
-
var _a;
|
|
192
|
-
this.value = prng.randomItem(this.seed, this.items);
|
|
193
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
194
|
-
return this.value;
|
|
195
|
-
};
|
|
196
|
-
return ItemController;
|
|
197
|
-
}(BasePRNGController));
|
|
198
|
-
export { ItemController };
|
|
199
|
-
var ObjectPropertyController = /** @class */ (function (_super) {
|
|
200
|
-
__extends(ObjectPropertyController, _super);
|
|
201
|
-
function ObjectPropertyController(seed, object) {
|
|
202
|
-
var _this = _super.call(this, seed) || this;
|
|
203
|
-
_this.object = object;
|
|
204
|
-
_this.value = _this.getValue();
|
|
205
|
-
return _this;
|
|
206
|
-
}
|
|
207
|
-
ObjectPropertyController.prototype.addGUI = function (gui) {
|
|
208
|
-
this.gui = gui.add(this, 'value', this.object).name(this.seed);
|
|
209
|
-
return this.gui;
|
|
210
|
-
};
|
|
211
|
-
ObjectPropertyController.prototype.getValue = function () {
|
|
212
|
-
var _a;
|
|
213
|
-
this.value = prng.randomObjectProperty(this.seed, this.object);
|
|
214
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
215
|
-
return this.value;
|
|
216
|
-
};
|
|
217
|
-
return ObjectPropertyController;
|
|
218
|
-
}(BasePRNGController));
|
|
219
|
-
export { ObjectPropertyController };
|
|
220
|
-
var WeightsController = /** @class */ (function (_super) {
|
|
221
|
-
__extends(WeightsController, _super);
|
|
222
|
-
function WeightsController(seed, items) {
|
|
223
|
-
var _this = _super.call(this, seed) || this;
|
|
224
|
-
_this.items = items;
|
|
225
|
-
_this.weights = _this.items.map(function (item) { return item.weight; });
|
|
226
|
-
_this.value = _this.getValue();
|
|
227
|
-
return _this;
|
|
228
|
-
}
|
|
229
|
-
WeightsController.prototype.addGUI = function (gui) {
|
|
230
|
-
this.gui = gui
|
|
231
|
-
.add(this, 'value', this.items.map(function (item) { return item.value; }))
|
|
232
|
-
.name(this.seed);
|
|
233
|
-
return this.gui;
|
|
234
|
-
};
|
|
235
|
-
WeightsController.prototype.getValue = function () {
|
|
236
|
-
var _a;
|
|
237
|
-
var index = prng.randomIndex(this.seed, this.weights);
|
|
238
|
-
this.value = this.items[index].value;
|
|
239
|
-
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
240
|
-
return this.value;
|
|
241
|
-
};
|
|
242
|
-
return WeightsController;
|
|
243
|
-
}(BasePRNGController));
|
|
244
|
-
export { WeightsController };
|
|
245
|
-
// *********************
|
|
246
|
-
// Group Controllers
|
|
247
|
-
// *********************
|
|
248
|
-
var BooleanGroupController = /** @class */ (function (_super) {
|
|
249
|
-
__extends(BooleanGroupController, _super);
|
|
250
|
-
function BooleanGroupController(seed, probability) {
|
|
251
|
-
var _this = _super.call(this, seed) || this;
|
|
252
|
-
_this.controllers = [];
|
|
253
|
-
_this.probability = probability;
|
|
254
|
-
return _this;
|
|
255
|
-
}
|
|
256
|
-
BooleanGroupController.prototype.createController = function (index) {
|
|
257
|
-
return new BooleanController("".concat(this.seed, "-").concat(index), this.probability);
|
|
258
|
-
};
|
|
259
|
-
return BooleanGroupController;
|
|
260
|
-
}(BasePRNGGroupController));
|
|
261
|
-
export { BooleanGroupController };
|
|
262
|
-
var SignGroupController = /** @class */ (function (_super) {
|
|
263
|
-
__extends(SignGroupController, _super);
|
|
264
|
-
function SignGroupController(seed, probability) {
|
|
265
|
-
var _this = _super.call(this, seed) || this;
|
|
266
|
-
_this.controllers = [];
|
|
267
|
-
_this.probability = probability;
|
|
268
|
-
return _this;
|
|
269
|
-
}
|
|
270
|
-
SignGroupController.prototype.createController = function (index) {
|
|
271
|
-
return new SignController("".concat(this.seed, "-").concat(index), this.probability);
|
|
272
|
-
};
|
|
273
|
-
return SignGroupController;
|
|
274
|
-
}(BasePRNGGroupController));
|
|
275
|
-
export { SignGroupController };
|
|
276
|
-
var FloatGroupController = /** @class */ (function (_super) {
|
|
277
|
-
__extends(FloatGroupController, _super);
|
|
278
|
-
function FloatGroupController(seed, min, max) {
|
|
279
|
-
var _this = _super.call(this, seed) || this;
|
|
280
|
-
_this.controllers = [];
|
|
281
|
-
_this.min = min;
|
|
282
|
-
_this.max = max;
|
|
283
|
-
return _this;
|
|
284
|
-
}
|
|
285
|
-
FloatGroupController.prototype.createController = function (index) {
|
|
286
|
-
return new FloatController("".concat(this.seed, "-").concat(index), this.min, this.max);
|
|
287
|
-
};
|
|
288
|
-
return FloatGroupController;
|
|
289
|
-
}(BasePRNGGroupController));
|
|
290
|
-
export { FloatGroupController };
|
|
291
|
-
var IntGroupController = /** @class */ (function (_super) {
|
|
292
|
-
__extends(IntGroupController, _super);
|
|
293
|
-
function IntGroupController(seed, min, max) {
|
|
294
|
-
var _this = _super.call(this, seed) || this;
|
|
295
|
-
_this.controllers = [];
|
|
296
|
-
_this.min = min;
|
|
297
|
-
_this.max = max;
|
|
298
|
-
return _this;
|
|
299
|
-
}
|
|
300
|
-
IntGroupController.prototype.createController = function (index) {
|
|
301
|
-
return new IntController("".concat(this.seed, "-").concat(index), this.min, this.max);
|
|
302
|
-
};
|
|
303
|
-
return IntGroupController;
|
|
304
|
-
}(BasePRNGGroupController));
|
|
305
|
-
export { IntGroupController };
|
|
306
|
-
var HexColorGroupController = /** @class */ (function (_super) {
|
|
307
|
-
__extends(HexColorGroupController, _super);
|
|
308
|
-
function HexColorGroupController() {
|
|
309
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
310
|
-
_this.controllers = [];
|
|
311
|
-
return _this;
|
|
312
|
-
}
|
|
313
|
-
// constructor(seed: string) {
|
|
314
|
-
// super(seed);
|
|
315
|
-
// }
|
|
316
|
-
HexColorGroupController.prototype.createController = function (index) {
|
|
317
|
-
return new HexColorController("".concat(this.seed, "-").concat(index));
|
|
318
|
-
};
|
|
319
|
-
return HexColorGroupController;
|
|
320
|
-
}(BasePRNGGroupController));
|
|
321
|
-
export { HexColorGroupController };
|
|
322
|
-
var ItemGroupController = /** @class */ (function (_super) {
|
|
323
|
-
__extends(ItemGroupController, _super);
|
|
324
|
-
function ItemGroupController(seed, items) {
|
|
325
|
-
var _this = _super.call(this, seed) || this;
|
|
326
|
-
_this.controllers = [];
|
|
327
|
-
_this.items = items;
|
|
328
|
-
return _this;
|
|
329
|
-
}
|
|
330
|
-
ItemGroupController.prototype.createController = function (index) {
|
|
331
|
-
return new ItemController("".concat(this.seed, "-").concat(index), this.items);
|
|
332
|
-
};
|
|
333
|
-
return ItemGroupController;
|
|
334
|
-
}(BasePRNGGroupController));
|
|
335
|
-
export { ItemGroupController };
|
|
336
|
-
var ObjectPropertyGroupController = /** @class */ (function (_super) {
|
|
337
|
-
__extends(ObjectPropertyGroupController, _super);
|
|
338
|
-
function ObjectPropertyGroupController(seed, object) {
|
|
339
|
-
var _this = _super.call(this, seed) || this;
|
|
340
|
-
_this.controllers = [];
|
|
341
|
-
_this.object = object;
|
|
342
|
-
return _this;
|
|
343
|
-
}
|
|
344
|
-
ObjectPropertyGroupController.prototype.createController = function (index) {
|
|
345
|
-
return new ObjectPropertyController("".concat(this.seed, "-").concat(index), this.object);
|
|
346
|
-
};
|
|
347
|
-
return ObjectPropertyGroupController;
|
|
348
|
-
}(BasePRNGGroupController));
|
|
349
|
-
export { ObjectPropertyGroupController };
|
|
350
|
-
var WeightsGroupController = /** @class */ (function (_super) {
|
|
351
|
-
__extends(WeightsGroupController, _super);
|
|
352
|
-
function WeightsGroupController(seed, items) {
|
|
353
|
-
var _this = _super.call(this, seed) || this;
|
|
354
|
-
_this.controllers = [];
|
|
355
|
-
_this.items = items;
|
|
356
|
-
return _this;
|
|
357
|
-
}
|
|
358
|
-
WeightsGroupController.prototype.createController = function (index) {
|
|
359
|
-
return new WeightsController("".concat(this.seed, "-").concat(index), this.items);
|
|
360
|
-
};
|
|
361
|
-
return WeightsGroupController;
|
|
362
|
-
}(BasePRNGGroupController));
|
|
363
|
-
export { WeightsGroupController };
|
package/lib/index.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { BooleanController, SignController, IntController, FloatController, HexColorController, ItemController, ObjectPropertyController, WeightsController, BooleanGroupController, SignGroupController, IntGroupController, FloatGroupController, HexColorGroupController, ItemGroupController, ObjectPropertyGroupController, WeightsGroupController } from './controllers';
|
|
2
|
-
export { default } from './prng';
|
|
3
|
-
export type * from './types';
|
package/lib/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { BooleanController, SignController, IntController, FloatController, HexColorController, ItemController, ObjectPropertyController, WeightsController, BooleanGroupController, SignGroupController, IntGroupController, FloatGroupController, HexColorGroupController, ItemGroupController, ObjectPropertyGroupController, WeightsGroupController } from './controllers';
|
|
2
|
-
export { default } from './prng';
|
package/lib/prng.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { PRNGController } from './controllers';
|
|
2
|
-
import { Algorithm } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* PRNG class
|
|
5
|
-
*
|
|
6
|
-
* @class PRNG
|
|
7
|
-
*/
|
|
8
|
-
declare class PRNG {
|
|
9
|
-
seed: string;
|
|
10
|
-
algorithm: Algorithm;
|
|
11
|
-
controllers: PRNGController[];
|
|
12
|
-
/**
|
|
13
|
-
* Add a controller to this PRNG
|
|
14
|
-
*
|
|
15
|
-
* @param {PRNGController} controller
|
|
16
|
-
*/
|
|
17
|
-
addController(controller: PRNGController): void;
|
|
18
|
-
/**
|
|
19
|
-
* Remove a controller from this PRNG
|
|
20
|
-
*
|
|
21
|
-
* @param {PRNGController} controller
|
|
22
|
-
*/
|
|
23
|
-
removeController(controller: PRNGController): void;
|
|
24
|
-
/**
|
|
25
|
-
* Set this PRNG seed
|
|
26
|
-
*
|
|
27
|
-
* @param {string} seed
|
|
28
|
-
*/
|
|
29
|
-
setSeed(seed: string): void;
|
|
30
|
-
/**
|
|
31
|
-
* Set this PRNG algorithm for generating pseudo-random values
|
|
32
|
-
*
|
|
33
|
-
* @param {Algorithm} algorithm Algorithm name
|
|
34
|
-
*/
|
|
35
|
-
setAlgorithm(algorithm: Algorithm): void;
|
|
36
|
-
/**
|
|
37
|
-
* Generate a pseudo-random number in the interval [0, 1]
|
|
38
|
-
* PRNG equivalent of `Math.random()`
|
|
39
|
-
*
|
|
40
|
-
* @param {string} seed
|
|
41
|
-
* @returns {number}
|
|
42
|
-
*/
|
|
43
|
-
random(seed: string): number;
|
|
44
|
-
/**
|
|
45
|
-
* Generate a pseudo-random boolean (true or false)
|
|
46
|
-
*
|
|
47
|
-
* @param {string} seed
|
|
48
|
-
* @param {number} [probability=0.5] Probability to get `true`
|
|
49
|
-
* @returns {boolean} Either `true` or `false`
|
|
50
|
-
*/
|
|
51
|
-
randomBoolean(seed: string, probability?: number): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Generate a pseudo-random sign (1 or -1)
|
|
54
|
-
*
|
|
55
|
-
* @param {string} seed
|
|
56
|
-
* @param {number} [probability=0.5] Probability to get 1
|
|
57
|
-
* @returns {number} Either 1 or -1
|
|
58
|
-
*/
|
|
59
|
-
randomSign(seed: string, probability?: number): number;
|
|
60
|
-
/**
|
|
61
|
-
* Generate a pseudo-random floating-point number within a specified range
|
|
62
|
-
*
|
|
63
|
-
* @param {string} seed
|
|
64
|
-
* @param {number} [min=0] Minimum boundary
|
|
65
|
-
* @param {number} [max=1] Maximum boundary
|
|
66
|
-
* @param {number} [precision=2] Number of digits after the decimal point
|
|
67
|
-
* @returns {number} Generated float
|
|
68
|
-
*/
|
|
69
|
-
randomFloat(seed: string, min?: number, max?: number, precision?: number): number;
|
|
70
|
-
/**
|
|
71
|
-
* Generate a pseudo-random integer number within a specified range
|
|
72
|
-
*
|
|
73
|
-
* @param {string} seed
|
|
74
|
-
* @param {number} min Minimum boundary
|
|
75
|
-
* @param {number} max Maximum boundary
|
|
76
|
-
* @returns {number} Generated integer
|
|
77
|
-
*/
|
|
78
|
-
randomInt(seed: string, min: number, max: number): number;
|
|
79
|
-
/**
|
|
80
|
-
* Generate a pseudo-random hexadecimal color
|
|
81
|
-
*
|
|
82
|
-
* @param {string} seed
|
|
83
|
-
* @returns {string} Generated hexadecimal color
|
|
84
|
-
*/
|
|
85
|
-
randomHexColor(seed: string): string;
|
|
86
|
-
/**
|
|
87
|
-
* Pick a pseudo-random item from a given array
|
|
88
|
-
*
|
|
89
|
-
* @param {string} seed
|
|
90
|
-
* @param {T[]} array Array to pick the item from
|
|
91
|
-
* @returns {T|undefined} Random item picked
|
|
92
|
-
*/
|
|
93
|
-
randomItem<T = unknown>(seed: string, array: T[]): T | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* Pick a pseudo-random property value from a given object
|
|
96
|
-
*
|
|
97
|
-
* @param {string} seed
|
|
98
|
-
* @param {object} object Object to pick the property from
|
|
99
|
-
* @returns {T|undefined} Random item picked
|
|
100
|
-
*/
|
|
101
|
-
randomObjectProperty<T = unknown>(seed: string, object: {
|
|
102
|
-
[key: string]: T;
|
|
103
|
-
}): T | undefined;
|
|
104
|
-
/**
|
|
105
|
-
* Select a pseudo-random index from an array of weighted items
|
|
106
|
-
*
|
|
107
|
-
* @param {string} seed
|
|
108
|
-
* @param {number[]} weights Array of weights
|
|
109
|
-
* @returns {number} Random index based on weights
|
|
110
|
-
*/
|
|
111
|
-
randomIndex(seed: string, weights: number[]): number;
|
|
112
|
-
}
|
|
113
|
-
declare const prng: PRNG;
|
|
114
|
-
export default prng;
|