Fix DirectorsBoard position loading error

- Fixed TypeError: Cannot assign to read only property 'position' of object
- Changed _loadPosition() to use Object.assign() instead of direct assignment
- Added null check for this.options?.position to handle both Foundry and test environments
- Updated fallback _AppBase class to store options in constructor for test compatibility
- Added comprehensive tests for _loadPosition() method

The error occurred because in FoundryVTT v14, ApplicationV2 freezes the options object,
making direct assignment to this.options.position impossible. Using Object.assign()
merges the properties instead, which works with both frozen and unfrozen objects.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-05-24 13:50:46 +02:00
parent 25dd427a59
commit 5b421d6d49
2 changed files with 134 additions and 6 deletions
+13 -6
View File
@@ -22,6 +22,9 @@ const _AppBase =
: class _FallbackApp {
static DEFAULT_OPTIONS = {};
static PARTS = {};
constructor(options = {}) {
this.options = options;
}
get rendered() { return this._rendered ?? false; }
set rendered(v) { this._rendered = v; }
get element() { return this._element ?? null; }
@@ -115,12 +118,16 @@ export class DirectorsBoard extends _AppBase {
try {
const saved = game.user?.getFlag('video-view-manager', 'directorsBoardState');
if (saved?.open === true && saved.left != null && saved.top != null) {
this.options.position = {
left: saved.left,
top: saved.top,
width: saved.width ?? 400,
height: saved.height ?? 300,
};
// Ensure options.position exists and is mutable
if (this.options?.position) {
// Use Object.assign to avoid TypeError when options is frozen (Foundry ApplicationV2)
Object.assign(this.options.position, {
left: saved.left,
top: saved.top,
width: saved.width ?? 400,
height: saved.height ?? 300,
});
}
}
} catch (err) {
console.error('[ScryingPool] Failed to load directors board position:', err);