mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: cards
This commit is contained in:
1 parent
f1462162f4
commit
c7017a7a15
6 files changed
+142
-28
No files matched your search
@@ -1,17 +1,22 @@
|
|||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
|
import { DissectorModuleCard } from './DissectorModuleCard';
|
||||||
import { DissectorSceneComponent } from './DissectorSceneComponent';
|
import { DissectorSceneComponent } from './DissectorSceneComponent';
|
||||||
|
|
||||||
export const Dissector = memo(() => {
|
export const Dissector = memo(() => {
|
||||||
return (
|
return (
|
||||||
<group>
|
<>
|
||||||
<DissectorSceneComponent group="hull" />
|
<DissectorModuleCard />
|
||||||
<DissectorSceneComponent group="chassis" />
|
|
||||||
<group position={[0.7, 1.6, 0]}>
|
<group>
|
||||||
<DissectorSceneComponent group="turret_01" />
|
<DissectorSceneComponent group="hull" />
|
||||||
<group position={[1, 0.36, 0]}>
|
<DissectorSceneComponent group="chassis" />
|
||||||
<DissectorSceneComponent group="gun_01" />
|
<group position={[0.7, 1.6, 0]}>
|
||||||
|
<DissectorSceneComponent group="turret_01" />
|
||||||
|
<group position={[1, 0.36, 0]}>
|
||||||
|
<DissectorSceneComponent group="gun_01" />
|
||||||
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { Card, Text } from '@radix-ui/themes';
|
||||||
|
import { Html } from '@react-three/drei';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
lastModuleSelect,
|
||||||
|
moduleSelectEvent,
|
||||||
|
type ModuleSelectEventData,
|
||||||
|
} from '../../../core/blitzkit/moduleSelect';
|
||||||
|
|
||||||
|
export function DissectorModuleCard() {
|
||||||
|
const [moduleSelection, setModuleSelection] = useState(lastModuleSelect);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function handleModuleSelectEvent(event: ModuleSelectEventData) {
|
||||||
|
setModuleSelection(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return moduleSelectEvent.on(handleModuleSelectEvent);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!moduleSelection.selected) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<group position={[0, 1, 0]}>
|
||||||
|
<Html position={moduleSelection.position}>
|
||||||
|
<Card>
|
||||||
|
<Text>{moduleSelection.module}</Text>
|
||||||
|
</Card>
|
||||||
|
</Html>
|
||||||
|
</group>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -18,9 +18,11 @@ import {
|
|||||||
type CSGGeometryRef,
|
type CSGGeometryRef,
|
||||||
} from '@react-three/csg';
|
} from '@react-three/csg';
|
||||||
import { useGLTF } from '@react-three/drei';
|
import { useGLTF } from '@react-three/drei';
|
||||||
|
import { useThree } from '@react-three/fiber';
|
||||||
import { Fragment, useEffect, useRef } from 'react';
|
import { Fragment, useEffect, useRef } from 'react';
|
||||||
import type { Mesh } from 'three';
|
import type { Mesh } from 'three';
|
||||||
import {
|
import {
|
||||||
|
Box3,
|
||||||
Color,
|
Color,
|
||||||
DoubleSide,
|
DoubleSide,
|
||||||
Group,
|
Group,
|
||||||
@@ -37,6 +39,11 @@ import {
|
|||||||
type DissectEventData,
|
type DissectEventData,
|
||||||
} from '../../../core/blitzkit/dissect';
|
} from '../../../core/blitzkit/dissect';
|
||||||
import { jsxTree } from '../../../core/blitzkit/jsxTree';
|
import { jsxTree } from '../../../core/blitzkit/jsxTree';
|
||||||
|
import {
|
||||||
|
lastModuleSelect,
|
||||||
|
moduleSelectEvent,
|
||||||
|
type ModuleSelectEventData,
|
||||||
|
} from '../../../core/blitzkit/moduleSelect';
|
||||||
import { Duel } from '../../../stores/duel';
|
import { Duel } from '../../../stores/duel';
|
||||||
import { TankopediaEphemeral } from '../../../stores/tankopediaEphemeral';
|
import { TankopediaEphemeral } from '../../../stores/tankopediaEphemeral';
|
||||||
import { groupNameRegex } from './StaticArmorSceneComponent';
|
import { groupNameRegex } from './StaticArmorSceneComponent';
|
||||||
@@ -88,6 +95,7 @@ export function DissectorSceneComponent({
|
|||||||
const armor = TankopediaEphemeral.use((state) => state.armor);
|
const armor = TankopediaEphemeral.use((state) => state.armor);
|
||||||
const groupName = group.match(groupNameRegex)![1];
|
const groupName = group.match(groupNameRegex)![1];
|
||||||
const groupArmor = armor.groups[groupName];
|
const groupArmor = armor.groups[groupName];
|
||||||
|
const camera = useThree((state) => state.camera);
|
||||||
|
|
||||||
return jsxTree(gltf.scene, {
|
return jsxTree(gltf.scene, {
|
||||||
mesh(mesh, props) {
|
mesh(mesh, props) {
|
||||||
@@ -115,7 +123,7 @@ export function DissectorSceneComponent({
|
|||||||
const material = useRef(
|
const material = useRef(
|
||||||
new MeshStandardMaterial({
|
new MeshStandardMaterial({
|
||||||
transparent: isTrack,
|
transparent: isTrack,
|
||||||
opacity: 2 ** -1,
|
opacity: 2 ** -5,
|
||||||
side: DoubleSide,
|
side: DoubleSide,
|
||||||
color: moduleColor[armorPlate.type],
|
color: moduleColor[armorPlate.type],
|
||||||
clippingPlanes: isModule ? [] : [clippingPlane.current],
|
clippingPlanes: isModule ? [] : [clippingPlane.current],
|
||||||
@@ -141,6 +149,8 @@ export function DissectorSceneComponent({
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const worldPosition = new Vector3();
|
const worldPosition = new Vector3();
|
||||||
|
const boundsTop = new Vector3();
|
||||||
|
const bounds = new Box3();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const offset = new Vector3();
|
const offset = new Vector3();
|
||||||
@@ -169,11 +179,28 @@ export function DissectorSceneComponent({
|
|||||||
csg.current.update();
|
csg.current.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleModuleSelectEvent(event: ModuleSelectEventData) {
|
||||||
|
if (!isModule) return;
|
||||||
|
|
||||||
|
const isThisComponentSelected =
|
||||||
|
event.selected &&
|
||||||
|
event.group === groupName &&
|
||||||
|
event.module === armorName;
|
||||||
|
const shouldBeVisible = !event.selected || isThisComponentSelected;
|
||||||
|
|
||||||
|
material.current.transparent = !shouldBeVisible;
|
||||||
|
outlineMaterial.current.transparent = !shouldBeVisible;
|
||||||
|
}
|
||||||
|
|
||||||
dissectEvent.on(handleDissectEvent);
|
dissectEvent.on(handleDissectEvent);
|
||||||
|
moduleSelectEvent.on(handleModuleSelectEvent);
|
||||||
|
|
||||||
handleDissectEvent(lastDissection);
|
handleDissectEvent(lastDissection);
|
||||||
|
handleModuleSelectEvent(lastModuleSelect);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
dissectEvent.off(handleDissectEvent);
|
dissectEvent.off(handleDissectEvent);
|
||||||
|
moduleSelectEvent.off(handleModuleSelectEvent);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -184,25 +211,44 @@ export function DissectorSceneComponent({
|
|||||||
</lineSegments>
|
</lineSegments>
|
||||||
|
|
||||||
{isModule && (
|
{isModule && (
|
||||||
<mesh
|
<>
|
||||||
material={material.current}
|
<mesh
|
||||||
ref={baseWrapper}
|
material={material.current}
|
||||||
onPointerDown={(event) => {
|
ref={baseWrapper}
|
||||||
event.stopPropagation();
|
onClick={(event) => {
|
||||||
}}
|
if (!baseWrapper.current) return;
|
||||||
>
|
|
||||||
<Geometry ref={csg}>
|
|
||||||
<Base geometry={props.geometry} />
|
|
||||||
|
|
||||||
<group rotation={[0, 0, 0]} ref={subtractionWrapper}>
|
const isAlreadySelected =
|
||||||
<Subtraction position={[NEGATIVE_SIZE / 2, 0, 0]}>
|
lastModuleSelect.selected &&
|
||||||
<boxGeometry
|
lastModuleSelect.group === groupName &&
|
||||||
args={[NEGATIVE_SIZE, NEGATIVE_SIZE, NEGATIVE_SIZE]}
|
lastModuleSelect.module === armorName;
|
||||||
/>
|
|
||||||
</Subtraction>
|
if (!isAlreadySelected) {
|
||||||
</group>
|
moduleSelectEvent.emit({
|
||||||
</Geometry>
|
selected: true,
|
||||||
</mesh>
|
group: groupName,
|
||||||
|
module: armorName,
|
||||||
|
position: event.point.toArray(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onPointerDown={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Geometry ref={csg}>
|
||||||
|
<Base geometry={props.geometry} />
|
||||||
|
|
||||||
|
<group rotation={[0, 0, 0]} ref={subtractionWrapper}>
|
||||||
|
<Subtraction position={[NEGATIVE_SIZE / 2, 0, 0]}>
|
||||||
|
<boxGeometry
|
||||||
|
args={[NEGATIVE_SIZE, NEGATIVE_SIZE, NEGATIVE_SIZE]}
|
||||||
|
/>
|
||||||
|
</Subtraction>
|
||||||
|
</group>
|
||||||
|
</Geometry>
|
||||||
|
</mesh>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isModule && (
|
{!isModule && (
|
||||||
|
|||||||
+8
@@ -1,6 +1,10 @@
|
|||||||
import { BLITZKIT_TANK_ICON_SIZE } from '@blitzkit/core';
|
import { BLITZKIT_TANK_ICON_SIZE } from '@blitzkit/core';
|
||||||
import { Canvas } from '@react-three/fiber';
|
import { Canvas } from '@react-three/fiber';
|
||||||
import { forwardRef, Suspense, useImperativeHandle, useRef } from 'react';
|
import { forwardRef, Suspense, useImperativeHandle, useRef } from 'react';
|
||||||
|
import {
|
||||||
|
lastModuleSelect,
|
||||||
|
moduleSelectEvent,
|
||||||
|
} from '../../../../../core/blitzkit/moduleSelect';
|
||||||
import { useOnScreen } from '../../../../../hooks/useOnScreen';
|
import { useOnScreen } from '../../../../../hooks/useOnScreen';
|
||||||
import { TankopediaEphemeral } from '../../../../../stores/tankopediaEphemeral';
|
import { TankopediaEphemeral } from '../../../../../stores/tankopediaEphemeral';
|
||||||
import { TankopediaPersistent } from '../../../../../stores/tankopediaPersistent';
|
import { TankopediaPersistent } from '../../../../../stores/tankopediaPersistent';
|
||||||
@@ -172,6 +176,10 @@ export const TankSandbox = forwardRef<HTMLCanvasElement, TankSandboxProps>(
|
|||||||
draft.shot = undefined;
|
draft.shot = undefined;
|
||||||
draft.highlightArmor = undefined;
|
draft.highlightArmor = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (lastModuleSelect.selected) {
|
||||||
|
moduleSelectEvent.emit({ selected: false });
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
userSelect: 'none',
|
userSelect: 'none',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { EventManager } from '@blitzkit/core';
|
import { EventManager } from '@blitzkit/core';
|
||||||
import { degToRad } from 'three/src/math/MathUtils.js';
|
import { degToRad } from 'three/src/math/MathUtils.js';
|
||||||
|
import { lastModuleSelect, moduleSelectEvent } from './moduleSelect';
|
||||||
|
|
||||||
export interface DissectEventData {
|
export interface DissectEventData {
|
||||||
rotation: number;
|
rotation: number;
|
||||||
@@ -13,4 +14,7 @@ export const lastDissection: DissectEventData = {
|
|||||||
offset: 0.8,
|
offset: 0.8,
|
||||||
};
|
};
|
||||||
|
|
||||||
dissectEvent.on((data) => Object.assign(lastDissection, data));
|
dissectEvent.on((data) => {
|
||||||
|
if (lastModuleSelect.selected) moduleSelectEvent.emit({ selected: false });
|
||||||
|
Object.assign(lastDissection, data);
|
||||||
|
});
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { EventManager } from '@blitzkit/core';
|
||||||
|
import type { Vector3Tuple } from 'three';
|
||||||
|
|
||||||
|
export type ModuleSelectEventData =
|
||||||
|
| {
|
||||||
|
selected: false;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
selected: true;
|
||||||
|
group: string;
|
||||||
|
module: string;
|
||||||
|
position: Vector3Tuple;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const moduleSelectEvent = new EventManager<ModuleSelectEventData>();
|
||||||
|
|
||||||
|
export const lastModuleSelect: ModuleSelectEventData = { selected: false };
|
||||||
|
|
||||||
|
moduleSelectEvent.on((data) => Object.assign(lastModuleSelect, data));
|
||||||
Reference in new issue
Block a user