import { DHUpdater } from './updater.js'; import { ActorUpdaterApp } from './apps/updater-app.js'; Hooks.once('init', () => { game.settings.register('dh-actor-updater', 'ignoredItems', { name: 'Ignored Items', scope: 'world', config: false, type: Object, default: {} }); game.settings.register('dh-actor-updater', 'lastCheckedVersion', { name: 'Last Checked System Version', scope: 'world', config: false, type: String, default: '0.0.0' }); game.settings.registerMenu('dh-actor-updater', 'manualCheck', { name: 'Check for Updates', label: 'Check Now', hint: 'Manually check for updates to your actors against the compendium.', icon: 'fas fa-search', type: ManualCheckConfig, restricted: true }); }); class ManualCheckConfig extends FormApplication { render() { game.modules.get('dh-actor-updater').api.checkAll(); // Don't actually render a form return this; } } Hooks.on('ready', async () => { if (!game.user.isGM) return; // Manual check hook exposed to API game.modules.get('dh-actor-updater').api = { checkAll: async () => { await checkAndPrompt(); } }; // Auto-check logic const lastVersion = game.settings.get('dh-actor-updater', 'lastCheckedVersion'); const currentVersion = game.system.version; if (currentVersion !== lastVersion) { console.log("Daggerheart Actor Updater | System update detected. Checking for item updates..."); await checkAndPrompt(); await game.settings.set('dh-actor-updater', 'lastCheckedVersion', currentVersion); } else { // Optional: Run on every startup? User "re-prompt again on manual check", not necessarily every startup unless version change. // "First run check" imply checking if it hasn't been checked before (implied by version 0.0.0). // "Re-prompt on system version update" -> Covered. // "Manual check" -> Covered by API. // Let's add a setting for "Check on every startup" if wanted, but instructions implied first run or version update. // "module should on first run check" -> handled by version diff check. } }); async function checkAndPrompt() { ui.notifications.info("Daggerheart Actor Updater | Checking for updates..."); // Collect updates from all actors // "configured actors" - likely means all actors or player characters. // Let's check all actors the GM has permission to update (which is all) let allUpdates = []; for (const actor of game.actors) { // Maybe restrict to Characters/Companions? // "configured actors" - usually implies Characters. Adversaries in world might not need updates or might be customizations. // Let's check 'character' and 'companion' types primarily, but maybe 'adversary' too if they are in the world. // User didn't strictly specify, but usually players care about their sheets. if (['character', 'companion'].includes(actor.type)) { const updates = await DHUpdater.checkActor(actor); allUpdates = allUpdates.concat(updates); } } if (allUpdates.length > 0) { new ActorUpdaterApp(allUpdates).render(true); } else { ui.notifications.info("Daggerheart Actor Updater | No updates found."); } }