Rework skill/skill categ links

This commit is contained in:
LeRatierBretonnien 2024-08-03 16:41:04 +02:00
parent 1f2558b680
commit cba4394a37
13 changed files with 231 additions and 127 deletions

View File

@ -1,3 +1,5 @@
import { RFRPUtility } from "../rfrp-utility.js";
export class RMSSItem extends Item { export class RMSSItem extends Item {
/** @override */ /** @override */
@ -100,21 +102,13 @@ export class RMSSItem extends Item {
} }
calculateSelectedSkillCategoryBonus(itemData) { calculateSelectedSkillCategoryBonus(itemData) {
if (this.isEmbedded === null) { // Find the relevant skill category
console.log(`rmss | item.js | Skill ${this.name} has no owner. Not calculating Skill Category bonus`); let skillC = this.parent?.items || RFRPUtility.getSkillCategories();
} if (skillC) {
else let item = skillC.find(it => it.type == "skill_category" && it.name.toLowerCase() == itemData.system.category.toLowerCase());
{ this.system.category_bonus = item.system.total_bonus;
const items = this.parent?.items; } else {
console.log(`rmss | item.js | Skill ${this.name} has owner, calculating skill category bonus.`); ui.notifications.warn("No Skill Categories found. Please create a Skill Category.");
if (items) {
for (const item of items) {
if (item.type === "skill_category" && item._id === itemData.system.category) {
console.log(`rmss | item.js | Calculating Skill Category bonus for skill: ${this.name}`);
this.system.category_bonus = item.system.total_bonus;
}
}
}
} }
} }
} }

174
module/rfrp-utility.js Normal file
View File

@ -0,0 +1,174 @@
/* -------------------------------------------- */
export class RFRPUtility {
/* -------------------------------------------- */
static async init() {
}
/* -------------------------------------------- */
static async ready() {
const skillCategories = await RFRPUtility.loadCompendium("fvtt-rolemaster-frp.skill_categories")
this.skillCategories = skillCategories.map(i => i.toObject())
}
/* -------------------------------------------- */
static getSkillCategories() {
return this.skillCategories
}
/* -------------------------------------------- */
static async loadCompendiumData(compendium) {
const pack = game.packs.get(compendium);
return await pack?.getDocuments() ?? [];
}
/* -------------------------------------------- */
static async loadCompendium(compendium, filter = item => true) {
let compendiumData = await RFRPUtility.loadCompendiumData(compendium);
return compendiumData.filter(filter);
}
/* -------------------------------------------- */
static removeChatMessageId(messageId) {
if (messageId) {
game.messages.get(messageId)?.delete();
}
}
static findChatMessageId(current) {
return RFRPUtility.getChatMessageId(HeritiersUtility.findChatMessage(current));
}
static getChatMessageId(node) {
return node?.attributes.getNamedItem('data-message-id')?.value;
}
static findChatMessage(current) {
return RFRPUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'))
}
static findNodeMatching(current, predicate) {
if (current) {
if (predicate(current)) {
return current;
}
return RFRPUtility.findNodeMatching(current.parentElement, predicate);
}
return undefined;
}
/* -------------------------------------------- */
static getUsers(filter) {
return game.users.filter(filter).map(user => user._id);
}
/* -------------------------------------------- */
static getWhisperRecipients(rollMode, name) {
switch (rollMode) {
case "blindroll": return this.getUsers(user => user.isGM);
case "gmroll": return this.getWhisperRecipientsAndGMs(name);
case "selfroll": return [game.user.id];
}
return undefined;
}
/* -------------------------------------------- */
static getWhisperRecipientsAndGMs(name) {
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
return recep1.concat(ChatMessage.getWhisperRecipients('GM'));
}
/* -------------------------------------------- */
static blindMessageToGM(chatOptions) {
let chatGM = foundry.utils.duplicate(chatOptions);
chatGM.whisper = this.getUsers(user => user.isGM);
chatGM.content = "Blinde message of " + game.user.name + "<br>" + chatOptions.content;
console.log("blindMessageToGM", chatGM);
game.socket.emit("system.fvtt-rolemaster-frp", { msg: "msg_gm_chat_message", data: chatGM });
}
/* -------------------------------------------- */
static async searchItem(dataItem) {
let item
if (dataItem.pack) {
let id = dataItem.id || dataItem._id
let items = await this.loadCompendium(dataItem.pack, item => item.id == id)
item = items[0] || undefined
} else {
item = game.items.get(dataItem.id)
}
return item
}
/* -------------------------------------------- */
static loadHandlebarsTemplates() {
const templatePaths = [
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-stats.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fixed-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-armor-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-resistance.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-race-stat-fixed-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-role-traits.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-background-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skill-categories.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-items.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-weapons.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-money.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skill-categories.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-armor.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-herbs.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-spells.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-spells.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-items.html",
"systems/fvtt-rolemaster-frp/templates/sheets/apps/app_skill_category_importer.html"
];
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
static loadHandlebarsHelpers() {
// Handlebars Helpers
Handlebars.registerHelper('count', function (list) {
return list.length;
})
Handlebars.registerHelper('includes', function (array, val) {
return array.includes(val);
})
Handlebars.registerHelper('upper', function (text) {
return text.toUpperCase();
})
Handlebars.registerHelper('lower', function (text) {
return text.toLowerCase()
})
Handlebars.registerHelper('upperFirst', function (text) {
if (typeof text !== 'string') return text
return text.charAt(0).toUpperCase() + text.slice(1)
})
Handlebars.registerHelper('notEmpty', function (list) {
return list.length > 0;
})
Handlebars.registerHelper('mul', function (a, b) {
return parseInt(a) * parseInt(b);
})
Handlebars.registerHelper("switch", function (value, options) {
this.switch_value = value;
return options.fn(this);
});
Handlebars.registerHelper("case", function (value, options) {
if (value === this.switch_value) {
return options.fn(this);
}
});
// Handle v12 removal of this helper
Handlebars.registerHelper('select', function (selected, options) {
const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected));
const rgx = new RegExp(' value=[\"\']' + escapedValue + '[\"\']');
const html = options.fn(this);
return html.replace(rgx, "$& selected");
});
}
}

View File

@ -171,7 +171,7 @@ export default class RMSSPlayerSheet extends ActorSheet {
for (let s of skillcat) { for (let s of skillcat) {
s.skills = []; s.skills = [];
for (let sk of playerskill) { for (let sk of playerskill) {
if (sk.system.category === s._id) { if (sk.system.category.toLowerCase() === s.name.toLowerCase()) {
s.skills.push(sk); s.skills.push(sk);
} }
} }

View File

@ -1,3 +1,5 @@
import { RFRPUtility } from "../../rfrp-utility.js";
// Our Item Sheet extends the default // Our Item Sheet extends the default
export default class RMSSSkillSheet extends ItemSheet { export default class RMSSSkillSheet extends ItemSheet {
@ -70,21 +72,20 @@ export default class RMSSSkillSheet extends ItemSheet {
// If this Skill is owned then we will return a list of Skill Categories and allow them to choose // 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' // Otherwise we'll just return 'Skill has no owner'
prepareSkillCategoryValues() { prepareSkillCategoryValues() {
let skillNoOwner = { None: "Skill Has No Owner" }; let skillCategories = RFRPUtility.getSkillCategories();
if (this.item.isEmbedded) {
if (!this.item.isEmbedded) { skillCategories = this.item.parent.items.filter(it => it.type == "skill_category");
return (skillNoOwner);
} else {
const skillCategories = this.item.parent.getOwnedItemsByType("skill_category");
return (skillCategories);
} }
console.log("CATEG", skillCategories);
return (skillCategories);
} }
// Determine which Skill Category is selected and test that it is in the current list of categories. // 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. // If it isn't set it to None.
prepareSelectedSkillCategory(ownedSkillCategories, selectedSkillCategory) { prepareSelectedSkillCategory(ownedSkillCategories, selectedSkillCategory) {
let defaultSelectedCategory = "None"; let defaultSelectedCategory = "None";
if (Object.keys(ownedSkillCategories).includes(selectedSkillCategory)) { let skillC = ownedSkillCategories.find(it => it.name.toLowerCase() == selectedSkillCategory.toLowerCase());
if (skillC) {
return (selectedSkillCategory); return (selectedSkillCategory);
} else { } else {
return (defaultSelectedCategory); return (defaultSelectedCategory);
@ -95,18 +96,14 @@ export default class RMSSSkillSheet extends ItemSheet {
// Iterate through the owned skill categories and if one of them matches the item id of currently // 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 // selected skill category then set the Skill Category Bonus field to the Total Bonus field of the Skill Category
prepareSelectedSkillCategoryBonus(selected_skillcat) { prepareSelectedSkillCategoryBonus(selected_skillcat) {
if (this.item.isEmbedded === null) { let skillC = this.parent?.items || RFRPUtility.getSkillCategories();
console.log("Skill has no owner"); if (skillC) {
} let item = skillC.find(it => it.type == "skill_category" && it.name.toLowerCase() == itemData.system.category.toLowerCase());
else { if (item) {
const items = this.object.parent.items; this.system.category_bonus = item.system.total_bonus;
return
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;
}
} }
} }
ui.notifications.warn("No Skill Categories found for " + this.name + ". Please create and link a Skill Category.");
} }
} }

View File

@ -1 +1 @@
MANIFEST-000056 MANIFEST-000060

View File

@ -1,8 +1,8 @@
2024/08/02-16:48:51.596152 7f2b120006c0 Recovering log #54 2024/08/03-16:17:28.988843 7f2b120006c0 Recovering log #58
2024/08/02-16:48:51.607028 7f2b120006c0 Delete type=3 #52 2024/08/03-16:17:29.000009 7f2b120006c0 Delete type=3 #56
2024/08/02-16:48:51.607119 7f2b120006c0 Delete type=0 #54 2024/08/03-16:17:29.000149 7f2b120006c0 Delete type=0 #58
2024/08/02-17:06:25.130824 7f2b110006c0 Level-0 table #59: started 2024/08/03-16:40:12.660059 7f2b110006c0 Level-0 table #63: started
2024/08/02-17:06:25.130880 7f2b110006c0 Level-0 table #59: 0 bytes OK 2024/08/03-16:40:12.660133 7f2b110006c0 Level-0 table #63: 0 bytes OK
2024/08/02-17:06:25.137382 7f2b110006c0 Delete type=0 #57 2024/08/03-16:40:12.666773 7f2b110006c0 Delete type=0 #61
2024/08/02-17:06:25.160338 7f2b110006c0 Manual compaction at level-0 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) 2024/08/03-16:40:12.677428 7f2b110006c0 Manual compaction at level-0 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end)
2024/08/02-17:06:25.160385 7f2b110006c0 Manual compaction at level-1 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) 2024/08/03-16:40:12.689036 7f2b110006c0 Manual compaction at level-1 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end)

View File

@ -1,8 +1,8 @@
2024/08/02-16:41:04.243624 7f2b134006c0 Recovering log #50 2024/08/02-16:48:51.596152 7f2b120006c0 Recovering log #54
2024/08/02-16:41:04.298794 7f2b134006c0 Delete type=3 #48 2024/08/02-16:48:51.607028 7f2b120006c0 Delete type=3 #52
2024/08/02-16:41:04.298940 7f2b134006c0 Delete type=0 #50 2024/08/02-16:48:51.607119 7f2b120006c0 Delete type=0 #54
2024/08/02-16:47:53.296999 7f2b110006c0 Level-0 table #55: started 2024/08/02-17:06:25.130824 7f2b110006c0 Level-0 table #59: started
2024/08/02-16:47:53.297027 7f2b110006c0 Level-0 table #55: 0 bytes OK 2024/08/02-17:06:25.130880 7f2b110006c0 Level-0 table #59: 0 bytes OK
2024/08/02-16:47:53.302866 7f2b110006c0 Delete type=0 #53 2024/08/02-17:06:25.137382 7f2b110006c0 Delete type=0 #57
2024/08/02-16:47:53.310260 7f2b110006c0 Manual compaction at level-0 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) 2024/08/02-17:06:25.160338 7f2b110006c0 Manual compaction at level-0 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end)
2024/08/02-16:47:53.310311 7f2b110006c0 Manual compaction at level-1 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) 2024/08/02-17:06:25.160385 7f2b110006c0 Manual compaction at level-1 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end)

Binary file not shown.

81
rmss.js
View File

@ -19,34 +19,7 @@ import RMSSSkillSheet from "./module/sheets/skills/rmss_skill_sheet.js";
import RMSSPlayerSheet from "./module/sheets/actors/rmss_player_sheet.js"; import RMSSPlayerSheet from "./module/sheets/actors/rmss_player_sheet.js";
import RMSSToolsSCImporter from "./module/sheets/apps/rmss_import_skill_categories.js"; import RMSSToolsSCImporter from "./module/sheets/apps/rmss_import_skill_categories.js";
import RMSSToolsDiceRoller from "./module/sheets/apps/rmss_dice_roller.js"; import RMSSToolsDiceRoller from "./module/sheets/apps/rmss_dice_roller.js";
import { RFRPUtility } from "./module/rfrp-utility.js";
/** Preload handlebars templates for character sheets */
async function preloadHandlebarsTemplates() {
const templatePaths = [
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-stats.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fixed-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-armor-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-resistance.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-race-stat-fixed-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-role-traits.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-background-info.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skill-categories.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-items.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-weapons.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-money.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skill-categories.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-skills.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-armor.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-herbs.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-spells.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-spells.html",
"systems/fvtt-rolemaster-frp/templates/sheets/actors/parts/actor-fav-items.html",
"systems/fvtt-rolemaster-frp/templates/sheets/apps/app_skill_category_importer.html"
];
return loadTemplates(templatePaths);
}
// Register Scene Controls // Register Scene Controls
// registerGetSceneControlButtonsHook(); // registerGetSceneControlButtonsHook();
@ -107,48 +80,14 @@ Hooks.once("init", function () {
// Actors // Actors
Actors.registerSheet("fvtt-rolemaster-frp", RMSSPlayerSheet, { makeDefault: true, label: "rmss.entity_sheet.player_characrer", types: ["character"] }); Actors.registerSheet("fvtt-rolemaster-frp", RMSSPlayerSheet, { makeDefault: true, label: "rmss.entity_sheet.player_characrer", types: ["character"] });
// Preload Handlebars Templates RFRPUtility.loadHandlebarsTemplates();
console.log("rmss | Preloading Handlebars Templates"); RFRPUtility.loadHandlebarsHelpers();
preloadHandlebarsTemplates();
// Handlebars Helpers
Handlebars.registerHelper('count', function (list) {
return list.length;
})
Handlebars.registerHelper('includes', function (array, val) {
return array.includes(val);
})
Handlebars.registerHelper('upper', function (text) {
return text.toUpperCase();
})
Handlebars.registerHelper('lower', function (text) {
return text.toLowerCase()
})
Handlebars.registerHelper('upperFirst', function (text) {
if (typeof text !== 'string') return text
return text.charAt(0).toUpperCase() + text.slice(1)
})
Handlebars.registerHelper('notEmpty', function (list) {
return list.length > 0;
})
Handlebars.registerHelper('mul', function (a, b) {
return parseInt(a) * parseInt(b);
})
Handlebars.registerHelper("switch", function (value, options) {
this.switch_value = value;
return options.fn(this);
});
Handlebars.registerHelper("case", function (value, options) {
if (value === this.switch_value) {
return options.fn(this);
}
});
// Handle v12 removal of this helper
Handlebars.registerHelper('select', function (selected, options) {
const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected));
const rgx = new RegExp(' value=[\"\']' + escapedValue + '[\"\']');
const html = options.fn(this);
return html.replace(rgx, "$& selected");
});
}); });
Hooks.once("ready", async function () {
console.log("rmss | Ready");
// Load Utility
await RFRPUtility.ready();
})

View File

@ -3,7 +3,7 @@
"title": "Rolemaster FRP System", "title": "Rolemaster FRP System",
"description": "The Rolemaster FRP system for FoundryVTT.", "description": "The Rolemaster FRP system for FoundryVTT.",
"manifest": "https://www.uberwald.me/gitea/public/fvtt-rolemaster-frp/raw/branch/develop/system.json", "manifest": "https://www.uberwald.me/gitea/public/fvtt-rolemaster-frp/raw/branch/develop/system.json",
"download": "https://www.uberwald.me/gitea/public/fvtt-rolemaster-frp/archive/v12.0.5.zip", "download": "https://www.uberwald.me/gitea/public/fvtt-rolemaster-frp/archive/v12.0.6.zip",
"authors": [ "authors": [
{ {
"name": "Cynicide", "name": "Cynicide",
@ -14,7 +14,7 @@
"email": "" "email": ""
} }
], ],
"version": "12.0.5", "version": "12.0.6",
"compatibility": { "compatibility": {
"minimum": "12", "minimum": "12",
"verified": "12" "verified": "12"

View File

@ -11,8 +11,8 @@
</div> </div>
<div> <div>
Skill Category Skill Category
<select name="system.category" class="app-stat-selector" value="{{system.category}}" itemid="{{ item._id }}"> <select name="system.category" class="app-stat-selector" value="{{system.category}}">
{{selectOptions owned_skillcats selected=selected_skillcat }} {{selectOptions owned_skillcats selected=selected_skillcat nameAttr="name" valueAttr="name" labelAttr="name"}}
</select> </select>
</div> </div>
<div> <div>