zeel01 / TokenHUDArtButton

A Foundry VTT module that adds a button to the token HUD that opens the target actor's artwork.
MIT License
6 stars 5 forks source link

Show image to specific players #17

Open lucasmiranda2711 opened 2 years ago

lucasmiranda2711 commented 2 years ago

I'm wondering if it's possible to show image only to specific players when using the command "Show to players", I see you're using the socket.emit function to show to all players,I don't know how socket.io works, but I think it would be an awesome feature.

lucasmiranda2711 commented 2 years ago

Actually I found out a possible solution for this, you can actually change the game.socket.on to filter the users by userId, for example:

shareImage() { game.socket.emit("module.token-hud-art-button", { image: this.object, title: this.options.title, uuid: this.options.uuid }, game.user.id); //sending the user }

and on creation of the socket creation:

Hooks.once("ready", () => {
    game.socket.on("module.token-hud-art-button", (multiMediaPopout,  userId) => {

     if ( userId !== game.user.id ) return;    //if the user sent on the emition is different of mine, then it won't show to me

     multiMediaPopout._handleShareMedia);
}
});