T
TyphonJS7mo ago
Relic

Global Arrays & Writable Stores

I currently have this set to use a settings array to use to pass data to the SanityApp and also check to see if the Application is live because the application is to close if the array is empty. It's "populating the app" part and checking if the array is empty part is working as intended, but the interval I have set up in the script of the SanityApp appears to not be working as it's not updating automatically. SanityApp and SanityApplication.js
import { SvelteApplication } from '#runtime/svelte/application';
import SanityApp from './templates/SanityApp.svelte';
import { FatesDescentRoll } from './FatesDescentRoll.js';
import { MODULE_ID } from './settings.js';
import { debugLog } from './utils.js';

export default class SanityApplication extends SvelteApplication
{
constructor(actor, type, config, performRoll)
{
debugLog("SanityApplication | constructor called with:", actor, type, config);
const actorName = game.actors.get(actor.id)?.name;
const globalRequests = game.settings.get(MODULE_ID, "globalSaveRequests");

globalRequests.push({ actorId: actor.id, actorName, type, config });
game.settings.set(MODULE_ID, "globalSaveRequests", globalRequests);

super({
title: 'Sanity Dialog',
width: 630,
height: 'auto',
resizable: false,
svelte: {
class: SanityApp,
target: document.body,
props: {
performRoll
}
},
id: `sanity-dialog-${actor.id}`
});
}

static get defaultOptions()
{
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ['sanity-dialog'],
resizable: false,
id: 'sanity-dialog'
});
}

static showSanityDialog(actorId, type, config)
{
const globalRequests = game.settings.get(MODULE_ID, "globalSaveRequests");

if (globalRequests.length === 0)
{
const actor = game.actors.get(actorId);
if (!actor) { return; }

const sanityApp = new SanityApplication(actor, type, config, FatesDescentRoll.performRoll);
sanityApp.render(true);
}
else
{
const actorName = game.actors.get(actorId)?.name;
globalRequests.push({ actorId, actorName, type, config });
game.settings.set(MODULE_ID, "globalSaveRequests", globalRequests);
}
}
}
import { SvelteApplication } from '#runtime/svelte/application';
import SanityApp from './templates/SanityApp.svelte';
import { FatesDescentRoll } from './FatesDescentRoll.js';
import { MODULE_ID } from './settings.js';
import { debugLog } from './utils.js';

export default class SanityApplication extends SvelteApplication
{
constructor(actor, type, config, performRoll)
{
debugLog("SanityApplication | constructor called with:", actor, type, config);
const actorName = game.actors.get(actor.id)?.name;
const globalRequests = game.settings.get(MODULE_ID, "globalSaveRequests");

globalRequests.push({ actorId: actor.id, actorName, type, config });
game.settings.set(MODULE_ID, "globalSaveRequests", globalRequests);

super({
title: 'Sanity Dialog',
width: 630,
height: 'auto',
resizable: false,
svelte: {
class: SanityApp,
target: document.body,
props: {
performRoll
}
},
id: `sanity-dialog-${actor.id}`
});
}

static get defaultOptions()
{
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ['sanity-dialog'],
resizable: false,
id: 'sanity-dialog'
});
}

static showSanityDialog(actorId, type, config)
{
const globalRequests = game.settings.get(MODULE_ID, "globalSaveRequests");

if (globalRequests.length === 0)
{
const actor = game.actors.get(actorId);
if (!actor) { return; }

const sanityApp = new SanityApplication(actor, type, config, FatesDescentRoll.performRoll);
sanityApp.render(true);
}
else
{
const actorName = game.actors.get(actorId)?.name;
globalRequests.push({ actorId, actorName, type, config });
game.settings.set(MODULE_ID, "globalSaveRequests", globalRequests);
}
}
}
16 Replies
TyphonJS (Michael)
Include a repo link as well if you can.
Relic
RelicOP7mo ago
I haven't gotten into the "making branches" part of my learning just yet and don't want to overwrite what is there. I will sort that out tonight though.
TyphonJS (Michael)
I'll have to see how you are initializing the game setting. There may be a Foundry gotcha there if it is a world setting. IE world settings are only modifiable by GM users and not normal users though normal users can read world settings. This is just how Foundry works. As long as it is the GM account that is modifying a world store then this should be fine. Then there is finding the appropriate existing store / Foundry integration aspect w/ TRL to use vs what you currently have attempted.
Relic
RelicOP7mo ago
I’m currently registering with socketLib and the player clients send the request via socket. After that it’s all handle on the GM’s side.
TyphonJS (Michael)
That's good. Also in general I recommend not using an additional module dependency. Something like this should be easy to create the raw socket.io code.
Relic
RelicOP7mo ago
I have checked the current state code for function in this way and they can loaded the app in the older version before I started this “app expansion” part I’m doing now. Currently it just opens a new app with each incoming request.
TyphonJS (Michael)
TRL does have reactive game settings integration which should make this easy.. Even better is that there is a reactive world setting array / object store in the standard library that is quite likely what you'll want to use. See: WorldSettingArrayStore. Automated Animations uses it, but like most sample code it's not always best to point you to it as a simple / copy / paste example: https://github.com/otigon/automated-jb2a-animations/blob/dd66d205d4699c03b7dfc5a134c5196218360bfe/src/formApps/_AutorecMenu/store/category/CategoryStore.js#L7 The AA module is a bit complex; I also will be helping update it after 0.2.0 drops.
Relic
RelicOP7mo ago
Alright. After this one is complete and more functionality added, this is just the dialog app side, I have a Feat -> Talents conversion module to start which will heavily use svelte and a master automation module to flesh out. This one here is my first module I need to get registered with FVTT
https://github.com/Relic-Repo/Fates-Folly
TyphonJS (Michael)
Just a quick tip... When putting links into Discord surround them with <> like <URL> to not show the large breadcrumb image. Also you can use [some text](<URL>) to create a link from the text name which is handy.
Relic
RelicOP7mo ago
Oh cool learned something new
TyphonJS (Michael)
Lots of new stuff incoming re: Svelte & TRL! 😄
Relic
RelicOP7mo ago
I got it working. Well to be honest the "import { writable } from 'svelte/store';" was working all along, it was the dumb human. See the code is sett up to take the Save/Test data after a player rolls a save and adds it to an array I have in settings. If the array is empty it also calls the SanityApp. The SanityApp reads the global array sets up the writable store to watch for changes. The handleRoll and handleCancel are set up respectively add the form data nad completes the roll and the later just passes the roll along. But they both remove their reference entry from the settings array. As other players roll it sees teh array is not empty and just appends the new request object. Wellllll if the App is closed like it would be on a refresh, but the array isn't empty because you haven't been going through all of the form process. So yeah it dawned on me to check the array and sure enough it was loaded down. After I cleared it function returned. Adding a clear array on setup hook too Going to add an option to expand this to all d20 tests.
TyphonJS (Michael)
If you are happy with your code that is great. Good job getting it to work. As mentioned though there are cleaner solutions that are more functional in TRL to solve this particular problem and provide more flexibility. A large part of TRL is optional / use what you need. The one thing I can't do much of is debug custom code that you write.
Relic
RelicOP7mo ago
It's coming along nicely. I will soon be ready to push the change to GitHub and I'll post code then. I'm sure there are many shorter paths, but the failing is my teacher lol
No description
TyphonJS (Michael)
Getting on the struggle bus is definitely the way to learn. Perhaps we can circle around after 0.2.0 drops and see how things can be tighened up. 😄
Relic
RelicOP7mo ago
I added in an indicator/toggle for the GM for those players that rolled the wrong thing. Check is Blue and Orange is Save. The button will toggle to fix those types of in game play errors. Current state https://github.com/Relic-Repo/Fates-Descent
Want results from more Discord servers?
Add your server