-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpause-control.mjs
More file actions
4 lines (3 loc) · 3.56 KB
/
Copy pathpause-control.mjs
File metadata and controls
4 lines (3 loc) · 3.56 KB
1
2
3
4
var CFG={id:"pause-control",COLORS:{main:"color:orangered",label:"color:mediumseagreen",unset:"color:unset",number:"color:mediumpurple"}};function unPauseCombat(combat,_settings,_id){if(!game.user.isGM)return;if(!combat.started)return;if(combat.combatants.size==0)return;if(game.paused)console.debug("%cPAUSE CONTROL%c | Combat starting. Unpausing.",CFG.COLORS.main,CFG.COLORS.unset),game.togglePause(!1,!0)}function toggleCombatUnpause(value){if(value)Hooks.on("updateCombat",unPauseCombat);else Hooks.off("updateCombat",unPauseCombat)}function combatPauseControl(combat,_settings,_id){if(!game.user.isGM)return;if(!combat.started)return;if(combat.data.combatants?.length<1)return;const actor=canvas.tokens.get(combat.current.tokenId)?.actor,newPauseState=!actor?.hasPlayerOwner;if(console.debug(`%cPAUSE CONTROL%c | Combat | Pausing: %c${newPauseState}%c; Actor:`,CFG.COLORS.main,CFG.COLORS.unset,CFG.COLORS.label,CFG.COLORS.unset,actor),game.paused!==newPauseState)game.togglePause(newPauseState,!0)}function togglePauseControl(value){if(value)Hooks.on("updateCombat",combatPauseControl);else Hooks.off("updateCombat",combatPauseControl)}async function saveState(combat,_options,_id){if(!game.user.isGM)return;const preCombatState=game.paused;return console.debug("%cPAUSE CONTROL%c | Restore Pause | Recording state as: ",CFG.COLORS.main,CFG.COLORS.unset,preCombatState),combat.setFlag(CFG.id,"preCombatState",preCombatState)}function restoreState(combat,_options,_id){if(!game.user.isGM)return;const preCombatState=combat.getFlag(CFG.id,"preCombatState");if(preCombatState===void 0)return;console.debug("%cPAUSE CONTROL%c | Restore Pause | Restoring state to: ",CFG.COLORS.main,CFG.COLORS.unset,preCombatState),game.togglePause(preCombatState,!0)}function togglePauseRestore(value){if(value)Hooks.on("createCombat",saveState),Hooks.on("deleteCombat",restoreState);else Hooks.off("deleteCombat",restoreState),Hooks.off("createCombat",saveState)}function registerSettings(){game.settings.register(CFG.id,"unpauseOnReady",{name:"Koboldworks.Unpause.OnReady",hint:"Koboldworks.Unpause.OnReadyHint",default:!1,type:Boolean,scope:"world",config:!0}),game.settings.register(CFG.id,"unpauseOnCombat",{name:"Koboldworks.Unpause.OnCombat",hint:"Koboldworks.Unpause.OnCombatHint",default:!1,type:Boolean,scope:"world",config:!0,onChange:toggleCombatUnpause}),game.settings.register(CFG.id,"pausedCombat",{name:"Koboldworks.Pause.CombatControl",hint:"Koboldworks.Pause.CombatControlHint",default:!1,type:Boolean,scope:"world",config:!0,onChange:togglePauseControl}),game.settings.register(CFG.id,"restorePause",{name:"Koboldworks.Pause.Restore",hint:"Koboldworks.Pause.RestoreHint",default:!1,type:Boolean,scope:"world",config:!0,onChange:togglePauseRestore})}function setPauseState(state){if(game.paused===state)return;if(console.debug("%cPAUSE CONTROL%c | setPauseState =",CFG.COLORS.main,CFG.COLORS.unset,state),game.user?.isGM)game.togglePause(state,!0);else game.data.paused=state,game.socket.emit("pause",state),ui.pause.render(),Hooks.callAll("pauseGame",state)}Hooks.once("init",registerSettings);Hooks.once("ready",()=>{const getSetting=(id)=>game.settings.get(CFG.id,id);if(getSetting("pausedCombat"))togglePauseControl(!0);if(getSetting("restorePause"))togglePauseRestore(!0);if(getSetting("unpauseOnCombat"))toggleCombatUnpause(!0);if(getSetting("unpauseOnReady"))setPauseState(!1);const mod=game.modules.get(CFG.id);console.log(`%cPAUSE CONTROL%c | %c${mod.version}%c | READY!`,CFG.COLORS.main,CFG.COLORS.unset,CFG.COLORS.label,CFG.COLORS.unset)});
//# debugId=B180E144F050A4C064756E2164756E21
//# sourceMappingURL=pause-control.mjs.map