diff --git a/src/stores/CalendarStore.ts b/src/stores/CalendarStore.ts index 50e261e..cd1aaed 100644 --- a/src/stores/CalendarStore.ts +++ b/src/stores/CalendarStore.ts @@ -224,6 +224,38 @@ export const useCalendar = defineStore('calendar', () => { params.month = newValue.toString() } + /** + * Get the previous month number + * + * @param monthNumber Initial month + * @returns The previous month number in the year + */ + function getPreviousMonth(monthNumber: number): number { + const target: number = monthNumber - 1 + + if (target < 0) { + return monthsPerYear - 1 + } + + return target + } + + /** + * Get the following month number + * + * @param monthNumber Initial month + * @returns The next month number in the year + */ + function getNextMonth(monthNumber: number): number { + const target: number = monthNumber + 1 + + if (target + 1 >= monthsPerYear) { + return 0 + } + + return target + } + /** * Moves the current date to a particular month */ @@ -370,6 +402,8 @@ export const useCalendar = defineStore('calendar', () => { incrementMonth, decrementMonth, setMonth, + getPreviousMonth, + getNextMonth, incrementYear, decrementYear, jumpToDate, diff --git a/src/stores/EventStore.ts b/src/stores/EventStore.ts index 04ba0ed..ad8b169 100644 --- a/src/stores/EventStore.ts +++ b/src/stores/EventStore.ts @@ -6,7 +6,7 @@ import { useCharacters } from './CharacterStore' import { regularEvents } from '@/data/Events' export const useCalendarEvents = defineStore('calendar-events', () => { - const { currentDate, currentConfig } = useCalendar() + const { currentDate, currentConfig, getNextMonth } = useCalendar() const { charactersWithBirthData, charactersWithDeathData } = useCharacters() const baseEvents = ref(regularEvents) @@ -16,7 +16,7 @@ export const useCalendarEvents = defineStore('calendar-events', () => { return { title: `Naissance de ${character.name}`, date: character.birth, - category: 'birth' + category: 'naissance' } as CalendarEvent }) }) @@ -26,7 +26,7 @@ export const useCalendarEvents = defineStore('calendar-events', () => { return { title: `Décès de ${character.name}`, date: character.death, - category: 'death' + category: 'mort' } as CalendarEvent }) }) @@ -56,7 +56,7 @@ export const useCalendarEvents = defineStore('calendar-events', () => { case 'month': return ( event.date.month === currentDate.currentMonth || - (event.date.month === currentDate.currentMonth + 1 && event.date.day <= 8) // This is to allow leap events from appearing on the last 8 tiles + (event.date.month === getNextMonth(currentDate.currentMonth) && event.date.day <= 8) // This is to allow leap events from appearing on the last 8 tiles ) case 'year':