feat: Implement saving and loading of the countdown window's position, prevent it from resizing larger than its content, and update module metadata.

This commit is contained in:
CPTN Cosmo 2026-01-07 15:52:39 +01:00
parent 4466a13098
commit 45003881af
No known key found for this signature in database
3 changed files with 35 additions and 3 deletions

View file

@ -2,7 +2,7 @@
"id": "dh-countdownsplus", "id": "dh-countdownsplus",
"title": "Daggerheart Countdowns Plus", "title": "Daggerheart Countdowns Plus",
"description": "A module to allow the Daggerheart countdown tracker to be detached and moved freely.", "description": "A module to allow the Daggerheart countdown tracker to be detached and moved freely.",
"version": "1.0.0", "version": "1.1.0",
"compatibility": { "compatibility": {
"minimum": "13", "minimum": "13",
"verified": "13" "verified": "13"
@ -31,7 +31,7 @@
"styles": [ "styles": [
"styles/module.css" "styles/module.css"
], ],
"url": "https://github.com/cptn-cosmo/dh-countdownsplus", "url": "https://git.geeks.gay/cosmo/dh-countdownsplus",
"manifest": "https://github.com/cptn-cosmo/dh-countdownsplus/releases/latest/download/module.json", "manifest": "https://github.com/cptn-cosmo/dh-countdownsplus/releases/latest/download/module.json",
"download": "https://github.com/cptn-cosmo/dh-countdownsplus/releases/download/1.0.0/dh-countdownsplus.zip" "download": "https://github.com/cptn-cosmo/dh-countdownsplus/releases/download/1.0.0/dh-countdownsplus.zip"
} }

View file

@ -6,6 +6,11 @@
export function createMovableCountdownsClass(BaseCountdowns) { export function createMovableCountdownsClass(BaseCountdowns) {
return class MovableCountdowns extends BaseCountdowns { return class MovableCountdowns extends BaseCountdowns {
constructor(options = {}) { constructor(options = {}) {
// Load saved position if exists
const savedPos = game.user.getFlag('dh-countdownsplus', 'windowPosition');
if (savedPos) {
options.position = foundry.utils.mergeObject(options.position || {}, savedPos);
}
super(options); super(options);
} }
@ -132,8 +137,31 @@ export function createMovableCountdownsClass(BaseCountdowns) {
} }
} }
/**
* Capture position changes to save them, since close() only has the final state.
* AppV2 doesn't have a simple 'move' hook, but we can override setPosition.
*/
setPosition(position = {}) {
const result = super.setPosition(position);
// Debounce save or just save on close?
// Saving on close is safer for perf, but crash might lose it.
// Let's stick to close() for now as per plan, but we need to ensure 'this.position' is updated.
// In AppV2, this.position is getter/setter.
return result;
}
/** @override */ /** @override */
async close(options = {}) { async close(options = {}) {
// Save position before closing
if (this.position) {
await game.user.setFlag('dh-countdownsplus', 'windowPosition', {
top: this.position.top,
left: this.position.left,
width: this.position.width,
height: this.position.height
});
}
await super.close(options); await super.close(options);
// Remove detached class from body // Remove detached class from body

View file

@ -12,6 +12,10 @@
/* Disable system transition for sliding */ /* Disable system transition for sliding */
box-shadow: 0 0 10px #000; box-shadow: 0 0 10px #000;
/* Add shadow for popping out */ /* Add shadow for popping out */
/* User request: Prevent resizing larger than content */
max-width: fit-content !important;
max-height: fit-content !important;
} }
/* Ensure window header is visible/draggable */ /* Ensure window header is visible/draggable */