From f4af3aad456bd8c94caad8eb28177a90b5a9a094 Mon Sep 17 00:00:00 2001 From: Mike Magarino Date: Tue, 26 Jan 2021 00:33:21 -0500 Subject: [PATCH 1/5] skills v1 --- module/characterImporter.js | 68 ++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/module/characterImporter.js b/module/characterImporter.js index e5af2c18..d517e4f7 100644 --- a/module/characterImporter.js +++ b/module/characterImporter.js @@ -49,6 +49,63 @@ export default class CharacterImporter { }, }; + const skills = { + acr: { + value: sourceCharacter.attribs.find(e => e.name == 'acrobatics_type').current + }, + ani: { + value: sourceCharacter.attribs.find(e => e.name == 'animal_handling_type').current + }, + ath: { + value: sourceCharacter.attribs.find(e => e.name == 'athletics_type').current + }, + dec: { + value: sourceCharacter.attribs.find(e => e.name == 'deception_type').current + }, + ins: { + value: sourceCharacter.attribs.find(e => e.name == 'insight_type').current + }, + inv: { + value: sourceCharacter.attribs.find(e => e.name == 'investigation_type').current + }, + itm: { + value: sourceCharacter.attribs.find(e => e.name == 'intimidation_type').current + }, + lor: { + value: sourceCharacter.attribs.find(e => e.name == 'lore_type').current + }, + med: { + value: sourceCharacter.attribs.find(e => e.name == 'medicine_type').current + }, + nat: { + value: sourceCharacter.attribs.find(e => e.name == 'nature_type').current + }, + per: { + value: sourceCharacter.attribs.find(e => e.name == 'persuasion_type').current + }, + pil: { + value: sourceCharacter.attribs.find(e => e.name == 'piloting_type').current + }, + prc: { + value: sourceCharacter.attribs.find(e => e.name == 'perception_type').current + }, + prf: { + value: sourceCharacter.attribs.find(e => e.name == 'performance_type').current + }, + slt: { + value: sourceCharacter.attribs.find(e => e.name == 'sleight_of_hand_type').current + }, + ste: { + value: sourceCharacter.attribs.find(e => e.name == 'stealth_type').current + }, + sur: { + value: sourceCharacter.attribs.find(e => e.name == 'survival_type').current + }, + tec: { + value: sourceCharacter.attribs.find(e => e.name == 'technology_type').current + } + }; + const targetCharacter = { name: sourceCharacter.name, type: "character", @@ -58,7 +115,8 @@ export default class CharacterImporter { attributes: { ac: ac, hp: hp - } + }, + skills: skills } }; @@ -77,6 +135,14 @@ export default class CharacterImporter { await actor.createEmbeddedEntity("OwnedItem", assignedClass.data, { displaySheet: false }); } + static async addSkils(){ + // data.skills.skill.value is all that matters + // value = 0 = regular + // value = 0.5 = half-proficient + // value = 1 = proficient + // value = 2 = expertise + } + static addImportButton(html){ const header = $("#actors").find("header.directory-header"); const search = $("#actors").children().find("div.header-search"); From 52fd477d397acea45b9573ad443ba2a5ff2c6046 Mon Sep 17 00:00:00 2001 From: Mike Magarino Date: Tue, 26 Jan 2021 01:24:16 -0500 Subject: [PATCH 2/5] skills v2 --- module/characterImporter.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/module/characterImporter.js b/module/characterImporter.js index d517e4f7..5339522c 100644 --- a/module/characterImporter.js +++ b/module/characterImporter.js @@ -49,6 +49,15 @@ export default class CharacterImporter { }, }; + /* ----------------------------------------------------------------- */ + /* character.data.skills..value is all that matters + /* values can be 0, 0.5, 1 or 2 + /* 0 = regular + /* 0.5 = half-proficient + /* 1 = proficient + /* 2 = expertise + /* foundry takes care of calculating the rest + /* ----------------------------------------------------------------- */ const skills = { acr: { value: sourceCharacter.attribs.find(e => e.name == 'acrobatics_type').current @@ -135,14 +144,6 @@ export default class CharacterImporter { await actor.createEmbeddedEntity("OwnedItem", assignedClass.data, { displaySheet: false }); } - static async addSkils(){ - // data.skills.skill.value is all that matters - // value = 0 = regular - // value = 0.5 = half-proficient - // value = 1 = proficient - // value = 2 = expertise - } - static addImportButton(html){ const header = $("#actors").find("header.directory-header"); const search = $("#actors").children().find("div.header-search"); From 6f90f19ad19ba12a2a92f020cb471b5d2f0cd282 Mon Sep 17 00:00:00 2001 From: Mike Magarino Date: Tue, 26 Jan 2021 02:00:30 -0500 Subject: [PATCH 3/5] Update characterImporter.js --- module/characterImporter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module/characterImporter.js b/module/characterImporter.js index 5339522c..3616496c 100644 --- a/module/characterImporter.js +++ b/module/characterImporter.js @@ -3,7 +3,7 @@ export default class CharacterImporter { // transform JSON from sw5e.com to Foundry friendly format // and insert new actor static async transform(rawCharacter){ - const sourceCharacter = JSON.parse(rawCharacter); //source character + const sourceCharacter = JSON.parse(rawCharacter); const details = { species: sourceCharacter.attribs.find(e => e.name == "race").current, @@ -131,12 +131,14 @@ export default class CharacterImporter { let actor = await Actor.create(targetCharacter); + //add class and level const profession = sourceCharacter.attribs.find(e => e.name == "class").current; let professionLevel = sourceCharacter.attribs.find(e => e.name == "class_display").current; professionLevel = parseInt( professionLevel.replace(/[^0-9]/g,'') ); //remove a-z, leaving only integers CharacterImporter.addClasses(profession, professionLevel, actor); } + //currently only works with 1 class static async addClasses(profession, level, actor){ let classes = await game.packs.get('sw5e.classes').getContent(); let assignedClass = classes.find( c => c.name === profession ); From 826f042dbb26de595d4437098a8af80375af2b60 Mon Sep 17 00:00:00 2001 From: Mike Magarino Date: Tue, 26 Jan 2021 10:09:28 -0500 Subject: [PATCH 4/5] skills and multiclass working --- module/characterImporter.js | 62 ++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/module/characterImporter.js b/module/characterImporter.js index 3616496c..c2584527 100644 --- a/module/characterImporter.js +++ b/module/characterImporter.js @@ -130,20 +130,58 @@ export default class CharacterImporter { }; let actor = await Actor.create(targetCharacter); - - //add class and level - const profession = sourceCharacter.attribs.find(e => e.name == "class").current; - let professionLevel = sourceCharacter.attribs.find(e => e.name == "class_display").current; - professionLevel = parseInt( professionLevel.replace(/[^0-9]/g,'') ); //remove a-z, leaving only integers - CharacterImporter.addClasses(profession, professionLevel, actor); + CharacterImporter.addProfessions(sourceCharacter, actor); } - //currently only works with 1 class - static async addClasses(profession, level, actor){ - let classes = await game.packs.get('sw5e.classes').getContent(); - let assignedClass = classes.find( c => c.name === profession ); - assignedClass.data.data.levels = level; - await actor.createEmbeddedEntity("OwnedItem", assignedClass.data, { displaySheet: false }); + static async addProfessions(sourceCharacter, actor){ + // "class" is a reserved word, therefore I use profession where I can. + let result = []; + + // parse all class and multiclassX items + // couldn't get Array.filter to work here for some reason + sourceCharacter.attribs.forEach( (e) => { + if ( CharacterImporter.classOrMulticlass(e.name) ){ + var t = { + profession: CharacterImporter.capitalize(e.current), + type: CharacterImporter.baseOrMulti(e.name), + level: CharacterImporter.getLevel(e, sourceCharacter) + } + result.push(t); + } + }); + + const professionsPack = await game.packs.get('sw5e.classes').getContent(); + result.forEach( (prof) => { + let assignedProfession = professionsPack.find( o => o.name === prof.profession ); + assignedProfession.data.data.levels = prof.level; + actor.createEmbeddedEntity("OwnedItem", assignedProfession.data, { displaySheet: false }); + }); + } + + static classOrMulticlass(name){ + return name === 'class' || (name.includes('multiclass') && name.length <= 12); + } + + static baseOrMulti(name){ + if (name === 'class'){ + return 'base_class'; + } else { + return 'multi_class'; + } + } + + static getLevel(item, sourceCharacter){ + if (item.name === 'class'){ + let result = sourceCharacter.attribs.find( e => e.name === 'base_level' ).current; + return parseInt(result); + } else { + let result = sourceCharacter.attribs.find( e => e.name === `${item.name}_lvl` ).current; + return parseInt(result); + } + } + + static capitalize(str){ + return str.charAt(0).toUpperCase() + str.slice(1); } static addImportButton(html){ From abc65220ec7a43d6c3bc3b10ac9eb974c0163dad Mon Sep 17 00:00:00 2001 From: Mike Magarino Date: Tue, 26 Jan 2021 10:11:52 -0500 Subject: [PATCH 5/5] skills and multiclass working --- module/characterImporter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/module/characterImporter.js b/module/characterImporter.js index c2584527..b87e50fc 100644 --- a/module/characterImporter.js +++ b/module/characterImporter.js @@ -133,12 +133,15 @@ export default class CharacterImporter { CharacterImporter.addProfessions(sourceCharacter, actor); } + // Parse all classes and add them to already created actor. + // "class" is a reserved word, therefore I use profession where I can. static async addProfessions(sourceCharacter, actor){ - // "class" is a reserved word, therefore I use profession where I can. + let result = []; // parse all class and multiclassX items // couldn't get Array.filter to work here for some reason + // result = array of objects. each object is a separate class sourceCharacter.attribs.forEach( (e) => { if ( CharacterImporter.classOrMulticlass(e.name) ){ var t = { @@ -150,6 +153,7 @@ export default class CharacterImporter { } }); + // pull classes directly from system compendium and add them to current actor const professionsPack = await game.packs.get('sw5e.classes').getContent(); result.forEach( (prof) => { let assignedProfession = professionsPack.find( o => o.name === prof.profession );