Huge refactor for backend and client

This is barely functionnal, but at least it can display some data without crashing
Most other functionnalities other than displaying events are broken, and so are the relative date operations, they need to be fixed asap
This commit is contained in:
Alexis
2024-05-16 22:58:19 +02:00
parent 49e523485b
commit 67f5a270af
28 changed files with 247 additions and 303 deletions

View File

@@ -1,6 +1,12 @@
import type { CalendarEvent } from "./CalendarEvent"
import type { CalendarMonth } from "./CalendarMonth"
export interface CalendarConfig {
months: string[]
monthsPerYear: number
months: CalendarMonth[]
daysPerMonth: number
// todayDate: any
}
export interface Calendar extends CalendarConfig {
id: number
events: CalendarEvent[]
}

18
models/CalendarEvent.ts Normal file
View File

@@ -0,0 +1,18 @@
import type { Category } from './Category'
import type { RPGDate } from './Date'
export interface CalendarEvent {
id: number
title: string
startDate: RPGDate
endDate?: RPGDate
description?: string
category?: Category
hidden?: boolean
wiki?: string
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isCalendarEvent(object: any): object is CalendarEvent {
return 'startDate' in object
}

6
models/CalendarMonth.ts Normal file
View File

@@ -0,0 +1,6 @@
export interface CalendarMonth {
id: number
days: number,
name: string,
position: number,
}

4
models/Category.ts Normal file
View File

@@ -0,0 +1,4 @@
export interface Category {
id: number
name: string
}

View File

@@ -1,10 +1,10 @@
import type { LeimDate } from './Date'
import type { RPGDate } from './Date'
export interface Character {
name: string
description?: string
birth?: LeimDate
death?: LeimDate
birth?: RPGDate
death?: RPGDate
hiddenBirth?: boolean
hiddenDeath?: boolean
category?: CharacterCategory

View File

@@ -1,13 +1,13 @@
export interface LeimDate {
export interface RPGDate {
day: number
month: number
year: number
period?: LeimPeriod
period?: RPGPeriod
}
export type LeimPeriod = 'ante' | 'nante'
export type LeimPeriodShort = 'A.R' | 'N.R'
export type LeimDateOrder = 'asc' | 'desc'
export type RPGPeriod = 'ante' | 'nante'
export type RPGPeriodShort = 'A.R' | 'N.R'
export type RPGDateOrder = 'asc' | 'desc'
export const monthsPerYear: number = 10
export const daysPerYear: number = 320
@@ -21,7 +21,7 @@ export const daysPerWeek: number = 6
* @param date2 Second date
* @returns True if the dates are identical
*/
export function areDatesIdentical(date1: LeimDate, date2: LeimDate): boolean {
export function areDatesIdentical(date1: RPGDate, date2: RPGDate): boolean {
return convertDateToDays({ ...date1 }) === convertDateToDays({ ...date2 })
}
@@ -32,7 +32,7 @@ export function areDatesIdentical(date1: LeimDate, date2: LeimDate): boolean {
* @param date2 Second date
* @returns 1 means the first date comes before the second, -1 means the second comes before the first, and 0 if they're identical
*/
export function compareDates(a: LeimDate, b: LeimDate, order: LeimDateOrder = 'desc'): number {
export function compareDates(a: RPGDate, b: RPGDate, order: RPGDateOrder = 'desc'): number {
// Reverses the order if specified
const orderFactor: number = order === 'desc' ? 1 : -1
@@ -58,13 +58,13 @@ export function compareDates(a: LeimDate, b: LeimDate, order: LeimDateOrder = 'd
}
/**
* Converts a LeimDate to its equivalent in days
* Converts a RPGDate to its equivalent in days
*
* @todo Handle negative dates
* @param dateToConvert The date object
* @returns How many days does it represent
*/
export function convertDateToDays(dateToConvert: LeimDate): number {
export function convertDateToDays(dateToConvert: RPGDate): number {
let numberOfDays: number = dateToConvert.day
numberOfDays = numberOfDays + dateToConvert.month * daysPerMonth
@@ -79,7 +79,7 @@ export function convertDateToDays(dateToConvert: LeimDate): number {
* @param relativeDate The year to compare it to
* @returns The number of days separating the two dates (both positive and negative numbers)
*/
export function getDifferenceInDays(baseDate: LeimDate, relativeDate: LeimDate): number {
export function getDifferenceInDays(baseDate: RPGDate, relativeDate: RPGDate): number {
return convertDateToDays(relativeDate) - convertDateToDays(baseDate)
}
@@ -91,8 +91,8 @@ export function getDifferenceInDays(baseDate: LeimDate, relativeDate: LeimDate):
* @returns A string with info on how the relative date differs to the base date
*/
export function getRelativeString(
baseDate: LeimDate,
relativeDate: LeimDate,
baseDate: RPGDate,
relativeDate: RPGDate,
formatting: 'compact' | 'complex' = 'complex'
): string {
const differenceInDays: number = getDifferenceInDays(baseDate, relativeDate)
@@ -177,11 +177,11 @@ export function getRelativeString(
return output
}
// export function getRelativeDate(baseDate: LeimDate, relativeDate: LeimDate) {
// export function getRelativeDate(baseDate: RPGDate, relativeDate: RPGDate) {
// let newDay: number
// let newMonth: number
// let newYear: number
// let newPeriod: LeimPeriod
// let newPeriod: RPGPeriod
// const differenceInDays = getDifferenceInDays(baseDate, relativeDate)

View File

@@ -1,39 +0,0 @@
import type { LeimDate } from './Date'
export interface CalendarEvent {
title: string
startDate: LeimDate
endDate?: LeimDate
description?: string
category?: CalendarEventCategory
secondaryCategories?: CalendarEventCategory[]
hidden?: boolean
wiki?: string
}
export const calendarEventCategories = [
'naissance',
'mort',
'catastrophe',
'législation',
'catastrophe naturelle',
'inauguration',
'religion',
'invention',
'science',
'bénédiction',
'joueurs',
'découverte',
'exploration',
'construction',
'arcanologie',
'criminalité',
'scandale',
'commerce'
] as const
export type CalendarEventCategory = (typeof calendarEventCategories)[number]
export function isCalendarEvent(object: any): object is CalendarEvent {
return 'startDate' in object
}