setPosition in SvelteApplication

The SvelteApplication class has a function called setPosition that is there to support core behavior. And while it exists and is called when opening the app. It isn't really called when minimizing, maximizing, or changing the position of the window itself. This means that any modules that try to wrap the setPosition function to extend features fail to do so.
29 Replies
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
Well you shouldn't wrap it per se. What type of feature are you trying to implement? The TRL / TJSPosition implementation is quite a bit richer. Quite likely there is an alternate way to accomplish most things.
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
I'm not the one trying to wrap the function in this case core foundry uses sheet.setPosition to change the position of sheets. Module makers that change the behavior of this function to add more functionality like attach other windows to the sheet generally wrap this function either manually or using libwrapper. And because SvelteApplication doesn't call setPosition while changing the position of the sheet means it breaks compatibility with all the other modules.
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
Indeed any module being refactored / rewritten for TRL may need to change a thing or two depending on the goals being accomplished. In TRL app.position is a store, so it can be subscribed to for implementations of attaching / following a target apps position. There is also a robust validation stage that can have user added validators for restricting movement / also useful for docking. So, unless it was a really strange use case there should be a cleaner way to implement the feature w/ TRL
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
the problem is that other modules don't use TRL 😄
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
Ah, so you are saying that there is a module out there that somehow affects the position of apps it doesn't own? Got an example of such a module?
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
ripper's paper doll is one example
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
No description
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
honestly a lot of modules do similar things with other functions as well
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
setPosition should be the only function where control flow is altered w/ TRL, so other Application functions are not diverted to an alternate implementation. In the paper doll example a small change would be needed to subscribe to the position changes of the host sheet. Not that this is a great solution.. Just a brainstorm hack I haven't tried. Because you have a system and can test against paper doll. Add this.position.subscribe((pos) => this.setPosition(pos)); to the constructor of your sheet. I'm not saying this is a good solution, but curious if that works or blows up.. ;P
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
yeah already tried that 😄 it's an infinite loop 😄
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
Yeah.. I'd have to check it out. Technically it should reject follow up position setting if the data is the same as current state, so I'll take a look at that. Not that the hack mentioned above is a good solution. It is a bit of a rub because the TRL position system is backward compatible with Foundry core except for the use case of an external module trying to integrate in an ad hoc manner with Applications it doesn't control.
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
technically this can be resolved with changing the 3 instances of this.position.set to this.setPosition. actually no 🤔 need to double check something 😄
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
I'll have to take a look. There is the draggable action / implementation that is the sticking point quite likely. This is in the platform neutral implementation for TJSPosition, so not at the Foundry integration layer: https://github.com/typhonjs-svelte/runtime-base/blob/main/src/svelte/store/position/action/draggable.js#L224
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
prolly core foundry calls app.setPosition
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
Yes.. The TJSPosition implementation is platform neutral and can be applied to any element to make something positionable / draggable, etc. It's not a hard coded 1:1 relationship to a specific implementation ala app.setPosition. Given that all of this could be upended with the v12 App v2 API I'd want to wait just a bit more to see how much damage that may cause. If Foundry core drastically changes how position state is stored or accessed there will be other aspects to work around and consider. I've been mum on trying to contact Atro and just not draw attention to this potential situation. The likelihood is that app.position as an object storing positional data will survive the App v2 changes. It may not though. --- All of this again is just a sticking point for "unclean" hackery of external modules which is the exception to the rule.
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
ok I've made a workaround
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
Do share.. I'll be at a computer soon.
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
constructor() {
...
this.position.subscribe((pos) => this.setPosition(pos, false));
}

setPosition(pos: any, propagate = true): any {
if (!propagate) return this.position.get();
return super.setPosition(pos);
}
constructor() {
...
this.position.subscribe((pos) => this.setPosition(pos, false));
}

setPosition(pos: any, propagate = true): any {
if (!propagate) return this.position.get();
return super.setPosition(pos);
}
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
result
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
Nice.. Yeah. I was going to check out potential solutions that required a small override to setPosition, but the above is a good take at it. Now... This works in the adhoc use case of paper doll, but perhaps may fail to work when an external module tries to change the position data versus just plug into getting a hard coded callback that just some position changed of an external app.
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
yup
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
It's conceivably possible to just make a "Foundry" implementation of draggable or just add the overridden setPosition implementation you came up with to SvelteApplication, but it really makes sense to wait until there is more details / access to App v2 before implementing anything. Essentially the current SvelteApplication implementation is going to be transferred to the legacy sub-path export #runtime/svelte/application/legacy and then a new App v2 implementation will be made as presumably there will be changes.
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
yup I'd deffo wait till application v2 before making any changes honestly
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
It is a low volume nuisance really just for system developers too. I don't think there are modules that try to do something to other modules in the same manner as paper doll does in respect to actor sheets.
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
a lot of modules do actually just not with sheets usually it's usually with other parts of the system
midi,
dae,
better-rolls,
midi,
dae,
better-rolls,
the list goes on Honestly, the way modules change stuff is by wrapping the original functions of sheets, documents, etc
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
For sure, but from a UI / control perspective it should be rare or non-existent that a module tries to change the behavior of another module. The paper doll situation is system specific for actor sheets.
Nekro Darkmoon
Nekro DarkmoonOP•11mo ago
Yeah Core foundry doesn't really have a hook for position change of a sheet So stuff like this ends up being needed Hopefully all these little things will be better with Appv2
TyphonJS (Michael)
TyphonJS (Michael)•11mo ago
Yeah.. I hope so too. I wished I had a better working relationship with Atro and the core team to be able to communicate lessons learned. You could drop in the TRL position implementation (which is JS) right in and get tremendous benefits. I want to remain positive that good things will come from App v2, but I expect it to be flawed as UI / UX is not a strong point of the core team. I remain hopefull nonetheless. Just as a note too re: no hook for position changes. If the TRL / TJSPosition implementation was the standard these kinds of problems would go away because app.position can be subscribed to. And if an external module wants to alter validation of position changes there is the validator API of TJSPosition: https://typhonjs-fvtt-lib.github.io/api-docs/classes/_runtime_svelte_store_position.AdapterValidators.html I definitely should try and get a demo of the validator API into essential-svelte-esm at some point.
Want results from more Discord servers?
Add your server