forked from GitHub-Mirrors/foundry-sw5e
Updated formatting
This commit is contained in:
parent
ea7a6e063a
commit
71a99e97a9
3 changed files with 346 additions and 355 deletions
117
examples/test_script.js
Normal file
117
examples/test_script.js
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
const targetCharacter = {
|
||||||
|
name: sourceCharacter.name,
|
||||||
|
type: "character",
|
||||||
|
data: {
|
||||||
|
abilities: {
|
||||||
|
str: {
|
||||||
|
value: strength,
|
||||||
|
proficient: strengthSaveProf
|
||||||
|
},
|
||||||
|
dex: {
|
||||||
|
value: dexterity,
|
||||||
|
proficient: dexteritySaveProf
|
||||||
|
},
|
||||||
|
con: {
|
||||||
|
value: constitution,
|
||||||
|
proficient: constitutionSaveProf
|
||||||
|
},
|
||||||
|
int: {
|
||||||
|
value: intelligence,
|
||||||
|
proficient: intelligenceSaveProf
|
||||||
|
},
|
||||||
|
wis: {
|
||||||
|
value: wisdom,
|
||||||
|
proficient: wisdomSaveProf
|
||||||
|
},
|
||||||
|
cha: {
|
||||||
|
value: charisma,
|
||||||
|
proficient: charismaSaveProf
|
||||||
|
},
|
||||||
|
},
|
||||||
|
attributes: {
|
||||||
|
ac: {
|
||||||
|
value: ac
|
||||||
|
},
|
||||||
|
hp: {
|
||||||
|
value: hp,
|
||||||
|
min: 0,
|
||||||
|
max: hp,
|
||||||
|
temp: hpTemp
|
||||||
|
}
|
||||||
|
}/*,
|
||||||
|
skills: {
|
||||||
|
acr: {
|
||||||
|
value: acrobaticsSkill,
|
||||||
|
ability: "dex"
|
||||||
|
},
|
||||||
|
ani: {
|
||||||
|
value: animalHandlingSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
ath: {
|
||||||
|
value: athleticsSkill,
|
||||||
|
ability: "str"
|
||||||
|
},
|
||||||
|
dec: {
|
||||||
|
value: deceptionSkill,
|
||||||
|
ability: "cha"
|
||||||
|
},
|
||||||
|
ins: {
|
||||||
|
value: insightSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
itm: {
|
||||||
|
value: intimidationSkill,
|
||||||
|
ability: "cha"
|
||||||
|
},
|
||||||
|
inv: {
|
||||||
|
value: investigationSkill,
|
||||||
|
ability: "int"
|
||||||
|
},
|
||||||
|
lor: {
|
||||||
|
value: loreSkill,
|
||||||
|
ability: "int"
|
||||||
|
},
|
||||||
|
med: {
|
||||||
|
value: medicineSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
nat: {
|
||||||
|
value: natureSkill,
|
||||||
|
ability: "int"
|
||||||
|
},
|
||||||
|
pil: {
|
||||||
|
value: pilotingSkill,
|
||||||
|
ability: "int"
|
||||||
|
},
|
||||||
|
prc: {
|
||||||
|
value: perceptionSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
prf: {
|
||||||
|
value: performanceSkill,
|
||||||
|
ability: "cha"
|
||||||
|
},
|
||||||
|
per: {
|
||||||
|
value: persuasionSkill,
|
||||||
|
ability: "cha"
|
||||||
|
},
|
||||||
|
slt: {
|
||||||
|
value: sleightOfHandSkill,
|
||||||
|
ability: "dex"
|
||||||
|
},
|
||||||
|
ste: {
|
||||||
|
value: stealthSkill,
|
||||||
|
ability: "dex"
|
||||||
|
},
|
||||||
|
sur: {
|
||||||
|
value: survivalSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
tec: {
|
||||||
|
value: technologySkill,
|
||||||
|
ability: "int"
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,372 +1,244 @@
|
||||||
import Actor5e from "./actor/entity.js";
|
|
||||||
import ActorSheet5eCharacterNew from "./actor/sheets/newSheet/character.js";
|
|
||||||
|
|
||||||
export default class CharacterImporter {
|
export default class CharacterImporter {
|
||||||
|
|
||||||
// transform JSON from sw5e.com to Foundry friendly format
|
// transform JSON from sw5e.com to Foundry friendly format
|
||||||
// and insert new actor
|
// and insert new actor
|
||||||
static async transform(rawCharacter){
|
static async transform(rawCharacter){
|
||||||
const sourceCharacter = JSON.parse(rawCharacter);
|
const sourceCharacter = JSON.parse(rawCharacter);
|
||||||
// v1 - just import the very basics: name, species, hp, ac and abilities
|
// v1 - just import the very basics: name, species, hp, ac and abilities
|
||||||
const name = sourceCharacter.name;
|
const name = sourceCharacter.name;
|
||||||
const species = sourceCharacter.attribs.find(o => o.name == "race").current;
|
const species = sourceCharacter.attribs.find(o => o.name == "race").current;
|
||||||
const hp = sourceCharacter.attribs.find(o => o.name == "hp").current;
|
const hp = sourceCharacter.attribs.find(o => o.name == "hp").current;
|
||||||
const hpTemp = sourceCharacter.attribs.find(o => o.name == "hp_temp").current;
|
const hpTemp = sourceCharacter.attribs.find(o => o.name == "hp_temp").current;
|
||||||
const ac = sourceCharacter.attribs.find(o => o.name == "ac").current;
|
const ac = sourceCharacter.attribs.find(o => o.name == "ac").current;
|
||||||
const strength = sourceCharacter.attribs.find(o => o.name == "strength").current;
|
const strength = sourceCharacter.attribs.find(o => o.name == "strength").current;
|
||||||
const dexterity = sourceCharacter.attribs.find(o => o.name == "dexterity").current;
|
const dexterity = sourceCharacter.attribs.find(o => o.name == "dexterity").current;
|
||||||
const constitution = sourceCharacter.attribs.find(o => o.name == "constitution").current;
|
const constitution = sourceCharacter.attribs.find(o => o.name == "constitution").current;
|
||||||
const intelligence = sourceCharacter.attribs.find(o => o.name == "intelligence").current;
|
const intelligence = sourceCharacter.attribs.find(o => o.name == "intelligence").current;
|
||||||
const wisdom = sourceCharacter.attribs.find(o => o.name == "wisdom").current;
|
const wisdom = sourceCharacter.attribs.find(o => o.name == "wisdom").current;
|
||||||
const charisma = sourceCharacter.attribs.find(o => o.name == "charisma").current;
|
const charisma = sourceCharacter.attribs.find(o => o.name == "charisma").current;
|
||||||
const strengthSaveProf = sourceCharacter.attribs.find(o => o.name == 'strength_save_prof').current ? 1 : 0;
|
const strengthSaveProf = sourceCharacter.attribs.find(o => o.name == 'strength_save_prof').current ? 1 : 0;
|
||||||
const dexteritySaveProf = sourceCharacter.attribs.find(o => o.name == 'dexterity_save_prof').current ? 1 : 0;
|
const dexteritySaveProf = sourceCharacter.attribs.find(o => o.name == 'dexterity_save_prof').current ? 1 : 0;
|
||||||
const constitutionSaveProf = sourceCharacter.attribs.find(o => o.name == 'constitution_save_prof').current ? 1 : 0;
|
const constitutionSaveProf = sourceCharacter.attribs.find(o => o.name == 'constitution_save_prof').current ? 1 : 0;
|
||||||
const intelligenceSaveProf = sourceCharacter.attribs.find(o => o.name == 'intelligence_save_prof').current ? 1 : 0;
|
const intelligenceSaveProf = sourceCharacter.attribs.find(o => o.name == 'intelligence_save_prof').current ? 1 : 0;
|
||||||
const wisdomSaveProf = sourceCharacter.attribs.find(o => o.name == 'wisdom_save_prof').current ? 1 : 0;
|
const wisdomSaveProf = sourceCharacter.attribs.find(o => o.name == 'wisdom_save_prof').current ? 1 : 0;
|
||||||
const charismaSaveProf = sourceCharacter.attribs.find(o => o.name == 'charisma_save_prof').current ? 1 : 0;
|
const charismaSaveProf = sourceCharacter.attribs.find(o => o.name == 'charisma_save_prof').current ? 1 : 0;
|
||||||
|
|
||||||
let characterJSON = {
|
const targetCharacter = {
|
||||||
character: character,
|
name: sourceCharacter.name,
|
||||||
features: features,
|
type: "character",
|
||||||
classes: classes,
|
data: {
|
||||||
inventory: inventory,
|
abilities: {
|
||||||
spells: spells,
|
str: {
|
||||||
actions: actions,
|
value: strength,
|
||||||
itemSpells: itemSpells,
|
proficient: strengthSaveProf
|
||||||
};
|
},
|
||||||
// v2 - skills and proficiencies
|
dex: {
|
||||||
/*
|
value: dexterity,
|
||||||
const acrobaticsSkill = sourceCharacter.attribs.find(o => o.name == 'acrobatics_bonus').current;
|
proficient: dexteritySaveProf
|
||||||
const animalHandlingSkill = sourceCharacter.attribs.find(o => o.name == 'animal_handling_bonus').current;
|
},
|
||||||
const athleticsSkill = sourceCharacter.attribs.find(o => o.name == 'athletics_bonus').current;
|
con: {
|
||||||
const deceptionSkill = sourceCharacter.attribs.find(o => o.name == 'deception_bonus').current;
|
value: constitution,
|
||||||
const insightSkill = sourceCharacter.attribs.find(o => o.name == 'insight_bonus').current;
|
proficient: constitutionSaveProf
|
||||||
const intimidationSkill = sourceCharacter.attribs.find(o => o.name == 'intimidation_bonus').current;
|
},
|
||||||
const investigationSkill = sourceCharacter.attribs.find(o => o.name == 'investigation_bonus').current;
|
int: {
|
||||||
const loreSkill = sourceCharacter.attribs.find(o => o.name == 'lore_bonus').current;
|
value: intelligence,
|
||||||
const medicineSkill = sourceCharacter.attribs.find(o => o.name == 'medicine_bonus').current;
|
proficient: intelligenceSaveProf
|
||||||
const natureSkill = sourceCharacter.attribs.find(o => o.name == 'nature_bonus').current;
|
},
|
||||||
const pilotingSkill = sourceCharacter.attribs.find(o => o.name == 'piloting_bonus').current;
|
wis: {
|
||||||
const perceptionSkill = sourceCharacter.attribs.find(o => o.name == 'perception_bonus').current;
|
value: wisdom,
|
||||||
const performanceSkill = sourceCharacter.attribs.find(o => o.name == 'performance_bonus').current;
|
proficient: wisdomSaveProf
|
||||||
const persuasionSkill = sourceCharacter.attribs.find(o => o.name == 'persuasion_bonus').current;
|
},
|
||||||
const sleightOfHandSkill = sourceCharacter.attribs.find(o => o.name == 'sleight_of_hand_bonus').current;
|
cha: {
|
||||||
const stealthSkill = sourceCharacter.attribs.find(o => o.name == 'stealth_bonus').current;
|
value: charisma,
|
||||||
const survivalSkill = sourceCharacter.attribs.find(o => o.name == 'survival_bonus').current;
|
proficient: charismaSaveProf
|
||||||
const technologySkill = sourceCharacter.attribs.find(o => o.name == 'technology_bonus').current;
|
},
|
||||||
|
},
|
||||||
const baseClassName = sourceCharacter.attribs.find(o => o.name == 'class').current;
|
attributes: {
|
||||||
const baseClassLvl = sourceCharacter.attribs.find(o => o.name == 'base_level').current;
|
ac: {
|
||||||
*/
|
value: ac
|
||||||
|
},
|
||||||
const targetCharacter = {
|
hp: {
|
||||||
name: sourceCharacter.name,
|
value: hp,
|
||||||
type: "character",
|
min: 0,
|
||||||
data: {
|
max: hp,
|
||||||
abilities: {
|
temp: hpTemp
|
||||||
str: {
|
|
||||||
value: strength,
|
|
||||||
proficient: strengthSaveProf
|
|
||||||
},
|
|
||||||
dex: {
|
|
||||||
value: dexterity,
|
|
||||||
proficient: dexteritySaveProf
|
|
||||||
},
|
|
||||||
con: {
|
|
||||||
value: constitution,
|
|
||||||
proficient: constitutionSaveProf
|
|
||||||
},
|
|
||||||
int: {
|
|
||||||
value: intelligence,
|
|
||||||
proficient: intelligenceSaveProf
|
|
||||||
},
|
|
||||||
wis: {
|
|
||||||
value: wisdom,
|
|
||||||
proficient: wisdomSaveProf
|
|
||||||
},
|
|
||||||
cha: {
|
|
||||||
value: charisma,
|
|
||||||
proficient: charismaSaveProf
|
|
||||||
},
|
|
||||||
},
|
|
||||||
attributes: {
|
|
||||||
ac: {
|
|
||||||
value: ac
|
|
||||||
},
|
|
||||||
hp: {
|
|
||||||
value: hp,
|
|
||||||
min: 0,
|
|
||||||
max: hp,
|
|
||||||
temp: hpTemp
|
|
||||||
}
|
|
||||||
}/*,
|
|
||||||
skills: {
|
|
||||||
acr: {
|
|
||||||
value: acrobaticsSkill,
|
|
||||||
ability: "dex"
|
|
||||||
},
|
|
||||||
ani: {
|
|
||||||
value: animalHandlingSkill,
|
|
||||||
ability: "wis"
|
|
||||||
},
|
|
||||||
ath: {
|
|
||||||
value: athleticsSkill,
|
|
||||||
ability: "str"
|
|
||||||
},
|
|
||||||
dec: {
|
|
||||||
value: deceptionSkill,
|
|
||||||
ability: "cha"
|
|
||||||
},
|
|
||||||
ins: {
|
|
||||||
value: insightSkill,
|
|
||||||
ability: "wis"
|
|
||||||
},
|
|
||||||
itm: {
|
|
||||||
value: intimidationSkill,
|
|
||||||
ability: "cha"
|
|
||||||
},
|
|
||||||
inv: {
|
|
||||||
value: investigationSkill,
|
|
||||||
ability: "int"
|
|
||||||
},
|
|
||||||
lor: {
|
|
||||||
value: loreSkill,
|
|
||||||
ability: "int"
|
|
||||||
},
|
|
||||||
med: {
|
|
||||||
value: medicineSkill,
|
|
||||||
ability: "wis"
|
|
||||||
},
|
|
||||||
nat: {
|
|
||||||
value: natureSkill,
|
|
||||||
ability: "int"
|
|
||||||
},
|
|
||||||
pil: {
|
|
||||||
value: pilotingSkill,
|
|
||||||
ability: "int"
|
|
||||||
},
|
|
||||||
prc: {
|
|
||||||
value: perceptionSkill,
|
|
||||||
ability: "wis"
|
|
||||||
},
|
|
||||||
prf: {
|
|
||||||
value: performanceSkill,
|
|
||||||
ability: "cha"
|
|
||||||
},
|
|
||||||
per: {
|
|
||||||
value: persuasionSkill,
|
|
||||||
ability: "cha"
|
|
||||||
},
|
|
||||||
slt: {
|
|
||||||
value: sleightOfHandSkill,
|
|
||||||
ability: "dex"
|
|
||||||
},
|
|
||||||
ste: {
|
|
||||||
value: stealthSkill,
|
|
||||||
ability: "dex"
|
|
||||||
},
|
|
||||||
sur: {
|
|
||||||
value: survivalSkill,
|
|
||||||
ability: "wis"
|
|
||||||
},
|
|
||||||
tec: {
|
|
||||||
value: technologySkill,
|
|
||||||
ability: "int"
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const classes = game.packs.get('sw5e.classes');
|
|
||||||
const content = await classes.getContent();
|
|
||||||
const scout = await content.find(o => o.name == 'Scout').clone();
|
|
||||||
scout.data.data.levels = 9;
|
|
||||||
targetCharacter.items = [scout];
|
|
||||||
let actor = await Actor.create(targetCharacter);
|
|
||||||
//assignSkills(actor.id);
|
|
||||||
|
|
||||||
async function assignSkills(id){
|
|
||||||
let hero = game.actor.get(id);
|
|
||||||
actor.data.data.skills.acr = sourceCharacter.attribs.find(o => o.name == 'acrobatics_bonus').current;
|
|
||||||
actor.data.data.skills.ani = sourceCharacter.attribs.find(o => o.name == 'animal_handling_bonus').current;
|
|
||||||
actor.data.data.skills.ath = sourceCharacter.attribs.find(o => o.name == 'athletics_bonus').current;
|
|
||||||
actor.data.data.skills.dec = sourceCharacter.attribs.find(o => o.name == 'deception_bonus').current;
|
|
||||||
actor.data.data.skills.ins = sourceCharacter.attribs.find(o => o.name == 'insight_bonus').current;
|
|
||||||
actor.data.data.skills.itm = sourceCharacter.attribs.find(o => o.name == 'intimidation_bonus').current;
|
|
||||||
actor.data.data.skills.inv = sourceCharacter.attribs.find(o => o.name == 'investigation_bonus').current;
|
|
||||||
actor.data.data.skills.lor = sourceCharacter.attribs.find(o => o.name == 'lore_bonus').current;
|
|
||||||
actor.data.data.skills.med = sourceCharacter.attribs.find(o => o.name == 'medicine_bonus').current;
|
|
||||||
actor.data.data.skills.nat = sourceCharacter.attribs.find(o => o.name == 'nature_bonus').current;
|
|
||||||
actor.data.data.skills.pil = sourceCharacter.attribs.find(o => o.name == 'piloting_bonus').current;
|
|
||||||
actor.data.data.skills.prc = sourceCharacter.attribs.find(o => o.name == 'perception_bonus').current;
|
|
||||||
actor.data.data.skills.prf = sourceCharacter.attribs.find(o => o.name == 'performance_bonus').current;
|
|
||||||
actor.data.data.skills.per = sourceCharacter.attribs.find(o => o.name == 'persuasion_bonus').current;
|
|
||||||
actor.data.data.skills.slt = sourceCharacter.attribs.find(o => o.name == 'sleight_of_hand_bonus').current;
|
|
||||||
actor.data.data.skills.ste = sourceCharacter.attribs.find(o => o.name == 'stealth_bonus').current;
|
|
||||||
actor.data.data.skills.sur = sourceCharacter.attribs.find(o => o.name == 'survival_bonus').current;
|
|
||||||
actor.data.data.skills.tec = sourceCharacter.attribs.find(o => o.name == 'technology_bonus').current;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//const baseClassName = sourceCharacter.attribs.find(o => o.name == 'class').current;
|
|
||||||
//const baseClassLvl = sourceCharacter.attribs.find(o => o.name == 'base_level').current;
|
|
||||||
|
|
||||||
/*
|
|
||||||
function addInitialClassAndLevel(itemData){
|
|
||||||
Actor5e.getClassFeatures(itemData).then(features => {
|
|
||||||
actor.createEmbeddedEntity("OwnedItem", features);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// async function addSubsequentLevels(targetLvl, actor){
|
|
||||||
// actor.data.data.details.level = targetLvl;
|
|
||||||
// var x = await actor.items.find(x => x.name == 'Scout');
|
|
||||||
// x.data.data.levels = 6;
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// function addSubsequentLevelsOld(/*targetLvl,*/ itemData, actorClass, actor){
|
|
||||||
// //const lvl = actorClass.data.data.levels;
|
|
||||||
// //const newLvl = Math.min(lvl + 1, 20 + lvl - actor.data.data.details.level);
|
|
||||||
// //if ( !(lvl === newLvl) ) {
|
|
||||||
// actorClass.update({"data.levels": newLvl});
|
|
||||||
// itemData.data.levels = newLvl;
|
|
||||||
// Actor5e.getClassFeatures(itemData).then(features => {
|
|
||||||
// actor.createEmbeddedEntity("OwnedItem", features);
|
|
||||||
// });
|
|
||||||
// //}
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
//const actorClass = await actor.itemTypes.class.find(c => c.name === itemData.name);
|
|
||||||
//const classWasAlreadyPresent = !!actorClass;
|
|
||||||
//const classes = await game.packs.get('sw5e.classes');
|
|
||||||
//const content = await classes.getContent();
|
|
||||||
//const scout = await content.find(o => o.name == 'Scout').clone();
|
|
||||||
//scout.data.data.levels = 6;
|
|
||||||
//let newActorSheet = new ActorSheet5eCharacterNew(actor);
|
|
||||||
//let sheet = new game.sw5e.applications.ActorSheet5eCharacterNew(actor);
|
|
||||||
//addInitialClassAndLevel(scout);
|
|
||||||
//sheet._onDropItem(false, scout);
|
|
||||||
|
|
||||||
|
|
||||||
//addSubsequentLevels(scout, actor);
|
|
||||||
|
|
||||||
// ActorSheet5eCharacterNew
|
|
||||||
//async _onDropItemCreate(itemData) {
|
|
||||||
// this is basically a direct copy of ActorSheet5eCharacterNew._onDropItemCreate()
|
|
||||||
function addActorClassLevel(itemData, actor) {
|
|
||||||
// Upgrade the number of class levels a character has and add features
|
|
||||||
if ( itemData.type === "class" ) {
|
|
||||||
const cls = actor.itemTypes.class.find(c => c.name === itemData.name);
|
|
||||||
const classWasAlreadyPresent = !!cls;
|
|
||||||
/*DEBUG*/
|
|
||||||
console.log("SW5e | Character Importer: cls: " + cls);
|
|
||||||
console.log("SW5e | Character Importer: classWasAlreadyPresent: " + classWasAlreadyPresent);
|
|
||||||
/*DEBUG*/
|
|
||||||
|
|
||||||
// Add new features for class level
|
|
||||||
if ( !classWasAlreadyPresent ) {
|
|
||||||
Actor5e.getClassFeatures(itemData).then(features => {
|
|
||||||
actor.createEmbeddedEntity("OwnedItem", features);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
}/*,
|
||||||
// If the actor already has the class, increment the level instead of creating a new item
|
skills: {
|
||||||
// then add new features as long as level increases
|
acr: {
|
||||||
if ( classWasAlreadyPresent ) {
|
value: acrobaticsSkill,
|
||||||
const lvl = cls.data.data.levels;
|
ability: "dex"
|
||||||
const newLvl = Math.min(lvl + 1, 20 + lvl - actor.data.data.details.level);
|
},
|
||||||
if ( !(lvl === newLvl) ) {
|
ani: {
|
||||||
cls.update({"data.levels": newLvl});
|
value: animalHandlingSkill,
|
||||||
itemData.data.levels = newLvl;
|
ability: "wis"
|
||||||
Actor5e.getClassFeatures(itemData).then(features => {
|
},
|
||||||
actor.createEmbeddedEntity("OwnedItem", features);
|
ath: {
|
||||||
});
|
value: athleticsSkill,
|
||||||
}
|
ability: "str"
|
||||||
return
|
},
|
||||||
|
dec: {
|
||||||
|
value: deceptionSkill,
|
||||||
|
ability: "cha"
|
||||||
|
},
|
||||||
|
ins: {
|
||||||
|
value: insightSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
itm: {
|
||||||
|
value: intimidationSkill,
|
||||||
|
ability: "cha"
|
||||||
|
},
|
||||||
|
inv: {
|
||||||
|
value: investigationSkill,
|
||||||
|
ability: "int"
|
||||||
|
},
|
||||||
|
lor: {
|
||||||
|
value: loreSkill,
|
||||||
|
ability: "int"
|
||||||
|
},
|
||||||
|
med: {
|
||||||
|
value: medicineSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
nat: {
|
||||||
|
value: natureSkill,
|
||||||
|
ability: "int"
|
||||||
|
},
|
||||||
|
pil: {
|
||||||
|
value: pilotingSkill,
|
||||||
|
ability: "int"
|
||||||
|
},
|
||||||
|
prc: {
|
||||||
|
value: perceptionSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
prf: {
|
||||||
|
value: performanceSkill,
|
||||||
|
ability: "cha"
|
||||||
|
},
|
||||||
|
per: {
|
||||||
|
value: persuasionSkill,
|
||||||
|
ability: "cha"
|
||||||
|
},
|
||||||
|
slt: {
|
||||||
|
value: sleightOfHandSkill,
|
||||||
|
ability: "dex"
|
||||||
|
},
|
||||||
|
ste: {
|
||||||
|
value: stealthSkill,
|
||||||
|
ability: "dex"
|
||||||
|
},
|
||||||
|
sur: {
|
||||||
|
value: survivalSkill,
|
||||||
|
ability: "wis"
|
||||||
|
},
|
||||||
|
tec: {
|
||||||
|
value: technologySkill,
|
||||||
|
ability: "int"
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
// from Actor5e._onDropItemCreate()
|
|
||||||
return actor.createEmbeddedEntity("OwnedItem", itemData);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function sleep(milliseconds) {
|
|
||||||
const date = Date.now();
|
|
||||||
let currentDate = null;
|
|
||||||
do {
|
|
||||||
currentDate = Date.now();
|
|
||||||
} while (currentDate - date < milliseconds);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let actor = await Actor.create(targetCharacter);
|
||||||
|
|
||||||
|
async function assignSkills(id){
|
||||||
|
let hero = game.actor.get(id);
|
||||||
|
actor.data.data.skills.acr = sourceCharacter.attribs.find(o => o.name == 'acrobatics_bonus').current;
|
||||||
|
actor.data.data.skills.ani = sourceCharacter.attribs.find(o => o.name == 'animal_handling_bonus').current;
|
||||||
|
actor.data.data.skills.ath = sourceCharacter.attribs.find(o => o.name == 'athletics_bonus').current;
|
||||||
|
actor.data.data.skills.dec = sourceCharacter.attribs.find(o => o.name == 'deception_bonus').current;
|
||||||
|
actor.data.data.skills.ins = sourceCharacter.attribs.find(o => o.name == 'insight_bonus').current;
|
||||||
|
actor.data.data.skills.itm = sourceCharacter.attribs.find(o => o.name == 'intimidation_bonus').current;
|
||||||
|
actor.data.data.skills.inv = sourceCharacter.attribs.find(o => o.name == 'investigation_bonus').current;
|
||||||
|
actor.data.data.skills.lor = sourceCharacter.attribs.find(o => o.name == 'lore_bonus').current;
|
||||||
|
actor.data.data.skills.med = sourceCharacter.attribs.find(o => o.name == 'medicine_bonus').current;
|
||||||
|
actor.data.data.skills.nat = sourceCharacter.attribs.find(o => o.name == 'nature_bonus').current;
|
||||||
|
actor.data.data.skills.pil = sourceCharacter.attribs.find(o => o.name == 'piloting_bonus').current;
|
||||||
|
actor.data.data.skills.prc = sourceCharacter.attribs.find(o => o.name == 'perception_bonus').current;
|
||||||
|
actor.data.data.skills.prf = sourceCharacter.attribs.find(o => o.name == 'performance_bonus').current;
|
||||||
|
actor.data.data.skills.per = sourceCharacter.attribs.find(o => o.name == 'persuasion_bonus').current;
|
||||||
|
actor.data.data.skills.slt = sourceCharacter.attribs.find(o => o.name == 'sleight_of_hand_bonus').current;
|
||||||
|
actor.data.data.skills.ste = sourceCharacter.attribs.find(o => o.name == 'stealth_bonus').current;
|
||||||
|
actor.data.data.skills.sur = sourceCharacter.attribs.find(o => o.name == 'survival_bonus').current;
|
||||||
|
actor.data.data.skills.tec = sourceCharacter.attribs.find(o => o.name == 'technology_bonus').current;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
//const baseClassName = sourceCharacter.attribs.find(o => o.name == 'class').current;
|
||||||
await newActorSheet._onDropItemCreate(scout);
|
//const baseClassLvl = sourceCharacter.attribs.find(o => o.name == 'base_level').current;
|
||||||
await newActorSheet._onDropItemCreate(scout);
|
|
||||||
await newActorSheet._onDropItemCreate(scout);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var newActor = game.actors.find(o => o.name === 'Strom Klovrah');
|
function addInitialClassAndLevel(itemData){
|
||||||
var classes = await game.packs.get('sw5e.classes');
|
Actor5e.getClassFeatures(itemData).then(features => {
|
||||||
var content = await classes.getContent();
|
actor.createEmbeddedEntity("OwnedItem", features);
|
||||||
var scout = content.find(o => o.name == 'Scout');
|
});
|
||||||
var newActorSheet = new game.sw5e.applications.ActorSheet5eCharacterNew(newActor);
|
}
|
||||||
await newActorSheet._onDropItemCreate(scout);
|
*/
|
||||||
await newActorSheet.close();
|
|
||||||
var newActorSheet = new game.sw5e.applications.ActorSheet5eCharacterNew(newActor);
|
// async function addSubsequentLevels(targetLvl, actor){
|
||||||
await newActorSheet._onDropItemCreate(scout);
|
// actor.data.data.details.level = targetLvl;
|
||||||
await newActorSheet.close();
|
// var x = await actor.items.find(x => x.name == 'Scout');
|
||||||
var newActorSheet = new game.sw5e.applications.ActorSheet5eCharacterNew(newActor);
|
// x.data.data.levels = 6;
|
||||||
await newActorSheet._onDropItemCreate(scout);
|
|
||||||
await newActorSheet.close();
|
|
||||||
*/
|
// }
|
||||||
|
|
||||||
|
// function addSubsequentLevelsOld(/*targetLvl,*/ itemData, actorClass, actor){
|
||||||
|
// //const lvl = actorClass.data.data.levels;
|
||||||
|
// //const newLvl = Math.min(lvl + 1, 20 + lvl - actor.data.data.details.level);
|
||||||
|
// //if ( !(lvl === newLvl) ) {
|
||||||
|
// actorClass.update({"data.levels": newLvl});
|
||||||
|
// itemData.data.levels = newLvl;
|
||||||
|
// Actor5e.getClassFeatures(itemData).then(features => {
|
||||||
|
// actor.createEmbeddedEntity("OwnedItem", features);
|
||||||
|
// });
|
||||||
|
// //}
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
//await newActorSheet.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
static addImportButton(html){
|
static addImportButton(html){
|
||||||
const header = $("#actors").find("header.directory-header");
|
const header = $("#actors").find("header.directory-header");
|
||||||
const search = $("#actors").children().find("div.header-search");
|
const search = $("#actors").children().find("div.header-search");
|
||||||
const newImportButtonDiv = $("#actors").children().find("div.header-actions").clone();
|
const newImportButtonDiv = $("#actors").children().find("div.header-actions").clone();
|
||||||
const newSearch = search.clone();
|
const newSearch = search.clone();
|
||||||
search.remove();
|
search.remove();
|
||||||
newImportButtonDiv.attr('id', 'character-sheet-import');
|
newImportButtonDiv.attr('id', 'character-sheet-import');
|
||||||
header.append(newImportButtonDiv);
|
header.append(newImportButtonDiv);
|
||||||
newImportButtonDiv.children("button").remove();
|
newImportButtonDiv.children("button").remove();
|
||||||
newImportButtonDiv.append("<button class='create-entity' id='cs-import-button'><i class='fas fa-upload'></i> Import Character</button>");
|
newImportButtonDiv.append("<button class='create-entity' id='cs-import-button'><i class='fas fa-upload'></i> Import Character</button>");
|
||||||
newSearch.appendTo(header);
|
newSearch.appendTo(header);
|
||||||
|
|
||||||
let characterImportButton = $("#cs-import-button");
|
let characterImportButton = $("#cs-import-button");
|
||||||
characterImportButton.click(ev => {
|
characterImportButton.click(ev => {
|
||||||
let content = '<h1>Saved Character JSON Import</h1> '
|
let content = '<h1>Saved Character JSON Import</h1> '
|
||||||
+ '<label for="character-json">Paste character JSON here:</label> '
|
+ '<label for="character-json">Paste character JSON here:</label> '
|
||||||
+ '</br>'
|
+ '</br>'
|
||||||
+ '<textarea id="character-json" name="character-json" rows="10" cols="50"></textarea>';
|
+ '<textarea id="character-json" name="character-json" rows="10" cols="50"></textarea>';
|
||||||
let importDialog = new Dialog({
|
let importDialog = new Dialog({
|
||||||
title: "Import Character from SW5e.com",
|
title: "Import Character from SW5e.com",
|
||||||
content: content,
|
content: content,
|
||||||
buttons: {
|
buttons: {
|
||||||
"Import": {
|
"Import": {
|
||||||
icon: '<i class="fas fa-file-import"></i>',
|
icon: '<i class="fas fa-file-import"></i>',
|
||||||
label: "Import Character",
|
label: "Import Character",
|
||||||
callback: (e) => {
|
callback: (e) => {
|
||||||
let characterData = $('#character-json').val();
|
let characterData = $('#character-json').val();
|
||||||
console.log('Parsing Character JSON');
|
console.log('Parsing Character JSON');
|
||||||
CharacterImporter.transform(characterData);
|
CharacterImporter.transform(characterData);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Cancel": {
|
"Cancel": {
|
||||||
icon: '<i class="fas fa-times-circle"></i>',
|
icon: '<i class="fas fa-times-circle"></i>',
|
||||||
label: "Cancel",
|
label: "Cancel",
|
||||||
callback: () => {},
|
callback: () => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
importDialog.render(true);
|
importDialog.render(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
2
sw5e.js
2
sw5e.js
|
@ -17,6 +17,7 @@ import { measureDistances, getBarAttribute } from "./module/canvas.js";
|
||||||
// Import Entities
|
// Import Entities
|
||||||
import Actor5e from "./module/actor/entity.js";
|
import Actor5e from "./module/actor/entity.js";
|
||||||
import Item5e from "./module/item/entity.js";
|
import Item5e from "./module/item/entity.js";
|
||||||
|
import CharacterImporter from "./module/characterImporter.js";
|
||||||
|
|
||||||
// Import Applications
|
// Import Applications
|
||||||
import AbilityTemplate from "./module/pixi/ability-template.js";
|
import AbilityTemplate from "./module/pixi/ability-template.js";
|
||||||
|
@ -248,6 +249,7 @@ Hooks.on("renderSceneDirectory", (app, html, data)=> {
|
||||||
});
|
});
|
||||||
Hooks.on("renderActorDirectory", (app, html, data)=> {
|
Hooks.on("renderActorDirectory", (app, html, data)=> {
|
||||||
setFolderBackground(html);
|
setFolderBackground(html);
|
||||||
|
CharacterImporter.addImportButton(html);
|
||||||
});
|
});
|
||||||
Hooks.on("renderItemDirectory", (app, html, data)=> {
|
Hooks.on("renderItemDirectory", (app, html, data)=> {
|
||||||
setFolderBackground(html);
|
setFolderBackground(html);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue