11import { VGActor } from "../actor/actor.js" ;
2+ import { VG } from "../config.js" ;
23import { VGItem } from "../item/item.js" ;
34import { randomName } from "./names.js" ;
5+ import { TABLES_PACK } from "../packutils.js" ;
6+ import { sample } from "../utils.js" ;
47
58export const createRandomScvm = async ( ) => {
69 const clazz = await pickRandomClass ( ) ;
@@ -18,40 +21,19 @@ export const scvmifyActor = async (actor, clazz) => {
1821} ;
1922
2023const 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
5638const 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
299278const 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
308287const 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 } ) ;
0 commit comments