View & Toggle Token Vision - crnormand/gurps GitHub Wiki

Type: Script

Contributor: Buzzard

Description: Displays a modal with the current state of Token Vision on the Viewed Scene and provides an option to toggle the Token Vision setting.

// Use Viewed Scene
const scene = canvas.scene;

if (!scene) {
  ui.notifications.warn("No scene is currently viewed.");
  return;
}

const currentState = scene.tokenVision;
const statusText = currentState ? "ON" : "OFF";

// Build Dialog
new Dialog({
  title: "View/Toggle Token Vision",
  content: `<p><strong>Scene: ${scene.name}</strong></p><p>Token Vision is currently <strong>${statusText}</strong>.</p><p>Would you like to toggle it?</p>`,
  buttons: {
    toggle: {
      label: `Turn ${currentState ? "OFF" : "ON"}`,
      callback: async () => {
        await scene.update({ tokenVision: !currentState });
        ui.notifications.info(`Token Vision is now ${!currentState ? "ON" : "OFF"} on "${scene.name}".`);
        canvas.scene = null;
      }
    },
    cancel: {
      label: "Cancel"
    }
  },
  default: "cancel"
}).render(true);
⚠️ **GitHub.com Fallback** ⚠️