Skip to content

Commit

Permalink
bring up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
jacc committed Oct 30, 2024
2 parents ed98a53 + 2accd38 commit e69c96b
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 192 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"eslint-config-next": "13.4.12",
"fast-xml-parser": "^4.2.6",
"mysql2": "^3.10.1",
"next": "13.4.12",
"next": "^14.2.3",
"next-themes": "^0.2.1",
"postcss": "8.4.24",
"posthog-js": "^1.110.0",
Expand Down
19 changes: 16 additions & 3 deletions scripts/achievements.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#! /usr/bin/env python3

# Purpose: Parsing all achievement info from wiki (iconURL, name, description)
# Result is saved to data/achievements.json
# { name: { iconURL, name, description, id } }
#
# Content Files used: None
# Content Files used: Achievements.json
# Wiki Pages used: https://stardewvalleywiki.com/Achievements

"""
Expand All @@ -16,16 +18,19 @@
from tqdm import tqdm
from bs4 import BeautifulSoup

from helpers.utils import save_json
from helpers.utils import save_json, load_content
from helpers.models import Achievement


def get_achievements() -> dict[str, Achievement]:
# Load the achievements.json file
achievementsData = load_content("Achievements.json")

# Get the page and relevant table body
URL = "https://stardewvalleywiki.com/Achievements"
page = requests.get(URL)
soup = BeautifulSoup(page.text, "html.parser")
tbody = soup.find("table").find("tbody") # Get the table body
tbody = soup.find("table", class_="wikitable").find("tbody") # Get the table body

id = 0 # This is not the accurate in game ID
achievements = {}
Expand All @@ -42,13 +47,21 @@ def get_achievements() -> dict[str, Achievement]:
# Get the text value of the 3rd and 4th <td> tags
name = tr.find_all("td")[2].text.strip()
description = tr.find_all("td")[3].text.strip()

# Attach the game ID to the achievement, if one exists
game_id = None # This is the accurate in game ID
for k, v in achievementsData.items():
game_name = v.split("^")[0]
if name.lower() in game_name.lower():
game_id = k

# Add the achievement to the dictionary
achievements[name] = {
"iconURL": "https://stardewvalleywiki.com" + iconURL,
"name": name,
"description": description.replace(" See (note below)", ""),
"id": id,
"gameID": int(game_id) if game_id else None,
}
id += 1

Expand Down
5 changes: 3 additions & 2 deletions src/components/cards/achievement-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ export const AchievementCard = ({
const { activePlayer } = usePlayers();
if (
activePlayer?.general?.achievements &&
activePlayer.general.achievements.includes(achievement.id)
achievement.gameID &&
activePlayer.general.achievements.includes(achievement.gameID)
) {
completed = true;
}

return (
<div
className={cn(
"flex select-none items-center space-x-3 rounded-lg border px-5 py-4 text-neutral-950 shadow-sm transition-colors dark:text-neutral-50",
"flex select-none items-center space-x-3 rounded-lg border px-5 py-4 text-neutral-950 shadow-sm transition-colors dark:text-neutral-50",
checkedClass,
)}
>
Expand Down
45 changes: 40 additions & 5 deletions src/components/ui/accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import * as AccordionPrimitive from "@radix-ui/react-accordion";
import { ChevronDownIcon } from "@radix-ui/react-icons";
import * as React from "react";

import { cn } from "@/lib/utils";

Expand All @@ -19,6 +19,36 @@ const AccordionItem = React.forwardRef<
AccordionItem.displayName = "AccordionItem";

const AccordionTrigger = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> & {
pullRight?: React.ReactNode;
}
>(({ className, children, pullRight, ...props }, ref) => (
<AccordionPrimitive.Header className="flex">
<AccordionPrimitive.Trigger
ref={ref}
className={cn(
// TODO: remove hover:underline ?
"flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all [&[data-state=open]>*>svg]:rotate-180 [&[data-state=open]>svg]:rotate-180",
className,
)}
{...props}
>
{children}
{pullRight ? (
<div className="flex">
{pullRight}
<ChevronDownIcon className=" ml-2 h-4 w-4 shrink-0 text-neutral-500 transition-transform duration-200 dark:text-neutral-400" />
</div>
) : (
<ChevronDownIcon className="h-4 w-4 shrink-0 text-neutral-500 transition-transform duration-200 dark:text-neutral-400" />
)}
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
));
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;

const AccordionTriggerNoToggle = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
Expand All @@ -27,17 +57,16 @@ const AccordionTrigger = React.forwardRef<
ref={ref}
className={cn(
// TODO: remove hover:underline ?
"flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
"flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all [&[data-state=open]>svg]:rotate-180",
className,
)}
{...props}
>
{children}
<ChevronDownIcon className="h-4 w-4 shrink-0 text-neutral-500 transition-transform duration-200 dark:text-neutral-400" />
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
));
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;
AccordionTriggerNoToggle.displayName = AccordionPrimitive.Trigger.displayName;

const AccordionContent = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Content>,
Expand All @@ -56,4 +85,10 @@ const AccordionContent = React.forwardRef<
));
AccordionContent.displayName = AccordionPrimitive.Content.displayName;

export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
export {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
AccordionTriggerNoToggle,
};
49 changes: 29 additions & 20 deletions src/components/ui/progress.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import * as React from "react"
import * as ProgressPrimitive from "@radix-ui/react-progress"
import * as React from "react";
import * as ProgressPrimitive from "@radix-ui/react-progress";

import { cn } from "@/lib/utils"
import { cn } from "@/lib/utils";

const Progress = React.forwardRef<
React.ElementRef<typeof ProgressPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
>(({ className, value, ...props }, ref) => (
<ProgressPrimitive.Root
ref={ref}
className={cn(
"relative h-2 w-full overflow-hidden rounded-full bg-neutral-900/20 dark:bg-neutral-50/20",
className
)}
{...props}
>
<ProgressPrimitive.Indicator
className="h-full w-full flex-1 bg-neutral-900 transition-all dark:bg-neutral-50"
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
/>
</ProgressPrimitive.Root>
))
Progress.displayName = ProgressPrimitive.Root.displayName
>(({ className, value, max, ...props }, ref) => (
<div className="flex items-center space-x-2">
<ProgressPrimitive.Root
ref={ref}
className={cn(
"relative flex h-2 w-full overflow-hidden rounded-full bg-neutral-900/20 dark:bg-neutral-50/20 ",
className,
)}
{...props}
>
<ProgressPrimitive.Indicator
className="h-full w-full flex-1 bg-neutral-900 transition-all dark:bg-neutral-50"
style={{
transform: `translateX(-${100 - (value && max ? (value / max) * 100 : 0)}%)`,
}}
/>
</ProgressPrimitive.Root>
<span className="flex text-sm">
{typeof value === "number" && typeof max === "number"
? `${value} / ${max}`
: ``}
</span>
</div>
));
Progress.displayName = ProgressPrimitive.Root.displayName;

export { Progress }
export { Progress };
4 changes: 3 additions & 1 deletion src/contexts/players-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ export function mergeDeep(target: any, ...sources: any[]): any {

if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (Array.isArray(source[key])) {
newTarget[key] = source[key];
} else if (isObject(source[key])) {
if (!target[key]) {
newTarget[key] = Array.isArray(source[key]) ? [] : {};
}
Expand Down
Loading

0 comments on commit e69c96b

Please sign in to comment.