wgge 2.0.21 → 2.0.23
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/core/Collection.js +10 -0
- package/core/model/vector/Vector3.js +5 -0
- package/package.json +1 -1
package/core/Collection.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import NodeWithEvents from "./model/event/NodeWithEvents";
|
|
2
|
+
import ArrayHelper from "./helper/ArrayHelper";
|
|
2
3
|
|
|
3
4
|
export default class Collection extends NodeWithEvents {
|
|
4
5
|
|
|
@@ -23,6 +24,10 @@ export default class Collection extends NodeWithEvents {
|
|
|
23
24
|
return element;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
get(index) {
|
|
28
|
+
return this.items[index];
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
insert(element, index) {
|
|
27
32
|
this.items.splice(index, 0, element);
|
|
28
33
|
this.triggerEvent('insert', element);
|
|
@@ -128,6 +133,11 @@ export default class Collection extends NodeWithEvents {
|
|
|
128
133
|
return this.items.sort(sortFunc);
|
|
129
134
|
}
|
|
130
135
|
|
|
136
|
+
random() {
|
|
137
|
+
if (this.isEmpty()) return undefined;
|
|
138
|
+
return this.get(ArrayHelper.randomIndex(this.count()-1));
|
|
139
|
+
}
|
|
140
|
+
|
|
131
141
|
addOnRemoveListener(listener) {
|
|
132
142
|
this.addEventListener('remove', listener);
|
|
133
143
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ModelBase from "../ModelBase";
|
|
2
|
+
import NumberHelper from "../../helper/NumberHelper";
|
|
2
3
|
|
|
3
4
|
export default class Vector3 extends ModelBase {
|
|
4
5
|
|
|
@@ -105,6 +106,10 @@ export default class Vector3 extends ModelBase {
|
|
|
105
106
|
static zero() {
|
|
106
107
|
return ZERO_VECTOR3;
|
|
107
108
|
}
|
|
109
|
+
|
|
110
|
+
toString(decimals = 2) {
|
|
111
|
+
return `[${NumberHelper.round(this.x, decimals)},${NumberHelper.round(this.y, decimals)},${NumberHelper.round(this.z, decimals)}]`;
|
|
112
|
+
}
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
export const ZERO_VECTOR3 = new Vector3(0, 0, 0);
|