Foundry V10 Compatability and Skill Calculations
This commit is contained in:
@ -14,10 +14,10 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
const context = super.getData();
|
||||
|
||||
// Use a safe clone of the actor data for further operations.
|
||||
const actorData = this.actor.data.toObject(false);
|
||||
const actorData = this.actor.toObject(false);
|
||||
|
||||
// Add the actor's data to context.data for easier access, as well as flags.
|
||||
context.data = actorData.data;
|
||||
context.system = actorData.system;
|
||||
context.flags = actorData.flags;
|
||||
|
||||
// Prepare character data and items.
|
||||
@ -29,11 +29,38 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
// Prepare NPC data and items.
|
||||
if (actorData.type == 'npc') {
|
||||
this._prepareItems(context);
|
||||
}
|
||||
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
//Override this method to check for duplicates when things are dragged to the sheet
|
||||
// We don't want duplicate skills and skill categories.
|
||||
async _onDropItem(event, data) {
|
||||
|
||||
// Reconstruct the item from the event
|
||||
const newitem = await Item.implementation.fromDropData(data);
|
||||
const itemData = newitem.toObject();
|
||||
|
||||
if (itemData.type === "skill_category" || itemData.type === "skill"){
|
||||
|
||||
// Get the already owned Items from the actor and push into an array
|
||||
const owneditems = this.object.getOwnedSkillCategories();
|
||||
|
||||
console.log(owneditems);
|
||||
|
||||
var owneditemslist = Object.values(owneditems);
|
||||
|
||||
// Check if the dragged item is not in the array and not owned
|
||||
if (!owneditemslist.includes(itemData.name)) {
|
||||
console.log("Not Owned!");
|
||||
super._onDropItem(event, data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
super._onDropItem(event, data);
|
||||
}
|
||||
}
|
||||
|
||||
_prepareCharacterData(context) {
|
||||
}
|
||||
|
||||
@ -96,7 +123,7 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
// Render the item sheet for viewing/editing prior to the editable check.
|
||||
html.find('.item-edit').click(ev => {
|
||||
const item = this.actor.items.get(ev.currentTarget.getAttribute("data-item-id"));
|
||||
console.log(this);
|
||||
//console.log(this);
|
||||
item.sheet.render(true);
|
||||
});
|
||||
|
||||
@ -110,7 +137,7 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
// Delete Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const item = this.actor.items.get(ev.currentTarget.getAttribute("data-item-id"));
|
||||
console.log(ev.currentTarget.getAttribute("data-item-id"));
|
||||
//console.log(ev.currentTarget.getAttribute("data-item-id"));
|
||||
item.delete();
|
||||
});
|
||||
}
|
||||
@ -131,8 +158,8 @@ export default class RMSSPlayerSheet extends ActorSheet {
|
||||
data: data
|
||||
};
|
||||
// Remove the type from the dataset since it's in the itemData.type prop.
|
||||
delete itemData.data["type"];
|
||||
|
||||
//delete itemData.data["type"];
|
||||
delete itemData.data.type;
|
||||
// Finally, create the item!
|
||||
return await Item.create(itemData, {parent: this.actor});
|
||||
}
|
||||
|
@ -17,15 +17,18 @@ export default class RMSSArmorSheet extends ItemSheet {
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
getData() {
|
||||
const baseData = super.getData();
|
||||
async getData() {
|
||||
const baseData = await super.getData();
|
||||
|
||||
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable :this.isEditable,
|
||||
item: baseData.item,
|
||||
data: baseData.item.data.data,
|
||||
config: CONFIG.rmss
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
|
@ -17,15 +17,18 @@ export default class RMSSHerbAndPoisonSheet extends ItemSheet {
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
getData() {
|
||||
const baseData = super.getData();
|
||||
async getData() {
|
||||
const baseData = await super.getData();
|
||||
|
||||
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable :this.isEditable,
|
||||
item: baseData.item,
|
||||
data: baseData.item.data.data,
|
||||
config: CONFIG.rmss
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
|
@ -17,15 +17,18 @@ export default class RMSSItemSheet extends ItemSheet {
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
getData() {
|
||||
const baseData = super.getData();
|
||||
async getData() {
|
||||
const baseData = await super.getData();
|
||||
|
||||
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable :this.isEditable,
|
||||
item: baseData.item,
|
||||
data: baseData.item.data.data,
|
||||
config: CONFIG.rmss
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
|
@ -17,15 +17,18 @@ export default class RMSSTransportSheet extends ItemSheet {
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
getData() {
|
||||
const baseData = super.getData();
|
||||
async getData() {
|
||||
const baseData = await super.getData();
|
||||
|
||||
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable :this.isEditable,
|
||||
item: baseData.item,
|
||||
data: baseData.item.data.data,
|
||||
config: CONFIG.rmss
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
|
@ -17,15 +17,18 @@ export default class RMSSWeaponSheet extends ItemSheet {
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
getData() {
|
||||
const baseData = super.getData();
|
||||
async getData() {
|
||||
const baseData = await super.getData();
|
||||
|
||||
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable :this.isEditable,
|
||||
item: baseData.item,
|
||||
data: baseData.item.data.data,
|
||||
config: CONFIG.rmss
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
|
@ -17,36 +17,36 @@ export default class RMSSSkillCategorySheet extends ItemSheet {
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
getData() {
|
||||
const baseData = super.getData();
|
||||
async getData() {
|
||||
const context = await super.getData();
|
||||
|
||||
// Get a list of stats that can be used as applicable stats
|
||||
var applicable_stat_list = this.prepareApplicableStatValues(CONFIG);
|
||||
|
||||
|
||||
//Get the currently selected value for all three applicable stats
|
||||
var applicable_stat_1_selected = this.prepareApplicableSelectedStat("app_stat_1");
|
||||
var applicable_stat_2_selected = this.prepareApplicableSelectedStat("app_stat_2");
|
||||
var applicable_stat_3_selected = this.prepareApplicableSelectedStat("app_stat_3");
|
||||
|
||||
// Build the string for Applicable Stats
|
||||
var applicable_stat_text = this.buildApplicableStatsText(applicable_stat_1_selected, applicable_stat_2_selected, applicable_stat_3_selected)
|
||||
baseData.item.data.data['applicable_stats'] = applicable_stat_text
|
||||
// Build and apply the display string for Applicable Stats
|
||||
var applicable_stat_text = this.buildApplicableStatsText(applicable_stat_1_selected, applicable_stat_2_selected, applicable_stat_3_selected);
|
||||
//context.item.system['applicable_stats'] = applicable_stat_text;
|
||||
context.item.system.applicable_stats = applicable_stat_text;
|
||||
|
||||
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable :this.isEditable,
|
||||
item: baseData.item,
|
||||
data: baseData.item.data.data,
|
||||
item: context.item,
|
||||
system: context.item.system,
|
||||
config: CONFIG.rmss,
|
||||
applicable_stat_list: applicable_stat_list,
|
||||
applicable_stat_1_selected: applicable_stat_1_selected,
|
||||
applicable_stat_2_selected: applicable_stat_2_selected,
|
||||
applicable_stat_3_selected: applicable_stat_3_selected
|
||||
applicable_stat_3_selected: applicable_stat_3_selected,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
console.log(this.item)
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
|
||||
@ -60,19 +60,19 @@ export default class RMSSSkillCategorySheet extends ItemSheet {
|
||||
}
|
||||
|
||||
prepareApplicableStatValues(CONFIG) {
|
||||
var applicable_stat_1_list = {None: "None"}
|
||||
var applicable_stat_list = {None: "None"};
|
||||
|
||||
// Get a list of stat shortnames from the config
|
||||
for (const item in CONFIG.rmss.stats) {
|
||||
applicable_stat_1_list[CONFIG.rmss.stats[item]['shortname']] = CONFIG.rmss.stats[item]['shortname'];
|
||||
applicable_stat_list[CONFIG.rmss.stats[item].shortname] = CONFIG.rmss.stats[item].shortname;
|
||||
}
|
||||
return applicable_stat_1_list;
|
||||
return applicable_stat_list;
|
||||
}
|
||||
|
||||
// Determine which Stat is selected for applicable stats
|
||||
prepareApplicableSelectedStat(app_stat) {
|
||||
var applicable_stat_selected = "";
|
||||
applicable_stat_selected = this.item.data.data[app_stat];
|
||||
applicable_stat_selected = this.item.system[app_stat];
|
||||
return applicable_stat_selected;
|
||||
}
|
||||
|
||||
@ -80,19 +80,19 @@ export default class RMSSSkillCategorySheet extends ItemSheet {
|
||||
buildApplicableStatsText(app_stat_1, app_stat_2, app_stat_3) {
|
||||
|
||||
if (app_stat_1 === "None") {
|
||||
return("None")
|
||||
return("None");
|
||||
}
|
||||
else if (app_stat_1 !== "None" && app_stat_2 === "None") {
|
||||
return(app_stat_1)
|
||||
return(app_stat_1);
|
||||
}
|
||||
else if (app_stat_1 !== "None" && app_stat_2 !== "None" && app_stat_3 === "None" ) {
|
||||
return(app_stat_1 + "/" + app_stat_2 )
|
||||
return(app_stat_1 + "/" + app_stat_2 );
|
||||
}
|
||||
else if (app_stat_1 !== "None" && app_stat_2 !== "None" && app_stat_3 !== "None" ) {
|
||||
return(app_stat_1 + "/" + app_stat_2 + "/" + app_stat_3 )
|
||||
return(app_stat_1 + "/" + app_stat_2 + "/" + app_stat_3 );
|
||||
}
|
||||
else {
|
||||
return("None")
|
||||
return("None");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,17 +17,74 @@ export default class RMSSSkillSheet extends ItemSheet {
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
getData() {
|
||||
const baseData = super.getData();
|
||||
async getData() {
|
||||
const baseData = await super.getData();
|
||||
|
||||
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
// Get a list of the parent item's skill categories for the dropdown
|
||||
var owned_skillcats = this.prepareSkillCategoryValues();
|
||||
|
||||
// Figure out if a valid Skill Category is already selected
|
||||
var selected_skillcat = this.prepareSelectedSkillCategory(owned_skillcats, this.object.system.category);
|
||||
|
||||
this.prepareSelectedSkillCategoryBonus(selected_skillcat);
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable :this.isEditable,
|
||||
item: baseData.item,
|
||||
data: baseData.item.data.data,
|
||||
config: CONFIG.rmss
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
owned_skillcats: owned_skillcats,
|
||||
enrichedDescription: enrichedDescription,
|
||||
selected_skillcat: selected_skillcat
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
|
||||
prepareSkillCategoryValues() {
|
||||
// If there is no player owning this Skill then we cannot assign a category.
|
||||
var skillcat_list = {None: "Skill Has No Owner", };
|
||||
|
||||
if (this.item.isEmbedded === null) {
|
||||
return(skillcat_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
const skillcats = this.item.parent.getOwnedSkillCategories();
|
||||
return(skillcats);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which Stat is selected and test that it is in the current list of categories.
|
||||
prepareSelectedSkillCategory(ownedskillcats, selected_category) {
|
||||
|
||||
// Start By setting the owned category to None, if nothing happens this will be the default
|
||||
var default_selected_category = "None";
|
||||
|
||||
// Get a list of keys from the currently owned skill categories and compare to the current value
|
||||
if (Object.keys(ownedskillcats).includes(selected_category)) {
|
||||
return(selected_category);
|
||||
} else {
|
||||
return(default_selected_category);
|
||||
}
|
||||
}
|
||||
|
||||
prepareSelectedSkillCategoryBonus(selected_skillcat) {
|
||||
if (this.item.isEmbedded === null) {
|
||||
console.log("Skill has no owner");
|
||||
}
|
||||
else
|
||||
{
|
||||
const items = this.object.parent.items;
|
||||
|
||||
for (const item of items) {
|
||||
if (item.type === "skill_category" && item._id === selected_skillcat) {
|
||||
this.object.system.category_bonus = item.system.total_bonus;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,15 +16,18 @@ export default class RMSSSpellSheet extends ItemSheet {
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
getData() {
|
||||
const baseData = super.getData();
|
||||
async getData() {
|
||||
const baseData = await super.getData();
|
||||
|
||||
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable :this.isEditable,
|
||||
item: baseData.item,
|
||||
data: baseData.item.data.data,
|
||||
config: CONFIG.rmss
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
|
Reference in New Issue
Block a user