starshard/peafowl
Template
1
Fork 0
mirror of https://github.com/starshardstudio/peafowl.git synced 2024-11-23 13:34:20 +00:00
peafowl/_utils/anime.ts

119 lines
3.1 KiB
TypeScript
Raw Permalink Normal View History

2024-11-21 05:37:11 +00:00
import { ReviewData, ReviewIdentifier, ReviewWikidataIdentifier } from "./review.ts";
export interface AnimeAnidbIdentifier extends ReviewIdentifier {
type: "anidb";
aid: string;
}
export interface AnimeMalIdentifier extends ReviewIdentifier {
type: "mal";
id: string;
}
export interface AnimeAnnIdentifier extends ReviewIdentifier {
type: "ann";
id: string;
}
export interface AnimeAnilistIdentifier extends ReviewIdentifier {
type: "anilist";
id: string;
}
export type AnimeIdentifier = ReviewWikidataIdentifier | AnimeAnidbIdentifier | AnimeMalIdentifier | AnimeAnnIdentifier | AnimeAnilistIdentifier;
2024-11-05 12:19:36 +00:00
2024-11-05 12:22:18 +00:00
export interface AnimeData extends ReviewData {
2024-11-05 12:19:36 +00:00
name_original: string;
active?: boolean;
progress?: AnimeProgress;
started_on?: Date;
completed_on?: Date;
mastered_on?: Date;
}
2024-11-05 12:39:28 +00:00
export type AnimePage = Lume.Page<AnimeData>;
2024-11-05 12:19:36 +00:00
export enum AnimeProgress {
Unset = "",
New = "new",
Started = "started",
Completed = "completed",
Mastered = "mastered",
}
export function animeProgressToIconDef(progress?: AnimeProgress): string {
switch (progress) {
case undefined:
return "";
case AnimeProgress.Unset:
return "";
case AnimeProgress.New:
return "fa-ellipsis";
case AnimeProgress.Started:
return "fa-play";
case AnimeProgress.Completed:
return "fa-circle-check";
case AnimeProgress.Mastered:
return "fa-heart";
}
}
export function animeProgressToClassName(progress?: AnimeProgress): string {
switch (progress) {
case undefined:
return "progress-unset";
case AnimeProgress.Unset:
return "progress-unset";
case AnimeProgress.New:
return "progress-new";
case AnimeProgress.Started:
return "progress-started";
case AnimeProgress.Completed:
return "progress-completed";
case AnimeProgress.Mastered:
return "progress-mastered";
}
}
export function animeProgressToTitle(progress?: AnimeProgress): string {
switch (progress) {
case undefined:
return "";
case AnimeProgress.Unset:
return "";
case AnimeProgress.New:
return "New";
case AnimeProgress.Started:
return "Started";
case AnimeProgress.Completed:
return "Completed";
case AnimeProgress.Mastered:
return "Mastered";
}
}
// Duplicated in _static/scripting/sort.js
export function animeProgressToNumber(progress?: AnimeProgress): number {
switch (progress) {
case undefined:
return 0;
case AnimeProgress.Unset:
return 0;
case AnimeProgress.New:
return 10;
case AnimeProgress.Started:
return 20;
case AnimeProgress.Completed:
return 35;
case AnimeProgress.Mastered:
return 50;
}
}
2024-11-05 12:39:28 +00:00
export function compareAnimeProgress(a: AnimeData, b: AnimeData): number {
2024-11-05 12:19:36 +00:00
return animeProgressToNumber(a.progress) - animeProgressToNumber(b.progress);
}