Created
June 7, 2025 22:06
-
-
Save therealjasonkenney/c91f53e16e1b39b941bfc96601ceaf9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MOON_PHASES = [ | |
"New Moon", | |
"Waxing Crescent", | |
"First Quarter", | |
"Waxing Gibbous", | |
"Full Moon", | |
"Waning Gibbous", | |
"Last Quarter", | |
"Waning Crescent" | |
]; | |
Hooks.once('init', () => { | |
console.log("Moon Phase Tracker | Initializing"); | |
// Register a world setting to store current phase index | |
game.settings.register('moon-phase-tracker', 'currentPhase', { | |
name: "Current Moon Phase", | |
hint: "Tracks the current moon phase index", | |
scope: "world", | |
config: false, | |
type: Number, | |
default: 0 | |
}); | |
}); | |
Hooks.once('ready', () => { | |
if (game.user.isGM) { | |
createMoonPhaseButton(); | |
} | |
}); | |
function createMoonPhaseButton() { | |
// Add a button to the Foundry sidebar | |
let button = $(`<button class="moon-phase-btn" title="Advance Moon Phase"> | |
🌙 <span class="moon-phase-text"></span> | |
</button>`); | |
button.click(() => { | |
advanceMoonPhase(); | |
}); | |
// Add styling | |
const style = ` | |
<style> | |
.moon-phase-btn { | |
background: none; | |
border: none; | |
cursor: pointer; | |
font-size: 1.5em; | |
color: #ddd; | |
margin: 5px; | |
} | |
.moon-phase-btn:hover { | |
color: #fff; | |
} | |
</style> | |
`; | |
$("head").append(style); | |
// Append the button to the controls sidebar (top area) | |
$('#controls').prepend(button); | |
updateMoonPhaseText(); | |
} | |
async function advanceMoonPhase() { | |
let current = game.settings.get('moon-phase-tracker', 'currentPhase'); | |
current = (current + 1) % MOON_PHASES.length; | |
await game.settings.set('moon-phase-tracker', 'currentPhase', current); | |
updateMoonPhaseText(); | |
} | |
function updateMoonPhaseText() { | |
let current = game.settings.get('moon-phase-tracker', 'currentPhase'); | |
$(".moon-phase-text").text(MOON_PHASES[current]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment