Rework folder organization
This commit is contained in:
390
module/sheets/actors/rmss_player_sheet.js
Normal file
390
module/sheets/actors/rmss_player_sheet.js
Normal file
@ -0,0 +1,390 @@
|
||||
export default class RMSSPlayerSheet extends ActorSheet {
|
||||
|
||||
// Override Default Options, Set CSS Classes, Set Default Sheet, Set up Sheet Tabs
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 860,
|
||||
height: 780,
|
||||
template: "systems/rmss/templates/sheets/actors/rmss-character-sheet.html",
|
||||
classes: ["rmss", "sheet", "actor"],
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "features" }]
|
||||
});
|
||||
}
|
||||
|
||||
// Make the data available to the sheet template
|
||||
async getData() {
|
||||
const context = super.getData();
|
||||
|
||||
// Use a safe clone of the actor data for further operations.
|
||||
const actorData = this.actor.toObject(false);
|
||||
|
||||
let enrichedDescription = await TextEditor.enrichHTML(this.actor.system.description, {async: true});
|
||||
|
||||
// Add the actor's data to context.data for easier access, as well as flags.
|
||||
context.system = actorData.system;
|
||||
context.flags = actorData.flags;
|
||||
context.enrichedDescription = enrichedDescription;
|
||||
|
||||
// Prepare character data and items.
|
||||
if (actorData.type === "character") {
|
||||
this._prepareItems(context);
|
||||
this._prepareCharacterData(context);
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
// To Do: Seperate Skills and Skill Categories. Increment Counts for items
|
||||
if (itemData.type === "skill_category") {
|
||||
|
||||
// Get the already owned Items from the actor and push into an array
|
||||
const owneditems = this.object.getOwnedItemsByType("skill_category");
|
||||
|
||||
let ownedskillcatlist = Object.values(owneditems);
|
||||
|
||||
// Check if the dragged item is not in the array and not owned
|
||||
if (!ownedskillcatlist.includes(itemData.name)) {
|
||||
console.log("Not Owned!");
|
||||
super._onDropItem(event, data);
|
||||
}
|
||||
} else if ( itemData.type === "skill") {
|
||||
// Get the already owned Items from the actor and push into an array
|
||||
const owneditems = this.object.getOwnedItemsByType("skill");
|
||||
|
||||
let ownedskilllist = Object.values(owneditems);
|
||||
|
||||
// Check if the dragged item is not in the array and not owned
|
||||
if (!ownedskilllist.includes(itemData.name)) {
|
||||
console.log("Not Owned!");
|
||||
super._onDropItem(event, data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
super._onDropItem(event, data);
|
||||
}
|
||||
}
|
||||
|
||||
_prepareCharacterData(context) {
|
||||
// Calculate Power Point Exhaustion
|
||||
let powerpointPercentage = (Number(context.system.attributes.power_points.current) / Number(context.system.attributes.power_points.max)) * 100;
|
||||
|
||||
console.log(true);
|
||||
|
||||
switch (true) {
|
||||
case (powerpointPercentage < 25):
|
||||
context.system.attributes.power_points.modifier = "PP Exhaustion Penalty: -30 ";
|
||||
break;
|
||||
case (powerpointPercentage < 50):
|
||||
context.system.attributes.power_points.modifier = "PP Exhaustion Penalty: -20 ";
|
||||
break;
|
||||
case (powerpointPercentage < 75):
|
||||
console.log("Less than 75");
|
||||
context.system.attributes.power_points.modifier = "PP Exhaustion Penalty: -10 ";
|
||||
break;
|
||||
default:
|
||||
console.log("Setting Default");
|
||||
context.system.attributes.power_points.modifier = "PP Exhaustion Penalty: 0 ";
|
||||
}
|
||||
|
||||
// Calculate Exhaustion Point Penalty
|
||||
let exhaustionPercentage = (Number(context.system.attributes.exhaustion_points.current) / Number(context.system.attributes.exhaustion_points.max)) * 100;
|
||||
|
||||
console.log(true);
|
||||
|
||||
switch (true) {
|
||||
case (exhaustionPercentage < 1):
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: -100 ";
|
||||
break;
|
||||
case (exhaustionPercentage < 10):
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: -60 ";
|
||||
break;
|
||||
case (exhaustionPercentage < 25):
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: -30 ";
|
||||
break;
|
||||
case (exhaustionPercentage < 50):
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: -15 ";
|
||||
break;
|
||||
case (exhaustionPercentage < 75):
|
||||
console.log("Less than 75");
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: -5 ";
|
||||
break;
|
||||
default:
|
||||
console.log("Setting Default");
|
||||
context.system.attributes.exhaustion_points.modifier = "Exhaustion Penalty: 0 ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_prepareItems(context) {
|
||||
console.log(`rmss | rmss_player_sheet.js | Preparing items for: ${this.name}`);
|
||||
// Initialize containers.
|
||||
const gear = [];
|
||||
const playerskill= [];
|
||||
const skillcat = [];
|
||||
const weapons = [];
|
||||
const armor = [];
|
||||
const herbs = [];
|
||||
const spells = [];
|
||||
const equipables = [];
|
||||
|
||||
// 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") {
|
||||
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);
|
||||
}
|
||||
// Append to playerskill
|
||||
else if (i.type === "skill") {
|
||||
playerskill.push(i);
|
||||
}
|
||||
else if (i.type === "armor") {
|
||||
armor.push(i);
|
||||
}
|
||||
else if (i.type === "spell") {
|
||||
spells.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sort Skill/Skillcat Arrays
|
||||
skillcat.sort(function(a, b) {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
playerskill.sort(function(a, b) {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
// Assign and return
|
||||
context.gear = gear;
|
||||
context.skillcat = skillcat;
|
||||
context.playerskill = playerskill;
|
||||
context.weapons = weapons;
|
||||
context.armor = armor;
|
||||
context.herbs = herbs;
|
||||
context.spells = spells;
|
||||
}
|
||||
|
||||
async renderCharacterSettings(data) {
|
||||
console.log(data);
|
||||
const configSheet = await renderTemplate("systems/rmss/templates/sheets/actors/dialogs/actor-settings.html", data);
|
||||
return (configSheet);
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// 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"));
|
||||
item.sheet.render(true);
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.isEditable) return;
|
||||
|
||||
// Add Item
|
||||
html.find(".item-create").click(this._onItemCreate.bind(this));
|
||||
|
||||
// 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"));
|
||||
item.delete();
|
||||
});
|
||||
|
||||
// Show Sheet Settings
|
||||
html.find(".import-skillcats").click(async ev => {
|
||||
|
||||
let selectOptions = {};
|
||||
for (const pack of game.packs) {
|
||||
selectOptions[pack.metadata.id] = pack.metadata.label;
|
||||
}
|
||||
|
||||
new game.rmss.applications.RMSSActorSheetConfig(selectOptions, this.actor).render(true);
|
||||
});
|
||||
|
||||
// Check/Uncheck Favorite Skill
|
||||
html.find(".skill-favorite").click(ev => {
|
||||
const item = this.actor.items.get(ev.currentTarget.getAttribute("data-item-id"));
|
||||
console.log(item);
|
||||
console.log(`Before change: ${item.system.favorite}`);
|
||||
if (item.system.favorite === true) {
|
||||
console.log("Setting False");
|
||||
item.update({system: {favorite: false}});
|
||||
} else {
|
||||
console.log("Setting True");
|
||||
item.update({system: {favorite: true}});
|
||||
}
|
||||
console.log(`After change: ${item.system.favorite}`);
|
||||
});
|
||||
|
||||
// Check/Uncheck Favorite Spell
|
||||
html.find(".spell-favorite").click(ev => {
|
||||
const item = this.actor.items.get(ev.currentTarget.getAttribute("data-item-id"));
|
||||
console.log(item);
|
||||
console.log(`Before change: ${item.system.favorite}`);
|
||||
if (item.system.favorite === true) {
|
||||
console.log("Setting False");
|
||||
item.update({system: {favorite: false}});
|
||||
} else {
|
||||
console.log("Setting True");
|
||||
item.update({system: {favorite: true}});
|
||||
}
|
||||
console.log(`After change: ${item.system.favorite}`);
|
||||
});
|
||||
|
||||
// Equip/Unequip Weapon/Armor
|
||||
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}`);
|
||||
});
|
||||
|
||||
// Wear/Remove Item
|
||||
html.find(".wearable").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.worn === true) {
|
||||
console.log("Setting False");
|
||||
item.update({system: {worn: false}});
|
||||
} else {
|
||||
console.log("Setting True");
|
||||
item.update({system: {worn: 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;
|
||||
}
|
||||
});
|
||||
|
||||
// Change New Ranks value when clicked in player sheet. From 0-3.
|
||||
html.find(".skillcategory-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 Category NewRanks is 0 setting to 1");
|
||||
item.update({system: {new_ranks: { value: 1 }}});
|
||||
break;
|
||||
|
||||
case "1":
|
||||
console.log("Skill Category NewRanks is 1 setting to 2");
|
||||
item.update({system: {new_ranks: { value: 2 }}});
|
||||
break;
|
||||
|
||||
case "2":
|
||||
console.log("Skill Category NewRanks is 2 setting to 3");
|
||||
item.update({system: {new_ranks: { value: 3 }}});
|
||||
break;
|
||||
|
||||
case "3":
|
||||
console.log("Skill Category NewRanks is 3 setting to 0");
|
||||
item.update({system: {new_ranks: { value: 0 }}});
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async _onItemCreate(event) {
|
||||
event.preventDefault();
|
||||
const header = event.currentTarget;
|
||||
|
||||
// Get the type of item to create.
|
||||
const type = header.dataset.type;
|
||||
|
||||
// Grab any data associated with this control.
|
||||
const data = duplicate(header.dataset);
|
||||
|
||||
// Initialize a default name.
|
||||
const name = `New ${type.capitalize()}`;
|
||||
|
||||
// Prepare the item object.
|
||||
const itemData = {
|
||||
name: name,
|
||||
type: type,
|
||||
data: data
|
||||
};
|
||||
// Remove the type from the dataset since it's in the itemData.type prop.
|
||||
delete itemData.data.type;
|
||||
// Finally, create the item!
|
||||
return await Item.create(itemData, {parent: this.actor});
|
||||
}
|
||||
}
|
55
module/sheets/actors/rmss_player_sheet_config.js
Normal file
55
module/sheets/actors/rmss_player_sheet_config.js
Normal file
@ -0,0 +1,55 @@
|
||||
export default class RMSSActorSheetConfig extends FormApplication {
|
||||
|
||||
constructor(selectOptions, character) {
|
||||
super();
|
||||
this.selectOptions = selectOptions;
|
||||
this.character = character;
|
||||
}
|
||||
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["form"],
|
||||
popOut: true,
|
||||
template: "systems/rmss/templates/sheets/actors/apps/actor-settings.html"
|
||||
});
|
||||
}
|
||||
|
||||
getData() {
|
||||
// Send data to the template
|
||||
return {
|
||||
selectOptions: this.selectOptions
|
||||
};
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
}
|
||||
|
||||
async _updateObject(event, formData) {
|
||||
console.log("Deleting Old Skill Categories.");
|
||||
for (const item of this.character.items) {
|
||||
if (item.type === "skill_category") {
|
||||
item.delete();
|
||||
}
|
||||
}
|
||||
|
||||
const pack = game.packs.get(formData.selectOptions);
|
||||
const skillCategoryData = await pack.getIndex();
|
||||
|
||||
console.log("Importing New Skill Categories.");
|
||||
|
||||
for (const sc of skillCategoryData) {
|
||||
const newitem = await pack.getDocument(sc._id);
|
||||
|
||||
let newDocuments = [];
|
||||
if (newitem.type === "skill_category") {
|
||||
console.log(newitem);
|
||||
newDocuments.push(newitem);
|
||||
}
|
||||
if (newDocuments.length > 0) {
|
||||
await Item.createDocuments(newDocuments, {parent: this.character});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
module/sheets/items/rmss_armor_sheet.js
Normal file
36
module/sheets/items/rmss_armor_sheet.js
Normal file
@ -0,0 +1,36 @@
|
||||
// Our Item Sheet extends the default
|
||||
export default class RMSSArmorSheet extends ItemSheet {
|
||||
|
||||
// Set the height and width
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 530,
|
||||
height: 440,
|
||||
template: "systems/rmss/templates/sheets/items/rmss-armor-sheet.html",
|
||||
classes: ["rmss", "sheet", "item"]
|
||||
});
|
||||
}
|
||||
|
||||
// If our sheet is called here it is.
|
||||
get template() {
|
||||
return "systems/rmss/templates/sheets/items/rmss-armor-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});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable: this.isEditable,
|
||||
item: baseData.item,
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
}
|
36
module/sheets/items/rmss_herb_or_poison_sheet.js
Normal file
36
module/sheets/items/rmss_herb_or_poison_sheet.js
Normal file
@ -0,0 +1,36 @@
|
||||
// Our Item Sheet extends the default
|
||||
export default class RMSSHerbAndPoisonSheet extends ItemSheet {
|
||||
|
||||
// Set the height and width
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 530,
|
||||
height: 440,
|
||||
template: "systems/rmss/templates/sheets/items/rmss-herb-or-poison-sheet.html",
|
||||
classes: ["rmss", "sheet", "item"]
|
||||
});
|
||||
}
|
||||
|
||||
// If our sheet is called here it is.
|
||||
get template() {
|
||||
return "systems/rmss/templates/sheets/items/rmss-herb-or-poison-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});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable: this.isEditable,
|
||||
item: baseData.item,
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
}
|
36
module/sheets/items/rmss_item_sheet.js
Normal file
36
module/sheets/items/rmss_item_sheet.js
Normal file
@ -0,0 +1,36 @@
|
||||
// Our Item Sheet extends the default
|
||||
export default class RMSSItemSheet extends ItemSheet {
|
||||
|
||||
// Set the height and width
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 530,
|
||||
height: 440,
|
||||
template: "systems/rmss/templates/sheets/items/rmss-item-sheet.html",
|
||||
classes: ["rmss", "sheet", "item"]
|
||||
});
|
||||
}
|
||||
|
||||
// If our sheet is called here it is.
|
||||
get template() {
|
||||
return "systems/rmss/templates/sheets/items/rmss-item-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});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable: this.isEditable,
|
||||
item: baseData.item,
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
}
|
36
module/sheets/items/rmss_transport_sheet.js
Normal file
36
module/sheets/items/rmss_transport_sheet.js
Normal file
@ -0,0 +1,36 @@
|
||||
// Our Item Sheet extends the default
|
||||
export default class RMSSTransportSheet extends ItemSheet {
|
||||
|
||||
// Set the height and width
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 530,
|
||||
height: 440,
|
||||
template: "systems/rmss/templates/sheets/items/rmss-transport-sheet.html",
|
||||
classes: ["rmss", "sheet", "item"]
|
||||
});
|
||||
}
|
||||
|
||||
// If our sheet is called here it is.
|
||||
get template() {
|
||||
return "systems/rmss/templates/sheets/items/rmss-transport-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});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable: this.isEditable,
|
||||
item: baseData.item,
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
}
|
36
module/sheets/items/rmss_weapon_sheet.js
Normal file
36
module/sheets/items/rmss_weapon_sheet.js
Normal file
@ -0,0 +1,36 @@
|
||||
// Our Item Sheet extends the default
|
||||
export default class RMSSWeaponSheet extends ItemSheet {
|
||||
|
||||
// Set the height and width
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 530,
|
||||
height: 440,
|
||||
template: "systems/rmss/templates/sheets/items/rmss-weapon-sheet.html",
|
||||
classes: ["rmss", "sheet", "item"]
|
||||
});
|
||||
}
|
||||
|
||||
// If our sheet is called here it is.
|
||||
get template() {
|
||||
return "systems/rmss/templates/sheets/items/rmss-weapon-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});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable: this.isEditable,
|
||||
item: baseData.item,
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
module/sheets/spells/rmss_spell_sheet.js
Normal file
35
module/sheets/spells/rmss_spell_sheet.js
Normal file
@ -0,0 +1,35 @@
|
||||
// Our Item Sheet extends the default
|
||||
export default class RMSSSpellSheet extends ItemSheet {
|
||||
|
||||
// Set the height and width
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
width: 530,
|
||||
height: 440,
|
||||
classes: ["rmss", "sheet", "item"]
|
||||
});
|
||||
}
|
||||
|
||||
// If our sheet is called here it is.
|
||||
get template() {
|
||||
return "systems/rmss/templates/sheets/spells/rmss-spell-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});
|
||||
|
||||
let sheetData = {
|
||||
owner: this.item.isOwner,
|
||||
editable: this.isEditable,
|
||||
item: baseData.item,
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmss,
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user