Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/inventory/InventoryTabPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const InventoryTabPanel: ReactTabsFunctionComponent<StoreTabContentProps> = ({
{items.map((item, index) =>
"level" in item ? (
type === "Store" ? (
petData.xpLevel >= item.level ? (
petData.xpLevel >= item.level &&
(!item.isStreakLocked ||
petData.currentStreak >= (item.streakRequirement || 3)) ? (
<Item
key={index}
type={type}
Expand All @@ -56,7 +58,11 @@ const InventoryTabPanel: ReactTabsFunctionComponent<StoreTabContentProps> = ({
setSelectedItem={setSelectedItem}
/>
) : (
<LockedItem key={index} item={item} />
<LockedItem
key={index}
item={item}
currentStreak={petData.currentStreak}
/>
)
) : (
<Item
Expand Down
16 changes: 14 additions & 2 deletions src/components/inventory/LockedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import { InventoryItem } from "@/types/inventory";

interface LockedItemProps {
item: InventoryItem;
currentStreak?: number;
}

const LockedItem: React.FC<LockedItemProps> = ({ item }) => {
const LockedItem: React.FC<LockedItemProps> = ({ item, currentStreak = 0 }) => {
const isStreakLocked =
item.isStreakLocked && currentStreak < (item.streakRequirement || 3);
const lockReason = isStreakLocked
? `Streak Required: ${item.streakRequirement || 3} days`
: `Level ${item.level}`;

return (
<div className={`p-4 mx-auto flex flex-col items-center mt-[60px]`}>
<Image
Expand All @@ -18,8 +25,13 @@ const LockedItem: React.FC<LockedItemProps> = ({ item }) => {
sizes="100vw"
/>
<div className="mt-[23px] font-quantico text-center text-black largeDesktop:text-[36px] desktop:text-[30px] tablet:text-[24px] font-bold leading-none">
{`Level ${item.level}`}
{lockReason}
</div>
{isStreakLocked && (
<div className="mt-2 font-quantico text-center text-gray-600 text-sm">
Current: {currentStreak} {currentStreak === 1 ? "day" : "days"}
</div>
)}
</div>
);
};
Expand Down
8 changes: 5 additions & 3 deletions src/components/ui/ExpBar.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Image from "next/image";
import { calculateXPForLevel } from "@/utils/constants";

interface ExpProps {
level: number;
currentExp: number;
totalExp?: number;
}

const ExpBar: React.FC<ExpProps> = ({ level, currentExp, totalExp = 100 }) => {
const progress = totalExp > 0 ? (currentExp / totalExp) * 100 : 0;
const ExpBar: React.FC<ExpProps> = ({ level, currentExp, totalExp }) => {
const xpNeeded = totalExp ?? calculateXPForLevel(level);
const progress = xpNeeded > 0 ? (currentExp / xpNeeded) * 100 : 0;

return (
<div className="relative w-fit h-full flex items-center flex-1">
Expand All @@ -34,7 +36,7 @@ const ExpBar: React.FC<ExpProps> = ({ level, currentExp, totalExp = 100 }) => {
</div>
</div>
<span className="h-fit z-10 font-quantico font-extrabold text-[2rem] text-white text-stroke-4 text-stroke-[#2A3213] text-shadow-[#444D29] paint-stroke letter-spacing-ui">
{currentExp}/{totalExp} XP
{currentExp}/{xpNeeded} XP
</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/ProfileInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ProfileInfo: React.FC<ProfileInfoProps> = ({
level,
coins,
currentExp,
totalExp = 100,
totalExp,
}) => {
return (
<div className="flex flex-col h-full w-fit gap-2">
Expand Down
8 changes: 8 additions & 0 deletions src/db/actions/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default class PetDAO {
xpLevel?: number;
coins?: number;
food?: number;
currentStreak?: number;
longestStreak?: number;
perfectWeeksCount?: number;
lastDoseDate?: Date | null;
},
): Promise<void> {
const userId = new Types.ObjectId(_userId);
Expand Down Expand Up @@ -107,6 +111,10 @@ export default class PetDAO {
xpLevel?: number;
coins?: number;
food?: number;
currentStreak?: number;
longestStreak?: number;
perfectWeeksCount?: number;
lastDoseDate?: Date | null;
},
): Promise<void> {
const petId = new Types.ObjectId(_petId);
Expand Down
24 changes: 24 additions & 0 deletions src/db/models/pet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface Pet {
food: number;
appearance: Appearance;
outfits: SavedOutfit[];
currentStreak: number;
longestStreak: number;
perfectWeeksCount: number;
lastDoseDate: Date | null;
}

const appearanceSchema = new Schema<Appearance>(
Expand Down Expand Up @@ -80,6 +84,26 @@ const petSchema = new Schema<PetDocument>(
type: [savedOutfitSchema],
default: [],
},
currentStreak: {
type: Number,
required: true,
default: 0,
},
longestStreak: {
type: Number,
required: true,
default: 0,
},
perfectWeeksCount: {
type: Number,
required: true,
default: 0,
},
lastDoseDate: {
type: Date,
required: false,
default: null,
},
},
{ timestamps: true },
);
Expand Down
Loading