Start 0.8 support
This commit is contained in:
@ -23,34 +23,48 @@ export class SoSActorSheet extends ActorSheet {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getData() {
|
||||
let data = super.getData();
|
||||
|
||||
const objectData = SoSUtility.data(this.object);
|
||||
let formData = {
|
||||
title: this.title,
|
||||
id: objectData.id,
|
||||
type: objectData.type,
|
||||
img: objectData.img,
|
||||
name: objectData.name,
|
||||
editable: this.isEditable,
|
||||
cssClass: this.isEditable ? "editable" : "locked",
|
||||
data: foundry.utils.deepClone(this.object.data),
|
||||
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
|
||||
limited: this.object.limited,
|
||||
options: this.options,
|
||||
owner: this.document.isOwner
|
||||
};
|
||||
|
||||
this.actor.checkDeck();
|
||||
|
||||
data.data.edgecard = this.actor.getEdgesCard();
|
||||
data.data.deckSize = this.actor.getDeckSize();
|
||||
formData.edgecard = this.actor.getEdgesCard();
|
||||
formData.deckSize = this.actor.getDeckSize();
|
||||
|
||||
data.data.skills = this.actor.data.items.filter( item => item.type == 'skill').sort( (a, b) => {
|
||||
formData.skills = this.actor.data.items.filter( item => item.type == 'skill').sort( (a, b) => {
|
||||
if ( a.name > b.name ) return 1;
|
||||
return -1;
|
||||
});
|
||||
|
||||
data.data.skill1 = data.data.skills.slice(0, Math.ceil(data.data.skills.length/2) )
|
||||
data.data.skill2 = data.data.skills.slice(Math.ceil(data.data.skills.length/2), data.data.skills.length )
|
||||
data.data.consequences = this.actor.data.items.filter( item => item.type == 'consequence').sort( (a, b) => {
|
||||
|
||||
formData.skill1 = formData.skills.slice(0, Math.ceil(formData.skills.length/2) )
|
||||
formData.skill2 = formData.skills.slice(Math.ceil(formData.skills.length/2), formData.skills.length )
|
||||
formData.consequences = this.actor.data.items.filter( item => item.type == 'consequence').sort( (a, b) => {
|
||||
if ( a.name > b.name ) return 1;
|
||||
return -1;
|
||||
});
|
||||
data.data.gears = this.actor.data.items.filter( item => item.type == 'gear').concat( this.actor.data.items.filter( item => item.type == 'container') );
|
||||
formData.gears = this.actor.data.items.filter( item => item.type == 'gear').concat( this.actor.data.items.filter( item => item.type == 'container') );
|
||||
|
||||
// Build the gear tree
|
||||
data.data.gearsRoot = data.data.gears.filter(item => item.data.containerid == "");
|
||||
for ( let container of data.data.gearsRoot) {
|
||||
formData.gearsRoot = formData.gears.filter(item => item.data.containerid == "");
|
||||
for ( let container of formData.gearsRoot) {
|
||||
if ( container.type == 'container') {
|
||||
container.data.contains = []
|
||||
container.data.containerEnc = 0;
|
||||
for (let gear of data.data.gears) {
|
||||
if ( gear.data.containerid == container._id) {
|
||||
if ( gear.data.containerid == container.id) {
|
||||
container.data.contains.push( gear );
|
||||
if ( !gear.data.neg && !gear.data.software ) {
|
||||
container.data.containerEnc += (gear.big > 0) ? gear.big : 1;
|
||||
@ -60,25 +74,25 @@ export class SoSActorSheet extends ActorSheet {
|
||||
}
|
||||
}
|
||||
|
||||
data.data.weapons = this.actor.data.items.filter( item => item.type == 'weapon');
|
||||
data.data.armors = this.actor.data.items.filter( item => item.type == 'armor');
|
||||
data.data.totalEncumbrance = SoSUtility.computeEncumbrance(this.actor.data.items);
|
||||
data.data.wounds = duplicate(this.actor.data.data.wounds);
|
||||
data.data.isGM = game.user.isGM;
|
||||
data.data.currentWounds = this.actor.computeCurrentWounds();
|
||||
data.data.totalWounds = this.actor.data.data.scores.wound.value;
|
||||
formData.weapons = this.actor.data.items.filter( item => item.type == 'weapon');
|
||||
formData.armors = this.actor.data.items.filter( item => item.type == 'armor');
|
||||
formData.totalEncumbrance = SoSUtility.computeEncumbrance(this.actor.data.items);
|
||||
formData.wounds = duplicate(this.actor.data.data.wounds);
|
||||
formData.isGM = game.user.isGM;
|
||||
formData.currentWounds = this.actor.computeCurrentWounds();
|
||||
formData.totalWounds = this.actor.data.data.scores.wound.value;
|
||||
|
||||
data.data.subcultureList = this.actor.data.items.filter( item => item.type == 'subculture');
|
||||
if ( data.data.subculture != "" ) { // background.subculture contains the main subculture ID
|
||||
data.data.mainSubculture = data.data.subcultureList.find( subc => subc._id == data.data.subculture);
|
||||
formData.subcultureList = this.actor.data.items.filter( item => item.type == 'subculture');
|
||||
if ( formData.subculture != "" ) { // background.subculture contains the main subculture ID
|
||||
formData.mainSubculture = formData.subcultureList.find( subc => subc._id == data.data.subculture);
|
||||
}
|
||||
data.data.languageList = this.actor.data.items.filter( item => item.type == 'language');
|
||||
data.data.weaknessList = this.actor.data.items.filter( item => item.type == 'weakness');
|
||||
data.data.geneline = this.actor.data.items.find( item => item.type == 'geneline');
|
||||
data.data.editStatSkill = this.options.editStatSkill;
|
||||
//console.log("stats", data);
|
||||
formData.languageList = this.actor.data.items.filter( item => item.type == 'language');
|
||||
formData.weaknessList = this.actor.data.items.filter( item => item.type == 'weakness');
|
||||
formData.geneline = this.actor.data.items.find( item => item.type == 'geneline');
|
||||
formData.editStatSkill = this.options.editStatSkill;
|
||||
|
||||
return data;
|
||||
console.log("stats", formData);
|
||||
return formData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -94,7 +108,7 @@ export class SoSActorSheet extends ActorSheet {
|
||||
// Update Inventory Item
|
||||
html.find('.item-edit').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
const item = this.actor.getOwnedItem(li.data("item-id"));
|
||||
const item = this.actor.items.get(li.data("item-id"));
|
||||
item.sheet.render(true);
|
||||
});
|
||||
html.find('.item-equip').click(ev => {
|
||||
@ -163,7 +177,7 @@ export class SoSActorSheet extends ActorSheet {
|
||||
const li = $(event.currentTarget).parents(".item");
|
||||
const item = this.actor.getOwnedItem(li.data("item-id"));
|
||||
let severity = $(event.currentTarget).val();
|
||||
this.actor.updateOwnedItem( { _id: item._id, 'data.severity': severity});
|
||||
this.actor.updateOwnedItem( { id: item.id, 'data.severity': severity});
|
||||
this.render(true);
|
||||
});
|
||||
html.find('.lock-unlock-sheet').click((event) => {
|
||||
|
@ -34,17 +34,19 @@ export class SoSActor extends Actor {
|
||||
return actor;
|
||||
}
|
||||
|
||||
data.items = [];
|
||||
let items = [];
|
||||
let compendiumName = "foundryvtt-shadows-over-sol.skills";
|
||||
if ( compendiumName ) {
|
||||
let skills = await SoSUtility.loadCompendium(compendiumName);
|
||||
data.items = data.items.concat( skills );
|
||||
items = skills.map(i => i.toObject());
|
||||
}
|
||||
compendiumName = "foundryvtt-shadows-over-sol.consequences";
|
||||
if ( compendiumName ) {
|
||||
let consequences = await SoSUtility.loadCompendium(compendiumName)
|
||||
data.items = data.items.concat(consequences);
|
||||
items = items.concat( consequences.map(i => i.toObject()) );
|
||||
}
|
||||
data.items = items;
|
||||
console.log(data);
|
||||
|
||||
return super.create(data, options);
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ Hooks.once("init", async function () {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Define custom Entity classes
|
||||
CONFIG.Actor.entityClass = SoSActor;
|
||||
CONFIG.Combat.entityClass = SoSCombat;
|
||||
CONFIG.Actor.documentClass = SoSActor;
|
||||
CONFIG.Combat.documentClass = SoSCombat;
|
||||
CONFIG.SoS = {
|
||||
}
|
||||
|
||||
@ -83,8 +83,8 @@ Hooks.once("init", async function () {
|
||||
function welcomeMessage() {
|
||||
//ChatUtility.removeMyChatMessageContaining('<div id="welcome-message-sos">');
|
||||
ChatMessage.create({
|
||||
user: game.user._id,
|
||||
whisper: [game.user._id],
|
||||
user: game.user.id,
|
||||
whisper: [game.user.id],
|
||||
content: `<div id="welcome-message-sos"><span class="rdd-roll-part">Welcome !</div>
|
||||
` });
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ const severity2malus = { "none": 0, "light": -1, "moderate": -2, "severe": -3, "
|
||||
const severity2bonus = { "none": 0, "light": 1, "moderate": 2, "severe": 3, "critical": 4};
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class SoSUtility extends Entity {
|
||||
export class SoSUtility {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async preloadHandlebarsTemplates() {
|
||||
@ -55,6 +55,32 @@ export class SoSUtility extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static data(it) {
|
||||
if (it instanceof Actor || it instanceof Item || it instanceof Combatant) {
|
||||
return it.data;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static templateData(it) {
|
||||
return SoSUtility.data(it)?.data ?? {}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendiumData(compendium) {
|
||||
const pack = game.packs.get(compendium);
|
||||
return await pack?.getDocuments() ?? [];
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendium(compendium, filter = item => true) {
|
||||
let compendiumData = await SoSUtility.loadCompendiumData(compendium);
|
||||
return compendiumData.filter(filter);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendiumNames(compendium) {
|
||||
const pack = game.packs.get(compendium);
|
||||
@ -64,13 +90,13 @@ export class SoSUtility extends Entity {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendium(compendium, filter = item => true) {
|
||||
/*static async loadCompendium(compendium, filter = item => true) {
|
||||
let compendiumItems = await SoSUtility.loadCompendiumNames(compendium);
|
||||
|
||||
const pack = game.packs.get(compendium);
|
||||
let list = [];
|
||||
for (let compendiumItem of compendiumItems) {
|
||||
await pack.getEntity(compendiumItem._id).then(it => {
|
||||
await pack.getEntity(compendiumItem.id).then(it => {
|
||||
const item = it.data;
|
||||
if (filter(item)) {
|
||||
list.push(item);
|
||||
@ -78,7 +104,7 @@ export class SoSUtility extends Entity {
|
||||
});
|
||||
};
|
||||
return list;
|
||||
}
|
||||
}*/
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static updateCombat(combat, round, diff, id) {
|
||||
|
Reference in New Issue
Block a user