Rework folder organization
This commit is contained in:
133
module/sheets/skills/rmss_skill_category_sheet.js
Normal file
133
module/sheets/skills/rmss_skill_category_sheet.js
Normal file
@ -0,0 +1,133 @@
|
||||
// Our Item Sheet extends the default
|
||||
export default class RMSSSkillCategorySheet extends ItemSheet {
|
||||
|
||||
// Set the height and width
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 580,
|
||||
height: 440,
|
||||
template: "systems/rmss/templates/sheets/skills/rmss-skill-category-sheet.html",
|
||||
classes: ["rmss", "sheet", "item"]
|
||||
});
|
||||
}
|
||||
|
||||
// If our sheet is called here it is.
|
||||
get template() {
|
||||
return "systems/rmss/templates/sheets/skills/rmss-skill-category-sheet.html";
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
async getData() {
|
||||
const context = await super.getData();
|
||||
|
||||
// Get a list of stats that can be used as applicable stats
|
||||
let applicableStatList = this.prepareApplicableStatNames(CONFIG);
|
||||
|
||||
// Get the currently selected value for all three applicable stats
|
||||
let firstApplicableStat = this.prepareApplicableSelectedStat("app_stat_1");
|
||||
let secondApplicableStat = this.prepareApplicableSelectedStat("app_stat_2");
|
||||
let thirdApplicableStat = this.prepareApplicableSelectedStat("app_stat_3");
|
||||
|
||||
// Build and apply the display string for Applicable Stats
|
||||
let applicableStatText =
|
||||
this.buildApplicableStatsText(firstApplicableStat, secondApplicableStat, thirdApplicableStat);
|
||||
context.item.system.applicable_stats = applicableStatText;
|
||||
|
||||
let enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable: this.isEditable,
|
||||
item: context.item,
|
||||
system: context.item.system,
|
||||
config: CONFIG.rmss,
|
||||
applicable_stat_list: applicableStatList,
|
||||
applicable_stat_1_selected: firstApplicableStat,
|
||||
applicable_stat_2_selected: secondApplicableStat,
|
||||
applicable_stat_3_selected: thirdApplicableStat,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
return sheetData;
|
||||
}
|
||||
|
||||
async _setApplicableStat(item, ev) {
|
||||
// Build a JSON Object from the selected tag value and selected name (item data attribute key)
|
||||
let updateKey = ev.currentTarget.getAttribute("name");
|
||||
let updateData = ev.target.value;
|
||||
|
||||
// Update Item Data
|
||||
await item.update({[updateKey]: updateData});
|
||||
}
|
||||
|
||||
// Each Skill Category can have up to three Applicable Stats that apply to it. We need to get a list of
|
||||
// the Stat Shortnames from Config so the user can select which stats are applicable to this Skill Category
|
||||
prepareApplicableStatNames(config) {
|
||||
let applicableStatList = {None: "None"};
|
||||
for (const item in config.rmss.stats) {
|
||||
applicableStatList[config.rmss.stats[item].shortname] = config.rmss.stats[item].shortname;
|
||||
}
|
||||
return applicableStatList;
|
||||
}
|
||||
|
||||
// Get the values for the currently selected Applicable Stat so we can display it on the Skill Category Sheet
|
||||
// If nothing is selected return an empty string.
|
||||
prepareApplicableSelectedStat(appStat) {
|
||||
let applicableStatSelected = "";
|
||||
applicableStatSelected = this.item.system[appStat];
|
||||
return applicableStatSelected;
|
||||
}
|
||||
|
||||
// The character sheet has an information field that displays the applicable stats in the following format
|
||||
// St/Ag/St. This method checks the current applicable stats and builds that field so
|
||||
// it can be displayed to the user.
|
||||
buildApplicableStatsText(firstAppStat, secondAppStat, thirdAppStat) {
|
||||
if (firstAppStat === "None") {
|
||||
return ("None");
|
||||
}
|
||||
else if (firstAppStat !== "None" && secondAppStat === "None") {
|
||||
return (firstAppStat);
|
||||
}
|
||||
else if (firstAppStat !== "None" && secondAppStat !== "None" && thirdAppStat === "None" ) {
|
||||
return (`${firstAppStat}/${secondAppStat}`);
|
||||
}
|
||||
else if (firstAppStat !== "None" && secondAppStat !== "None" && thirdAppStat !== "None" ) {
|
||||
return (`${firstAppStat}/${secondAppStat}/${thirdAppStat}`);
|
||||
}
|
||||
else {
|
||||
return ("None");
|
||||
}
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.isEditable) return;
|
||||
|
||||
// Every time the user selects one of the Applicable Stat dropdowns
|
||||
// fire an event to change the value in the Skill Category
|
||||
html.find(".stat-selector").change(ev => {
|
||||
this._setApplicableStat(this.item, ev);
|
||||
});
|
||||
|
||||
// Catch the event when the user clicks one of the New Ranks Checkboxes in a Skill Category.
|
||||
// It will increment by one or wrap back to zero on a value of three
|
||||
html.find(".skillcategorysheet-newrank").click(ev => {
|
||||
switch (ev.currentTarget.getAttribute("value")) {
|
||||
case "0":
|
||||
this.object.update({system: {new_ranks: { value: 1 }}});
|
||||
break;
|
||||
case "1":
|
||||
this.object.update({system: {new_ranks: { value: 2 }}});
|
||||
break;
|
||||
case "2":
|
||||
this.object.update({system: {new_ranks: { value: 3 }}});
|
||||
break;
|
||||
case "3":
|
||||
this.object.update({system: {new_ranks: { value: 0 }}});
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
115
module/sheets/skills/rmss_skill_sheet.js
Normal file
115
module/sheets/skills/rmss_skill_sheet.js
Normal file
@ -0,0 +1,115 @@
|
||||
// Our Item Sheet extends the default
|
||||
export default class RMSSSkillSheet extends ItemSheet {
|
||||
|
||||
// Set the height and width
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 530,
|
||||
height: 440,
|
||||
template: "systems/rmss/templates/sheets/skills/rmss-skill-sheet.html",
|
||||
classes: ["rmss", "sheet", "item"]
|
||||
});
|
||||
}
|
||||
|
||||
// If our sheet is called here it is.
|
||||
get template() {
|
||||
return "systems/rmss/templates/sheets/skills/rmss-skill-sheet.html";
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
async getData() {
|
||||
const baseData = await super.getData();
|
||||
|
||||
let enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
|
||||
|
||||
// Get a list of the parent item's skill categories for the dropdown
|
||||
let ownedSkillCategories = this.prepareSkillCategoryValues();
|
||||
|
||||
// Figure out if a valid Skill Category is already selected
|
||||
let selectedSkillCategory = this.prepareSelectedSkillCategory(ownedSkillCategories, this.object.system.category);
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable: this.isEditable,
|
||||
item: baseData.item,
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
owned_skillcats: ownedSkillCategories,
|
||||
enrichedDescription: enrichedDescription,
|
||||
selected_skillcat: selectedSkillCategory,
|
||||
designations: CONFIG.rmss.skill_designations
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Catch the event when the user clicks one of the New Ranks Checkboxes in a Skill.
|
||||
// It will increment by one or wrap back to zero on a value of three
|
||||
html.find(".skillsheet-newrank").click(ev => {
|
||||
switch (ev.currentTarget.getAttribute("value")) {
|
||||
case "0":
|
||||
this.object.update({system: {new_ranks: { value: 1 }}});
|
||||
break;
|
||||
case "1":
|
||||
this.object.update({system: {new_ranks: { value: 2 }}});
|
||||
break;
|
||||
case "2":
|
||||
this.object.update({system: {new_ranks: { value: 3 }}});
|
||||
break;
|
||||
case "3":
|
||||
this.object.update({system: {new_ranks: { value: 0 }}});
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Skills are related to Skill Categories so we need something to allow the user to choose that relationship
|
||||
// If this Skill is owned then we will return a list of Skill Categories and allow them to choose
|
||||
// Otherwise we'll just return 'Skill has no owner'
|
||||
prepareSkillCategoryValues() {
|
||||
let skillNoOwner = {None: "Skill Has No Owner"};
|
||||
|
||||
if (this.item.isEmbedded === null) {
|
||||
return (skillNoOwner);
|
||||
}
|
||||
else
|
||||
{
|
||||
const skillCategories = this.item.parent.getOwnedItemsByType("skill_category");
|
||||
return (skillCategories);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which Skill Category is selected and test that it is in the current list of categories.
|
||||
// If it isn't set it to None.
|
||||
prepareSelectedSkillCategory(ownedSkillCategories, selectedSkillCategory) {
|
||||
let defaultSelectedCategory = "None";
|
||||
if (Object.keys(ownedSkillCategories).includes(selectedSkillCategory)) {
|
||||
return (selectedSkillCategory);
|
||||
} else {
|
||||
return (defaultSelectedCategory);
|
||||
}
|
||||
}
|
||||
|
||||
// Populate the Skill Category Bonus field on the Skill Sheet.
|
||||
// Iterate through the owned skill categories and if one of them matches the item id of currently
|
||||
// selected skill category then set the Skill Category Bonus field to the Total Bonus field of the Skill 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) {
|
||||
console.log(`rmss | rmss_skill_sheet | Calculating Skill Category bonus for skill: ${this.object.name}`);
|
||||
this.object.system.category_bonus = item.system.total_bonus;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user