@caspertech/node-metaverse 0.6.5 → 0.6.7

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.
Files changed (32) hide show
  1. package/dist/lib/classes/Caps.js +7 -0
  2. package/dist/lib/classes/Caps.js.map +1 -1
  3. package/dist/lib/classes/Circuit.js +0 -3
  4. package/dist/lib/classes/Circuit.js.map +1 -1
  5. package/dist/lib/classes/LLGLTFMaterial.spec.js +47 -17
  6. package/dist/lib/classes/LLGLTFMaterial.spec.js.map +1 -1
  7. package/dist/lib/classes/LLGLTFMaterialData.d.ts +184 -24
  8. package/dist/lib/classes/LLGLTFMaterialOverride.d.ts +20 -0
  9. package/dist/lib/classes/LLGLTFMaterialOverride.js +261 -0
  10. package/dist/lib/classes/LLGLTFMaterialOverride.js.map +1 -0
  11. package/dist/lib/classes/LLGLTFMaterialOverride.spec.d.ts +1 -0
  12. package/dist/lib/classes/LLGLTFMaterialOverride.spec.js +225 -0
  13. package/dist/lib/classes/LLGLTFMaterialOverride.spec.js.map +1 -0
  14. package/dist/lib/classes/ObjectStoreFull.js +86 -58
  15. package/dist/lib/classes/ObjectStoreFull.js.map +1 -1
  16. package/dist/lib/classes/ObjectStoreLite.d.ts +38 -15
  17. package/dist/lib/classes/ObjectStoreLite.js +232 -112
  18. package/dist/lib/classes/ObjectStoreLite.js.map +1 -1
  19. package/dist/lib/classes/TextureEntry.d.ts +2 -0
  20. package/dist/lib/classes/TextureEntry.js +1 -0
  21. package/dist/lib/classes/TextureEntry.js.map +1 -1
  22. package/dist/lib/classes/llsd/LLSDNotationParser.js +1 -10
  23. package/dist/lib/classes/llsd/LLSDNotationParser.js.map +1 -1
  24. package/dist/lib/classes/public/ExtraParams.spec.d.ts +1 -0
  25. package/dist/lib/classes/public/ExtraParams.spec.js +31 -0
  26. package/dist/lib/classes/public/ExtraParams.spec.js.map +1 -0
  27. package/dist/lib/classes/public/GameObject.js +42 -2
  28. package/dist/lib/classes/public/GameObject.js.map +1 -1
  29. package/dist/lib/classes/public/GameObject.spec.d.ts +1 -0
  30. package/dist/lib/classes/public/GameObject.spec.js +148 -0
  31. package/dist/lib/classes/public/GameObject.spec.js.map +1 -0
  32. package/package.json +1 -1
@@ -35,18 +35,22 @@ const ObjectResolvedEvent_1 = require("../events/ObjectResolvedEvent");
35
35
  const Avatar_1 = require("./public/Avatar");
36
36
  const LLSDNotationParser_1 = require("./llsd/LLSDNotationParser");
37
37
  const LLSDMap_1 = require("./llsd/LLSDMap");
38
+ const LLGLTFMaterialOverride_1 = require("./LLGLTFMaterialOverride");
38
39
  class ObjectStoreLite {
39
40
  constructor(circuit, agent, clientEvents, options) {
40
- this.objects = {};
41
- this.objectsByUUID = {};
42
- this.objectsByParent = {};
43
- this.requestedObjects = {};
41
+ this.objects = new Map();
42
+ this.objectsByUUID = new Map();
43
+ this.objectsByParent = new Map();
44
+ this.fullStore = false;
45
+ this.requestedObjects = new Set();
44
46
  this.deadObjects = [];
45
47
  this.persist = false;
46
- this.pendingObjectProperties = {};
47
- this.selectedPrimsWithoutUpdate = {};
48
+ this.cachedMaterialOverrides = new Map();
49
+ this.pendingObjectProperties = new Map;
50
+ this.selectedPrimsWithoutUpdate = new Map();
48
51
  agent.localID = 0;
49
52
  this.options = options;
53
+ this.fullStore = false;
50
54
  this.clientEvents = clientEvents;
51
55
  this.circuit = circuit;
52
56
  this.agent = agent;
@@ -62,16 +66,110 @@ class ObjectStoreLite {
62
66
  switch (packet.message.id) {
63
67
  case Message_1.Message.GenericStreamingMessage:
64
68
  {
69
+ if (!this.fullStore) {
70
+ return;
71
+ }
65
72
  const genMsg = packet.message;
66
73
  if (genMsg.MethodData.Method === 0x4175) {
67
74
  const result = LLSDNotationParser_1.LLSDNotationParser.parse(genMsg.DataBlock.Data.toString('utf-8'));
68
75
  if (result instanceof LLSDMap_1.LLSDMap) {
69
- const arr = result.get('te');
70
- if (Array.isArray(arr)) {
71
- if (arr.length === 0) {
72
- return;
76
+ const localID = result.get('id');
77
+ if (typeof localID !== 'number') {
78
+ return;
79
+ }
80
+ const tes = result.get('te');
81
+ const ods = result.get('od');
82
+ const overrides = new Map();
83
+ if (Array.isArray(tes) && Array.isArray(ods) && tes.length === ods.length) {
84
+ for (let x = 0; x < tes.length; x++) {
85
+ const te = tes[x];
86
+ if (typeof te !== 'number') {
87
+ continue;
88
+ }
89
+ const params = ods[x];
90
+ if (!(params instanceof LLSDMap_1.LLSDMap)) {
91
+ continue;
92
+ }
93
+ const textureIDs = params.get('tex');
94
+ const baseColor = params.get('bc');
95
+ const emissiveColor = params.get('ec');
96
+ const metallicFactor = params.get('mf');
97
+ const roughnessFactor = params.get('rf');
98
+ const alphaMode = params.get('am');
99
+ const alphaCutoff = params.get('ac');
100
+ const doubleSided = params.get('ds');
101
+ const textureTransforms = params.get('ti');
102
+ const override = new LLGLTFMaterialOverride_1.LLGLTFMaterialOverride();
103
+ overrides.set(te, override);
104
+ if (textureIDs !== undefined && Array.isArray(textureIDs) && textureIDs.length === 4) {
105
+ override.textures = [];
106
+ for (const tex of textureIDs) {
107
+ if (typeof tex === 'string') {
108
+ override.textures.push(tex);
109
+ }
110
+ else if (tex instanceof UUID_1.UUID) {
111
+ override.textures.push(tex.toString());
112
+ }
113
+ }
114
+ }
115
+ function isNumberArray(array) {
116
+ return array.every(element => typeof element === 'number');
117
+ }
118
+ if (baseColor !== undefined && Array.isArray(baseColor) && baseColor.length === 4 && isNumberArray(baseColor)) {
119
+ override.baseColor = baseColor;
120
+ }
121
+ if (emissiveColor !== undefined && Array.isArray(emissiveColor) && emissiveColor.length === 3 && isNumberArray(emissiveColor)) {
122
+ override.emissiveFactor = emissiveColor;
123
+ }
124
+ if (metallicFactor !== undefined && typeof metallicFactor === 'number') {
125
+ override.metallicFactor = metallicFactor;
126
+ }
127
+ if (roughnessFactor !== undefined && typeof roughnessFactor === 'number') {
128
+ override.roughnessFactor = roughnessFactor;
129
+ }
130
+ if (alphaMode !== undefined && typeof alphaMode === 'number') {
131
+ override.alphaMode = alphaMode;
132
+ }
133
+ if (alphaCutoff !== undefined && typeof alphaCutoff === 'number') {
134
+ override.alphaCutoff = alphaCutoff;
135
+ }
136
+ if (doubleSided !== undefined && typeof doubleSided === 'boolean') {
137
+ override.doubleSided = doubleSided;
138
+ }
139
+ function isLLGLTFTextureTransformOverride(objToCheck) {
140
+ const isArrayOfNumbers = (value) => {
141
+ return Array.isArray(value) && value.every(item => typeof item === 'number');
142
+ };
143
+ return (typeof objToCheck === 'object' &&
144
+ objToCheck !== null &&
145
+ 'offset' in objToCheck && isArrayOfNumbers(objToCheck.offset) &&
146
+ 'scale' in objToCheck && isArrayOfNumbers(objToCheck.scale) &&
147
+ 'rotation' in objToCheck && typeof objToCheck.rotation === 'number');
148
+ }
149
+ if (textureTransforms !== undefined && Array.isArray(textureTransforms) && textureTransforms.length === 4) {
150
+ override.textureTransforms = [];
151
+ for (const transform of textureTransforms) {
152
+ if (transform instanceof LLSDMap_1.LLSDMap) {
153
+ const tObj = {
154
+ offset: transform.get('o'),
155
+ scale: transform.get('s'),
156
+ rotation: transform.get('r')
157
+ };
158
+ if (isLLGLTFTextureTransformOverride(tObj)) {
159
+ override.textureTransforms.push(tObj);
160
+ }
161
+ }
162
+ }
163
+ }
164
+ }
165
+ const obj = this.objects.get(localID);
166
+ const textureEntry = obj === null || obj === void 0 ? void 0 : obj.TextureEntry;
167
+ if (textureEntry) {
168
+ textureEntry.gltfMaterialOverrides = overrides;
169
+ }
170
+ else {
171
+ this.cachedMaterialOverrides.set(localID, overrides);
73
172
  }
74
- console.log(JSON.stringify(result, null, 4));
75
173
  }
76
174
  }
77
175
  }
@@ -81,13 +179,13 @@ class ObjectStoreLite {
81
179
  {
82
180
  const objProp = packet.message;
83
181
  for (const obj of objProp.ObjectData) {
84
- const obje = this.objectsByUUID[obj.ObjectID.toString()];
85
- if (obje !== undefined && this.objects[obje] !== undefined) {
86
- const o = this.objects[obje];
182
+ const obje = this.objectsByUUID.get(obj.ObjectID.toString());
183
+ const o = this.objects.get(obje !== null && obje !== void 0 ? obje : 0);
184
+ if (obje !== undefined && o !== undefined) {
87
185
  this.applyObjectProperties(o, obj);
88
186
  }
89
187
  else {
90
- this.pendingObjectProperties[obj.ObjectID.toString()] = obj;
188
+ this.pendingObjectProperties.set(obj.ObjectID.toString(), obj);
91
189
  }
92
190
  }
93
191
  break;
@@ -125,12 +223,13 @@ class ObjectStoreLite {
125
223
  }
126
224
  }));
127
225
  this.physicsSubscription = this.clientEvents.onPhysicsDataEvent.subscribe((evt) => {
128
- if (this.objects[evt.localID]) {
129
- this.objects[evt.localID].physicsShapeType = evt.physicsShapeType;
130
- this.objects[evt.localID].density = evt.density;
131
- this.objects[evt.localID].restitution = evt.restitution;
132
- this.objects[evt.localID].gravityMultiplier = evt.gravityMultiplier;
133
- this.objects[evt.localID].friction = evt.friction;
226
+ const obj = this.objects.get(evt.localID);
227
+ if (obj) {
228
+ obj.physicsShapeType = evt.physicsShapeType;
229
+ obj.density = evt.density;
230
+ obj.restitution = evt.restitution;
231
+ obj.gravityMultiplier = evt.gravityMultiplier;
232
+ obj.friction = evt.friction;
134
233
  }
135
234
  });
136
235
  this.selectedChecker = setInterval(() => {
@@ -177,9 +276,7 @@ class ObjectStoreLite {
177
276
  }, 1000);
178
277
  }
179
278
  applyObjectProperties(o, obj) {
180
- if (this.selectedPrimsWithoutUpdate[o.ID]) {
181
- delete this.selectedPrimsWithoutUpdate[o.ID];
182
- }
279
+ this.selectedPrimsWithoutUpdate.delete(o.ID);
183
280
  o.creatorID = obj.CreatorID;
184
281
  o.creationDate = obj.CreationDate;
185
282
  o.baseMask = obj.BaseMask;
@@ -223,13 +320,13 @@ class ObjectStoreLite {
223
320
  }
224
321
  requestMissingObject(localID, attempt = 0) {
225
322
  return __awaiter(this, void 0, void 0, function* () {
226
- if (this.requestedObjects[localID]) {
323
+ if (this.requestedObjects.has(localID)) {
227
324
  return;
228
325
  }
229
326
  if (this.circuit === undefined) {
230
327
  return;
231
328
  }
232
- this.requestedObjects[localID] = true;
329
+ this.requestedObjects.add(localID);
233
330
  const rmo = new RequestMultipleObjects_1.RequestMultipleObjectsMessage();
234
331
  rmo.AgentData = {
235
332
  AgentID: this.agent.agentID,
@@ -261,10 +358,10 @@ class ObjectStoreLite {
261
358
  }
262
359
  return FilterResponse_1.FilterResponse.NoMatch;
263
360
  });
264
- delete this.requestedObjects[localID];
361
+ this.requestedObjects.delete(localID);
265
362
  }
266
363
  catch (error) {
267
- delete this.requestedObjects[localID];
364
+ this.requestedObjects.delete(localID);
268
365
  if (attempt < 5) {
269
366
  yield this.requestMissingObject(localID, ++attempt);
270
367
  }
@@ -299,52 +396,58 @@ class ObjectStoreLite {
299
396
  const parentID = objData.ParentID;
300
397
  let addToParentList = true;
301
398
  let newObject = false;
302
- if (this.objects[localID]) {
303
- if (this.objects[localID].ParentID !== parentID && this.objectsByParent[parentID]) {
304
- const ind = this.objectsByParent[parentID].indexOf(localID);
399
+ let obj = this.objects.get(localID);
400
+ if (obj) {
401
+ const p = this.objectsByParent.get(parentID);
402
+ if (obj.ParentID !== parentID && p !== undefined) {
403
+ const ind = p.indexOf(localID);
305
404
  if (ind !== -1) {
306
- this.objectsByParent[parentID].splice(ind, 1);
405
+ p.splice(ind, 1);
307
406
  }
308
407
  }
309
- else if (this.objectsByParent[parentID]) {
408
+ else if (p) {
310
409
  addToParentList = false;
311
410
  }
312
411
  }
313
412
  else {
314
413
  newObject = true;
315
- this.objects[localID] = new GameObject_1.GameObject();
316
- this.objects[localID].region = this.agent.currentRegion;
414
+ const newObj = new GameObject_1.GameObject();
415
+ newObj.region = this.agent.currentRegion;
416
+ this.objects.set(localID, newObj);
317
417
  }
318
- const obj = this.objects[localID];
418
+ obj = this.objects.get(localID);
319
419
  obj.deleted = false;
320
420
  obj.ID = objData.ID;
321
421
  obj.FullID = objData.FullID;
322
422
  obj.ParentID = objData.ParentID;
323
423
  obj.OwnerID = objData.OwnerID;
324
424
  obj.PCode = objData.PCode;
325
- this.objects[localID].NameValue = this.parseNameValues(Utils_1.Utils.BufferToStringSimple(objData.NameValue));
326
- this.objects[localID].IsAttachment = this.objects[localID].NameValue['AttachItemID'] !== undefined;
425
+ obj.NameValue = this.parseNameValues(Utils_1.Utils.BufferToStringSimple(objData.NameValue));
426
+ obj.IsAttachment = obj.NameValue.AttachItemID !== undefined;
327
427
  if (obj.IsAttachment && obj.State !== undefined) {
328
- this.objects[localID].attachmentPoint = this.decodeAttachPoint(obj.State);
428
+ obj.attachmentPoint = this.decodeAttachPoint(obj.State);
329
429
  }
330
- if (objData.PCode === PCode_1.PCode.Avatar && this.objects[localID].FullID.toString() === this.agent.agentID.toString()) {
430
+ if (objData.PCode === PCode_1.PCode.Avatar && obj.FullID.toString() === this.agent.agentID.toString()) {
331
431
  this.agent.localID = localID;
332
432
  if (this.options & BotOptionFlags_1.BotOptionFlags.StoreMyAttachmentsOnly) {
333
433
  for (const objParentID of Object.keys(this.objectsByParent)) {
334
434
  const parent = parseInt(objParentID, 10);
335
435
  if (parent !== this.agent.localID) {
336
436
  let foundAvatars = false;
337
- for (const objID of this.objectsByParent[parent]) {
338
- if (this.objects[objID]) {
339
- const o = this.objects[objID];
340
- if (o.PCode === PCode_1.PCode.Avatar) {
341
- foundAvatars = true;
437
+ const p = this.objectsByParent.get(parent);
438
+ if (p !== undefined) {
439
+ for (const objID of p) {
440
+ const childObj = this.objects.get(objID);
441
+ if (childObj) {
442
+ if (childObj.PCode === PCode_1.PCode.Avatar) {
443
+ foundAvatars = true;
444
+ }
342
445
  }
343
446
  }
344
447
  }
345
- if (this.objects[parent]) {
346
- const o = this.objects[parent];
347
- if (o.PCode === PCode_1.PCode.Avatar) {
448
+ const parentObj = this.objects.get(parent);
449
+ if (parentObj) {
450
+ if (parentObj.PCode === PCode_1.PCode.Avatar) {
348
451
  foundAvatars = true;
349
452
  }
350
453
  }
@@ -355,12 +458,14 @@ class ObjectStoreLite {
355
458
  }
356
459
  }
357
460
  }
358
- this.objectsByUUID[objData.FullID.toString()] = localID;
359
- if (!this.objectsByParent[parentID]) {
360
- this.objectsByParent[parentID] = [];
461
+ this.objectsByUUID.set(objData.FullID.toString(), localID);
462
+ let objByParent = this.objectsByParent.get(parentID);
463
+ if (!objByParent) {
464
+ objByParent = [];
465
+ this.objectsByParent.set(parentID, objByParent);
361
466
  }
362
467
  if (addToParentList) {
363
- this.objectsByParent[parentID].push(localID);
468
+ objByParent.push(localID);
364
469
  }
365
470
  if (objData.PCode !== PCode_1.PCode.Avatar && this.options & BotOptionFlags_1.BotOptionFlags.StoreMyAttachmentsOnly) {
366
471
  if (this.agent.localID !== 0 && obj.ParentID !== this.agent.localID) {
@@ -369,13 +474,13 @@ class ObjectStoreLite {
369
474
  }
370
475
  }
371
476
  this.notifyObjectUpdate(newObject, obj);
372
- if (objData.ParentID !== undefined && objData.ParentID !== 0 && !this.objects[objData.ParentID]) {
477
+ if (objData.ParentID !== undefined && objData.ParentID !== 0 && !this.objects.get(objData.ParentID)) {
373
478
  this.requestMissingObject(objData.ParentID);
374
479
  }
375
480
  }
376
481
  }
377
482
  notifyTerseUpdate(obj) {
378
- if (this.objects[obj.ID]) {
483
+ if (this.objects.get(obj.ID)) {
379
484
  if (obj.PCode === PCode_1.PCode.Avatar) {
380
485
  if (this.agent.currentRegion.agents[obj.FullID.toString()] !== undefined) {
381
486
  this.agent.currentRegion.agents[obj.FullID.toString()].processObjectUpdate(obj);
@@ -392,6 +497,7 @@ class ObjectStoreLite {
392
497
  }
393
498
  }
394
499
  notifyObjectUpdate(newObject, obj) {
500
+ var _a;
395
501
  if (obj.PCode === PCode_1.PCode.Avatar) {
396
502
  const avatarID = obj.FullID.toString();
397
503
  if (newObject) {
@@ -413,11 +519,12 @@ class ObjectStoreLite {
413
519
  }
414
520
  }
415
521
  }
416
- if (obj.ParentID === 0 || (obj.ParentID !== undefined && this.objects[obj.ParentID] !== undefined && this.objects[obj.ParentID].PCode === PCode_1.PCode.Avatar)) {
522
+ const parentObj = this.objects.get((_a = obj.ParentID) !== null && _a !== void 0 ? _a : 0);
523
+ if (obj.ParentID === 0 || (obj.ParentID !== undefined && parentObj !== undefined && parentObj.PCode === PCode_1.PCode.Avatar)) {
417
524
  if (newObject) {
418
525
  if (obj.IsAttachment && obj.ParentID !== undefined) {
419
- if (this.objects[obj.ParentID] !== undefined && this.objects[obj.ParentID].PCode === PCode_1.PCode.Avatar) {
420
- const avatar = this.agent.currentRegion.agents[this.objects[obj.ParentID].FullID.toString()];
526
+ if (parentObj !== undefined && parentObj.PCode === PCode_1.PCode.Avatar) {
527
+ const avatar = this.agent.currentRegion.agents[parentObj.FullID.toString()];
421
528
  let invItemID = UUID_1.UUID.zero();
422
529
  if (obj.NameValue['AttachItemID']) {
423
530
  invItemID = new UUID_1.UUID(obj.NameValue['AttachItemID'].value);
@@ -446,8 +553,8 @@ class ObjectStoreLite {
446
553
  newObj.object = obj;
447
554
  newObj.createSelected = obj.Flags !== undefined && (obj.Flags & PrimFlags_1.PrimFlags.CreateSelected) !== 0;
448
555
  obj.createdSelected = newObj.createSelected;
449
- if (obj.Flags !== undefined && obj.Flags & PrimFlags_1.PrimFlags.CreateSelected && !this.pendingObjectProperties[obj.FullID.toString()]) {
450
- this.selectedPrimsWithoutUpdate[obj.ID] = true;
556
+ if (obj.Flags !== undefined && obj.Flags & PrimFlags_1.PrimFlags.CreateSelected && !this.pendingObjectProperties.get(obj.FullID.toString())) {
557
+ this.selectedPrimsWithoutUpdate.set(obj.ID, true);
451
558
  }
452
559
  this.clientEvents.onNewObjectEvent.next(newObj);
453
560
  }
@@ -458,9 +565,10 @@ class ObjectStoreLite {
458
565
  updObj.object = obj;
459
566
  this.clientEvents.onObjectUpdatedEvent.next(updObj);
460
567
  }
461
- if (this.pendingObjectProperties[obj.FullID.toString()]) {
462
- this.applyObjectProperties(obj, this.pendingObjectProperties[obj.FullID.toString()]);
463
- delete this.pendingObjectProperties[obj.FullID.toString()];
568
+ const pendingProp = this.pendingObjectProperties.get(obj.FullID.toString());
569
+ if (pendingProp) {
570
+ this.applyObjectProperties(obj, pendingProp);
571
+ this.pendingObjectProperties.delete(obj.FullID.toString());
464
572
  }
465
573
  }
466
574
  }
@@ -491,17 +599,17 @@ class ObjectStoreLite {
491
599
  const localID = buf.readUInt32LE(pos);
492
600
  pos += 4;
493
601
  const pcode = buf.readUInt8(pos++);
494
- let newObj = false;
495
- if (!this.objects[localID]) {
496
- newObj = true;
497
- this.objects[localID] = new GameObject_1.GameObject();
498
- this.objects[localID].region = this.agent.currentRegion;
602
+ const newObj = false;
603
+ let o = this.objects.get(localID);
604
+ if (!o) {
605
+ o = new GameObject_1.GameObject();
606
+ o.region = this.agent.currentRegion;
607
+ this.objects.set(localID, o);
499
608
  }
500
- const o = this.objects[localID];
501
609
  o.deleted = false;
502
610
  o.ID = localID;
503
611
  o.PCode = pcode;
504
- this.objectsByUUID[fullID.toString()] = localID;
612
+ this.objectsByUUID.set(fullID.toString(), localID);
505
613
  o.FullID = fullID;
506
614
  pos++;
507
615
  pos = pos + 42;
@@ -520,21 +628,24 @@ class ObjectStoreLite {
520
628
  o.ParentID = newParentID;
521
629
  let add = true;
522
630
  if (!newObj && o.ParentID !== undefined) {
523
- if (newParentID !== o.ParentID) {
524
- const index = this.objectsByParent[o.ParentID].indexOf(localID);
525
- if (index !== -1) {
526
- this.objectsByParent[o.ParentID].splice(index, 1);
631
+ const p = this.objectsByParent.get(o.ParentID);
632
+ if (newParentID !== o.ParentID && p) {
633
+ const ind = p.indexOf(localID);
634
+ if (ind !== -1) {
635
+ p.splice(ind, 1);
527
636
  }
528
637
  }
529
- else if (this.objectsByParent[o.ParentID]) {
638
+ else if (p) {
530
639
  add = false;
531
640
  }
532
641
  }
533
642
  if (add) {
534
- if (!this.objectsByParent[newParentID]) {
535
- this.objectsByParent[newParentID] = [];
643
+ let objByParent = this.objectsByParent.get(newParentID);
644
+ if (!objByParent) {
645
+ objByParent = [];
646
+ this.objectsByParent.set(newParentID, objByParent);
536
647
  }
537
- this.objectsByParent[newParentID].push(localID);
648
+ objByParent.push(localID);
538
649
  }
539
650
  if (pcode !== PCode_1.PCode.Avatar && newObj && this.options & BotOptionFlags_1.BotOptionFlags.StoreMyAttachmentsOnly) {
540
651
  if (this.agent.localID !== 0 && o.ParentID !== this.agent.localID) {
@@ -542,8 +653,10 @@ class ObjectStoreLite {
542
653
  return;
543
654
  }
544
655
  }
545
- if (o.ParentID !== undefined && o.ParentID !== 0 && !this.objects[o.ParentID]) {
546
- this.requestMissingObject(o.ParentID);
656
+ if (o.ParentID !== undefined && o.ParentID !== 0 && !this.objects.has(o.ParentID)) {
657
+ this.requestMissingObject(o.ParentID).catch((e) => {
658
+ console.error(e);
659
+ });
547
660
  }
548
661
  if (compressedflags & CompressedFlags_1.CompressedFlags.Tree) {
549
662
  pos++;
@@ -599,7 +712,7 @@ class ObjectStoreLite {
599
712
  killObject(killObj) {
600
713
  for (const obj of killObj.ObjectData) {
601
714
  const objectID = obj.ID;
602
- if (this.objects[objectID]) {
715
+ if (this.objects.has(objectID)) {
603
716
  this.deleteObject(objectID);
604
717
  }
605
718
  }
@@ -615,56 +728,59 @@ class ObjectStoreLite {
615
728
  }
616
729
  deleteObject(objectID) {
617
730
  var _a;
618
- if (this.objects[objectID]) {
619
- const objectUUID = this.objects[objectID].FullID;
620
- const obj = this.objects[objectID];
731
+ const obj = this.objects.get(objectID);
732
+ if (obj) {
733
+ const objectUUID = obj.FullID;
621
734
  obj.deleted = true;
622
735
  if (this.persist) {
623
736
  this.deadObjects.push(objectID);
624
737
  return;
625
738
  }
626
739
  if (obj.IsAttachment && obj.ParentID !== undefined) {
627
- if (this.objects[obj.ParentID] !== undefined && this.objects[obj.ParentID].PCode === PCode_1.PCode.Avatar) {
628
- (_a = this.agent.currentRegion.agents[this.objects[obj.ParentID].FullID.toString()]) === null || _a === void 0 ? void 0 : _a.removeAttachment(obj);
740
+ const parent = this.objects.get(obj.ParentID);
741
+ if (parent !== undefined && parent.PCode === PCode_1.PCode.Avatar) {
742
+ (_a = this.agent.currentRegion.agents[parent.FullID.toString()]) === null || _a === void 0 ? void 0 : _a.removeAttachment(obj);
629
743
  }
630
744
  }
631
745
  if (this.agent.currentRegion.agents[objectUUID.toString()] !== undefined) {
632
746
  this.agent.currentRegion.agents[objectUUID.toString()].isVisible = false;
633
747
  }
634
- if (this.objectsByParent[objectID]) {
635
- for (const childObjID of this.objectsByParent[objectID]) {
748
+ const objsByParent = this.objectsByParent.get(objectID);
749
+ if (objsByParent) {
750
+ for (const childObjID of objsByParent) {
636
751
  this.deleteObject(childObjID);
637
752
  }
638
753
  }
639
- delete this.objectsByParent[objectID];
754
+ this.objectsByParent.delete(objectID);
640
755
  const uuid = obj.FullID.toString();
641
- if (this.objectsByUUID[uuid]) {
642
- delete this.objectsByUUID[uuid];
643
- }
756
+ this.objectsByUUID.delete(uuid);
644
757
  if (obj.ParentID !== undefined) {
645
758
  const parentID = obj.ParentID;
646
- if (this.objectsByParent[parentID]) {
647
- const ind = this.objectsByParent[parentID].indexOf(objectID);
759
+ const objsByParentParent = this.objectsByParent.get(parentID);
760
+ if (objsByParentParent) {
761
+ const ind = objsByParentParent.indexOf(objectID);
648
762
  if (ind !== -1) {
649
- this.objectsByParent[parentID].splice(ind, 1);
763
+ objsByParentParent.splice(ind, 1);
650
764
  }
651
765
  }
652
766
  }
653
767
  if (this.rtree && obj.rtreeEntry !== undefined) {
654
768
  this.rtree.remove(obj.rtreeEntry);
655
769
  }
656
- delete this.objects[objectID];
770
+ this.objects.delete(objectID);
771
+ this.cachedMaterialOverrides.delete(objectID);
657
772
  }
658
773
  }
659
774
  getObjectsByParent(parentID) {
660
- const list = this.objectsByParent[parentID];
775
+ const list = this.objectsByParent.get(parentID);
661
776
  if (list === undefined) {
662
777
  return [];
663
778
  }
664
779
  const result = [];
665
780
  for (const localID of list) {
666
- if (this.objects[localID]) {
667
- result.push(this.objects[localID]);
781
+ const obj = this.objects.get(localID);
782
+ if (obj) {
783
+ result.push(obj);
668
784
  }
669
785
  }
670
786
  result.sort((a, b) => {
@@ -702,20 +818,22 @@ class ObjectStoreLite {
702
818
  delete this.selectedChecker;
703
819
  }
704
820
  this.physicsSubscription.unsubscribe();
705
- this.objects = {};
821
+ this.objects.clear();
706
822
  if (this.rtree) {
707
823
  this.rtree.clear();
708
824
  }
709
- this.objectsByUUID = {};
710
- this.objectsByParent = {};
825
+ this.objectsByUUID.clear();
826
+ this.objectsByParent.clear();
711
827
  delete this.circuit;
712
828
  }
713
829
  findParent(go) {
714
- if (go.ParentID !== undefined && go.ParentID !== 0 && this.objects[go.ParentID]) {
715
- return this.findParent(this.objects[go.ParentID]);
830
+ var _a;
831
+ const parentObj = this.objects.get((_a = go.ParentID) !== null && _a !== void 0 ? _a : 0);
832
+ if (go.ParentID !== undefined && go.ParentID !== 0 && parentObj) {
833
+ return this.findParent(parentObj);
716
834
  }
717
835
  else {
718
- if (go.ParentID !== undefined && go.ParentID !== 0 && !this.objects[go.ParentID]) {
836
+ if (go.ParentID !== undefined && go.ParentID !== 0 && !parentObj) {
719
837
  this.requestMissingObject(go.ParentID).catch((e) => {
720
838
  Logger_1.Logger.Error(e);
721
839
  });
@@ -743,9 +861,9 @@ class ObjectStoreLite {
743
861
  return __awaiter(this, void 0, void 0, function* () {
744
862
  const results = [];
745
863
  const found = {};
746
- for (const k of Object.keys(this.objects)) {
747
- const go = this.objects[parseInt(k, 10)];
748
- if (go.PCode !== PCode_1.PCode.Avatar && (go.IsAttachment === undefined || !go.IsAttachment)) {
864
+ for (const localID of this.objects.keys()) {
865
+ const go = this.objects.get(localID);
866
+ if (go && go.PCode !== PCode_1.PCode.Avatar && (go.IsAttachment === undefined || !go.IsAttachment)) {
749
867
  try {
750
868
  const parent = this.findParent(go);
751
869
  if (parent.ParentID === 0) {
@@ -816,17 +934,19 @@ class ObjectStoreLite {
816
934
  if (fullID instanceof UUID_1.UUID) {
817
935
  fullID = fullID.toString();
818
936
  }
819
- if (!this.objectsByUUID[fullID]) {
937
+ const localID = this.objectsByUUID.get(fullID);
938
+ const go = this.objects.get(localID !== null && localID !== void 0 ? localID : 0);
939
+ if (localID === undefined || go === undefined) {
820
940
  throw new Error('No object found with that UUID');
821
941
  }
822
- const localID = this.objectsByUUID[fullID];
823
- return this.objects[localID];
942
+ return go;
824
943
  }
825
944
  getObjectByLocalID(localID) {
826
- if (!this.objects[localID]) {
945
+ const go = this.objects.get(localID);
946
+ if (!go) {
827
947
  throw new Error('No object found with that UUID');
828
948
  }
829
- return this.objects[localID];
949
+ return go;
830
950
  }
831
951
  insertIntoRtree(obj) {
832
952
  if (!this.rtree) {