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

131 lines
3.4 KiB
TypeScript
Raw Normal View History

2024-11-05 12:11:03 +00:00
import { ReviewData } from "./review.ts";
2024-06-16 11:49:13 +00:00
export interface GameBaseIdentifier {
2024-11-05 12:11:03 +00:00
type: string;
synced_on?: string;
2024-06-16 11:49:13 +00:00
}
export interface GameSteamIdentifier extends GameBaseIdentifier {
2024-11-05 12:11:03 +00:00
type: "steam";
appid: string;
name?: string;
2024-06-16 11:49:13 +00:00
}
export type GameIdentifier = GameSteamIdentifier;
export interface GameData extends ReviewData {
2024-11-05 12:11:03 +00:00
active?: boolean;
progress?: GameProgress;
hours_played?: number;
2024-06-16 11:49:13 +00:00
2024-11-05 12:11:03 +00:00
purchased_on?: Date;
started_on?: Date;
beaten_on?: Date;
completed_on?: Date;
mastered_on?: Date;
identifiers?: GameIdentifier[];
}
2024-06-16 11:49:13 +00:00
2024-11-05 12:11:03 +00:00
export type GamePage = Lume.Page<GameData>;
2024-06-16 11:49:13 +00:00
2024-11-05 12:11:03 +00:00
export enum GameProgress {
Unset = "",
NotApplicable = "notapplicable",
New = "new",
Started = "started",
Beaten = "beaten",
Completed = "completed",
Mastered = "mastered",
2024-06-16 11:49:13 +00:00
}
2024-11-05 12:11:03 +00:00
export function gameProgressToIconDef(progress?: GameProgress): string {
switch (progress) {
case undefined:
return "";
case GameProgress.Unset:
return "";
case GameProgress.NotApplicable:
return "fa-x";
case GameProgress.New:
return "fa-ellipsis";
case GameProgress.Started:
return "fa-play";
case GameProgress.Beaten:
return "fa-circle-check";
case GameProgress.Completed:
return "fa-star";
case GameProgress.Mastered:
return "fa-trophy";
}
}
export function gameProgressToClassName(progress?: GameProgress): string {
switch (progress) {
case undefined:
return "progress-unset";
case GameProgress.Unset:
return "progress-unset";
case GameProgress.NotApplicable:
return "progress-notapplicable";
case GameProgress.New:
return "progress-new";
case GameProgress.Started:
return "progress-started";
case GameProgress.Beaten:
return "progress-beaten";
case GameProgress.Completed:
return "progress-completed";
case GameProgress.Mastered:
return "progress-mastered";
}
}
export function gameProgressToTitle(progress?: GameProgress): string {
switch (progress) {
case undefined:
return "";
case GameProgress.Unset:
return "";
case GameProgress.NotApplicable:
return "Not applicable";
case GameProgress.New:
return "New";
case GameProgress.Started:
return "Started";
case GameProgress.Beaten:
return "Beaten";
case GameProgress.Completed:
return "Completed";
case GameProgress.Mastered:
return "Mastered";
}
}
// Duplicated in _static/scripting/sort.js
export function gameProgressToNumber(progress?: GameProgress): number {
switch (progress) {
case undefined:
return 0;
case GameProgress.Unset:
return 0;
case GameProgress.NotApplicable:
return 5;
case GameProgress.New:
return 10;
case GameProgress.Started:
return 20;
case GameProgress.Beaten:
return 30;
case GameProgress.Completed:
return 40;
case GameProgress.Mastered:
return 50;
}
}
export function compareGameProgress(a: GameData, b: GameData): number {
return gameProgressToNumber(a.progress) - gameProgressToNumber(b.progress);
}