Skip to content
Open
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
21 changes: 11 additions & 10 deletions src/components/chess/RaumschachBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useRef, useEffect, useState } from "react";
import { Canvas, useFrame, useThree, ThreeEvent } from "@react-three/fiber";
import { OrbitControls, Text } from "@react-three/drei";
import type { OrbitControls as OrbitControlsImpl } from "three-stdlib";
import * as THREE from "three";
import { GameState, Position, ChessPiece } from "@/hooks/useRaumschach";

Expand All @@ -21,8 +22,8 @@ interface RaumschachBoardProps {
validMoves: Position[];
onSquareClick: (position: Position) => void;
onCanvasClick?: () => void;
onCanvasPointerDown?: (event: any) => void;
onCanvasPointerMove?: (event: any) => void;
onCanvasPointerDown?: (event: React.PointerEvent) => void;
onCanvasPointerMove?: (event: React.PointerEvent) => void;
onCanvasPointerUp?: () => void;
isActive: boolean;
currentPlayer: string;
Expand Down Expand Up @@ -150,7 +151,7 @@ function ChessPieceComponent({ piece, position, isSelected, boardPosition }: Che
/>
);

const createMeshWithUserData = (geometryJsx: any, materialJsx: any, meshPosition?: [number, number, number]) => (
const createMeshWithUserData = (geometryJsx: React.ReactElement, materialJsx: React.ReactElement, meshPosition?: [number, number, number]) => (
<mesh
ref={(mesh) => { if (mesh) addUserDataToMesh(mesh); }}
position={meshPosition}
Expand Down Expand Up @@ -381,7 +382,7 @@ function CameraControls({ isActive, onRotateLeft, onRotateRight, onAzimuthChange
onAzimuthChange?: (azimuth: number) => void;
}) {
const { camera, gl, scene } = useThree();
const controlsRef = useRef<any>(null);
const controlsRef = useRef<OrbitControlsImpl | null>(null);

// Track azimuth changes
useEffect(() => {
Expand All @@ -399,7 +400,7 @@ function CameraControls({ isActive, onRotateLeft, onRotateRight, onAzimuthChange
// Expose rotation functions
useEffect(() => {
if (onRotateLeft) {
(window as any).rotateCameraLeft = () => {
(window as unknown as { rotateCameraLeft: () => void }).rotateCameraLeft = () => {
if (controlsRef.current) {
const currentAzimuth = controlsRef.current.getAzimuthalAngle();
controlsRef.current.setAzimuthalAngle(currentAzimuth - Math.PI / 4); // 45 degrees left
Expand All @@ -408,7 +409,7 @@ function CameraControls({ isActive, onRotateLeft, onRotateRight, onAzimuthChange
};
}
if (onRotateRight) {
(window as any).rotateCameraRight = () => {
(window as unknown as { rotateCameraRight: () => void }).rotateCameraRight = () => {
if (controlsRef.current) {
const currentAzimuth = controlsRef.current.getAzimuthalAngle();
controlsRef.current.setAzimuthalAngle(currentAzimuth + Math.PI / 4); // 45 degrees right
Expand All @@ -420,7 +421,7 @@ function CameraControls({ isActive, onRotateLeft, onRotateRight, onAzimuthChange

// Expose enhanced focus on piece function
useEffect(() => {
(window as any).focusOnPiece = (level: number | string, file: number | string, rank: number | string) => {
(window as unknown as { focusOnPiece: (level: number | string, file: number | string, rank: number | string) => void }).focusOnPiece = (level: number | string, file: number | string, rank: number | string) => {
if (!controlsRef.current) {
console.error('Camera controls not available');
return;
Expand Down Expand Up @@ -763,7 +764,7 @@ function ClickHandler({ onSquareClick, isActive, isDragging }: { onSquareClick:
canvas.addEventListener('click', handleClick);
return () => canvas.removeEventListener('click', handleClick);
}
}, [camera, scene, raycaster, pointer, onSquareClick, isActive]);
}, [camera, scene, raycaster, pointer, onSquareClick, isActive, isDragging]);

return null;
}
Expand Down Expand Up @@ -832,8 +833,8 @@ function HoverHandler({

function Scene({ gameState, selectedPosition, validMoves, onSquareClick, isActive, cursorPosition, isKeyboardMode, onMouseInteraction, onCameraAzimuthChange, isDragging }: Pick<RaumschachBoardProps, 'gameState' | 'selectedPosition' | 'validMoves' | 'onSquareClick' | 'isActive' | 'cursorPosition' | 'isKeyboardMode' | 'onMouseInteraction' | 'onCameraAzimuthChange' | 'isDragging'>) {
const [hoveredPosition, setHoveredPosition] = useState<Position | null>(null);
const rotateLeft = () => (window as any).rotateCameraLeft?.();
const rotateRight = () => (window as any).rotateCameraRight?.();
const rotateLeft = () => (window as unknown as { rotateCameraLeft?: () => void }).rotateCameraLeft?.();
const rotateRight = () => (window as unknown as { rotateCameraRight?: () => void }).rotateCameraRight?.();

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/components/simulator/SimpleSimulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ function SceneContent({
position: THREE.Vector3;
rotation: THREE.Euler;
speed: number;
update: (controls: any, joystickData?: { angle: number; magnitude: number; forward?: number; turn?: number }, cameraMode?: 'orbit' | 'follow') => void;
update: (controls: Record<string, boolean>, joystickData?: { angle: number; magnitude: number; forward?: number; turn?: number }, cameraMode?: 'orbit' | 'follow') => void;
getSpeed: () => number;
reset: () => void;
} | null>(null);
Expand All @@ -375,7 +375,7 @@ function SceneContent({
position: new THREE.Vector3(-40, 1, 40),
rotation: new THREE.Euler(0, 0, 0),
speed: 0,
update: function(controls: any, joystickData?: { angle: number; magnitude: number; forward?: number; turn?: number }, cameraMode: 'orbit' | 'follow' = 'orbit') {
update: function(controls: Record<string, boolean>, joystickData?: { angle: number; magnitude: number; forward?: number; turn?: number }, cameraMode: 'orbit' | 'follow' = 'orbit') {
const deltaTime = 1/60;
const walls = [
// Outer walls
Expand Down
2 changes: 1 addition & 1 deletion src/components/simulator/SimulatorEngine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Vehicle({ position, rotation, isActive, controls }: {
position: THREE.Vector3;
rotation: THREE.Euler;
isActive: boolean;
controls?: any;
controls?: Record<string, boolean>;
}) {
const meshRef = useRef<THREE.Group>(null);

Expand Down
4 changes: 2 additions & 2 deletions src/components/simulator/VirtualJoystick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ export function VirtualJoystick({ onControlChange, isActive, cameraMode = 'orbit
if (isDragging) {
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', handleMouseUp);
document.addEventListener('touchmove', handleTouchMove as any);
document.addEventListener('touchmove', handleTouchMove as EventListener);
document.addEventListener('touchend', handleEnd);
}

return () => {
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', handleMouseUp);
document.removeEventListener('touchmove', handleTouchMove as any);
document.removeEventListener('touchmove', handleTouchMove as EventListener);
document.removeEventListener('touchend', handleEnd);
};
}, [isDragging, handleMove, handleEnd, handleTouchMove]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react"
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"

import { cn } from "@/lib/utils"
import { buttonVariants } from "@/components/ui/button"
import { buttonVariants } from "@/components/ui/button-variants"

const AlertDialog = AlertDialogPrimitive.Root

Expand Down
21 changes: 21 additions & 0 deletions src/components/ui/badge-variants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { cva } from "class-variance-authority";

export const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
);
25 changes: 3 additions & 22 deletions src/components/ui/badge.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { type VariantProps } from "class-variance-authority"

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

const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
)
import { badgeVariants } from "./badge-variants"

export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
Expand All @@ -33,4 +14,4 @@ function Badge({ className, variant, ...props }: BadgeProps) {
)
}

export { Badge, badgeVariants }
export { Badge }
30 changes: 30 additions & 0 deletions src/components/ui/button-variants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { cva } from "class-variance-authority";

export const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive:
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline:
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
);
34 changes: 3 additions & 31 deletions src/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { type VariantProps } from "class-variance-authority"

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

const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive:
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline:
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
import { buttonVariants } from "./button-variants"

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
Expand All @@ -53,4 +25,4 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
)
Button.displayName = "Button"

export { Button, buttonVariants }
export { Button }
2 changes: 1 addition & 1 deletion src/components/ui/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChevronLeft, ChevronRight } from "lucide-react";
import { DayPicker } from "react-day-picker";

import { cn } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";
import { buttonVariants } from "@/components/ui/button-variants";

export type CalendarProps = React.ComponentProps<typeof DayPicker>;

Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Command = React.forwardRef<
))
Command.displayName = CommandPrimitive.displayName

interface CommandDialogProps extends DialogProps {}
type CommandDialogProps = DialogProps;

const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
return (
Expand Down
44 changes: 44 additions & 0 deletions src/components/ui/form-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as React from "react"
import { type FieldPath, type FieldValues, useFormContext } from "react-hook-form"

type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
> = {
name: TName
}

export const FormFieldContext = React.createContext<FormFieldContextValue>(
{} as FormFieldContextValue
)

type FormItemContextValue = {
id: string
}

export const FormItemContext = React.createContext<FormItemContextValue>(
{} as FormItemContextValue
)

export const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext)
const itemContext = React.useContext(FormItemContext)
const { getFieldState, formState } = useFormContext()

const fieldState = getFieldState(fieldContext.name, formState)

if (!fieldContext) {
throw new Error("useFormField should be used within <FormField>")
}

const { id } = itemContext

return {
id,
name: fieldContext.name,
formItemId: `${id}-form-item`,
formDescriptionId: `${id}-form-item-description`,
formMessageId: `${id}-form-item-message`,
...fieldState,
}
};
Loading