forked from GitHub-Mirrors/foundry-sw5e
Temp - everything is broken
This commit is contained in:
parent
a291d0c909
commit
3d7c24ca17
2 changed files with 122 additions and 14 deletions
|
@ -347,7 +347,11 @@ export default class ActorSheet5eCharacterNew extends ActorSheet5e {
|
||||||
if ( itemData.type === "class" ) {
|
if ( itemData.type === "class" ) {
|
||||||
const cls = this.actor.itemTypes.class.find(c => c.name === itemData.name);
|
const cls = this.actor.itemTypes.class.find(c => c.name === itemData.name);
|
||||||
const classWasAlreadyPresent = !!cls;
|
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
|
// Add new features for class level
|
||||||
if ( !classWasAlreadyPresent ) {
|
if ( !classWasAlreadyPresent ) {
|
||||||
Actor5e.getClassFeatures(itemData).then(features => {
|
Actor5e.getClassFeatures(itemData).then(features => {
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
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
|
||||||
|
@ -44,6 +47,10 @@ export default class CharacterImporter {
|
||||||
const survivalSkill = sourceCharacter.attribs.find(o => o.name == 'survival_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 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 = {
|
const targetCharacter = {
|
||||||
name: sourceCharacter.name,
|
name: sourceCharacter.name,
|
||||||
type: "character",
|
type: "character",
|
||||||
|
@ -160,20 +167,117 @@ export default class CharacterImporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let newActor = await Actor.create(targetCharacter);
|
function addInitialClassAndLevel(itemData){
|
||||||
let actor = await game.actors.get(newActor.id);
|
Actor5e.getClassFeatures(itemData).then(features => {
|
||||||
let classes = await game.packs.get('sw5e.classes');
|
actor.createEmbeddedEntity("OwnedItem", features);
|
||||||
let content = await classes.getContent();
|
});
|
||||||
let scout = content.find(o => o.name == 'Scout');
|
}
|
||||||
console.log(actor);
|
|
||||||
console.log(classes);
|
async function addSubsequentLevels(targetLvl, actor){
|
||||||
console.log(content);
|
actor.data.data.details.level = targetLvl;
|
||||||
console.log(Object.entries(actor.apps))
|
var x = await actor.items.find(x => x.name == 'Scout');
|
||||||
console.log(Object.keys(actor.apps))
|
x.data.data.levels = 6;
|
||||||
console.log(Object.values(actor.apps))
|
|
||||||
//actor.apps[46]._onDropItemCreate(scout);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
let actor = await Actor.create(targetCharacter);
|
||||||
|
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);
|
||||||
|
|
||||||
|
addInitialClassAndLevel(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();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static addImportButton(html){
|
static addImportButton(html){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue