Skip to content

Commit ff2753c

Browse files
authored
Merge pull request #4 from fvtt-fria-ligan/v11
v11 compatibility plus compendium reorg.
2 parents 8cdd732 + 857456d commit ff2753c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+262
-515
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2.0.0
2+
3+
- Foundry v11 compatibility.
4+
- Reorganize compendiums using Foundry folders.
5+
- Use classUuids array in config to list available classes for generator.
6+
17
# 1.0.1
28

39
- Fix ChatMessage sound param when using DiceSoNice.

module/config.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,27 @@ VG.tributeTypes = {
154154
VG.weaponTypes = {
155155
"melee": "VG.WeaponTypeMelee",
156156
"ranged": "VG.WeaponTypeRanged"
157-
};
157+
};
158+
159+
// Config variables for the Scvmfactory character generator
160+
VG.scvmFactory = {
161+
// modules wanting to add more character classes to the generator should append uuids to this list
162+
classUuids: [
163+
// Devout
164+
"Compendium.vastgrimm.vast-grimm-items.Item.0O4qPm6FnmhBA264",
165+
// EmoBot
166+
"Compendium.vastgrimm.vast-grimm-items.Item.ig6NF53yqX9oMXrI",
167+
// Harvester
168+
"Compendium.vastgrimm.vast-grimm-items.Item.sRnn6JUlCqbRmglx",
169+
// Lost Technomaniac
170+
"Compendium.vastgrimm.vast-grimm-items.Item.apAIAVLMV2i0CV0N",
171+
// MAnchiNe
172+
"Compendium.vastgrimm.vast-grimm-items.Item.fdInjY5EDKKpuiCm",
173+
// Soul Survivor
174+
"Compendium.vastgrimm.vast-grimm-items.Item.9x8XQ0VcqBk0je06",
175+
// Treacherous Merc
176+
"Compendium.vastgrimm.vast-grimm-items.Item.JKAJz3RUXajVJtlQ",
177+
// Twisted Biochemist
178+
"Compendium.vastgrimm.vast-grimm-items.Item.eqcNCawo1aSlGvZQ"
179+
],
180+
};

module/packutils.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
export const ACTORS_PACK = "vastgrimm.vast-grimm-actors";
2+
export const ITEMS_PACK = "vastgrimm.vast-grimm-items";
3+
export const MACROS_PACK = "vastgrimm.vast-grimm-macros";
4+
export const TABLES_PACK = "vastgrimm.vast-grimm-tables";
5+
6+
export const documentFromPack = async (packName, docName) => {
7+
const pack = game.packs.get(packName);
8+
if (!pack) {
9+
console.error(`Could not find pack ${packName}.`);
10+
return;
11+
}
12+
const docs = await pack.getDocuments();
13+
const doc = docs.find((i) => i.name === docName);
14+
if (!doc) {
15+
console.error(`Could not find doc ${docName} in pack ${packName}.`);
16+
}
17+
return doc;
18+
};
19+
20+
export const drawFromTable = async (
21+
packName,
22+
tableName,
23+
formula = null,
24+
displayChat = false
25+
) => {
26+
const table = await documentFromPack(packName, tableName);
27+
if (!table) {
28+
console.log(`Could not load ${tableName} from pack ${packName}`);
29+
return;
30+
}
31+
const roll = formula ? new Roll(formula) : undefined;
32+
const tableDraw = await table.draw({ displayChat, roll });
33+
// TODO: decide if/how we want to handle multiple results
34+
return tableDraw;
35+
};
36+
37+
export const drawText = async (packName, tableName) => {
38+
const draw = await drawFromTable(packName, tableName);
39+
if (draw) {
40+
return draw.results[0].text;
41+
}
42+
};
43+
44+
export const drawDocument = async (packName, tableName) => {
45+
const draw = await drawFromTable(packName, tableName);
46+
const doc = await documentFromDraw(draw);
47+
return doc;
48+
};
49+
50+
export const drawDocuments = async (packName, tableName) => {
51+
const draw = await drawFromTable(packName, tableName);
52+
const docs = await documentsFromDraw(draw);
53+
return docs;
54+
};
55+
56+
export const documentsFromDraw = async (draw) => {
57+
const docResults = draw.results.filter((r) => r.type === 2);
58+
return Promise.all(docResults.map((r) => documentFromResult(r)));
59+
};
60+
61+
export const documentFromDraw = async (draw) => {
62+
const doc = await documentFromResult(draw.results[0]);
63+
return doc;
64+
};
65+
66+
export const documentFromResult = async (result) => {
67+
if (!result.documentCollection) {
68+
console.log("No documentCollection for result; skipping");
69+
return;
70+
}
71+
const collectionName =
72+
result.type === 2
73+
? "Compendium." + result.documentCollection
74+
: result.documentCollection;
75+
const uuid = `${collectionName}.${result.documentId}`;
76+
const doc = await fromUuid(uuid);
77+
if (!doc) {
78+
console.log(`Could not find ${uuid}`);
79+
console.log(result);
80+
}
81+
return doc;
82+
};
83+
84+
export const dupeData = (doc) => {
85+
return {
86+
data: doc.system,
87+
img: doc.img,
88+
name: doc.name,
89+
type: doc.type,
90+
};
91+
};

module/scvm/scvm-dialog.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { classItemFromPack, createScvm, findClassPacks, scvmifyActor } from "./scvmfactory.js";
1+
import { createScvm, findClasses, scvmifyActor } from "./scvmfactory.js";
2+
import { byName, sample } from "../utils.js";
23

3-
export default class ScvmDialog extends Application {
4+
export const showScvmDialog = async (actor) => {
5+
const dialog = new ScvmDialog();
6+
dialog.actor = actor;
7+
const classes = await findClasses();
8+
classes.sort(byName);
9+
dialog.classes = classes.map(x => {
10+
return { name: x.name, uuid: x.uuid};
11+
});
12+
dialog.render(true);
13+
};
414

5-
constructor(actor=null, options={}) {
6-
super(options);
7-
this.actor = actor;
8-
const classPacks = findClassPacks();
9-
this.classes = classPacks.map(p => {
10-
return {
11-
name: p.split("class-")[1].replace(/-/g, " "),
12-
pack: p
13-
}});
14-
this.classes.sort((a, b) => (a.name > b.name) ? 1 : -1);
15-
}
15+
export default class ScvmDialog extends Application {
1616

1717
/** @override */
1818
static get defaultOptions() {
@@ -63,18 +63,16 @@ export default class ScvmDialog extends Application {
6363
async _onScvm(event) {
6464
event.preventDefault();
6565
const form = $(event.currentTarget).parents(".scvm-dialog")[0];
66-
const selected = [];
66+
const uuids = [];
6767
$(form).find("input:checked").each(function() {
68-
selected.push($(this).attr("name"));
68+
uuids.push($(this).attr("name"));
6969
});
70-
71-
if (selected.length === 0) {
70+
if (uuids.length === 0) {
7271
// nothing selected, so bail
7372
return;
7473
}
75-
76-
const packName = selected[Math.floor(Math.random() * selected.length)];
77-
const clazz = await classItemFromPack(packName);
74+
const uuid = sample(uuids);
75+
const clazz = await fromUuid(uuid);
7876
if (!clazz) {
7977
// couldn't find class item, so bail
8078
const err = `No class item found in compendium ${packName}`;

module/scvm/scvmfactory.js

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {VGActor} from "../actor/actor.js";
2+
import { VG } from "../config.js";
23
import {VGItem} from "../item/item.js";
34
import {randomName} from "./names.js";
5+
import { TABLES_PACK } from "../packutils.js";
6+
import { sample } from "../utils.js";
47

58
export const createRandomScvm = async () => {
69
const clazz = await pickRandomClass();
@@ -18,40 +21,19 @@ export const scvmifyActor = async (actor, clazz) => {
1821
};
1922

2023
const pickRandomClass = async () => {
21-
const classPacks = findClassPacks();
22-
if (classPacks.length === 0) {
23-
// TODO: error on 0-length classPaths
24-
return;
25-
}
26-
const packName = classPacks[Math.floor(Math.random() * classPacks.length)];
27-
// TODO: debugging hardcodes
28-
const pack = game.packs.get(packName);
29-
let content = await pack.getDocuments();
30-
return content.find(i => i.type === "class");
31-
};
32-
33-
export const findClassPacks = () => {
34-
const classPacks = [];
35-
const packKeys = game.packs.keys();
36-
for (const packKey of packKeys) {
37-
// moduleOrSystemName.packName
38-
const keyParts = packKey.split(".");
39-
if (keyParts.length === 2) {
40-
const packName = keyParts[1];
41-
if (packName.startsWith("class-") && packName.length > 6) {
42-
// class pack
43-
classPacks.push(packKey);
44-
}
45-
}
46-
}
47-
return classPacks;
24+
const uuid = sample(VG.scvmFactory.classUuids);
25+
const clazz = await fromUuid(uuid);
26+
return clazz;
4827
};
4928

50-
export const classItemFromPack = async (packName) => {
51-
const pack = game.packs.get(packName);
52-
const content = await pack.getDocuments();
53-
return content.find(i => i.type === "class");
54-
};
29+
export const findClasses = async () => {
30+
const classes = [];
31+
for (let uuid of VG.scvmFactory.classUuids) {
32+
const clazz = await fromUuid(uuid);
33+
classes.push(clazz);
34+
}
35+
return classes;
36+
}
5537

5638
const rollScvmForClass = async (clazz) => {
5739
console.log(`Creating new ${clazz.name}`);
@@ -77,7 +59,7 @@ const rollScvmForClass = async (clazz) => {
7759
const hitPoints = Math.max(1, hpRoll.total + toughness);
7860
const neuromancyPoints = Math.max(0, neuromancyPointsRoll.total + presence);
7961

80-
const ccPack = game.packs.get("vastgrimm.character-creation");
62+
const ccPack = game.packs.get(TABLES_PACK);
8163
const ccContent = await ccPack.getDocuments();
8264
const myTable = ccContent.find(i => i.name === "Misspent Youth");
8365
const bsTable = ccContent.find(i => i.name === "Battle Scars");
@@ -288,16 +270,13 @@ const docsFromResults = async (results) => {
288270
const doc = await docFromResult(result);
289271
if (doc) {
290272
docs.push(doc);
291-
} else {
292-
console.log("No document from result:");
293-
console.log(result);
294273
}
295274
}
296275
return docs;
297276
}
298277

299278
const randomHackedTribute = async () => {
300-
const collection = game.packs.get("vastgrimm.character-creation");
279+
const collection = game.packs.get(TABLES_PACK);
301280
const content = await collection.getDocuments();
302281
const table = content.find(i => i.name === "Hacked Tributes");
303282
const draw = await table.draw({displayChat: false});
@@ -306,7 +285,7 @@ const randomHackedTribute = async () => {
306285
};
307286

308287
const randomEncryptedTribute = async () => {
309-
const collection = game.packs.get("vastgrimm.character-creation");
288+
const collection = game.packs.get(TABLES_PACK);
310289
const content = await collection.getDocuments();
311290
const table = content.find(i => i.name === "Encrypted Tributes");
312291
const draw = await table.draw({displayChat: false});

module/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const byName = (a, b) =>
2+
a.name > b.name ? 1 : b.name > a.name ? -1 : 0;
3+
4+
export const sample = (array) => {
5+
if (!array) {
6+
return;
7+
}
8+
return array[Math.floor(Math.random() * array.length)];
9+
};

module/vastgrimm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { VG } from "./config.js";
1212
import { VGItem } from "./item/item.js";
1313
import { VGItemSheet } from "./item/sheet/item-sheet.js";
1414
import { createVastGrimmMacro, rollItemMacro } from "./macros.js";
15-
import ScvmDialog from "./scvm/scvm-dialog.js";
15+
import { showScvmDialog } from "./scvm/scvm-dialog.js";
1616
import { registerSystemSettings } from "./settings.js";
1717

1818
const VG_DOC_CLASS = "vastgrimm";
@@ -181,7 +181,7 @@ Hooks.on('renderActorDirectory', (app, html, data) => {
181181
</div>
182182
`);
183183
section.querySelector('.create-scvm-button').addEventListener('click', (ev) => {
184-
new ScvmDialog().render(true);
184+
showScvmDialog();
185185
});
186186
}
187187
});

0 commit comments

Comments
 (0)