toosoon-prng 1.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/.prettierrc +7 -0
- package/LICENSE +21 -0
- package/lib/controllers.d.ts +160 -0
- package/lib/controllers.js +382 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +31 -0
- package/lib/prng.d.ts +28 -0
- package/lib/prng.js +106 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/utils.d.ts +38 -0
- package/lib/utils.js +108 -0
- package/package.json +31 -0
- package/src/controllers.ts +420 -0
- package/src/index.ts +24 -0
- package/src/prng.ts +112 -0
- package/src/utils.ts +106 -0
- package/tsconfig.json +24 -0
package/.prettierrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 TOOSOON
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { Gui, GuiController } from 'toosoon-gui';
|
|
2
|
+
export declare enum PRNGControllerTypes {
|
|
3
|
+
Boolean = "Boolean",
|
|
4
|
+
Sign = "Sign",
|
|
5
|
+
Int = "Int",
|
|
6
|
+
Float = "Float",
|
|
7
|
+
HexColor = "HexColor",
|
|
8
|
+
Item = "Item",
|
|
9
|
+
ObjectProperty = "ObjectProperty",
|
|
10
|
+
Weights = "Weights"
|
|
11
|
+
}
|
|
12
|
+
export interface PRNGController<T = unknown> {
|
|
13
|
+
seed: string;
|
|
14
|
+
value: T;
|
|
15
|
+
addGUI(gui: Gui, min?: number, max?: number, step?: number): GuiController;
|
|
16
|
+
getValue(): T;
|
|
17
|
+
dispose(): void;
|
|
18
|
+
}
|
|
19
|
+
export interface PRNGGroupController<T = unknown> {
|
|
20
|
+
seed: string;
|
|
21
|
+
addGUI(gui: Gui, min?: number, max?: number, step?: number): Gui;
|
|
22
|
+
createController(index: number): PRNGController<T>;
|
|
23
|
+
getValueAt(index: number): T;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
|
26
|
+
declare abstract class BasePRNGController<T> implements PRNGController<T> {
|
|
27
|
+
seed: string;
|
|
28
|
+
abstract value: T;
|
|
29
|
+
gui: GuiController;
|
|
30
|
+
constructor(seed: string);
|
|
31
|
+
abstract addGUI(gui: Gui, min?: number, max?: number, step?: number): GuiController;
|
|
32
|
+
abstract getValue(): T;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|
|
35
|
+
declare abstract class BasePRNGGroupController<T> implements PRNGGroupController<T> {
|
|
36
|
+
seed: string;
|
|
37
|
+
controllers: PRNGController<T>[];
|
|
38
|
+
gui: Gui;
|
|
39
|
+
guiArgs: {
|
|
40
|
+
min?: number;
|
|
41
|
+
max?: number;
|
|
42
|
+
step?: number;
|
|
43
|
+
};
|
|
44
|
+
constructor(seed: string);
|
|
45
|
+
addGUI(gui: Gui, min?: number, max?: number, step?: number): Gui;
|
|
46
|
+
abstract createController(index: number): PRNGController<T>;
|
|
47
|
+
getValueAt(index: number): T;
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
50
|
+
export declare class BooleanController extends BasePRNGController<boolean> {
|
|
51
|
+
value: boolean;
|
|
52
|
+
probability: number;
|
|
53
|
+
constructor(seed: string, probability?: number);
|
|
54
|
+
addGUI(gui: Gui): GuiController;
|
|
55
|
+
getValue(): boolean;
|
|
56
|
+
}
|
|
57
|
+
export declare class SignController extends BasePRNGController<number> {
|
|
58
|
+
value: number;
|
|
59
|
+
probability: number;
|
|
60
|
+
constructor(seed: string, probability?: number);
|
|
61
|
+
addGUI(gui: Gui): GuiController;
|
|
62
|
+
getValue(): number;
|
|
63
|
+
}
|
|
64
|
+
export declare class IntController extends BasePRNGController<number> {
|
|
65
|
+
value: number;
|
|
66
|
+
min: number;
|
|
67
|
+
max: number;
|
|
68
|
+
constructor(seed: string, min?: number, max?: number);
|
|
69
|
+
addGUI(gui: Gui, min: number, max: number, step?: number): GuiController;
|
|
70
|
+
getValue(): number;
|
|
71
|
+
}
|
|
72
|
+
export declare class FloatController extends BasePRNGController<number> {
|
|
73
|
+
value: number;
|
|
74
|
+
min: number;
|
|
75
|
+
max: number;
|
|
76
|
+
constructor(seed: string, min?: number, max?: number);
|
|
77
|
+
addGUI(gui: Gui, min: number, max: number, step?: number): GuiController;
|
|
78
|
+
getValue(): number;
|
|
79
|
+
}
|
|
80
|
+
export declare class HexColorController extends BasePRNGController<string> {
|
|
81
|
+
value: string;
|
|
82
|
+
constructor(seed: string);
|
|
83
|
+
addGUI(gui: Gui): GuiController;
|
|
84
|
+
getValue(): string;
|
|
85
|
+
}
|
|
86
|
+
export declare class ItemController<T = unknown> extends BasePRNGController<T> {
|
|
87
|
+
value: T;
|
|
88
|
+
items: T[];
|
|
89
|
+
constructor(seed: string, items: T[]);
|
|
90
|
+
addGUI(gui: Gui): GuiController;
|
|
91
|
+
getValue(): T;
|
|
92
|
+
}
|
|
93
|
+
export declare class ObjectPropertyController<T = unknown> extends BasePRNGController<T> {
|
|
94
|
+
value: T;
|
|
95
|
+
object: Object;
|
|
96
|
+
constructor(seed: string, object: Object);
|
|
97
|
+
addGUI(gui: Gui): GuiController;
|
|
98
|
+
getValue(): T;
|
|
99
|
+
}
|
|
100
|
+
type WeightsItems<T> = Array<{
|
|
101
|
+
weight: number;
|
|
102
|
+
value: T;
|
|
103
|
+
}>;
|
|
104
|
+
export declare class WeightsController<T = unknown> extends BasePRNGController<T> {
|
|
105
|
+
value: T;
|
|
106
|
+
items: WeightsItems<T>;
|
|
107
|
+
weights: number[];
|
|
108
|
+
constructor(seed: string, items: WeightsItems<T>);
|
|
109
|
+
addGUI(gui: Gui): GuiController;
|
|
110
|
+
getValue(): T;
|
|
111
|
+
}
|
|
112
|
+
export declare class BooleanGroupController extends BasePRNGGroupController<boolean> {
|
|
113
|
+
probability: number;
|
|
114
|
+
controllers: BooleanController[];
|
|
115
|
+
constructor(seed: string, probability: number);
|
|
116
|
+
createController(index: number): BooleanController;
|
|
117
|
+
}
|
|
118
|
+
export declare class SignGroupController extends BasePRNGGroupController<number> {
|
|
119
|
+
probability: number;
|
|
120
|
+
controllers: SignController[];
|
|
121
|
+
constructor(seed: string, probability: number);
|
|
122
|
+
createController(index: number): SignController;
|
|
123
|
+
}
|
|
124
|
+
export declare class IntGroupController extends BasePRNGGroupController<number> {
|
|
125
|
+
min: number;
|
|
126
|
+
max: number;
|
|
127
|
+
controllers: IntController[];
|
|
128
|
+
constructor(seed: string, min: number, max: number);
|
|
129
|
+
createController(index: number): IntController;
|
|
130
|
+
}
|
|
131
|
+
export declare class FloatGroupController extends BasePRNGGroupController<number> {
|
|
132
|
+
min: number;
|
|
133
|
+
max: number;
|
|
134
|
+
controllers: FloatController[];
|
|
135
|
+
constructor(seed: string, min: number, max: number);
|
|
136
|
+
createController(index: number): FloatController;
|
|
137
|
+
}
|
|
138
|
+
export declare class HexColorGroupController extends BasePRNGGroupController<string> {
|
|
139
|
+
controllers: HexColorController[];
|
|
140
|
+
createController(index: number): HexColorController;
|
|
141
|
+
}
|
|
142
|
+
export declare class ItemGroupController<T = unknown> extends BasePRNGGroupController<T> {
|
|
143
|
+
items: T[];
|
|
144
|
+
controllers: ItemController<T>[];
|
|
145
|
+
constructor(seed: string, items: T[]);
|
|
146
|
+
createController(index: number): ItemController<T>;
|
|
147
|
+
}
|
|
148
|
+
export declare class ObjectPropertyGroupController<T = unknown> extends BasePRNGGroupController<T> {
|
|
149
|
+
object: Object;
|
|
150
|
+
controllers: ObjectPropertyController<T>[];
|
|
151
|
+
constructor(seed: string, object: Object);
|
|
152
|
+
createController(index: number): ObjectPropertyController<T>;
|
|
153
|
+
}
|
|
154
|
+
export declare class WeightsGroupController<T = unknown> extends BasePRNGGroupController<T> {
|
|
155
|
+
items: WeightsItems<T>;
|
|
156
|
+
controllers: WeightsController<T>[];
|
|
157
|
+
constructor(seed: string, items: WeightsItems<T>);
|
|
158
|
+
createController(index: number): WeightsController<T>;
|
|
159
|
+
}
|
|
160
|
+
export {};
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.WeightsGroupController = exports.ObjectPropertyGroupController = exports.ItemGroupController = exports.HexColorGroupController = exports.FloatGroupController = exports.IntGroupController = exports.SignGroupController = exports.BooleanGroupController = exports.WeightsController = exports.ObjectPropertyController = exports.ItemController = exports.HexColorController = exports.FloatController = exports.IntController = exports.SignController = exports.BooleanController = exports.PRNGControllerTypes = void 0;
|
|
22
|
+
var prng_1 = __importDefault(require("./prng"));
|
|
23
|
+
var PRNGControllerTypes;
|
|
24
|
+
(function (PRNGControllerTypes) {
|
|
25
|
+
PRNGControllerTypes["Boolean"] = "Boolean";
|
|
26
|
+
PRNGControllerTypes["Sign"] = "Sign";
|
|
27
|
+
PRNGControllerTypes["Int"] = "Int";
|
|
28
|
+
PRNGControllerTypes["Float"] = "Float";
|
|
29
|
+
PRNGControllerTypes["HexColor"] = "HexColor";
|
|
30
|
+
PRNGControllerTypes["Item"] = "Item";
|
|
31
|
+
PRNGControllerTypes["ObjectProperty"] = "ObjectProperty";
|
|
32
|
+
PRNGControllerTypes["Weights"] = "Weights";
|
|
33
|
+
})(PRNGControllerTypes || (exports.PRNGControllerTypes = PRNGControllerTypes = {}));
|
|
34
|
+
// *********************
|
|
35
|
+
// Abstract controllers
|
|
36
|
+
// *********************
|
|
37
|
+
var BasePRNGController = /** @class */ (function () {
|
|
38
|
+
function BasePRNGController(seed) {
|
|
39
|
+
this.seed = seed;
|
|
40
|
+
prng_1.default.addController(this);
|
|
41
|
+
}
|
|
42
|
+
BasePRNGController.prototype.dispose = function () {
|
|
43
|
+
var _a;
|
|
44
|
+
prng_1.default.removeController(this);
|
|
45
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
46
|
+
};
|
|
47
|
+
return BasePRNGController;
|
|
48
|
+
}());
|
|
49
|
+
var BasePRNGGroupController = /** @class */ (function () {
|
|
50
|
+
function BasePRNGGroupController(seed) {
|
|
51
|
+
this.controllers = [];
|
|
52
|
+
this.seed = seed;
|
|
53
|
+
}
|
|
54
|
+
BasePRNGGroupController.prototype.addGUI = function (gui, min, max, step) {
|
|
55
|
+
this.gui = gui.addFolder(this.seed).close();
|
|
56
|
+
this.guiArgs = { min: min, max: max, step: step };
|
|
57
|
+
return this.gui;
|
|
58
|
+
};
|
|
59
|
+
BasePRNGGroupController.prototype.getValueAt = function (index) {
|
|
60
|
+
var controller = this.controllers[index];
|
|
61
|
+
if (!controller) {
|
|
62
|
+
controller = this.createController(index);
|
|
63
|
+
if (this.gui) {
|
|
64
|
+
controller
|
|
65
|
+
.addGUI(this.gui, this.guiArgs.min, this.guiArgs.max, this.guiArgs.step)
|
|
66
|
+
.name("".concat(this.seed, "-").concat(index));
|
|
67
|
+
}
|
|
68
|
+
this.controllers[index] = controller;
|
|
69
|
+
}
|
|
70
|
+
return controller.value;
|
|
71
|
+
};
|
|
72
|
+
BasePRNGGroupController.prototype.dispose = function () {
|
|
73
|
+
var _a;
|
|
74
|
+
this.controllers.forEach(function (controller) { return controller.dispose(); });
|
|
75
|
+
this.controllers = [];
|
|
76
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
77
|
+
};
|
|
78
|
+
return BasePRNGGroupController;
|
|
79
|
+
}());
|
|
80
|
+
// *********************
|
|
81
|
+
// Controllers
|
|
82
|
+
// *********************
|
|
83
|
+
var BooleanController = /** @class */ (function (_super) {
|
|
84
|
+
__extends(BooleanController, _super);
|
|
85
|
+
function BooleanController(seed, probability) {
|
|
86
|
+
if (probability === void 0) { probability = 0.5; }
|
|
87
|
+
var _this = _super.call(this, seed) || this;
|
|
88
|
+
_this.probability = probability;
|
|
89
|
+
_this.value = _this.getValue();
|
|
90
|
+
return _this;
|
|
91
|
+
}
|
|
92
|
+
BooleanController.prototype.addGUI = function (gui) {
|
|
93
|
+
this.gui = gui.add(this, 'value').name(this.seed);
|
|
94
|
+
return this.gui;
|
|
95
|
+
};
|
|
96
|
+
BooleanController.prototype.getValue = function () {
|
|
97
|
+
var _a;
|
|
98
|
+
this.value = prng_1.default.randomBoolean(this.seed, this.probability);
|
|
99
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
100
|
+
return this.value;
|
|
101
|
+
};
|
|
102
|
+
return BooleanController;
|
|
103
|
+
}(BasePRNGController));
|
|
104
|
+
exports.BooleanController = BooleanController;
|
|
105
|
+
var SignController = /** @class */ (function (_super) {
|
|
106
|
+
__extends(SignController, _super);
|
|
107
|
+
function SignController(seed, probability) {
|
|
108
|
+
if (probability === void 0) { probability = 0.5; }
|
|
109
|
+
var _this = _super.call(this, seed) || this;
|
|
110
|
+
_this.probability = probability;
|
|
111
|
+
_this.value = _this.getValue();
|
|
112
|
+
return _this;
|
|
113
|
+
}
|
|
114
|
+
SignController.prototype.addGUI = function (gui) {
|
|
115
|
+
this.gui = gui.add(this, 'value', [-1, 1]).name(this.seed);
|
|
116
|
+
return this.gui;
|
|
117
|
+
};
|
|
118
|
+
SignController.prototype.getValue = function () {
|
|
119
|
+
var _a;
|
|
120
|
+
this.value = prng_1.default.randomSign(this.seed, this.probability);
|
|
121
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
122
|
+
return this.value;
|
|
123
|
+
};
|
|
124
|
+
return SignController;
|
|
125
|
+
}(BasePRNGController));
|
|
126
|
+
exports.SignController = SignController;
|
|
127
|
+
var IntController = /** @class */ (function (_super) {
|
|
128
|
+
__extends(IntController, _super);
|
|
129
|
+
function IntController(seed, min, max) {
|
|
130
|
+
if (min === void 0) { min = 0; }
|
|
131
|
+
if (max === void 0) { max = 1; }
|
|
132
|
+
var _this = _super.call(this, seed) || this;
|
|
133
|
+
_this.min = min;
|
|
134
|
+
_this.max = max;
|
|
135
|
+
_this.value = prng_1.default.randomInt(_this.seed, min, max);
|
|
136
|
+
return _this;
|
|
137
|
+
}
|
|
138
|
+
IntController.prototype.addGUI = function (gui, min, max, step) {
|
|
139
|
+
if (step === void 0) { step = 1; }
|
|
140
|
+
this.gui = gui.add(this, 'value', min, max, step).name(this.seed);
|
|
141
|
+
return this.gui;
|
|
142
|
+
};
|
|
143
|
+
IntController.prototype.getValue = function () {
|
|
144
|
+
var _a;
|
|
145
|
+
this.value = prng_1.default.randomInt(this.seed, this.min, this.max);
|
|
146
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
147
|
+
return this.value;
|
|
148
|
+
};
|
|
149
|
+
return IntController;
|
|
150
|
+
}(BasePRNGController));
|
|
151
|
+
exports.IntController = IntController;
|
|
152
|
+
var FloatController = /** @class */ (function (_super) {
|
|
153
|
+
__extends(FloatController, _super);
|
|
154
|
+
function FloatController(seed, min, max) {
|
|
155
|
+
if (min === void 0) { min = 0; }
|
|
156
|
+
if (max === void 0) { max = 1; }
|
|
157
|
+
var _this = _super.call(this, seed) || this;
|
|
158
|
+
_this.min = min;
|
|
159
|
+
_this.max = max;
|
|
160
|
+
_this.value = _this.getValue();
|
|
161
|
+
return _this;
|
|
162
|
+
}
|
|
163
|
+
FloatController.prototype.addGUI = function (gui, min, max, step) {
|
|
164
|
+
if (step === void 0) { step = 0.01; }
|
|
165
|
+
this.gui = gui.add(this, 'value', min, max, step).name(this.seed);
|
|
166
|
+
return this.gui;
|
|
167
|
+
};
|
|
168
|
+
FloatController.prototype.getValue = function () {
|
|
169
|
+
var _a;
|
|
170
|
+
this.value = prng_1.default.randomFloat(this.seed, this.min, this.max);
|
|
171
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
172
|
+
return this.value;
|
|
173
|
+
};
|
|
174
|
+
return FloatController;
|
|
175
|
+
}(BasePRNGController));
|
|
176
|
+
exports.FloatController = FloatController;
|
|
177
|
+
var HexColorController = /** @class */ (function (_super) {
|
|
178
|
+
__extends(HexColorController, _super);
|
|
179
|
+
function HexColorController(seed) {
|
|
180
|
+
var _this = _super.call(this, seed) || this;
|
|
181
|
+
_this.value = _this.getValue();
|
|
182
|
+
return _this;
|
|
183
|
+
}
|
|
184
|
+
HexColorController.prototype.addGUI = function (gui) {
|
|
185
|
+
this.gui = gui.addColor(this, 'value').name(this.seed);
|
|
186
|
+
return this.gui;
|
|
187
|
+
};
|
|
188
|
+
HexColorController.prototype.getValue = function () {
|
|
189
|
+
var _a;
|
|
190
|
+
this.value = prng_1.default.randomHexColor(this.seed);
|
|
191
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
192
|
+
return this.value;
|
|
193
|
+
};
|
|
194
|
+
return HexColorController;
|
|
195
|
+
}(BasePRNGController));
|
|
196
|
+
exports.HexColorController = HexColorController;
|
|
197
|
+
var ItemController = /** @class */ (function (_super) {
|
|
198
|
+
__extends(ItemController, _super);
|
|
199
|
+
function ItemController(seed, items) {
|
|
200
|
+
var _this = _super.call(this, seed) || this;
|
|
201
|
+
_this.items = items;
|
|
202
|
+
_this.value = _this.getValue();
|
|
203
|
+
return _this;
|
|
204
|
+
}
|
|
205
|
+
ItemController.prototype.addGUI = function (gui) {
|
|
206
|
+
this.gui = gui.add(this, 'value', this.items).name(this.seed);
|
|
207
|
+
return this.gui;
|
|
208
|
+
};
|
|
209
|
+
ItemController.prototype.getValue = function () {
|
|
210
|
+
var _a;
|
|
211
|
+
this.value = prng_1.default.randomItem(this.seed, this.items);
|
|
212
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
213
|
+
return this.value;
|
|
214
|
+
};
|
|
215
|
+
return ItemController;
|
|
216
|
+
}(BasePRNGController));
|
|
217
|
+
exports.ItemController = ItemController;
|
|
218
|
+
var ObjectPropertyController = /** @class */ (function (_super) {
|
|
219
|
+
__extends(ObjectPropertyController, _super);
|
|
220
|
+
function ObjectPropertyController(seed, object) {
|
|
221
|
+
var _this = _super.call(this, seed) || this;
|
|
222
|
+
_this.object = object;
|
|
223
|
+
_this.value = _this.getValue();
|
|
224
|
+
return _this;
|
|
225
|
+
}
|
|
226
|
+
ObjectPropertyController.prototype.addGUI = function (gui) {
|
|
227
|
+
this.gui = gui.add(this, 'value', this.object).name(this.seed);
|
|
228
|
+
return this.gui;
|
|
229
|
+
};
|
|
230
|
+
ObjectPropertyController.prototype.getValue = function () {
|
|
231
|
+
var _a;
|
|
232
|
+
this.value = prng_1.default.randomObjectProperty(this.seed, this.object);
|
|
233
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
234
|
+
return this.value;
|
|
235
|
+
};
|
|
236
|
+
return ObjectPropertyController;
|
|
237
|
+
}(BasePRNGController));
|
|
238
|
+
exports.ObjectPropertyController = ObjectPropertyController;
|
|
239
|
+
var WeightsController = /** @class */ (function (_super) {
|
|
240
|
+
__extends(WeightsController, _super);
|
|
241
|
+
function WeightsController(seed, items) {
|
|
242
|
+
var _this = _super.call(this, seed) || this;
|
|
243
|
+
_this.items = items;
|
|
244
|
+
_this.weights = _this.items.map(function (item) { return item.weight; });
|
|
245
|
+
_this.value = _this.getValue();
|
|
246
|
+
return _this;
|
|
247
|
+
}
|
|
248
|
+
WeightsController.prototype.addGUI = function (gui) {
|
|
249
|
+
this.gui = gui
|
|
250
|
+
.add(this, 'value', this.items.map(function (item) { return item.value; }))
|
|
251
|
+
.name(this.seed);
|
|
252
|
+
return this.gui;
|
|
253
|
+
};
|
|
254
|
+
WeightsController.prototype.getValue = function () {
|
|
255
|
+
var _a;
|
|
256
|
+
var index = prng_1.default.randomIndex(this.seed, this.weights);
|
|
257
|
+
this.value = this.items[index].value;
|
|
258
|
+
(_a = this.gui) === null || _a === void 0 ? void 0 : _a.updateDisplay();
|
|
259
|
+
return this.value;
|
|
260
|
+
};
|
|
261
|
+
return WeightsController;
|
|
262
|
+
}(BasePRNGController));
|
|
263
|
+
exports.WeightsController = WeightsController;
|
|
264
|
+
// *********************
|
|
265
|
+
// Group Controllers
|
|
266
|
+
// *********************
|
|
267
|
+
var BooleanGroupController = /** @class */ (function (_super) {
|
|
268
|
+
__extends(BooleanGroupController, _super);
|
|
269
|
+
function BooleanGroupController(seed, probability) {
|
|
270
|
+
var _this = _super.call(this, seed) || this;
|
|
271
|
+
_this.controllers = [];
|
|
272
|
+
_this.probability = probability;
|
|
273
|
+
return _this;
|
|
274
|
+
}
|
|
275
|
+
BooleanGroupController.prototype.createController = function (index) {
|
|
276
|
+
return new BooleanController("".concat(this.seed, "-").concat(index), this.probability);
|
|
277
|
+
};
|
|
278
|
+
return BooleanGroupController;
|
|
279
|
+
}(BasePRNGGroupController));
|
|
280
|
+
exports.BooleanGroupController = BooleanGroupController;
|
|
281
|
+
var SignGroupController = /** @class */ (function (_super) {
|
|
282
|
+
__extends(SignGroupController, _super);
|
|
283
|
+
function SignGroupController(seed, probability) {
|
|
284
|
+
var _this = _super.call(this, seed) || this;
|
|
285
|
+
_this.controllers = [];
|
|
286
|
+
_this.probability = probability;
|
|
287
|
+
return _this;
|
|
288
|
+
}
|
|
289
|
+
SignGroupController.prototype.createController = function (index) {
|
|
290
|
+
return new SignController("".concat(this.seed, "-").concat(index), this.probability);
|
|
291
|
+
};
|
|
292
|
+
return SignGroupController;
|
|
293
|
+
}(BasePRNGGroupController));
|
|
294
|
+
exports.SignGroupController = SignGroupController;
|
|
295
|
+
var IntGroupController = /** @class */ (function (_super) {
|
|
296
|
+
__extends(IntGroupController, _super);
|
|
297
|
+
function IntGroupController(seed, min, max) {
|
|
298
|
+
var _this = _super.call(this, seed) || this;
|
|
299
|
+
_this.controllers = [];
|
|
300
|
+
_this.min = min;
|
|
301
|
+
_this.max = max;
|
|
302
|
+
return _this;
|
|
303
|
+
}
|
|
304
|
+
IntGroupController.prototype.createController = function (index) {
|
|
305
|
+
return new IntController("".concat(this.seed, "-").concat(index), this.min, this.max);
|
|
306
|
+
};
|
|
307
|
+
return IntGroupController;
|
|
308
|
+
}(BasePRNGGroupController));
|
|
309
|
+
exports.IntGroupController = IntGroupController;
|
|
310
|
+
var FloatGroupController = /** @class */ (function (_super) {
|
|
311
|
+
__extends(FloatGroupController, _super);
|
|
312
|
+
function FloatGroupController(seed, min, max) {
|
|
313
|
+
var _this = _super.call(this, seed) || this;
|
|
314
|
+
_this.controllers = [];
|
|
315
|
+
_this.min = min;
|
|
316
|
+
_this.max = max;
|
|
317
|
+
return _this;
|
|
318
|
+
}
|
|
319
|
+
FloatGroupController.prototype.createController = function (index) {
|
|
320
|
+
return new FloatController("".concat(this.seed, "-").concat(index), this.min, this.max);
|
|
321
|
+
};
|
|
322
|
+
return FloatGroupController;
|
|
323
|
+
}(BasePRNGGroupController));
|
|
324
|
+
exports.FloatGroupController = FloatGroupController;
|
|
325
|
+
var HexColorGroupController = /** @class */ (function (_super) {
|
|
326
|
+
__extends(HexColorGroupController, _super);
|
|
327
|
+
function HexColorGroupController() {
|
|
328
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
329
|
+
_this.controllers = [];
|
|
330
|
+
return _this;
|
|
331
|
+
}
|
|
332
|
+
// constructor(seed: string) {
|
|
333
|
+
// super(seed);
|
|
334
|
+
// }
|
|
335
|
+
HexColorGroupController.prototype.createController = function (index) {
|
|
336
|
+
return new HexColorController("".concat(this.seed, "-").concat(index));
|
|
337
|
+
};
|
|
338
|
+
return HexColorGroupController;
|
|
339
|
+
}(BasePRNGGroupController));
|
|
340
|
+
exports.HexColorGroupController = HexColorGroupController;
|
|
341
|
+
var ItemGroupController = /** @class */ (function (_super) {
|
|
342
|
+
__extends(ItemGroupController, _super);
|
|
343
|
+
function ItemGroupController(seed, items) {
|
|
344
|
+
var _this = _super.call(this, seed) || this;
|
|
345
|
+
_this.controllers = [];
|
|
346
|
+
_this.items = items;
|
|
347
|
+
return _this;
|
|
348
|
+
}
|
|
349
|
+
ItemGroupController.prototype.createController = function (index) {
|
|
350
|
+
return new ItemController("".concat(this.seed, "-").concat(index), this.items);
|
|
351
|
+
};
|
|
352
|
+
return ItemGroupController;
|
|
353
|
+
}(BasePRNGGroupController));
|
|
354
|
+
exports.ItemGroupController = ItemGroupController;
|
|
355
|
+
var ObjectPropertyGroupController = /** @class */ (function (_super) {
|
|
356
|
+
__extends(ObjectPropertyGroupController, _super);
|
|
357
|
+
function ObjectPropertyGroupController(seed, object) {
|
|
358
|
+
var _this = _super.call(this, seed) || this;
|
|
359
|
+
_this.controllers = [];
|
|
360
|
+
_this.object = object;
|
|
361
|
+
return _this;
|
|
362
|
+
}
|
|
363
|
+
ObjectPropertyGroupController.prototype.createController = function (index) {
|
|
364
|
+
return new ObjectPropertyController("".concat(this.seed, "-").concat(index), this.object);
|
|
365
|
+
};
|
|
366
|
+
return ObjectPropertyGroupController;
|
|
367
|
+
}(BasePRNGGroupController));
|
|
368
|
+
exports.ObjectPropertyGroupController = ObjectPropertyGroupController;
|
|
369
|
+
var WeightsGroupController = /** @class */ (function (_super) {
|
|
370
|
+
__extends(WeightsGroupController, _super);
|
|
371
|
+
function WeightsGroupController(seed, items) {
|
|
372
|
+
var _this = _super.call(this, seed) || this;
|
|
373
|
+
_this.controllers = [];
|
|
374
|
+
_this.items = items;
|
|
375
|
+
return _this;
|
|
376
|
+
}
|
|
377
|
+
WeightsGroupController.prototype.createController = function (index) {
|
|
378
|
+
return new WeightsController("".concat(this.seed, "-").concat(index), this.items);
|
|
379
|
+
};
|
|
380
|
+
return WeightsGroupController;
|
|
381
|
+
}(BasePRNGGroupController));
|
|
382
|
+
exports.WeightsGroupController = WeightsGroupController;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BooleanController, SignController, IntController, FloatController, HexColorController, ItemController, ObjectPropertyController, WeightsController, BooleanGroupController, SignGroupController, IntGroupController, FloatGroupController, HexColorGroupController, ItemGroupController, ObjectPropertyGroupController, WeightsGroupController } from './controllers';
|
|
2
|
+
export { cyrb128, sfc32, mulberry32, jsf32, xoshiro128ss } from './utils';
|
|
3
|
+
export type { PRNGControllerTypes, PRNGController, PRNGGroupController } from './controllers';
|
|
4
|
+
export { default } from './prng';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = exports.xoshiro128ss = exports.jsf32 = exports.mulberry32 = exports.sfc32 = exports.cyrb128 = exports.WeightsGroupController = exports.ObjectPropertyGroupController = exports.ItemGroupController = exports.HexColorGroupController = exports.FloatGroupController = exports.IntGroupController = exports.SignGroupController = exports.BooleanGroupController = exports.WeightsController = exports.ObjectPropertyController = exports.ItemController = exports.HexColorController = exports.FloatController = exports.IntController = exports.SignController = exports.BooleanController = void 0;
|
|
7
|
+
var controllers_1 = require("./controllers");
|
|
8
|
+
Object.defineProperty(exports, "BooleanController", { enumerable: true, get: function () { return controllers_1.BooleanController; } });
|
|
9
|
+
Object.defineProperty(exports, "SignController", { enumerable: true, get: function () { return controllers_1.SignController; } });
|
|
10
|
+
Object.defineProperty(exports, "IntController", { enumerable: true, get: function () { return controllers_1.IntController; } });
|
|
11
|
+
Object.defineProperty(exports, "FloatController", { enumerable: true, get: function () { return controllers_1.FloatController; } });
|
|
12
|
+
Object.defineProperty(exports, "HexColorController", { enumerable: true, get: function () { return controllers_1.HexColorController; } });
|
|
13
|
+
Object.defineProperty(exports, "ItemController", { enumerable: true, get: function () { return controllers_1.ItemController; } });
|
|
14
|
+
Object.defineProperty(exports, "ObjectPropertyController", { enumerable: true, get: function () { return controllers_1.ObjectPropertyController; } });
|
|
15
|
+
Object.defineProperty(exports, "WeightsController", { enumerable: true, get: function () { return controllers_1.WeightsController; } });
|
|
16
|
+
Object.defineProperty(exports, "BooleanGroupController", { enumerable: true, get: function () { return controllers_1.BooleanGroupController; } });
|
|
17
|
+
Object.defineProperty(exports, "SignGroupController", { enumerable: true, get: function () { return controllers_1.SignGroupController; } });
|
|
18
|
+
Object.defineProperty(exports, "IntGroupController", { enumerable: true, get: function () { return controllers_1.IntGroupController; } });
|
|
19
|
+
Object.defineProperty(exports, "FloatGroupController", { enumerable: true, get: function () { return controllers_1.FloatGroupController; } });
|
|
20
|
+
Object.defineProperty(exports, "HexColorGroupController", { enumerable: true, get: function () { return controllers_1.HexColorGroupController; } });
|
|
21
|
+
Object.defineProperty(exports, "ItemGroupController", { enumerable: true, get: function () { return controllers_1.ItemGroupController; } });
|
|
22
|
+
Object.defineProperty(exports, "ObjectPropertyGroupController", { enumerable: true, get: function () { return controllers_1.ObjectPropertyGroupController; } });
|
|
23
|
+
Object.defineProperty(exports, "WeightsGroupController", { enumerable: true, get: function () { return controllers_1.WeightsGroupController; } });
|
|
24
|
+
var utils_1 = require("./utils");
|
|
25
|
+
Object.defineProperty(exports, "cyrb128", { enumerable: true, get: function () { return utils_1.cyrb128; } });
|
|
26
|
+
Object.defineProperty(exports, "sfc32", { enumerable: true, get: function () { return utils_1.sfc32; } });
|
|
27
|
+
Object.defineProperty(exports, "mulberry32", { enumerable: true, get: function () { return utils_1.mulberry32; } });
|
|
28
|
+
Object.defineProperty(exports, "jsf32", { enumerable: true, get: function () { return utils_1.jsf32; } });
|
|
29
|
+
Object.defineProperty(exports, "xoshiro128ss", { enumerable: true, get: function () { return utils_1.xoshiro128ss; } });
|
|
30
|
+
var prng_1 = require("./prng");
|
|
31
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(prng_1).default; } });
|
package/lib/prng.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PRNGController } from './controllers';
|
|
2
|
+
export declare enum PRNGMethod {
|
|
3
|
+
jsf32 = "jsf32",
|
|
4
|
+
mulberry32 = "mulberry32",
|
|
5
|
+
sfc32 = "sfc32",
|
|
6
|
+
xoshiro128ss = "xoshiro128**"
|
|
7
|
+
}
|
|
8
|
+
declare class PRNG {
|
|
9
|
+
seed: string;
|
|
10
|
+
method: PRNGMethod;
|
|
11
|
+
controllers: PRNGController[];
|
|
12
|
+
constructor(seed?: string);
|
|
13
|
+
addController(controller: PRNGController): void;
|
|
14
|
+
removeController(controller: PRNGController): void;
|
|
15
|
+
setSeed(seed: string): void;
|
|
16
|
+
setMethod(method: PRNGMethod): void;
|
|
17
|
+
random(seed: string): number;
|
|
18
|
+
randomBoolean(seed: string, probability?: number): boolean;
|
|
19
|
+
randomSign(seed: string, probability?: number): number;
|
|
20
|
+
randomInt(seed: string, min: number, max: number): number;
|
|
21
|
+
randomFloat(seed: string, min?: number, max?: number, precision?: number): number;
|
|
22
|
+
randomHexColor(seed: string): string;
|
|
23
|
+
randomItem<T = unknown>(seed: string, array?: T[]): T | undefined;
|
|
24
|
+
randomObjectProperty(seed: string, object: object): unknown | undefined;
|
|
25
|
+
randomIndex(seed: string, weights?: number[]): number;
|
|
26
|
+
}
|
|
27
|
+
declare const prng: PRNG;
|
|
28
|
+
export default prng;
|