@n3rdw1z4rd/core 0.15.0 → 0.16.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.mts +42 -95
- package/dist/index.d.ts +42 -95
- package/dist/index.js +128 -354
- package/dist/index.mjs +123 -349
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -107,12 +107,10 @@ __export(index_exports, {
|
|
|
107
107
|
imul: () => imul,
|
|
108
108
|
isNullOrUndefined: () => isNullOrUndefined,
|
|
109
109
|
isPositiveString: () => isPositiveString,
|
|
110
|
+
k2xy: () => k2xy,
|
|
111
|
+
k2xyz: () => k2xyz,
|
|
110
112
|
lerp: () => lerp,
|
|
111
113
|
log: () => log,
|
|
112
|
-
logdev: () => logdev,
|
|
113
|
-
logerr: () => logerr,
|
|
114
|
-
loginf: () => loginf,
|
|
115
|
-
logwrn: () => logwrn,
|
|
116
114
|
manhattanDistance: () => manhattanDistance,
|
|
117
115
|
max: () => max,
|
|
118
116
|
min: () => min,
|
|
@@ -122,7 +120,9 @@ __export(index_exports, {
|
|
|
122
120
|
roundTo: () => roundTo,
|
|
123
121
|
sin: () => sin,
|
|
124
122
|
sqrt: () => sqrt,
|
|
125
|
-
squaredDistance: () => squaredDistance
|
|
123
|
+
squaredDistance: () => squaredDistance,
|
|
124
|
+
xy2k: () => xy2k,
|
|
125
|
+
xyz2k: () => xyz2k
|
|
126
126
|
});
|
|
127
127
|
module.exports = __toCommonJS(index_exports);
|
|
128
128
|
|
|
@@ -293,6 +293,7 @@ var Clock = class extends Emitter {
|
|
|
293
293
|
};
|
|
294
294
|
requestAnimationFrame(update);
|
|
295
295
|
}
|
|
296
|
+
return this;
|
|
296
297
|
}
|
|
297
298
|
stop() {
|
|
298
299
|
this._isRunning = false;
|
|
@@ -513,12 +514,12 @@ var Vector = class _Vector {
|
|
|
513
514
|
// src/dungeon-generator.ts
|
|
514
515
|
var import_heap_js = require("heap-js");
|
|
515
516
|
|
|
516
|
-
// src/
|
|
517
|
-
var
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
517
|
+
// src/log.ts
|
|
518
|
+
var log = console.debug.bind(
|
|
519
|
+
console,
|
|
520
|
+
"%c[dev]",
|
|
521
|
+
"font-weight: bold; color: #888;"
|
|
522
|
+
);
|
|
522
523
|
|
|
523
524
|
// src/map2d.ts
|
|
524
525
|
var DEFAULT_VALUE = -1;
|
|
@@ -609,6 +610,28 @@ var RandomNumberGenerator = class {
|
|
|
609
610
|
const theta = this.nextf * 2 * PI;
|
|
610
611
|
return [cos(theta), sin(theta)];
|
|
611
612
|
}
|
|
613
|
+
pointInUnitCircle(radius = 1, floored = false) {
|
|
614
|
+
const theta = this.nextf * 2 * PI;
|
|
615
|
+
const r = sqrt(this.nextf) * radius;
|
|
616
|
+
const x = r * cos(theta);
|
|
617
|
+
const y = r * sin(theta);
|
|
618
|
+
return !floored ? [x, y] : [floor(x), floor(y)];
|
|
619
|
+
}
|
|
620
|
+
pointInUnitSphere(radius = 1, floored = false) {
|
|
621
|
+
var u = this.nextf;
|
|
622
|
+
var v = this.nextf;
|
|
623
|
+
var theta = u * 2 * PI;
|
|
624
|
+
var phi = Math.acos(2 * v - 1);
|
|
625
|
+
var r = radius * Math.cbrt(rng.nextf);
|
|
626
|
+
var sinTheta = sin(theta);
|
|
627
|
+
var cosTheta = cos(theta);
|
|
628
|
+
var sinPhi = sin(phi);
|
|
629
|
+
var cosPhi = cos(phi);
|
|
630
|
+
var x = r * sinPhi * cosTheta;
|
|
631
|
+
var y = r * sinPhi * sinTheta;
|
|
632
|
+
var z = r * cosPhi;
|
|
633
|
+
return !floored ? [x, y, z] : [floor(x), floor(y), floor(z)];
|
|
634
|
+
}
|
|
612
635
|
parkMillerNormal() {
|
|
613
636
|
const mean = 1 / 2;
|
|
614
637
|
const stddev = 1 / 6;
|
|
@@ -872,353 +895,100 @@ function GenerateWalls(map) {
|
|
|
872
895
|
}
|
|
873
896
|
|
|
874
897
|
// src/ecs.ts
|
|
875
|
-
var ECS = class
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
createComponent(uid, data = null) {
|
|
903
|
-
if (!this._components.has(uid)) {
|
|
904
|
-
this._components.set(uid, data);
|
|
905
|
-
log("created component:", { uid, data });
|
|
906
|
-
} else {
|
|
907
|
-
logwrn("createComponent: a component already exists with uid:", uid);
|
|
908
|
-
}
|
|
909
|
-
return this;
|
|
910
|
-
}
|
|
911
|
-
includeAsDefaultComponents(...components) {
|
|
912
|
-
components.forEach((component) => {
|
|
913
|
-
if (!this._defaultComponents.includes(component)) {
|
|
914
|
-
this._defaultComponents.push(component);
|
|
915
|
-
log("includeAsDefaultComponents:", component);
|
|
916
|
-
} else {
|
|
917
|
-
log("includeAsDefaultComponents: already exists:", component);
|
|
918
|
-
}
|
|
919
|
-
});
|
|
920
|
-
return this;
|
|
921
|
-
}
|
|
922
|
-
createSystem(uid, ...components) {
|
|
923
|
-
const callback = components.pop();
|
|
924
|
-
const comps = components.filter((comp) => typeof comp === "string");
|
|
925
|
-
if (!this._systems.has(uid)) {
|
|
926
|
-
this._systems.set(uid, { components: comps, callback });
|
|
927
|
-
log("created system:", { uid, components, callback });
|
|
928
|
-
} else {
|
|
929
|
-
logwrn("createSystem: a system already exists with uid:", uid);
|
|
930
|
-
}
|
|
931
|
-
return this;
|
|
932
|
-
}
|
|
933
|
-
createEntityWithUid(uid, ...components) {
|
|
934
|
-
if (!this._entities.has(uid)) {
|
|
935
|
-
const componentList = [
|
|
936
|
-
.../* @__PURE__ */ new Set([
|
|
937
|
-
...this._defaultComponents,
|
|
938
|
-
...components
|
|
939
|
-
])
|
|
940
|
-
];
|
|
941
|
-
const comps = /* @__PURE__ */ new Map();
|
|
942
|
-
componentList.forEach((component) => {
|
|
943
|
-
if (this._components.has(component)) {
|
|
944
|
-
const componentData = this._components.get(component);
|
|
945
|
-
const data = {};
|
|
946
|
-
for (const uid2 in componentData) {
|
|
947
|
-
const value = componentData[uid2];
|
|
948
|
-
data[uid2] = typeof value === "function" ? value(uid2) : value;
|
|
949
|
-
}
|
|
950
|
-
comps.set(component, data);
|
|
951
|
-
} else {
|
|
952
|
-
logwrn("createEntityWithUid: missing component:", component);
|
|
953
|
-
}
|
|
954
|
-
});
|
|
955
|
-
if (comps.size === componentList.length) {
|
|
956
|
-
const entity = { uid, components: comps };
|
|
957
|
-
this._entities.set(uid, entity);
|
|
958
|
-
log("created entity:", entity);
|
|
959
|
-
} else {
|
|
960
|
-
logwrn("createEntityWithUid: failed to create an entity with missing components");
|
|
898
|
+
var ECS = class {
|
|
899
|
+
nextEntityId = 1;
|
|
900
|
+
components = /* @__PURE__ */ new Map();
|
|
901
|
+
createEntity() {
|
|
902
|
+
return this.nextEntityId++;
|
|
903
|
+
}
|
|
904
|
+
addComponent(entity, name, data) {
|
|
905
|
+
if (!this.components.has(name)) {
|
|
906
|
+
this.components.set(name, /* @__PURE__ */ new Map());
|
|
907
|
+
}
|
|
908
|
+
this.components.get(name).set(entity, data);
|
|
909
|
+
}
|
|
910
|
+
getComponent(entity, name) {
|
|
911
|
+
return this.components.get(name)?.get(entity);
|
|
912
|
+
}
|
|
913
|
+
removeComponent(entity, name) {
|
|
914
|
+
this.components.get(name)?.delete(entity);
|
|
915
|
+
}
|
|
916
|
+
getEntitiesWithComponents(...componentNames) {
|
|
917
|
+
if (componentNames.length === 0) return [];
|
|
918
|
+
const first = this.components.get(componentNames[0]);
|
|
919
|
+
if (!first) return [];
|
|
920
|
+
const result = [];
|
|
921
|
+
for (const entity of first.keys()) {
|
|
922
|
+
if (componentNames.every((name) => this.components.get(name)?.has(entity))) {
|
|
923
|
+
result.push(entity);
|
|
961
924
|
}
|
|
962
|
-
} else {
|
|
963
|
-
logwrn("createEntityWithUid: an entity already exists with uid:", uid);
|
|
964
|
-
}
|
|
965
|
-
return this;
|
|
966
|
-
}
|
|
967
|
-
createEntity(...components) {
|
|
968
|
-
const uid = this.uid();
|
|
969
|
-
return this.createEntityWithUid(uid, ...components);
|
|
970
|
-
}
|
|
971
|
-
createEntities(count, ...components) {
|
|
972
|
-
for (; count > 0; count--) {
|
|
973
|
-
this.createEntity(...components);
|
|
974
925
|
}
|
|
975
|
-
return
|
|
976
|
-
}
|
|
977
|
-
getEntity(uid) {
|
|
978
|
-
return this._entities.get(uid);
|
|
979
|
-
}
|
|
980
|
-
getEntitiesWithComponents(...components) {
|
|
981
|
-
const filter = components.pop();
|
|
982
|
-
const uids = components.filter((component) => typeof component === "string");
|
|
983
|
-
const entities = [];
|
|
984
|
-
this._entities.forEach((entity) => {
|
|
985
|
-
if (uids.every(
|
|
986
|
-
(component) => [...entity.components.keys()].includes(component)
|
|
987
|
-
)) {
|
|
988
|
-
for (const filterComponent in filter) {
|
|
989
|
-
for (const filterKey in filter[filterComponent]) {
|
|
990
|
-
const entityValue = entity.components.get(filterComponent)[filterKey];
|
|
991
|
-
const filterValue = filter[filterComponent][filterKey];
|
|
992
|
-
if (entityValue === filterValue) {
|
|
993
|
-
entities.push(entity);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
});
|
|
999
|
-
return entities;
|
|
1000
|
-
}
|
|
1001
|
-
addComponent(uid, component, values = {}) {
|
|
1002
|
-
const entity = this._entities.get(uid);
|
|
1003
|
-
if (entity) {
|
|
1004
|
-
if (this._components.has(component)) {
|
|
1005
|
-
const comp = this._components.get(component);
|
|
1006
|
-
const componentData = {
|
|
1007
|
-
...comp,
|
|
1008
|
-
...values
|
|
1009
|
-
};
|
|
1010
|
-
entity.components.set(component, componentData);
|
|
1011
|
-
log("addComponent: added component:", component, "to entity:", uid);
|
|
1012
|
-
} else {
|
|
1013
|
-
logwrn("addComponent: component not found:", component);
|
|
1014
|
-
}
|
|
1015
|
-
} else {
|
|
1016
|
-
logwrn("addComponent: entity not found:", uid);
|
|
1017
|
-
}
|
|
1018
|
-
return this;
|
|
1019
|
-
}
|
|
1020
|
-
onAllEntitiesNow(callback) {
|
|
1021
|
-
this._entities.forEach((entity) => callback(entity));
|
|
1022
|
-
log("onAllEntitiesNow: executed on all entities:", callback);
|
|
1023
|
-
return this;
|
|
1024
|
-
}
|
|
1025
|
-
duplicateEntity(uid, count = 1, deep = false) {
|
|
1026
|
-
const entity = this._entities.get(uid);
|
|
1027
|
-
if (entity) {
|
|
1028
|
-
if (!deep) {
|
|
1029
|
-
for (let i = 0; i < count; i++) this.createEntity(...entity.components.keys());
|
|
1030
|
-
} else {
|
|
1031
|
-
for (let i = 0; i < count; i++) {
|
|
1032
|
-
const newEntity = { uid: this.uid(), components: /* @__PURE__ */ new Map() };
|
|
1033
|
-
entity.components.forEach((value, key) => {
|
|
1034
|
-
newEntity.components.set(key, value);
|
|
1035
|
-
});
|
|
1036
|
-
this._entities.set(newEntity.uid, newEntity);
|
|
1037
|
-
}
|
|
1038
|
-
;
|
|
1039
|
-
}
|
|
1040
|
-
log("duplicateEntity: duplicated entity:", uid);
|
|
1041
|
-
} else {
|
|
1042
|
-
logwrn("duplicateEntity: entity not found:", uid);
|
|
1043
|
-
}
|
|
1044
|
-
return this;
|
|
1045
|
-
}
|
|
1046
|
-
getGlobal(key) {
|
|
1047
|
-
return this._globals.get(key);
|
|
1048
|
-
}
|
|
1049
|
-
setGlobal(key, value) {
|
|
1050
|
-
this._globals.set(key, value);
|
|
1051
|
-
return this;
|
|
1052
|
-
}
|
|
1053
|
-
beforeTick(callback) {
|
|
1054
|
-
this._onTickStartCallbacks.push(callback);
|
|
1055
|
-
log("beforeTick: added:", callback);
|
|
1056
|
-
return this;
|
|
1057
|
-
}
|
|
1058
|
-
afterTick(callback) {
|
|
1059
|
-
this._onTickEndCallbacks.push(callback);
|
|
1060
|
-
log("afterTick: added:", callback);
|
|
1061
|
-
return this;
|
|
1062
|
-
}
|
|
1063
|
-
runSystem(uid) {
|
|
1064
|
-
const system = this._systems.get(uid);
|
|
1065
|
-
if (system) {
|
|
1066
|
-
this._entities.forEach((entity) => {
|
|
1067
|
-
if (system.components.every(
|
|
1068
|
-
(component) => [...entity.components.keys()].includes(component)
|
|
1069
|
-
)) {
|
|
1070
|
-
system.callback(entity, Object.fromEntries(entity.components));
|
|
1071
|
-
}
|
|
1072
|
-
});
|
|
1073
|
-
} else {
|
|
1074
|
-
logwrn("runSystem: system not found:", uid);
|
|
1075
|
-
}
|
|
1076
|
-
return this;
|
|
1077
|
-
}
|
|
1078
|
-
update() {
|
|
1079
|
-
this._onTickStartCallbacks.forEach((cb) => cb());
|
|
1080
|
-
this._systems.forEach((_, uid) => this.runSystem(uid));
|
|
1081
|
-
this._onTickEndCallbacks.forEach((cb) => cb());
|
|
1082
|
-
}
|
|
1083
|
-
static get instance() {
|
|
1084
|
-
if (!_ECS._instance) {
|
|
1085
|
-
_ECS._instance = new _ECS();
|
|
1086
|
-
}
|
|
1087
|
-
return _ECS._instance;
|
|
1088
|
-
}
|
|
1089
|
-
static _instance;
|
|
1090
|
-
constructor() {
|
|
926
|
+
return result;
|
|
1091
927
|
}
|
|
1092
928
|
};
|
|
1093
929
|
|
|
1094
930
|
// src/input/index.ts
|
|
1095
931
|
var Input = class extends Emitter {
|
|
932
|
+
_down = /* @__PURE__ */ new Map();
|
|
933
|
+
_pointerPosition = new Vector();
|
|
1096
934
|
inputThreshold = 200;
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
_mousePosition = [0, 0];
|
|
1100
|
-
_mousePosition2 = [0, 0];
|
|
1101
|
-
_contextMenuTarget;
|
|
1102
|
-
get mousePosition() {
|
|
1103
|
-
return this._mousePosition;
|
|
935
|
+
get down() {
|
|
936
|
+
return this._down;
|
|
1104
937
|
}
|
|
1105
|
-
get
|
|
1106
|
-
return this.
|
|
938
|
+
get pointerPosition() {
|
|
939
|
+
return this._pointerPosition;
|
|
1107
940
|
}
|
|
1108
941
|
constructor() {
|
|
1109
942
|
super();
|
|
1110
|
-
window.addEventListener("
|
|
1111
|
-
|
|
1112
|
-
window.addEventListener("mousedown", this._onMouseButtonDown.bind(this));
|
|
1113
|
-
window.addEventListener("mouseup", this._onMouseButtonUp.bind(this));
|
|
1114
|
-
window.addEventListener("mousemove", this._onMouseMove.bind(this));
|
|
1115
|
-
window.addEventListener("wheel", this._onWheel.bind(this));
|
|
1116
|
-
}
|
|
1117
|
-
blockContextMenu(target) {
|
|
1118
|
-
this.stopBlockingContextMenu();
|
|
1119
|
-
this._contextMenuTarget = target;
|
|
1120
|
-
target.addEventListener("contextmenu", this._onContextMenu);
|
|
1121
|
-
}
|
|
1122
|
-
stopBlockingContextMenu() {
|
|
1123
|
-
this._contextMenuTarget?.removeEventListener("contextmenu", this._onContextMenu);
|
|
1124
|
-
this._contextMenuTarget = void 0;
|
|
1125
|
-
}
|
|
1126
|
-
_onContextMenu = (ev) => {
|
|
1127
|
-
ev.preventDefault();
|
|
1128
|
-
this.emit("contextmenu");
|
|
1129
|
-
};
|
|
1130
|
-
_getCommonEventProps(ev) {
|
|
1131
|
-
const props = {
|
|
1132
|
-
timeStamp: ev.timeStamp,
|
|
1133
|
-
altKey: ev.altKey,
|
|
1134
|
-
ctrlKey: ev.ctrlKey,
|
|
1135
|
-
metaKey: ev.metaKey,
|
|
1136
|
-
shiftKey: ev.shiftKey
|
|
1137
|
-
};
|
|
1138
|
-
return props;
|
|
1139
|
-
}
|
|
1140
|
-
_onKeyDown(ev) {
|
|
1141
|
-
const props = this._getCommonEventProps(ev);
|
|
1142
|
-
const { code, key } = ev;
|
|
1143
|
-
if (!ev.repeat) {
|
|
1144
|
-
this._keyStates[code] = { state: 1, timeStamp: props.timeStamp };
|
|
1145
|
-
this.emit("key_down", { ...props, code, key });
|
|
1146
|
-
this.emit(`${code.toLowerCase()}_down`, props);
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
_onKeyUp(ev) {
|
|
1150
|
-
const props = this._getCommonEventProps(ev);
|
|
1151
|
-
const { code, key } = ev;
|
|
1152
|
-
const deltaStamp = props.timeStamp - (this._keyStates[code]?.timeStamp ?? 0);
|
|
1153
|
-
this._keyStates[code] = { state: 0, timeStamp: props.timeStamp };
|
|
1154
|
-
this.emit("key_up", { ...props, code, key });
|
|
1155
|
-
this.emit(`${code.toLowerCase()}_up`, props);
|
|
1156
|
-
if (deltaStamp < this.inputThreshold) {
|
|
1157
|
-
this.emit("key_pressed", { ...props, code, key });
|
|
1158
|
-
this.emit(`${code.toLowerCase()}_pressed`, props);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
_onMouseButtonDown(ev) {
|
|
1162
|
-
const props = this._getCommonEventProps(ev);
|
|
1163
|
-
const { button } = ev;
|
|
1164
|
-
if (!this._mouseButtonStates[button]?.state) {
|
|
1165
|
-
this._mouseButtonStates[button] = { state: 1, timeStamp: props.timeStamp };
|
|
1166
|
-
this.emit("mouse_button_down", { ...props, button });
|
|
1167
|
-
this.emit(`mouse_button_${button}_down`, props);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
_onMouseButtonUp(ev) {
|
|
1171
|
-
const props = this._getCommonEventProps(ev);
|
|
1172
|
-
const { button } = ev;
|
|
1173
|
-
const deltaStamp = props.timeStamp - (this._mouseButtonStates[button]?.timeStamp ?? 0);
|
|
1174
|
-
this._mouseButtonStates[button] = { state: 0, timeStamp: props.timeStamp };
|
|
1175
|
-
this.emit("mouse_button_up", { ...props, button });
|
|
1176
|
-
this.emit(`mouse_button_${button}_up`, props);
|
|
1177
|
-
if (deltaStamp < this.inputThreshold) {
|
|
1178
|
-
this.emit("mouse_button_clicked", { ...props, button });
|
|
1179
|
-
this.emit(`mouse_button_${button}_clicked`, props);
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
_onMouseMove(ev) {
|
|
1183
|
-
const props = this._getCommonEventProps(ev);
|
|
1184
|
-
const { buttons, offsetX, offsetY, movementX, movementY } = ev;
|
|
1185
|
-
this._mousePosition = [offsetX, offsetY];
|
|
1186
|
-
const width = window.innerWidth;
|
|
1187
|
-
const height = window.innerHeight;
|
|
1188
|
-
this._mousePosition2 = [
|
|
1189
|
-
ev.clientX / width * 2 - 1,
|
|
1190
|
-
-(ev.clientY / height) * 2 + 1
|
|
1191
|
-
];
|
|
1192
|
-
this.emit("mouse_move", {
|
|
1193
|
-
...props,
|
|
1194
|
-
buttons,
|
|
1195
|
-
x: offsetX,
|
|
1196
|
-
y: offsetY,
|
|
1197
|
-
deltaX: movementX,
|
|
1198
|
-
deltaY: movementY
|
|
943
|
+
window.addEventListener("contextmenu", (ev) => {
|
|
944
|
+
log("contextmenu:", ev);
|
|
1199
945
|
});
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
946
|
+
window.addEventListener("keydown", (ev) => {
|
|
947
|
+
const { code, repeat, timeStamp } = ev;
|
|
948
|
+
if (!repeat) {
|
|
949
|
+
this._down.set(code, { state: 1, time: timeStamp });
|
|
950
|
+
this.emit("key_down", code, ev);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
window.addEventListener("keyup", (ev) => {
|
|
954
|
+
const { code, timeStamp } = ev;
|
|
955
|
+
const delta = timeStamp - (this._down.get(code)?.time ?? 0);
|
|
956
|
+
this._down.set(code, { state: 0, time: timeStamp });
|
|
957
|
+
this.emit("key_up", code, ev);
|
|
958
|
+
if (delta < this.inputThreshold) {
|
|
959
|
+
this.emit("key_pressed", code, ev);
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
window.addEventListener("pointerdown", (ev) => {
|
|
963
|
+
const { button, timeStamp } = ev;
|
|
964
|
+
const code = `Button${button}`;
|
|
965
|
+
if (!this._down.get(code)) {
|
|
966
|
+
this._down.set(code, { state: 1, time: timeStamp });
|
|
967
|
+
this.emit("pointer_down", code, ev);
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
window.addEventListener("pointerup", (ev) => {
|
|
971
|
+
const { button, timeStamp } = ev;
|
|
972
|
+
const code = `Button${button}`;
|
|
973
|
+
const delta = timeStamp - (this._down.get(code)?.time ?? 0);
|
|
974
|
+
this._down.set(code, { state: 0, time: timeStamp });
|
|
975
|
+
if (delta < this.inputThreshold) {
|
|
976
|
+
this.emit("button_clicked", code, ev);
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
window.addEventListener("mousemove", (ev) => {
|
|
980
|
+
const { offsetX, offsetY, movementX, movementY } = ev;
|
|
981
|
+
this._pointerPosition.x = offsetX;
|
|
982
|
+
this._pointerPosition.y = offsetY;
|
|
983
|
+
this.emit("pointer_move", movementX, movementY, ev);
|
|
984
|
+
});
|
|
985
|
+
window.addEventListener("wheel", (ev) => {
|
|
986
|
+
const { deltaY } = ev;
|
|
987
|
+
this.emit("wheel", deltaY, ev);
|
|
1209
988
|
});
|
|
1210
989
|
}
|
|
1211
|
-
|
|
1212
|
-
return this.
|
|
1213
|
-
}
|
|
1214
|
-
getKeyState(keyCode) {
|
|
1215
|
-
return this._keyStates[keyCode]?.state ?? 0;
|
|
1216
|
-
}
|
|
1217
|
-
isMouseButtonDown(mouseButton) {
|
|
1218
|
-
return this._mouseButtonStates[mouseButton]?.state === 1 ? true : false;
|
|
1219
|
-
}
|
|
1220
|
-
getMouseButtonState(button) {
|
|
1221
|
-
return this._mouseButtonStates[button]?.state ?? 0;
|
|
990
|
+
isDown(name) {
|
|
991
|
+
return this._down.get(name) ? true : false;
|
|
1222
992
|
}
|
|
1223
993
|
};
|
|
1224
994
|
|
|
@@ -1306,6 +1076,10 @@ function GetUrlParams() {
|
|
|
1306
1076
|
}
|
|
1307
1077
|
return params;
|
|
1308
1078
|
}
|
|
1079
|
+
var xy2k = (x, y, delimiter = ",") => `${x}${delimiter}${y}`;
|
|
1080
|
+
var k2xy = (key, delimiter = ",") => key.split(delimiter).map(parseFloat);
|
|
1081
|
+
var xyz2k = (x, y, z, delimiter = ",") => `${x}${delimiter},${y},${delimiter},${z}`;
|
|
1082
|
+
var k2xyz = (key, delimiter = ",") => key.split(delimiter).map(parseFloat);
|
|
1309
1083
|
|
|
1310
1084
|
// src/noise.ts
|
|
1311
1085
|
var import_simplex_noise = require("simplex-noise");
|
|
@@ -1411,7 +1185,7 @@ var Color = class _Color {
|
|
|
1411
1185
|
[this._r, this._g, this._b, this._a] = this._parse_hex_color_string(value);
|
|
1412
1186
|
this._hex = value;
|
|
1413
1187
|
} else {
|
|
1414
|
-
|
|
1188
|
+
log(`Color: invalid color string: ${value}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Keeping the current color.`);
|
|
1415
1189
|
}
|
|
1416
1190
|
}
|
|
1417
1191
|
get rgba() {
|
|
@@ -1422,7 +1196,7 @@ var Color = class _Color {
|
|
|
1422
1196
|
if (r.startsWith("#")) {
|
|
1423
1197
|
[r, g, b, a] = this._parse_hex_color_string(r);
|
|
1424
1198
|
} else {
|
|
1425
|
-
|
|
1199
|
+
log(`Color: invalid color string: ${r}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Defaulting to opaque white.`);
|
|
1426
1200
|
r = g = b = a = 255;
|
|
1427
1201
|
}
|
|
1428
1202
|
} else {
|
|
@@ -1523,7 +1297,7 @@ var Color = class _Color {
|
|
|
1523
1297
|
const [r, g, b, a] = rgba.map(Number);
|
|
1524
1298
|
return new _Color(r, g, b, a);
|
|
1525
1299
|
} else {
|
|
1526
|
-
|
|
1300
|
+
log(`Color: invalid CSS color name: ${name}. Defaulting to transparent.`);
|
|
1527
1301
|
return _Color.TRANSPARENT;
|
|
1528
1302
|
}
|
|
1529
1303
|
}
|
|
@@ -2159,7 +1933,7 @@ var ThreeJsBoilerPlate = class {
|
|
|
2159
1933
|
this.orbitControls?.dispose();
|
|
2160
1934
|
this.orbitControls = void 0;
|
|
2161
1935
|
this.input.on("mouse_move", ({ deltaX, deltaY }) => {
|
|
2162
|
-
if (this.input.
|
|
1936
|
+
if (this.input.isDown("Button0")) {
|
|
2163
1937
|
this.cameraRig.orbit(deltaX, deltaY);
|
|
2164
1938
|
}
|
|
2165
1939
|
}).on("mouse_wheel", ({ deltaY }) => this.cameraRig.dolly(deltaY));
|
|
@@ -2206,8 +1980,8 @@ var ThreeJsBoilerPlate = class {
|
|
|
2206
1980
|
}
|
|
2207
1981
|
}
|
|
2208
1982
|
pick() {
|
|
2209
|
-
const pickX = this.input.
|
|
2210
|
-
const pickY = -(this.input.
|
|
1983
|
+
const pickX = this.input.pointerPosition.x / this.renderer.domElement.width * 2 - 1;
|
|
1984
|
+
const pickY = -(this.input.pointerPosition.y / this.renderer.domElement.height) * 2 + 1;
|
|
2211
1985
|
this.raycaster.setFromCamera(new import_three4.Vector2(pickX, pickY), this.cameraRig.camera);
|
|
2212
1986
|
const intersected = this.raycaster.intersectObjects(this.scene.children);
|
|
2213
1987
|
return intersected.length ? intersected[0] : null;
|
|
@@ -3463,12 +3237,10 @@ var WorkerInterface = class extends Emitter {
|
|
|
3463
3237
|
imul,
|
|
3464
3238
|
isNullOrUndefined,
|
|
3465
3239
|
isPositiveString,
|
|
3240
|
+
k2xy,
|
|
3241
|
+
k2xyz,
|
|
3466
3242
|
lerp,
|
|
3467
3243
|
log,
|
|
3468
|
-
logdev,
|
|
3469
|
-
logerr,
|
|
3470
|
-
loginf,
|
|
3471
|
-
logwrn,
|
|
3472
3244
|
manhattanDistance,
|
|
3473
3245
|
max,
|
|
3474
3246
|
min,
|
|
@@ -3478,5 +3250,7 @@ var WorkerInterface = class extends Emitter {
|
|
|
3478
3250
|
roundTo,
|
|
3479
3251
|
sin,
|
|
3480
3252
|
sqrt,
|
|
3481
|
-
squaredDistance
|
|
3253
|
+
squaredDistance,
|
|
3254
|
+
xy2k,
|
|
3255
|
+
xyz2k
|
|
3482
3256
|
});
|