Browse Source

Dashed Line, and some comments added

master
Cailean Finn 2 weeks ago
parent
commit
d6a026ea3e
  1. 13
      js/ItemManager.js

13
js/ItemManager.js

@ -94,10 +94,12 @@ export class ItemManager {
itemDef.model,
itemDef.texture,
[], // spawnedObjects placeholder
contentObject // The created content object
contentObject
);
newItem.id = itemDef.id;
// Set links
if (itemDef.links) {
newItem.links = itemDef.links;
}
@ -106,6 +108,7 @@ export class ItemManager {
this.interactableItems.push(newItem);
}
// Setting a key and value pair in the Map (id, item)
this.itemData.set(itemDef.id, newItem);
}
}
@ -113,15 +116,16 @@ export class ItemManager {
_createLinkLines() {
this.itemData.forEach(item => {
console.log(item.id)
if (!item.links) return;
item.links.forEach(linkedItemId => {
// Goes through each connection; links = [0, 1, 2..]
const linkedItem = this.itemData.get(linkedItemId);
if (!linkedItem) return;
// Creates a key for the Set; a Set can only have unique values, so used for no overlap
const key = [item.id, linkedItemId].sort().join('-');
if (this.drawnLinks.has(key)) return;
const material = new THREE.LineDashedMaterial({
@ -141,7 +145,10 @@ export class ItemManager {
line.computeLineDistances();
this.scene.add(line);
// The Set is used as the key "0-1", then the item and the linkedItem are set as values in the Map?
this.linkLines.set(key, { line, item1: item, item2: linkedItem });
// Make sure it is not drawn again, adding the unique pair here
this.drawnLinks.add(key);
});
});

Loading…
Cancel
Save