Skip to content

Commit

Permalink
better duplicate prevention; a bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigafoos committed Sep 2, 2020
1 parent 38bb7d5 commit 54ee122
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
7 changes: 6 additions & 1 deletion scripts/journallink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 54ee122

Please sign in to comment.