alessiocali / card-tiles

A Foundry VTT Module for automatically showing cards on the canvas.
MIT License
3 stars 5 forks source link

Allow non-gm users to play cards to the canvas. #16

Closed SalieriC closed 2 years ago

SalieriC commented 2 years ago

In core Foundry, non-gm players lack permission to place tiles, thus only the GM can play cards from their hands onto the canvas. Allowing non-gm players to place their cards could be a great enhancement of this module. I have a working code already, but it uses the event system provided by Warpgate to relay the placement to a GM account, thus adding another dependency. As you've mentioned here, less dependencies are better. But I don't think reinventing the wheel for this module is worth the effort. What do you think of adding a new dependency? If you're fine with it, I'll create a PR once #15 is resolved (don't want to mix things up in case you're making changes to that).

alessiocali commented 2 years ago

It's true that less dependencies are better, but I'm fine with adding libraries. My problem with having Monk's tiles as a dependency is that it's not meant to be a library, so we have no guarantee on the stability of their interface.

That being said the same goes that my spare time is pretty limited, I'll try to give it a look in the weekend.

alessiocali commented 2 years ago

Also this is definitely a bug, players should totally be able to play their cards.

SalieriC commented 2 years ago

As I said, I have working code already. We just need to make minor adjustments to respect #17. We can do this right now if you wish and in 15-20 minutes it'll be done I think.

SalieriC commented 2 years ago

Here is the code, all commented: https://github.com/SalieriC/card-tiles/blob/warpgate/scripts/card-tiles.js

The gist is that the request to play a card is sent from the players account here: https://github.com/SalieriC/card-tiles/blob/5b9b698e5c8f1cf5d65a4be170a5ecc951b38cab/scripts/card-tiles.js#L26-L56 Note that passing stuff is finicky in warpgate, thus I just pass IDs.

This request is picked up by the GM, using a listener set up on the ready hook: https://github.com/SalieriC/card-tiles/blob/5b9b698e5c8f1cf5d65a4be170a5ecc951b38cab/scripts/card-tiles.js#L3-L7 Note that it checks for the first active GM in the event listener using a separate function here: https://github.com/SalieriC/card-tiles/blob/5b9b698e5c8f1cf5d65a4be170a5ecc951b38cab/scripts/card-tiles.js#L9-L12

Then, if the user is the first GM, the gm part of the tile creation will be executed: https://github.com/SalieriC/card-tiles/blob/5b9b698e5c8f1cf5d65a4be170a5ecc951b38cab/scripts/card-tiles.js#L58-L82 Because I passed IDs, the cardEventData object will be set up here and no earlier.

Basically, the tile creation was just pulled apart in one player function and one gm function while warpgates event system closes the gap between them. Let me know and I can build that into your code at #17. =)

alessiocali commented 2 years ago

I definitely don't have the mental energy right now to follow it through 😅 It's 9 pm in my timezone and I come from a day of work. As I said I'll try to check it in the weekend.

alessiocali commented 2 years ago

Ok I got the gist of it, makes sense. I'll open up a pull request and do some flavor edits. Thanks for the suggestion!