From 45ee08e6c2bac9b19eec3e59cec13a5320de9c36 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Thu, 15 Aug 2024 22:52:36 +0200 Subject: [PATCH] Import RMFRP tables + properly rename all files --- module/documents/item.js | 4 +- module/rmfrp-process-table.js | 50 ++++++++++++++++++ module/{sheets/apps => }/rmfrp-tables.js | 0 module/{rfrp-utility.js => rmfrp-utility.js} | 8 ++- .../apps/rmfrp_import_skill_categories.js | 4 +- module/sheets/skills/rmfrp_skill_sheet.js | 6 +-- .../{000148.log => 000151.log} | 0 packs/skill_categories/CURRENT | 2 +- packs/skill_categories/LOG | 11 ++-- packs/skill_categories/LOG.old | 16 +++--- .../{MANIFEST-000146 => MANIFEST-000150} | Bin 176 -> 158 bytes packs/skills/{000054.log => 000057.log} | 0 packs/skills/CURRENT | 2 +- packs/skills/LOG | 11 ++-- packs/skills/LOG.old | 16 +++--- .../{MANIFEST-000052 => MANIFEST-000056} | Bin 173 -> 157 bytes rmfrp.js | 9 ++-- 17 files changed, 92 insertions(+), 47 deletions(-) create mode 100644 module/rmfrp-process-table.js rename module/{sheets/apps => }/rmfrp-tables.js (100%) rename module/{rfrp-utility.js => rmfrp-utility.js} (97%) rename packs/skill_categories/{000148.log => 000151.log} (100%) rename packs/skill_categories/{MANIFEST-000146 => MANIFEST-000150} (72%) rename packs/skills/{000054.log => 000057.log} (100%) rename packs/skills/{MANIFEST-000052 => MANIFEST-000056} (73%) diff --git a/module/documents/item.js b/module/documents/item.js index f06be2b..f135138 100644 --- a/module/documents/item.js +++ b/module/documents/item.js @@ -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) { diff --git a/module/rmfrp-process-table.js b/module/rmfrp-process-table.js new file mode 100644 index 0000000..d94f54d --- /dev/null +++ b/module/rmfrp-process-table.js @@ -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; + } +} diff --git a/module/sheets/apps/rmfrp-tables.js b/module/rmfrp-tables.js similarity index 100% rename from module/sheets/apps/rmfrp-tables.js rename to module/rmfrp-tables.js diff --git a/module/rfrp-utility.js b/module/rmfrp-utility.js similarity index 97% rename from module/rfrp-utility.js rename to module/rmfrp-utility.js index 9aced1c..2fe0dc8 100644 --- a/module/rfrp-utility.js +++ b/module/rmfrp-utility.js @@ -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(); diff --git a/module/sheets/apps/rmfrp_import_skill_categories.js b/module/sheets/apps/rmfrp_import_skill_categories.js index aab8509..be6c4e3 100644 --- a/module/sheets/apps/rmfrp_import_skill_categories.js +++ b/module/sheets/apps/rmfrp_import_skill_categories.js @@ -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)) { diff --git a/module/sheets/skills/rmfrp_skill_sheet.js b/module/sheets/skills/rmfrp_skill_sheet.js index b3015ad..90916f6 100644 --- a/module/sheets/skills/rmfrp_skill_sheet.js +++ b/module/sheets/skills/rmfrp_skill_sheet.js @@ -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) { diff --git a/packs/skill_categories/000148.log b/packs/skill_categories/000151.log similarity index 100% rename from packs/skill_categories/000148.log rename to packs/skill_categories/000151.log diff --git a/packs/skill_categories/CURRENT b/packs/skill_categories/CURRENT index ffd4a01..939d9b8 100644 --- a/packs/skill_categories/CURRENT +++ b/packs/skill_categories/CURRENT @@ -1 +1 @@ -MANIFEST-000146 +MANIFEST-000150 diff --git a/packs/skill_categories/LOG b/packs/skill_categories/LOG index edfb491..ef3e783 100644 --- a/packs/skill_categories/LOG +++ b/packs/skill_categories/LOG @@ -1,8 +1,3 @@ -2024/08/15-22:19:09.675609 7fdec34006c0 Recovering log #144 -2024/08/15-22:19:09.731573 7fdec34006c0 Delete type=3 #142 -2024/08/15-22:19:09.731716 7fdec34006c0 Delete type=0 #144 -2024/08/15-22:24:10.619452 7fdec0c006c0 Level-0 table #149: started -2024/08/15-22:24:10.619485 7fdec0c006c0 Level-0 table #149: 0 bytes OK -2024/08/15-22:24:10.626074 7fdec0c006c0 Delete type=0 #147 -2024/08/15-22:24:10.632684 7fdec0c006c0 Manual compaction at level-0 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) -2024/08/15-22:24:10.646015 7fdec0c006c0 Manual compaction at level-1 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) +2024/08/15-22:43:42.844641 7fdec20006c0 Recovering log #148 +2024/08/15-22:43:42.854211 7fdec20006c0 Delete type=3 #146 +2024/08/15-22:43:42.854261 7fdec20006c0 Delete type=0 #148 diff --git a/packs/skill_categories/LOG.old b/packs/skill_categories/LOG.old index 5514cf9..edfb491 100644 --- a/packs/skill_categories/LOG.old +++ b/packs/skill_categories/LOG.old @@ -1,8 +1,8 @@ -2024/08/11-18:35:03.709029 7f47856006c0 Recovering log #139 -2024/08/11-18:35:03.719540 7f47856006c0 Delete type=3 #137 -2024/08/11-18:35:03.719589 7f47856006c0 Delete type=0 #139 -2024/08/11-19:09:53.738475 7f4782e006c0 Level-0 table #145: started -2024/08/11-19:09:53.738526 7f4782e006c0 Level-0 table #145: 0 bytes OK -2024/08/11-19:09:53.744948 7f4782e006c0 Delete type=0 #143 -2024/08/11-19:09:53.757342 7f4782e006c0 Manual compaction at level-0 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) -2024/08/11-19:09:53.767613 7f4782e006c0 Manual compaction at level-1 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) +2024/08/15-22:19:09.675609 7fdec34006c0 Recovering log #144 +2024/08/15-22:19:09.731573 7fdec34006c0 Delete type=3 #142 +2024/08/15-22:19:09.731716 7fdec34006c0 Delete type=0 #144 +2024/08/15-22:24:10.619452 7fdec0c006c0 Level-0 table #149: started +2024/08/15-22:24:10.619485 7fdec0c006c0 Level-0 table #149: 0 bytes OK +2024/08/15-22:24:10.626074 7fdec0c006c0 Delete type=0 #147 +2024/08/15-22:24:10.632684 7fdec0c006c0 Manual compaction at level-0 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) +2024/08/15-22:24:10.646015 7fdec0c006c0 Manual compaction at level-1 from '!items!1HevhbCbvMonyQXe' @ 72057594037927935 : 1 .. '!items!yRIFroc5VC9Oj3qY' @ 0 : 0; will stop at (end) diff --git a/packs/skill_categories/MANIFEST-000146 b/packs/skill_categories/MANIFEST-000150 similarity index 72% rename from packs/skill_categories/MANIFEST-000146 rename to packs/skill_categories/MANIFEST-000150 index c5a746e4f485c4062d4f41e48d45d3c42637b9cb..efe30aab92fe4f276e1dda352dfb1d7ac95a8175 100644 GIT binary patch delta 25 hcmdnMIFE5ckI+5eV~e;M7@4LsaxyT_U}U+*2mo#n2RHx# delta 43 tcmbQoxPfs(k4jIG1rkuR!3Nba74wMkY&624*Xk4mJQ#umw^8 delta 39 qcmbQsxR!B3ufl~B$_<