Skip to content

Commit d7efbb3

Browse files
authored
Merge pull request #110 from vtt-lair/support_uuids
support actors uuids as well as actor ids for roll requests
2 parents 5769ddb + 9c437a3 commit d7efbb3

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/lmrtfy.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class LMRTFY {
144144
else if (data.user === "tokens")
145145
actors = canvas.tokens.controlled.map(t => t.actor).filter(a => data.actors.includes(a.id));
146146
else
147-
actors = data.actors.map(id => game.actors.get(id));
147+
actors = data.actors.map(aid => LMRTFY.fromUuid(aid));
148148
actors = actors.filter(a => a);
149149
if (actors.length === 0) return;
150150
new LMRTFYRoller(actors, data).render(true);
@@ -193,6 +193,34 @@ class LMRTFY {
193193
}
194194
}
195195
}
196+
197+
static fromUuid(uuid) {
198+
let parts = uuid.split(".");
199+
let doc;
200+
201+
if (parts.length === 1) return game.actors.get(uuid);
202+
// Compendium Documents
203+
if ( parts[0] === "Compendium" ) {
204+
return undefined;
205+
}
206+
207+
// World Documents
208+
else {
209+
const [docName, docId] = parts.slice(0, 2);
210+
parts = parts.slice(2);
211+
const collection = CONFIG[docName].collection.instance;
212+
doc = collection.get(docId);
213+
}
214+
215+
// Embedded Documents
216+
while ( parts.length > 1 ) {
217+
const [embeddedName, embeddedId] = parts.slice(0, 2);
218+
doc = doc.getEmbeddedDocument(embeddedName, embeddedId);
219+
parts = parts.slice(2);
220+
}
221+
if (doc.actor) doc = doc.actor;
222+
return doc || undefined;
223+
}
196224
}
197225

198226
Hooks.once('init', LMRTFY.init);

0 commit comments

Comments
 (0)