Skip to content

Commit

Permalink
sync method; more manifest entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigafoos committed Sep 3, 2020
1 parent 54ee122 commit f9bc045
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ Add the manifest to your Foundry modules: https://raw.githubusercontent.com/Siga

## Settings
* **Rebuild on save**: if disabled, won't automatically generate links between entities (default: enabled)
* **Heading tag**: By default it uses `<h1>` tags for the section. If you'd like to change it to `<h2>`, etc, you can (note: this doesn't support custom classes yet)

## Bugs?
This is very alpha, and doesn't work with at least one other journal plugin. I'll do my best to address any issues that are filed.
* **Heading tag**: by default it uses `<h1>` tags for the section. If you'd like to change it to `<h2>`, etc, you can (note: this doesn't support custom classes, attributes, etc)
* **Debug**: will print more detailed information about the linking process in the developer console (default: disabled)
7 changes: 5 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"name": "journal-links",
"title": "Journal Links",
"description": "See relationships between journal entries",
"version": "0.1.3",
"description": "Include links to entities that reference the viewed journal, actor, item, etc.",
"version": "0.2.0",
"author": "dconley",
"esmodules": ["./scripts/index.js"],
"scripts": [],
"styles": [],
"packs": [],
"minimumCoreVersion": "0.6.6",
"compatibleCoreVersion": "0.6.6",
"url": "https://github.com/Sigafoos/journal-links",
"license": "https://raw.githubusercontent.com/Sigafoos/journal-links/master/LICENSE",
"bugs": "https://github.com/Sigafoos/journal-links/issues",
"manifest": "https://raw.githubusercontent.com/Sigafoos/journal-links/master/module.json",
"download": "https://github.com/Sigafoos/journal-links/archive/master.zip"
}
18 changes: 17 additions & 1 deletion scripts/journallink.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class JournalLink {

let existingOfType = existing[reference.type] || [];
if (existingOfType.includes(reference.id)) {
this.debug(reference.type + ' ' + reference.id + ' already exists, skipping');
this.debug(reference.type + ' ' + reference.id + ' is already referenced, skipping');
continue;
}

Expand Down Expand Up @@ -164,6 +164,22 @@ export class JournalLink {
element.append(linksDiv);
}

// clears and recreates references
sync() {
this.log('syncing links...');
let keys = Object.values(this.entityMap);

for (let key of keys) {
this.log('wiping referencedBy for ' + key);
Array.from(game[key]).forEach(async e => await e.unsetFlag('journal-links', 'referencedBy'))
}

for (let key of keys) {
this.log('wiping references for ' + key);
Array.from(game[key]).forEach(async e => await e.unsetFlag('journal-links', 'references'))
}
}

references(text) {
return Array.from(text.matchAll(this.re)).map(
m => {
Expand Down

0 comments on commit f9bc045

Please sign in to comment.