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:
parent
4466a13098
commit
45003881af
3 changed files with 35 additions and 3 deletions
|
|
@ -6,6 +6,11 @@
|
|||
export function createMovableCountdownsClass(BaseCountdowns) {
|
||||
return class MovableCountdowns extends BaseCountdowns {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -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 */
|
||||
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);
|
||||
|
||||
// Remove detached class from body
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue