mirror of
https://github.com/starshardstudio/peafowl.git
synced 2024-11-21 12:34:20 +00:00
Move progress to being game-specific
This commit is contained in:
parent
e4189e1bf0
commit
ef52a09787
6 changed files with 133 additions and 137 deletions
|
@ -1,6 +1,6 @@
|
|||
import {formatDateIso} from "../_utils/date.ts"
|
||||
import {GameData} from "../_utils/game.ts"
|
||||
import {Progress, progressToClassName, progressToIconDef, progressToTitle} from "../_utils/progress.ts"
|
||||
import {GameProgress, gameProgressToClassName, gameProgressToIconDef, gameProgressToTitle} from "../_utils/game.ts"
|
||||
import {ratingToClassName} from "../_utils/rating.ts"
|
||||
|
||||
|
||||
|
@ -25,9 +25,9 @@ export function GameRow({game, columns = gameRowColumnKindDefault, priority}: Ga
|
|||
|
||||
const ratingClass: string = ratingToClassName(game.rating)
|
||||
|
||||
const progressClass: string = progressToClassName(game.progress)
|
||||
const progressIcon: string = progressToIconDef(game.progress)
|
||||
const progressTitle: string = progressToTitle(game.progress)
|
||||
const progressClass: string = gameProgressToClassName(game.progress)
|
||||
const progressIcon: string = gameProgressToIconDef(game.progress)
|
||||
const progressTitle: string = gameProgressToTitle(game.progress)
|
||||
|
||||
const priorityClass: string = priority ? `priority-${priority}` : ""
|
||||
|
||||
|
@ -45,7 +45,7 @@ export function GameRow({game, columns = gameRowColumnKindDefault, priority}: Ga
|
|||
case "progress": {
|
||||
return (
|
||||
<td key={index} className={`game-progress ${progressClass}`}>
|
||||
<data value={game.progress ?? Progress.Unset} title={progressTitle}>
|
||||
<data value={game.progress ?? GameProgress.Unset} title={progressTitle}>
|
||||
{progressIcon && <i className={`fa-sharp fa-regular ${progressIcon} ${activeClassFa}`}></i>}
|
||||
</data>
|
||||
</td>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {formatDateIso} from "../_utils/date.ts"
|
||||
import {GameData, GameIdentifier} from "../_utils/game.ts"
|
||||
import {Progress, progressToClassName, progressToIconDef, progressToTitle} from "../_utils/progress.ts"
|
||||
import {GameProgress, gameProgressToClassName, gameProgressToIconDef, gameProgressToTitle} from "../_utils/game.ts"
|
||||
import {ReviewInfo} from "../_components/ReviewInfo.tsx"
|
||||
|
||||
|
||||
|
@ -20,12 +20,12 @@ export default function(data: GameData, helpers: Lume.Helpers) {
|
|||
|
||||
const progressRow = data.progress ? (
|
||||
<ReviewInfo.MetadataRow
|
||||
className={`game-progress ${progressToClassName(data.progress)}`}
|
||||
className={`game-progress ${gameProgressToClassName(data.progress)}`}
|
||||
label={"Progress"}
|
||||
icon={<i className={`fa-sharp fa-regular ${progressToIconDef(data.progress)} ${data.active ? "fa-beat-fade" : ""}`}/>}
|
||||
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(data.progress)} ${data.active ? "fa-beat-fade" : ""}`}/>}
|
||||
>
|
||||
<data value={data.progress}>
|
||||
{progressToTitle(data.progress)}
|
||||
{gameProgressToTitle(data.progress)}
|
||||
</data>
|
||||
{data.active &&
|
||||
<>
|
||||
|
@ -56,7 +56,7 @@ export default function(data: GameData, helpers: Lume.Helpers) {
|
|||
<ReviewInfo.MetadataRow
|
||||
className={`game-purchasedon`}
|
||||
label={"Purchased on"}
|
||||
icon={<i className={`fa-sharp fa-regular ${progressToIconDef(Progress.New)}`}/>}
|
||||
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.New)}`}/>}
|
||||
>
|
||||
<time dateTime={purchasedOnValue}>
|
||||
{purchasedOnValue}
|
||||
|
@ -69,7 +69,7 @@ export default function(data: GameData, helpers: Lume.Helpers) {
|
|||
<ReviewInfo.MetadataRow
|
||||
className={`game-startedon`}
|
||||
label={"Started on"}
|
||||
icon={<i className={`fa-sharp fa-regular ${progressToIconDef(Progress.Started)}`}/>}
|
||||
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.Started)}`}/>}
|
||||
>
|
||||
<time dateTime={startedOnValue}>
|
||||
{startedOnValue}
|
||||
|
@ -82,7 +82,7 @@ export default function(data: GameData, helpers: Lume.Helpers) {
|
|||
<ReviewInfo.MetadataRow
|
||||
className={`game-beatenon`}
|
||||
label={"Beaten on"}
|
||||
icon={<i className={`fa-sharp fa-regular ${progressToIconDef(Progress.Beaten)}`}/>}
|
||||
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.Beaten)}`}/>}
|
||||
>
|
||||
<time dateTime={beatenOnValue}>
|
||||
{beatenOnValue}
|
||||
|
@ -95,7 +95,7 @@ export default function(data: GameData, helpers: Lume.Helpers) {
|
|||
<ReviewInfo.MetadataRow
|
||||
className={`game-completedon`}
|
||||
label={"Completed on"}
|
||||
icon={<i className={`fa-sharp fa-regular ${progressToIconDef(Progress.Completed)}`}/>}
|
||||
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.Completed)}`}/>}
|
||||
>
|
||||
<time dateTime={completedOnValue}>
|
||||
{completedOnValue}
|
||||
|
@ -108,7 +108,7 @@ export default function(data: GameData, helpers: Lume.Helpers) {
|
|||
<ReviewInfo.MetadataRow
|
||||
className={`game-masteredon`}
|
||||
label={"Mastered on"}
|
||||
icon={<i className={`fa-sharp fa-regular ${progressToIconDef(Progress.Mastered)}`}/>}
|
||||
icon={<i className={`fa-sharp fa-regular ${gameProgressToIconDef(GameProgress.Mastered)}`}/>}
|
||||
>
|
||||
<time dateTime={masteredOnValue}>
|
||||
{masteredOnValue}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {compareDate} from "../_utils/date.ts"
|
||||
import { GameData } from "../_utils/game.ts";
|
||||
import {GameTable} from "../_components/GameTable.tsx"
|
||||
import {compare_progress} from "../_utils/progress.ts"
|
||||
import {compareGameProgress} from "../_utils/game.ts"
|
||||
import {GlobalData} from "../_utils/site.ts"
|
||||
|
||||
|
||||
|
@ -62,7 +62,7 @@ export default function(data: GlobalData, helpers: Lume.Helpers) {
|
|||
)
|
||||
|
||||
const progress_games = games
|
||||
.sort((a, b) => -compare_progress(a, b))
|
||||
.sort((a, b) => -compareGameProgress(a, b))
|
||||
.slice(0, 10)
|
||||
|
||||
const progress_games_section = (
|
||||
|
|
|
@ -3,7 +3,7 @@ import {default as site} from "../_config.ts"
|
|||
import {formatDateIso} from "../_utils/date.ts"
|
||||
import {GameData, GameIdentifier, GamePage} from "../_utils/game.ts"
|
||||
import {stringifyYaml} from "lume/cms/deps/std.ts"
|
||||
import {Progress} from "../_utils/progress.ts"
|
||||
import {GameProgress} from "../_utils/game.ts"
|
||||
|
||||
/* This is arguably one of the worst scripts I've ever written. */
|
||||
|
||||
|
@ -102,7 +102,7 @@ for(const game of games) {
|
|||
name_sort: page?.name_sort ?? game?.sort_as ?? "",
|
||||
rating: page?.rating ?? 0,
|
||||
active: page?.active ?? false,
|
||||
progress: page?.progress ?? Progress.Unset,
|
||||
progress: page?.progress ?? GameProgress.Unset,
|
||||
hours_played: Math.max(page?.hours_played ?? 0, Math.round((game?.playtime_forever ?? 0) / 60)),
|
||||
purchased_on: page?.purchased_on ?? NaN,
|
||||
started_on: page?.started_on ?? NaN,
|
||||
|
|
133
_utils/game.ts
133
_utils/game.ts
|
@ -1,33 +1,130 @@
|
|||
import {Progress} from "./progress.ts"
|
||||
import {ReviewData} from "./review.ts"
|
||||
|
||||
import { ReviewData } from "./review.ts";
|
||||
|
||||
export interface GameBaseIdentifier {
|
||||
type: string,
|
||||
synced_on?: string,
|
||||
type: string;
|
||||
synced_on?: string;
|
||||
}
|
||||
|
||||
export interface GameSteamIdentifier extends GameBaseIdentifier {
|
||||
type: "steam",
|
||||
appid: string,
|
||||
name?: string,
|
||||
type: "steam";
|
||||
appid: string;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export type GameIdentifier = GameSteamIdentifier;
|
||||
|
||||
export interface GameData extends ReviewData {
|
||||
active?: boolean,
|
||||
active?: boolean;
|
||||
|
||||
progress?: Progress,
|
||||
hours_played?: number
|
||||
progress?: GameProgress;
|
||||
hours_played?: number;
|
||||
|
||||
purchased_on?: Date,
|
||||
started_on?: Date,
|
||||
beaten_on?: Date,
|
||||
completed_on?: Date,
|
||||
mastered_on?: Date,
|
||||
purchased_on?: Date;
|
||||
started_on?: Date;
|
||||
beaten_on?: Date;
|
||||
completed_on?: Date;
|
||||
mastered_on?: Date;
|
||||
|
||||
identifiers?: GameIdentifier[]
|
||||
identifiers?: GameIdentifier[];
|
||||
}
|
||||
|
||||
export type GamePage = Lume.Page<GameData>
|
||||
export type GamePage = Lume.Page<GameData>;
|
||||
|
||||
export enum GameProgress {
|
||||
Unset = "",
|
||||
NotApplicable = "notapplicable",
|
||||
New = "new",
|
||||
Started = "started",
|
||||
Beaten = "beaten",
|
||||
Completed = "completed",
|
||||
Mastered = "mastered",
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
import {GameData} from "./game.ts"
|
||||
|
||||
|
||||
export enum Progress {
|
||||
Unset = "",
|
||||
NotApplicable = "notapplicable",
|
||||
New = "new",
|
||||
Started = "started",
|
||||
Beaten = "beaten",
|
||||
Completed = "completed",
|
||||
Mastered = "mastered",
|
||||
}
|
||||
|
||||
export function progressToIconDef(progress?: Progress): string {
|
||||
switch (progress) {
|
||||
case undefined:
|
||||
return "";
|
||||
case Progress.Unset:
|
||||
return "";
|
||||
case Progress.NotApplicable:
|
||||
return "fa-x";
|
||||
case Progress.New:
|
||||
return "fa-ellipsis";
|
||||
case Progress.Started:
|
||||
return "fa-play";
|
||||
case Progress.Beaten:
|
||||
return "fa-circle-check";
|
||||
case Progress.Completed:
|
||||
return "fa-star";
|
||||
case Progress.Mastered:
|
||||
return "fa-trophy";
|
||||
}
|
||||
}
|
||||
|
||||
export function progressToClassName(progress?: Progress): string {
|
||||
switch (progress) {
|
||||
case undefined:
|
||||
return "progress-unset";
|
||||
case Progress.Unset:
|
||||
return "progress-unset";
|
||||
case Progress.NotApplicable:
|
||||
return "progress-notapplicable";
|
||||
case Progress.New:
|
||||
return "progress-new";
|
||||
case Progress.Started:
|
||||
return "progress-started";
|
||||
case Progress.Beaten:
|
||||
return "progress-beaten";
|
||||
case Progress.Completed:
|
||||
return "progress-completed";
|
||||
case Progress.Mastered:
|
||||
return "progress-mastered";
|
||||
}
|
||||
}
|
||||
|
||||
export function progressToTitle(progress?: Progress): string {
|
||||
switch (progress) {
|
||||
case undefined:
|
||||
return "";
|
||||
case Progress.Unset:
|
||||
return "";
|
||||
case Progress.NotApplicable:
|
||||
return "Not applicable";
|
||||
case Progress.New:
|
||||
return "New";
|
||||
case Progress.Started:
|
||||
return "Started";
|
||||
case Progress.Beaten:
|
||||
return "Beaten";
|
||||
case Progress.Completed:
|
||||
return "Completed";
|
||||
case Progress.Mastered:
|
||||
return "Mastered";
|
||||
}
|
||||
}
|
||||
|
||||
// Duplicated in _static/scripting/sort.js
|
||||
export function progress_to_number(progress?: Progress): number {
|
||||
switch (progress) {
|
||||
case undefined:
|
||||
return 0;
|
||||
case Progress.Unset:
|
||||
return 0;
|
||||
case Progress.NotApplicable:
|
||||
return 5;
|
||||
case Progress.New:
|
||||
return 10;
|
||||
case Progress.Started:
|
||||
return 20;
|
||||
case Progress.Beaten:
|
||||
return 30;
|
||||
case Progress.Completed:
|
||||
return 40;
|
||||
case Progress.Mastered:
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
|
||||
export function compare_progress(a: GameData, b: GameData): number {
|
||||
return progress_to_number(a.progress) - progress_to_number(b.progress)
|
||||
}
|
Loading…
Reference in a new issue