Import RMFRP tables + properly rename all files

This commit is contained in:
2024-08-15 22:52:36 +02:00
parent fe36edfeff
commit 45ee08e6c2
17 changed files with 92 additions and 47 deletions

View File

@ -1,4 +1,4 @@
import { RFRPUtility } from "../rfrp-utility.js";
import { RMFRPUtility } from "../rmfrp-utility.js";
export class RMFRPItem extends Item {
@ -107,7 +107,7 @@ export class RMFRPItem extends Item {
// Find the relevant skill category
if (!this.parent) { return; } // Only if attached to an actor
let skillC = this.parent?.items || RFRPUtility.getSkillCategories();
let skillC = this.parent?.items || RMFRPUtility.getSkillCategories();
if (skillC) {
let item = skillC.find(it => it.type == "skill_category" && it.name.toLowerCase() == itemData.system.category.toLowerCase());
if (item) {

View File

@ -0,0 +1,50 @@
export class RMFRPProcessTable {
constructor() {
// Load a reference to the rmfrp-tables.json file
this.rmfrpTables = require('./rmfrp-tables.json');
// Loop thru the tables and create a definition object, with key, name and min/ax value of each table
this.rmfrpTablesDef = {}
for (let table in this.rmfrpTables) {
let tableData = this.rmfrpTables[table]
// Search min and max values in the tableData
let min = Number.MAX_SAFE_INTEGER;
let max = Number.MIN_SAFE_INTEGER;
tableData.forEach((element) => {
if (element.result) {
if (Number(element.result)) {
min = Math.min(min, Number(element.result));
max = Math.max(max, Number(element.result));
} else {
let range = element.result.split("-");
min = Math.min(min, Number(range[0]));
max = Math.max(max, Number(range[1]));
}
}
});
this.rmfrpTablesDef[table] = {
key: table,
name: RMFRPUtility.capitalizeFirstLetters(table.replace(/_/g, " ")),
min: min,
max: max
};
}
super();
}
// Get roll result from table
getAttackRollResult(table, roll, armorValue) {
let result = this.rmfrpTables[table].find((element) => {
if (Number(element.result) && Number(element.result) == Number(roll)) {
return element[String(armorValue)];
} else {
// SPlit the result into a range
let range = element.result.split("-");
if (Number(roll) >= Number(range[0]) && Number(roll) <= Number(range[1])) {
return element[String(armorValue)];
}
}
});
return undefined;
}
}

View File

@ -1,11 +1,17 @@
/* -------------------------------------------- */
export class RFRPUtility {
export class RMFRPUtility {
/* -------------------------------------------- */
static async init() {
}
static capitalizeFirstLetters(str){
return str.toLowerCase().replace(/^\w|\s\w/g, function (letter) {
return letter.toUpperCase();
})
}
/* -------------------------------------------- */
static async ready() {
this.registerSettings();

View File

@ -1,4 +1,4 @@
import { RFRPUtility } from "../../rfrp-utility.js";
import { RMFRPUtility } from "../../rmfrp-utility.js";
export default class RMFRPToolsSCImporter extends FormApplication {
@ -50,7 +50,7 @@ export default class RMFRPToolsSCImporter extends FormApplication {
console.log("Importing New Skills/Skill Categories.");
let newDocuments = [];
let gameSystem = RFRPUtility.getGameSystem();
let gameSystem = RMFRPUtility.getGameSystem();
for (const sc of skillCategoryData) {
const newitem = await pack.getDocument(sc._id);
if (newitem.type === itemType && (newitem.system.game_system === "common" || newitem.system.game_system === gameSystem)) {

View File

@ -1,4 +1,4 @@
import { RFRPUtility } from "../../rfrp-utility.js";
import { RMFRPUtility } from "../../rmfrp-utility.js";
// Our Item Sheet extends the default
export default class RMFRPSkillSheet extends ItemSheet {
@ -72,7 +72,7 @@ export default class RMFRPSkillSheet extends ItemSheet {
// 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 skillCategories = RFRPUtility.getSkillCategories();
let skillCategories = RMFRPUtility.getSkillCategories();
if (this.item.isEmbedded) {
skillCategories = this.item.parent.items.filter(it => it.type == "skill_category");
}
@ -96,7 +96,7 @@ export default class RMFRPSkillSheet extends ItemSheet {
// 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) {
let skillC = this.parent?.items || RFRPUtility.getSkillCategories();
let skillC = this.parent?.items || RMFRPUtility.getSkillCategories();
if (skillC) {
let item = skillC.find(it => it.type == "skill_category" && it.name.toLowerCase() == itemData.system.category.toLowerCase());
if (item) {