Fixed bug with unseen events

The bug occured because the currentMonth + 1 went over the limit
This commit is contained in:
Alexis
2024-04-08 21:45:37 +02:00
parent cffdc7653d
commit c7fb5bec39
2 changed files with 38 additions and 4 deletions

View File

@@ -224,6 +224,38 @@ export const useCalendar = defineStore('calendar', () => {
params.month = newValue.toString() 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 * Moves the current date to a particular month
*/ */
@@ -370,6 +402,8 @@ export const useCalendar = defineStore('calendar', () => {
incrementMonth, incrementMonth,
decrementMonth, decrementMonth,
setMonth, setMonth,
getPreviousMonth,
getNextMonth,
incrementYear, incrementYear,
decrementYear, decrementYear,
jumpToDate, jumpToDate,

View File

@@ -6,7 +6,7 @@ import { useCharacters } from './CharacterStore'
import { regularEvents } from '@/data/Events' import { regularEvents } from '@/data/Events'
export const useCalendarEvents = defineStore('calendar-events', () => { export const useCalendarEvents = defineStore('calendar-events', () => {
const { currentDate, currentConfig } = useCalendar() const { currentDate, currentConfig, getNextMonth } = useCalendar()
const { charactersWithBirthData, charactersWithDeathData } = useCharacters() const { charactersWithBirthData, charactersWithDeathData } = useCharacters()
const baseEvents = ref<CalendarEvent[]>(regularEvents) const baseEvents = ref<CalendarEvent[]>(regularEvents)
@@ -16,7 +16,7 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
return { return {
title: `Naissance de ${character.name}`, title: `Naissance de ${character.name}`,
date: character.birth, date: character.birth,
category: 'birth' category: 'naissance'
} as CalendarEvent } as CalendarEvent
}) })
}) })
@@ -26,7 +26,7 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
return { return {
title: `Décès de ${character.name}`, title: `Décès de ${character.name}`,
date: character.death, date: character.death,
category: 'death' category: 'mort'
} as CalendarEvent } as CalendarEvent
}) })
}) })
@@ -56,7 +56,7 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
case 'month': case 'month':
return ( return (
event.date.month === currentDate.currentMonth || 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': case 'year':