forked from GitHub-Mirrors/foundry-sw5e
Add species
This commit is contained in:
parent
e8d4153333
commit
9bbc9af285
1 changed files with 60 additions and 49 deletions
|
@ -1,52 +1,51 @@
|
||||||
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); //source character
|
const sourceCharacter = JSON.parse(rawCharacter); //source character
|
||||||
|
|
||||||
const details = {
|
const details = {
|
||||||
species: sourceCharacter.attribs.find(e => e.name == "race").current,
|
species: sourceCharacter.attribs.find((e) => e.name == "race").current,
|
||||||
background: sourceCharacter.attribs.find(e => e.name == "background").current,
|
background: sourceCharacter.attribs.find((e) => e.name == "background").current,
|
||||||
alignment: sourceCharacter.attribs.find(e => e.name == "alignment").current
|
alignment: sourceCharacter.attribs.find((e) => e.name == "alignment").current
|
||||||
}
|
};
|
||||||
|
|
||||||
const hp = {
|
const hp = {
|
||||||
value: sourceCharacter.attribs.find(e => e.name == "hp").current,
|
value: sourceCharacter.attribs.find((e) => e.name == "hp").current,
|
||||||
min: 0,
|
min: 0,
|
||||||
max: sourceCharacter.attribs.find(e => e.name == "hp").current,
|
max: sourceCharacter.attribs.find((e) => e.name == "hp").current,
|
||||||
temp: sourceCharacter.attribs.find(e => e.name == "hp_temp").current
|
temp: sourceCharacter.attribs.find((e) => e.name == "hp_temp").current
|
||||||
};
|
};
|
||||||
|
|
||||||
const ac = {
|
const ac = {
|
||||||
value: sourceCharacter.attribs.find(e => e.name == "ac").current
|
value: sourceCharacter.attribs.find((e) => e.name == "ac").current
|
||||||
};
|
};
|
||||||
|
|
||||||
const abilities = {
|
const abilities = {
|
||||||
str: {
|
str: {
|
||||||
value: sourceCharacter.attribs.find(e => e.name == "strength").current,
|
value: sourceCharacter.attribs.find((e) => e.name == "strength").current,
|
||||||
proficient: sourceCharacter.attribs.find(e => e.name == 'strength_save_prof').current ? 1 : 0
|
proficient: sourceCharacter.attribs.find((e) => e.name == "strength_save_prof").current ? 1 : 0
|
||||||
},
|
},
|
||||||
dex: {
|
dex: {
|
||||||
value: sourceCharacter.attribs.find(e => e.name == "dexterity").current,
|
value: sourceCharacter.attribs.find((e) => e.name == "dexterity").current,
|
||||||
proficient: sourceCharacter.attribs.find(e => e.name == 'dexterity_save_prof').current ? 1 : 0
|
proficient: sourceCharacter.attribs.find((e) => e.name == "dexterity_save_prof").current ? 1 : 0
|
||||||
},
|
},
|
||||||
con: {
|
con: {
|
||||||
value: sourceCharacter.attribs.find(e => e.name == "constitution").current,
|
value: sourceCharacter.attribs.find((e) => e.name == "constitution").current,
|
||||||
proficient: sourceCharacter.attribs.find(e => e.name == 'constitution_save_prof').current ? 1 : 0
|
proficient: sourceCharacter.attribs.find((e) => e.name == "constitution_save_prof").current ? 1 : 0
|
||||||
},
|
},
|
||||||
int: {
|
int: {
|
||||||
value: sourceCharacter.attribs.find(e => e.name == "intelligence").current,
|
value: sourceCharacter.attribs.find((e) => e.name == "intelligence").current,
|
||||||
proficient: sourceCharacter.attribs.find(e => e.name == 'intelligence_save_prof').current ? 1 : 0
|
proficient: sourceCharacter.attribs.find((e) => e.name == "intelligence_save_prof").current ? 1 : 0
|
||||||
},
|
},
|
||||||
wis: {
|
wis: {
|
||||||
value: sourceCharacter.attribs.find(e => e.name == "wisdom").current,
|
value: sourceCharacter.attribs.find((e) => e.name == "wisdom").current,
|
||||||
proficient: sourceCharacter.attribs.find(e => e.name == 'wisdom_save_prof').current ? 1 : 0
|
proficient: sourceCharacter.attribs.find((e) => e.name == "wisdom_save_prof").current ? 1 : 0
|
||||||
},
|
},
|
||||||
cha: {
|
cha: {
|
||||||
value: sourceCharacter.attribs.find(e => e.name == "charisma").current,
|
value: sourceCharacter.attribs.find((e) => e.name == "charisma").current,
|
||||||
proficient: sourceCharacter.attribs.find(e => e.name == 'charisma_save_prof').current ? 1 : 0
|
proficient: sourceCharacter.attribs.find((e) => e.name == "charisma_save_prof").current ? 1 : 0
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const targetCharacter = {
|
const targetCharacter = {
|
||||||
|
@ -64,58 +63,70 @@ export default class CharacterImporter {
|
||||||
|
|
||||||
let actor = await Actor.create(targetCharacter);
|
let actor = await Actor.create(targetCharacter);
|
||||||
|
|
||||||
const profession = sourceCharacter.attribs.find(e => e.name == "class").current;
|
const profession = sourceCharacter.attribs.find((e) => e.name == "class").current;
|
||||||
let professionLevel = sourceCharacter.attribs.find(e => e.name == "class_display").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
|
professionLevel = parseInt(professionLevel.replace(/[^0-9]/g, "")); //remove a-z, leaving only integers
|
||||||
CharacterImporter.addClasses(profession, professionLevel, actor);
|
this.addClasses(profession, professionLevel, actor);
|
||||||
|
|
||||||
|
this.addSpecies(sourceCharacter.attribs.find((e) => e.name == "race").current, actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async addClasses(profession, level, actor){
|
static async addClasses(profession, level, actor) {
|
||||||
let classes = await game.packs.get('sw5e.classes').getContent();
|
let classes = await game.packs.get("sw5e.classes").getContent();
|
||||||
let assignedClass = classes.find( c => c.name === profession );
|
let assignedClass = classes.find((c) => c.name === profession);
|
||||||
assignedClass.data.data.levels = level;
|
assignedClass.data.data.levels = level;
|
||||||
await actor.createEmbeddedEntity("OwnedItem", assignedClass.data, { displaySheet: false });
|
await actor.createEmbeddedEntity("OwnedItem", assignedClass.data, { displaySheet: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
static addImportButton(html){
|
static async addSpecies(race, actor) {
|
||||||
|
let species = await game.packs.get("sw5e.species").getContent();
|
||||||
|
let assignedSpecies = species.find((c) => c.name === race);
|
||||||
|
|
||||||
|
await actor.createEmbeddedEntity("OwnedItem", assignedSpecies.data, { displaySheet: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
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 =
|
||||||
+ '<label for="character-json">Paste character JSON here:</label> '
|
"<h1>Saved Character JSON Import</h1> " +
|
||||||
+ '</br>'
|
'<label for="character-json">Paste character JSON here:</label> ' +
|
||||||
+ '<textarea id="character-json" name="character-json" rows="10" cols="50"></textarea>';
|
"</br>" +
|
||||||
|
'<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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue