fix: sync on click inspector

This commit is contained in:
TrèsAbhi committed 2024-03-30 12:38:53 -05:00
1 parent e8b91648b1
commit 095ffc3d6a
2 files changed
+26 -7

No files matched your search

@@ -4,6 +4,7 @@ import { useFrame } from '@react-three/fiber';
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { Mesh } from 'three'; import { Mesh } from 'three';
import { radToDeg } from 'three/src/math/MathUtils'; import { radToDeg } from 'three/src/math/MathUtils';
import { canSplash } from '../../../core/blitz/canSplash';
import { isExplosive } from '../../../core/blitz/isExplosive'; import { isExplosive } from '../../../core/blitz/isExplosive';
import { NaNFallback } from '../../../core/math/NaNFallback'; import { NaNFallback } from '../../../core/math/NaNFallback';
import { normalToEuler } from '../../../core/math/normalToEuler'; import { normalToEuler } from '../../../core/math/normalToEuler';
@@ -42,6 +43,7 @@ export function ShotDisplay() {
); );
const { shell } = useDuel.getState().antagonist!; const { shell } = useDuel.getState().antagonist!;
const explosive = isExplosive(shell.type); const explosive = isExplosive(shell.type);
const splashing = canSplash(shell.type);
const midPointLayer = (shot?.layers.findLast( const midPointLayer = (shot?.layers.findLast(
(layer) => layer.type !== null && layer.status === 'ricochet', (layer) => layer.type !== null && layer.status === 'ricochet',
) ?? shot?.layers.findLast((layer) => layer.type !== null)) as ShotLayerBase; ) ?? shot?.layers.findLast((layer) => layer.type !== null)) as ShotLayerBase;
@@ -64,6 +66,18 @@ export function ShotDisplay() {
return accumulator; return accumulator;
}, 0) + LENGTH_INFINITY }, 0) + LENGTH_INFINITY
: undefined; : undefined;
const preMidPointThickness = shot
? preMidPointLayers!.reduce(
(accumulator, layer) =>
accumulator +
(layer.type === null
? 0
: layer.type === ArmorType.External
? layer.thickness
: layer.thicknessAngled),
0,
)
: undefined;
const postMidPointGap = shot const postMidPointGap = shot
? postMidPointLayers!.reduce((accumulator, layer) => { ? postMidPointLayers!.reduce((accumulator, layer) => {
if (layer.type === null) return accumulator + layer.distance; if (layer.type === null) return accumulator + layer.distance;
@@ -246,8 +260,9 @@ export function ShotDisplay() {
(1 - (1 -
distanceFromSpacedArmor! / shell.explosionRadius!) - distanceFromSpacedArmor! / shell.explosionRadius!) -
1.1 * 1.1 *
(midPointLayer as ShotLayerNonExternal) ((midPointLayer as ShotLayerNonExternal)
.thicknessAngled, .thicknessAngled +
preMidPointThickness!),
), ),
), ),
0, 0,
@@ -255,7 +270,7 @@ export function ShotDisplay() {
</Text> </Text>
{shot.layers.map((layer, index) => { {shot.layers.map((layer, index) => {
if (layer.type === null && !explosive) return null; if (layer.type === null && (!explosive || splashing)) return null;
return ( return (
<Flex key={index} align="center" gap="2"> <Flex key={index} align="center" gap="2">
@@ -179,7 +179,7 @@ export function SpacedArmorSceneComponent({
const distance = ( const distance = (
shot.layers.at(-1) as ShotLayerBase shot.layers.at(-1) as ShotLayerBase
).point.distanceTo(intersections[0].point); ).point.distanceTo(intersections[0].point);
if (explosive) if (explosive && !splashing)
remainingPenetration -= 0.5 * remainingPenetration * distance; remainingPenetration -= 0.5 * remainingPenetration * distance;
const blocked = remainingPenetration < 0; const blocked = remainingPenetration < 0;
@@ -205,7 +205,7 @@ export function SpacedArmorSceneComponent({
const previousIntersection = intersections[layerIndex - 1]; const previousIntersection = intersections[layerIndex - 1];
const distance = const distance =
intersection.distance - previousIntersection.distance; intersection.distance - previousIntersection.distance;
if (explosive) if (explosive && !splashing)
remainingPenetration -= remainingPenetration -=
0.5 * remainingPenetration * distance; 0.5 * remainingPenetration * distance;
const wasted = remainingPenetration < 0; const wasted = remainingPenetration < 0;
@@ -216,7 +216,7 @@ export function SpacedArmorSceneComponent({
distance, distance,
}); });
if (wasted) return; if (wasted && !splashing) return;
} }
if (intersection.object.userData.type === ArmorType.External) { if (intersection.object.userData.type === ArmorType.External) {
@@ -233,7 +233,11 @@ export function SpacedArmorSceneComponent({
status: blocked ? 'blocked' : 'penetration', status: blocked ? 'blocked' : 'penetration',
}); });
if (blocked) break; if (splashing) {
remainingPenetration = Math.max(0, remainingPenetration);
} else if (blocked) {
break;
}
} else { } else {
const type = intersection.object.userData.type; const type = intersection.object.userData.type;
const angle = surfaceNormal.angleTo(shellNormal); const angle = surfaceNormal.angleTo(shellNormal);