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,6 +1,3 @@
|
|||
import Actor5e from "./actor/entity.js";
|
||||
import ActorSheet5eCharacterNew from "./actor/sheets/newSheet/character.js";
|
||||
|
||||
export default class CharacterImporter {
|
||||
|
||||
// transform JSON from sw5e.com to Foundry friendly format
|
||||
|
@ -26,40 +23,6 @@ export default class CharacterImporter {
|
|||
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;
|
||||
|
||||
let characterJSON = {
|
||||
character: character,
|
||||
features: features,
|
||||
classes: classes,
|
||||
inventory: inventory,
|
||||
spells: spells,
|
||||
actions: actions,
|
||||
itemSpells: itemSpells,
|
||||
};
|
||||
// v2 - skills and proficiencies
|
||||
/*
|
||||
const acrobaticsSkill = sourceCharacter.attribs.find(o => o.name == 'acrobatics_bonus').current;
|
||||
const animalHandlingSkill = sourceCharacter.attribs.find(o => o.name == 'animal_handling_bonus').current;
|
||||
const athleticsSkill = sourceCharacter.attribs.find(o => o.name == 'athletics_bonus').current;
|
||||
const deceptionSkill = sourceCharacter.attribs.find(o => o.name == 'deception_bonus').current;
|
||||
const insightSkill = sourceCharacter.attribs.find(o => o.name == 'insight_bonus').current;
|
||||
const intimidationSkill = sourceCharacter.attribs.find(o => o.name == 'intimidation_bonus').current;
|
||||
const investigationSkill = sourceCharacter.attribs.find(o => o.name == 'investigation_bonus').current;
|
||||
const loreSkill = sourceCharacter.attribs.find(o => o.name == 'lore_bonus').current;
|
||||
const medicineSkill = sourceCharacter.attribs.find(o => o.name == 'medicine_bonus').current;
|
||||
const natureSkill = sourceCharacter.attribs.find(o => o.name == 'nature_bonus').current;
|
||||
const pilotingSkill = sourceCharacter.attribs.find(o => o.name == 'piloting_bonus').current;
|
||||
const perceptionSkill = sourceCharacter.attribs.find(o => o.name == 'perception_bonus').current;
|
||||
const performanceSkill = sourceCharacter.attribs.find(o => o.name == 'performance_bonus').current;
|
||||
const persuasionSkill = sourceCharacter.attribs.find(o => o.name == 'persuasion_bonus').current;
|
||||
const sleightOfHandSkill = sourceCharacter.attribs.find(o => o.name == 'sleight_of_hand_bonus').current;
|
||||
const stealthSkill = sourceCharacter.attribs.find(o => o.name == 'stealth_bonus').current;
|
||||
const survivalSkill = sourceCharacter.attribs.find(o => o.name == 'survival_bonus').current;
|
||||
const technologySkill = 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;
|
||||
*/
|
||||
|
||||
const targetCharacter = {
|
||||
name: sourceCharacter.name,
|
||||
type: "character",
|
||||
|
@ -178,13 +141,7 @@ export default class CharacterImporter {
|
|||
}
|
||||
};
|
||||
|
||||
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);
|
||||
|
@ -240,92 +197,7 @@ export default class CharacterImporter {
|
|||
// //}
|
||||
// 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
|
||||
// then add new features as long as level increases
|
||||
if ( classWasAlreadyPresent ) {
|
||||
const lvl = cls.data.data.levels;
|
||||
const newLvl = Math.min(lvl + 1, 20 + lvl - actor.data.data.details.level);
|
||||
if ( !(lvl === newLvl) ) {
|
||||
cls.update({"data.levels": newLvl});
|
||||
itemData.data.levels = newLvl;
|
||||
Actor5e.getClassFeatures(itemData).then(features => {
|
||||
actor.createEmbeddedEntity("OwnedItem", features);
|
||||
});
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
/*
|
||||
await newActorSheet._onDropItemCreate(scout);
|
||||
await newActorSheet._onDropItemCreate(scout);
|
||||
await newActorSheet._onDropItemCreate(scout);
|
||||
*/
|
||||
|
||||
/*
|
||||
var newActor = game.actors.find(o => o.name === 'Strom Klovrah');
|
||||
var classes = await game.packs.get('sw5e.classes');
|
||||
var content = await classes.getContent();
|
||||
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);
|
||||
await newActorSheet._onDropItemCreate(scout);
|
||||
await newActorSheet.close();
|
||||
var newActorSheet = new game.sw5e.applications.ActorSheet5eCharacterNew(newActor);
|
||||
await newActorSheet._onDropItemCreate(scout);
|
||||
await newActorSheet.close();
|
||||
*/
|
||||
//await newActorSheet.close();
|
||||
}
|
||||
|
||||
static addImportButton(html){
|
||||
|
|
2
sw5e.js
2
sw5e.js
|
@ -17,6 +17,7 @@ import { measureDistances, getBarAttribute } from "./module/canvas.js";
|
|||
// Import Entities
|
||||
import Actor5e from "./module/actor/entity.js";
|
||||
import Item5e from "./module/item/entity.js";
|
||||
import CharacterImporter from "./module/characterImporter.js";
|
||||
|
||||
// Import Applications
|
||||
import AbilityTemplate from "./module/pixi/ability-template.js";
|
||||
|
@ -248,6 +249,7 @@ Hooks.on("renderSceneDirectory", (app, html, data)=> {
|
|||
});
|
||||
Hooks.on("renderActorDirectory", (app, html, data)=> {
|
||||
setFolderBackground(html);
|
||||
CharacterImporter.addImportButton(html);
|
||||
});
|
||||
Hooks.on("renderItemDirectory", (app, html, data)=> {
|
||||
setFolderBackground(html);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue