From 2b929bde5768a8a6b9dec9c3759165ac7ea913c8 Mon Sep 17 00:00:00 2001 From: Paul Maskelyne Date: Thu, 28 Mar 2024 16:50:58 +0000 Subject: [PATCH 1/2] closes #280 --- CHANGELOG.md | 8 ++++++++ system/src/config.mjs | 14 ++++++++++++++ system/src/hooks/setupHook.mjs | 6 +++++- system/src/sheets/FalloutItemSheet.mjs | 19 ++++++------------- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6122447..3df96ba9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v11.6.1 + +# Enhancements +- [#280] Cache available Ammo items in compendiums at startup to improve performance on slow systems with large amounts of compendium items + * This will mean that if you add a new ammo item type it won't be available on Weapon item sheets until the system is reloaded. + +--- + # v11.6.0 # Enhancements diff --git a/system/src/config.mjs b/system/src/config.mjs index 86af2d92..16d02dd8 100644 --- a/system/src/config.mjs +++ b/system/src/config.mjs @@ -341,6 +341,20 @@ FALLOUT.WEAPON_TYPES = { unarmed: "FALLOUT.WEAPONS.weaponType.unarmed", }; +export async function discoverAvailableAmmoTypes() { + const ammo = await fallout.compendiums.ammo(); + + CONFIG.FALLOUT.AMMO_BY_UUID = {}; + let ammoTypes = []; + for (const ammoType of ammo) { + ammoTypes.push(ammoType.name); + CONFIG.FALLOUT.AMMO_BY_UUID[ammoType.uuid] = ammoType.name; + } + ammoTypes = [...new Set(ammoTypes)]; // de-dupe + + CONFIG.FALLOUT.AMMO_TYPES = ammoTypes.sort((a, b) => a.localeCompare(b)); +} + export async function generateEnrichedTooltips() { CONFIG.FALLOUT.WEAPON_QUALITY_TOOLTIPS = {}; CONFIG.FALLOUT.WEAPON_QUALITY_HAS_RANK = {}; diff --git a/system/src/hooks/setupHook.mjs b/system/src/hooks/setupHook.mjs index f6f1f4b3..4770e705 100644 --- a/system/src/hooks/setupHook.mjs +++ b/system/src/hooks/setupHook.mjs @@ -1,4 +1,7 @@ -import { generateEnrichedTooltips } from "../config.mjs"; +import { + discoverAvailableAmmoTypes, + generateEnrichedTooltips, +} from "../config.mjs"; export const setupHook = { attach: () => { @@ -20,6 +23,7 @@ export const setupHook = { } generateEnrichedTooltips(); + discoverAvailableAmmoTypes(); }); }, }; diff --git a/system/src/sheets/FalloutItemSheet.mjs b/system/src/sheets/FalloutItemSheet.mjs index 461e7ee9..953fce47 100644 --- a/system/src/sheets/FalloutItemSheet.mjs +++ b/system/src/sheets/FalloutItemSheet.mjs @@ -80,20 +80,13 @@ export default class FalloutItemSheet extends ItemSheet { } if (item.type === "weapon") { - const ammo = await fallout.compendiums.ammo(); - - context.ammoUuid = ammo.find( - a => a.name === this.item.system.ammo - )?.uuid ?? ""; - - - let ammoTypes = []; - for (const ammoType of ammo) { - ammoTypes.push(ammoType.name); + for (const [uuid, name] of Object.entries(CONFIG.FALLOUT.AMMO_BY_UUID)) { + if (name === this.item.system.ammo) { + context.ammoUuid = uuid; + break; + } } - ammoTypes = [...new Set(ammoTypes)]; // de-dupe - - context.ammoTypes = ammoTypes.sort((a, b) => a.localeCompare(b)); + context.ammoTypes = CONFIG.FALLOUT.AMMO_TYPES; context.damageTypes = []; for (const key in CONFIG.FALLOUT.DAMAGE_TYPES) { From 9909156c8788b3864981cd9e8f5b80b6de6591d2 Mon Sep 17 00:00:00 2001 From: Paul Maskelyne Date: Thu, 28 Mar 2024 16:51:18 +0000 Subject: [PATCH 2/2] bump version --- system/system.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/system.json b/system/system.json index c7c45542..330d491e 100644 --- a/system/system.json +++ b/system/system.json @@ -2,7 +2,7 @@ "id": "fallout", "title": "Fallout: The Roleplaying Game", "description": "An unofficial system for playing the Fallout RPG from Modiphius Entertainment Ltd.", - "version": "11.6.0", + "version": "11.6.1", "compatibility": { "minimum": "11", "verified": "11"