Add New Ranks chceckboxes

Fix Updates for Skill/Skill Category Totals
Inventory Implementation
This commit is contained in:
Anthony Murphy
2022-09-18 21:31:15 +10:00
parent cfc645d888
commit cab5aa07f3
32 changed files with 1180 additions and 333 deletions

View File

@ -53,8 +53,8 @@ rmss.stats = {
};
rmss.skill_designations = {
none: "None",
occupational: "Occupational",
everyman: "Everyman",
restricted: "Restricted"
None: "None",
Occupational: "Occupational",
Everyman: "Everyman",
Restricted: "Restricted"
};

View File

@ -146,26 +146,17 @@ export class RMSSActor extends Actor {
// For each skill category return an object in this format.
// {{ _id: "skill category name"}}
// This is the format that the select helper on the skill sheet needs
getOwnedSkillCategories() {
var ownedSkillCategories = {None: "None"};
console.log("rmss | actor.js | Getting owned skill categories for: " + this.name);
getOwnedItemsByType(item_type) {
var ownedItems = {None: "None"};
console.log("rmss | actor.js | Getting owned " + item_type + " for: " + this.name);
for (const item of this.items) {
if (item.type === "skill_category") {
ownedSkillCategories[item._id] = item.name;
if (item.type === item_type) {
ownedItems[item._id] = item.name;
}
}
return(ownedSkillCategories);
return(ownedItems);
}
getOwnedSkills() {
var ownedSkills = {None: "None"};
console.log("rmss | actor.js | Getting owned skills for: " + this.name);
for (const item of this.items) {
if (item.type === "skill") {
ownedSkills[item._id] = item.name;
}
}
return(ownedSkills);
}
}

View File

@ -45,9 +45,7 @@ export default class RMSSPlayerSheet extends ActorSheet {
if (itemData.type === "skill_category"){
// Get the already owned Items from the actor and push into an array
const owneditems = this.object.getOwnedSkillCategories();
console.log(owneditems);
const owneditems = this.object.getOwnedItemsByType("skill_category");
var ownedskillcatlist = Object.values(owneditems);
@ -58,9 +56,7 @@ export default class RMSSPlayerSheet extends ActorSheet {
}
} else if ( itemData.type === "skill") {
// Get the already owned Items from the actor and push into an array
const owneditems = this.object.getOwnedSkills();
console.log(owneditems);
const owneditems = this.object.getOwnedItemsByType("skill");
var ownedskilllist = Object.values(owneditems);
@ -84,14 +80,23 @@ export default class RMSSPlayerSheet extends ActorSheet {
const gear = [];
const playerskill= [];
const skillcat = [];
const weapons = [];
const equipables = [];
const herbs = [];
// Iterate through items, allocating to containers
for (let i of context.items) {
i.img = i.img || DEFAULT_TOKEN;
// Append to gear.
if (i.type === 'item' || i.type === 'armor' || i.type === 'weapon' || i.type === 'herb_or_poison') {
if (i.type === 'item') {
gear.push(i);
}
else if (i.type === 'weapon') {
weapons.push(i);
}
else if (i.type === 'herb_or_poison') {
herbs.push(i);
}
// Append to skill categories.
else if (i.type === 'skill_category') {
skillcat.push(i);
@ -99,9 +104,13 @@ export default class RMSSPlayerSheet extends ActorSheet {
// Append to playerskill
else if (i.type === 'skill') {
playerskill.push(i);
}
else if (i.type === 'armor') {
equipables.push(i);
}
}
// Sort Skill/Skillcat Arrays
skillcat.sort(function (a, b){
if (a.name < b.name) {
@ -128,13 +137,14 @@ export default class RMSSPlayerSheet extends ActorSheet {
context.gear = gear;
context.skillcat = skillcat;
context.playerskill = playerskill;
context.weapons = weapons;
context.equipables = equipables;
context.herbs = herbs;
}
activateListeners(html) {
super.activateListeners(html);
// NOTE: Can you do skill/item favorites this way?
// 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"));
@ -151,8 +161,8 @@ export default class RMSSPlayerSheet extends ActorSheet {
// Delete Item
html.find('.item-delete').click(ev => {
console.log(ev.currentTarget.getAttribute("data-item-id"));
const item = this.actor.items.get(ev.currentTarget.getAttribute("data-item-id"));
//console.log(ev.currentTarget.getAttribute("data-item-id"));
item.delete();
});
@ -170,6 +180,52 @@ export default class RMSSPlayerSheet extends ActorSheet {
}
console.log("After change: " + item.system.favorite);
});
// Equip/Unequip Item
html.find('.equippable').click(ev => {
const item = this.actor.items.get(ev.currentTarget.getAttribute("data-item-id"));
console.log(item);
console.log("Before change: " + item.system.equipped);
if (item.system.equipped === true) {
console.log("Setting False");
item.update({system: {"equipped": false}});
} else {
console.log("Setting True");
item.update({system: {"equipped": true}});
}
console.log("After change: " + item.system.equipped);
});
// Change New Ranks value when clicked in player sheet. From 0-3.
html.find('.skill-newrank').click(ev => {
const item = this.actor.items.get(ev.currentTarget.getAttribute("data-item-id"));
console.log("Firing in the Player Sheet");
console.log(ev.currentTarget.getAttribute("value"));
console.log(ev.currentTarget.getAttribute("data-item-id"));
switch(ev.currentTarget.getAttribute("value")) {
case "0":
console.log("Skill NewRanks is 0 setting to 1");
item.update({system: {new_ranks:{ "value": 1 }}});
break;
case "1":
console.log("Skill NewRanks is 1 setting to 2");
item.update({system: {new_ranks:{ "value": 2 }}});
break;
case "2":
console.log("Skill NewRanks is 2 setting to 3");
item.update({system: {new_ranks:{ "value": 3 }}});
break;
case "3":
console.log("Skill NewRanks is 3 setting to 0");
item.update({system: {new_ranks:{ "value": 0 }}});
break;
}
});
}
async _onItemCreate(event) {

View File

@ -21,17 +21,16 @@ export default class RMSSSkillCategorySheet extends ItemSheet {
const context = await super.getData();
// Get a list of stats that can be used as applicable stats
var applicable_stat_list = this.prepareApplicableStatValues(CONFIG);
var applicableStatList = this.prepareApplicableStatNames(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");
var firstApplicableStat = this.prepareApplicableSelectedStat("app_stat_1");
var secondApplicableStat = this.prepareApplicableSelectedStat("app_stat_2");
var thirdApplicableStat = this.prepareApplicableSelectedStat("app_stat_3");
// 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 applicableStatText = this.buildApplicableStatsText(firstApplicableStat, secondApplicableStat, thirdApplicableStat);
context.item.system.applicable_stats = applicableStatText;
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
@ -41,55 +40,57 @@ export default class RMSSSkillCategorySheet extends ItemSheet {
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_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 select tag value and select name (item data attribute key)
var update_key = ev.currentTarget.getAttribute("name");
var update_data = ev.target.value;
// Build a JSON Object from the selected tag value and selected name (item data attribute key)
var updateKey = ev.currentTarget.getAttribute("name");
var updateData = ev.target.value;
// Update Item Data
await item.update({[update_key]: update_data});
await item.update({[updateKey]: updateData});
}
prepareApplicableStatValues(CONFIG) {
var applicable_stat_list = {None: "None"};
// Get a list of stat shortnames from the config
for (const item in CONFIG.rmss.stats) {
applicable_stat_list[CONFIG.rmss.stats[item].shortname] = CONFIG.rmss.stats[item].shortname;
// 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) {
var applicableStatList = {None: "None"};
for (const item in config.rmss.stats) {
applicableStatList[config.rmss.stats[item].shortname] = config.rmss.stats[item].shortname;
}
return applicable_stat_list;
return applicableStatList;
}
// Determine which Stat is selected for applicable stats
prepareApplicableSelectedStat(app_stat) {
var applicable_stat_selected = "";
applicable_stat_selected = this.item.system[app_stat];
return applicable_stat_selected;
// 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) {
var applicableStatSelected = "";
applicableStatSelected = this.item.system[appStat];
return applicableStatSelected;
}
// Build the text that is displayed in the Applicable Stats field
buildApplicableStatsText(app_stat_1, app_stat_2, app_stat_3) {
if (app_stat_1 === "None") {
// 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 (app_stat_1 !== "None" && app_stat_2 === "None") {
return(app_stat_1);
else if (firstAppStat !== "None" && secondAppStat === "None") {
return(firstAppStat);
}
else if (app_stat_1 !== "None" && app_stat_2 !== "None" && app_stat_3 === "None" ) {
return(app_stat_1 + "/" + app_stat_2 );
else if (firstAppStat !== "None" && secondAppStat !== "None" && thirdAppStat === "None" ) {
return(firstAppStat + "/" + secondAppStat );
}
else if (app_stat_1 !== "None" && app_stat_2 !== "None" && app_stat_3 !== "None" ) {
return(app_stat_1 + "/" + app_stat_2 + "/" + app_stat_3 );
else if (firstAppStat !== "None" && secondAppStat !== "None" && thirdAppStat !== "None" ) {
return(firstAppStat + "/" + secondAppStat + "/" + thirdAppStat );
}
else {
return("None");
@ -103,7 +104,8 @@ export default class RMSSSkillCategorySheet extends ItemSheet {
// Everything below here is only needed if the sheet is editable
if (!this.isEditable) return;
// Update Applicable Stats for Skill Categories
// 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);
});

View File

@ -22,16 +22,11 @@ export default class RMSSSkillSheet extends ItemSheet {
var enrichedDescription = await TextEditor.enrichHTML(this.item.system.description, {async: true});
// Get a list of stats that can be used as applicable stats
var designations = this.getSkillDesignations(CONFIG);
// Get a list of the parent item's skill categories for the dropdown
var owned_skillcats = this.prepareSkillCategoryValues();
var ownedSkillCategories = 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);
var selectedSkillCategory = this.prepareSelectedSkillCategory(ownedSkillCategories, this.object.system.category);
let sheetData = {
owner: this.item.isOwner,
@ -39,53 +34,68 @@ export default class RMSSSkillSheet extends ItemSheet {
item: baseData.item,
system: baseData.item.system,
config: CONFIG.rmss,
owned_skillcats: owned_skillcats,
owned_skillcats: ownedSkillCategories,
enrichedDescription: enrichedDescription,
selected_skillcat: selected_skillcat,
designations: designations
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.
// 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() {
// If there is no player owning this Skill then we cannot assign a category.
var skillcat_list = {None: "Skill Has No Owner", };
var skillNoOwner = {None: "Skill Has No Owner", };
if (this.item.isEmbedded === null) {
return(skillcat_list);
return(skillNoOwner);
}
else
{
const skillcats = this.item.parent.getOwnedSkillCategories();
return(skillcats);
const skillCategories = this.item.parent.getOwnedItemsByType("skill_category");
return(skillCategories);
}
}
getSkillDesignations(CONFIG) {
var designations = {};
// Get a list of designations from the config
for (const item in CONFIG.rmss.skill_designations) {
designations[CONFIG.rmss.skill_designations[item]] = CONFIG.rmss.skill_designations[item];
}
return designations;
}
// 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);
// 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) {
var defaultSelectedCategory = "None";
if (Object.keys(ownedSkillCategories).includes(selectedSkillCategory)) {
return(selectedSkillCategory);
} else {
return(default_selected_category);
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 select 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");