Fuckaway Windows line endings

This commit is contained in:
HugeFrog24
2026-02-11 18:17:50 +01:00
parent 39cbf58dbd
commit dd9bb4a24b
31 changed files with 1858 additions and 681 deletions

View File

@@ -18,7 +18,6 @@ export function LanguageToggle() {
const [isOpen, setIsOpen] = useState(false);
const dropdownRef = useRef<HTMLDivElement>(null);
// Define the available locales
const locales: Locale[] = ['en', 'de', 'ru', 'ka', 'ar'];
const languageOptions: LanguageOption[] = locales.map((code) => ({
@@ -28,7 +27,6 @@ export function LanguageToggle() {
const currentLanguage = languageOptions.find(lang => lang.code === locale) || languageOptions[0];
// Handle clicking outside to close dropdown
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
@@ -45,7 +43,6 @@ export function LanguageToggle() {
};
}, [isOpen]);
// Handle escape key to close dropdown
useEffect(() => {
const handleEscape = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
@@ -68,7 +65,6 @@ export function LanguageToggle() {
return (
<div className="relative" ref={dropdownRef}>
{/* Main toggle button */}
<button
onClick={toggleDropdown}
className="flex items-center gap-2 p-2 rounded-lg bg-gray-200 dark:bg-gray-800 hover:bg-gray-300 dark:hover:bg-gray-700 transition-colors"
@@ -87,7 +83,6 @@ export function LanguageToggle() {
/>
</button>
{/* Dropdown menu */}
{isOpen && (
<div className="absolute left-0 mt-2 w-36 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 z-50">
<div className="py-1">
@@ -118,4 +113,4 @@ export function LanguageToggle() {
)}
</div>
);
}
}

View File

@@ -0,0 +1,143 @@
'use client';
import { useState } from 'react';
import { useParams } from 'next/navigation';
import { appConfig } from '../config/app';
import { SkinId } from '../types';
import { useLocalizedSkinName } from '../hooks/useLocalizedSkinName';
import { usePrices } from '../hooks/usePrices';
import { useFeature } from '../providers/FeatureProvider';
interface PremiumCheckoutProps {
skinId: SkinId;
onClose: () => void;
}
export function PremiumCheckout({ skinId, onClose }: PremiumCheckoutProps) {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const params = useParams();
const getLocalizedSkinName = useLocalizedSkinName();
const paymentsEnabled = useFeature('paymentsEnabled');
const { getPrice, loading: pricesLoading } = usePrices();
const skin = appConfig.skins[skinId];
const skinName = getLocalizedSkinName(skinId);
const price = getPrice(skinId);
const locale = params.locale as string;
// Guard: never render if payments are disabled or skin is not premium
if (!paymentsEnabled || !skin?.isPremium) {
return null;
}
const handlePurchase = async () => {
setIsLoading(true);
setError(null);
try {
const response = await fetch('/api/checkout', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ skinId, locale }),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Failed to create checkout');
}
// Redirect to Lemon Squeezy checkout
if (data.checkoutUrl) {
window.location.href = data.checkoutUrl;
} else {
throw new Error('No checkout URL received');
}
} catch (err) {
console.error('Checkout error:', err);
setError(err instanceof Error ? err.message : 'An error occurred');
} finally {
setIsLoading(false);
}
};
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
<div className="bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full p-6">
<div className="flex justify-between items-center mb-4">
<h2 className="text-xl font-bold text-gray-900 dark:text-white">
Premium Skin
</h2>
<button
onClick={onClose}
className="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
disabled={isLoading}
>
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div className="text-center mb-6">
<div className="w-24 h-24 mx-auto mb-4 bg-gray-100 dark:bg-gray-700 rounded-lg flex items-center justify-center">
<img
src={skin.normal}
alt={skinName}
className="w-16 h-16"
/>
</div>
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-2">
{skinName}
</h3>
<p className="text-gray-600 dark:text-gray-300 mb-4">
Unlock this premium skin to customize your experience!
</p>
<div className="text-2xl font-bold text-green-600 dark:text-green-400">
{pricesLoading ? '...' : (price ?? '')}
</div>
</div>
{error && (
<div className="mb-4 p-3 bg-red-100 dark:bg-red-900 border border-red-300 dark:border-red-700 rounded-md">
<p className="text-red-700 dark:text-red-300 text-sm">{error}</p>
</div>
)}
<div className="flex gap-3">
<button
onClick={onClose}
className="flex-1 px-4 py-2 text-gray-700 dark:text-gray-300 bg-gray-200 dark:bg-gray-700 rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors"
disabled={isLoading}
>
Cancel
</button>
<button
onClick={handlePurchase}
disabled={isLoading}
className="flex-1 px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center"
>
{isLoading ? (
<>
<svg className="animate-spin -ml-1 mr-2 h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
Processing...
</>
) : (
'Purchase'
)}
</button>
</div>
<p className="text-xs text-gray-500 dark:text-gray-400 text-center mt-4">
Secure payment powered by Lemon Squeezy
</p>
</div>
</div>
);
}

View File

@@ -6,7 +6,10 @@ import Image from 'next/image';
import { appConfig } from '../config/app';
import { SkinId } from '../types';
import { useLocalizedSkinName } from '../hooks/useLocalizedSkinName';
import { ChevronDownIcon } from '@heroicons/react/24/outline';
import { usePrices } from '../hooks/usePrices';
import { useFeature } from '../providers/FeatureProvider';
import { ChevronDownIcon, LockClosedIcon } from '@heroicons/react/24/outline';
import { PremiumCheckout } from './PremiumCheckout';
interface SkinOption {
id: SkinId;
@@ -18,14 +21,20 @@ export function SkinSelector() {
const router = useRouter();
const searchParams = useSearchParams();
const getLocalizedSkinName = useLocalizedSkinName();
const paymentsEnabled = useFeature('paymentsEnabled');
const { getPrice, loading: pricesLoading } = usePrices();
const [isOpen, setIsOpen] = useState(false);
const [showCheckout, setShowCheckout] = useState<SkinId | null>(null);
const dropdownRef = useRef<HTMLDivElement>(null);
const skinOptions: SkinOption[] = Object.entries(appConfig.skins).map(([id, skin]) => ({
id: id as SkinId,
name: getLocalizedSkinName(id),
image: skin.normal
}));
// When payments are disabled, filter out premium skins entirely
const skinOptions: SkinOption[] = Object.entries(appConfig.skins)
.filter(([, skin]) => paymentsEnabled || !skin.isPremium)
.map(([id, skin]) => ({
id: id as SkinId,
name: getLocalizedSkinName(id),
image: skin.normal
}));
const skinParam = searchParams.get('skin');
@@ -37,6 +46,16 @@ export function SkinSelector() {
const currentSkinOption = skinOptions.find(skin => skin.id === currentSkin) || skinOptions[0];
const handleSkinChange = useCallback((newSkin: SkinId) => {
const skin = appConfig.skins[newSkin];
// If it's a premium skin, show checkout modal
if (skin.isPremium) {
setShowCheckout(newSkin);
setIsOpen(false);
return;
}
// For free skins, change immediately
const params = new URLSearchParams(searchParams.toString());
if (newSkin === appConfig.defaultSkin) {
@@ -50,6 +69,10 @@ export function SkinSelector() {
setIsOpen(false);
}, [router, searchParams]);
const handleCheckoutClose = useCallback(() => {
setShowCheckout(null);
}, []);
// Handle clicking outside to close dropdown
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
@@ -119,33 +142,56 @@ export function SkinSelector() {
{isOpen && (
<div className="absolute left-0 mt-2 w-36 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 z-50">
<div className="py-1">
{skinOptions.map((option) => (
<button
key={option.id}
onClick={() => handleSkinChange(option.id)}
className={`w-full flex items-center gap-3 px-3 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors ${
currentSkin === option.id
? 'bg-gray-100 dark:bg-gray-700 text-blue-600 dark:text-blue-400'
: 'text-gray-700 dark:text-gray-300'
}`}
role="menuitem"
>
<Image
src={option.image}
alt={option.name}
width={16}
height={16}
className="rounded"
/>
<span>{option.name}</span>
{currentSkin === option.id && (
<div className="ml-auto w-2 h-2 bg-blue-600 dark:bg-blue-400 rounded-full"></div>
)}
</button>
))}
{skinOptions.map((option) => {
const skin = appConfig.skins[option.id];
const isPremium = skin.isPremium;
return (
<button
key={option.id}
onClick={() => handleSkinChange(option.id)}
className={`w-full flex items-center gap-3 px-3 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors ${
currentSkin === option.id
? 'bg-gray-100 dark:bg-gray-700 text-blue-600 dark:text-blue-400'
: 'text-gray-700 dark:text-gray-300'
}`}
role="menuitem"
>
<div className="relative">
<Image
src={option.image}
alt={option.name}
width={16}
height={16}
className="rounded"
/>
{isPremium && (
<LockClosedIcon className="absolute -top-1 -right-1 w-3 h-3 text-yellow-500" />
)}
</div>
<span className="flex-1">{option.name}</span>
{isPremium && paymentsEnabled && (
<span className="text-xs text-yellow-600 dark:text-yellow-400 font-medium">
{pricesLoading ? '...' : (getPrice(option.id) ?? '')}
</span>
)}
{currentSkin === option.id && (
<div className="w-2 h-2 bg-blue-600 dark:bg-blue-400 rounded-full"></div>
)}
</button>
);
})}
</div>
</div>
)}
{/* Premium Checkout Modal */}
{showCheckout && (
<PremiumCheckout
skinId={showCheckout}
onClose={handleCheckoutClose}
/>
)}
</div>
);
}

View File

@@ -2,9 +2,8 @@ import { useEffect, useState, useCallback, useRef } from 'react';
import { useMessages } from 'next-intl';
import { getRandomEmoji } from '../config/emojis';
// Increase visibility duration for speech bubbles
const VISIBILITY_MS = 3000; // 3 seconds for message visibility
const COOLDOWN_MS = 2000; // 2 seconds between new messages
const VISIBILITY_MS = 3000;
const COOLDOWN_MS = 2000;
interface SpeechBubbleProps {
isShaken: boolean;
@@ -21,17 +20,13 @@ export function SpeechBubble({ triggerCount }: SpeechBubbleProps) {
const showTimeRef = useRef<number>(0);
const lastFadeTime = useRef(0);
// Load messages when component mounts or language changes
useEffect(() => {
// Only run if we haven't loaded messages yet
if (messagesRef.current.length > 0) return;
// Get the character messages from the messages object
try {
const characterMessages = allMessages.character;
if (characterMessages && typeof characterMessages === 'object') {
// Convert object values to array
const messageArray = Object.values(characterMessages) as string[];
if (messageArray.length === 0) {
@@ -47,24 +42,22 @@ export function SpeechBubble({ triggerCount }: SpeechBubbleProps) {
} catch (error) {
console.error(`Error loading character messages:`, error);
}
}, [allMessages]); // Depend on allMessages to reload when they change
}, [allMessages]);
const getRandomMessage = useCallback(() => {
const currentMessages = messagesRef.current;
if (currentMessages.length === 0) return '';
const randomIndex = Math.floor(Math.random() * currentMessages.length);
const message = currentMessages[randomIndex];
return `${message} ${getRandomEmoji()}`;
}, []); // No dependencies needed since we use ref
const messageValue = currentMessages[randomIndex];
return `${messageValue} ${getRandomEmoji()}`;
}, []);
// Handle new trigger events
useEffect(() => {
if (triggerCount === 0 || messagesRef.current.length === 0) return;
const now = Date.now();
const timeSinceLastFade = now - lastFadeTime.current;
// If we're in cooldown, or a message is visible, queue the new message
if (timeSinceLastFade < COOLDOWN_MS || isVisible) {
const newMessage = getRandomMessage();
if (newMessage) {
@@ -73,7 +66,6 @@ export function SpeechBubble({ triggerCount }: SpeechBubbleProps) {
return;
}
// Otherwise, show the message immediately
lastTriggerTime.current = now;
showTimeRef.current = now;
const newMessage = getRandomMessage();
@@ -83,17 +75,15 @@ export function SpeechBubble({ triggerCount }: SpeechBubbleProps) {
}
}, [triggerCount, isVisible, getRandomMessage]);
// Handle message queue
useEffect(() => {
if (messageQueue.length === 0 || isVisible) return;
const now = Date.now();
const timeSinceLastFade = now - lastFadeTime.current;
// Only show next message if cooldown has expired
if (timeSinceLastFade >= COOLDOWN_MS) {
const nextMessage = messageQueue[0];
setMessageQueue(prev => prev.slice(1)); // Remove the message from queue
setMessageQueue(prev => prev.slice(1));
lastTriggerTime.current = now;
showTimeRef.current = now;
setMessage(nextMessage);
@@ -101,7 +91,6 @@ export function SpeechBubble({ triggerCount }: SpeechBubbleProps) {
}
}, [messageQueue, isVisible]);
// Handle visibility duration
useEffect(() => {
if (!isVisible) return;