From 54ee12292697ece7c217d27dcecbeda6531f994a Mon Sep 17 00:00:00 2001 From: Dan Conley Date: Wed, 2 Sep 2020 19:02:57 -0400 Subject: [PATCH] better duplicate prevention; a bugfix --- module.json | 2 +- scripts/journallink.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/module.json b/module.json index 1c27644..759c1b0 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "name": "journal-links", "title": "Journal Links", "description": "See relationships between journal entries", - "version": "0.1.2", + "version": "0.1.3", "author": "dconley", "esmodules": ["./scripts/index.js"], "scripts": [], diff --git a/scripts/journallink.js b/scripts/journallink.js index f4a25c9..7d10751 100644 --- a/scripts/journallink.js +++ b/scripts/journallink.js @@ -54,7 +54,8 @@ export class JournalLink { continue; } - let referenced = game[this.entityMap[reference.type]].get(reference.id); + let mappedEntity = this.entityMap[reference.type]; + let referenced = mappedEntity && game[mappedEntity] && game[mappedEntity].get(reference.id); if (!referenced) { this.debug('no referenced entity ' + reference.type + ' ' + reference.id + '; skipping'); continue; @@ -63,6 +64,10 @@ export class JournalLink { this.debug('adding to referencedBy in ' + reference.type + ' ' + referenced.name); let links = referenced.getFlag('journal-links', 'referencedBy') || {}; let linksOfType = links[entityType] || []; + if (linksOfType.includes(data._id)) { + this.debug(entityType + ' ' + data._id + ' already exists, skipping'); + continue; + } linksOfType.push(data._id); links[entityType] = linksOfType;