Skip to content

Commit

Permalink
a bit of code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jtracey committed Apr 9, 2022
1 parent 5fef53d commit e260293
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions scripts/journallink.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,12 @@ export class JournalLink {
}

let mappedEntity = this.entityMap[reference.type];
var referencedById = mappedEntity && game[mappedEntity] && game[mappedEntity].get(reference.id);
var referencedByName = mappedEntity && game[mappedEntity] && game[mappedEntity].getName(reference.id); //Az
var referenced = referencedById;

if (referencedByName) {
referenced = referencedByName;
}else if (!referencedById) {
this.debug('no referenced entity ' + reference.type + ' ' + reference.id + '; skipping');
var referenced = mappedEntity && game[mappedEntity] && (game[mappedEntity].get(reference.id) || game[mappedEntity].getName(reference.id));

if (!referenced) {
this.debug('no referenced entity ' + reference.type + ' ' + reference.id + '; skipping');
continue;
}
}

this.debug('adding to referencedBy in ' + reference.type + ' ' + referenced.name);
let links = await referenced.getFlag('journal-backlinks', 'referencedBy') || {};
Expand All @@ -92,11 +88,7 @@ export class JournalLink {
linksOfType.push(entity.id);

links[entityType] = linksOfType;
if (referencedByName) {
await game[mappedEntity].getName(reference.id).setFlag('journal-backlinks', 'referencedBy', duplicate(links))
}else {
await game[mappedEntity].get(reference.id).setFlag('journal-backlinks', 'referencedBy', duplicate(links))
}
referenced.setFlag('journal-backlinks', 'referencedBy', duplicate(links));
}

for (const [type, values] of Object.entries(existing)) {
Expand Down

2 comments on commit e260293

@AzfarBadaroudine
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clean up.
I'm obviously very new to JavaScript

@jtracey
Copy link
Owner Author

@jtracey jtracey commented on e260293 Apr 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no worries, I figured this was just a drive-by commit and it was easy to clean up myself. If you file any future PRs I can give the full code review process. :)

Please sign in to comment.