From 74d4b8edf4a27ba4a651673508308c1057c42e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:11:09 -0500 Subject: [PATCH] feat: remove assertion --- .../components/Consumables.tsx | 10 +-- .../Characteristics/components/Equipment.tsx | 8 +-- .../components/Miscellaneous.tsx | 24 +++---- .../Characteristics/components/Modules.tsx | 69 +++++++++---------- .../Characteristics/components/Provisions.tsx | 8 +-- .../[id]/components/Characteristics/index.tsx | 20 +++--- .../tankopedia/[id]/components/Control.tsx | 8 +-- .../[id]/components/HistorySection.tsx | 2 +- .../tankopedia/[id]/components/Lighting.tsx | 2 +- .../[id]/components/Model/HeroSection.tsx | 4 +- .../[id]/components/Model/TankSandbox.tsx | 20 +++--- .../[id]/components/Model/TechTreeSection.tsx | 2 +- .../components/Model/components/Options.tsx | 42 +++++------ .../components/Model/components/TankModel.tsx | 18 ++--- .../[id]/components/QuickInputs/index.tsx | 10 +-- .../tankopedia/[id]/components/Title.tsx | 4 +- .../[id]/components/VideoSection.tsx | 2 +- src/app/tools/tankopedia/[id]/page.tsx | 10 +-- .../Armor/components/CoreArmorScene.tsx | 8 +-- .../CoreArmorSceneComponent/index.tsx | 25 +++---- .../Armor/components/SpacedArmorScene.tsx | 8 +-- .../SpacedArmorSubExternal/index.tsx | 21 +++--- .../components/SpacedArmorSubSpaced/index.tsx | 21 +++--- .../SpacedArmorSceneComponent/index.tsx | 10 +-- src/hooks/useEccentricity.ts | 2 +- src/hooks/useProvision.ts | 2 +- 26 files changed, 172 insertions(+), 188 deletions(-) diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Consumables.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Consumables.tsx index 4a79a3b06..dfdb633b6 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Consumables.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Consumables.tsx @@ -17,9 +17,9 @@ import { ConfigurationChildWrapper } from './ConfigurationChildWrapper'; export function Consumables() { const mutateDuel = Duel.useMutation(); - const protagonist = Duel.use((state) => state.protagonist!); + const protagonist = Duel.use((state) => state.protagonist); const awaitedConsumableDefinitions = use(consumableDefinitions); - const consumables = Duel.use((state) => state.protagonist!.consumables); + const consumables = Duel.use((state) => state.protagonist.consumables); const consumablesList = Object.values(awaitedConsumableDefinitions).filter( (consumable) => checkConsumableProvisionInclusivity( @@ -29,7 +29,7 @@ export function Consumables() { ), ); const cooldownBooster = Duel.use( - (state) => state.protagonist!.cooldownBooster, + (state) => state.protagonist.cooldownBooster, ); const hasConsumableDeliverySystem = useEquipment(118); const hasHighEndConsumables = useEquipment(101); @@ -61,7 +61,7 @@ export function Consumables() { color="red" onClick={() => { mutateDuel((draft) => { - draft.protagonist!.consumables = []; + draft.protagonist.consumables = []; }); }} > @@ -79,7 +79,7 @@ export function Consumables() { timers onChange={(consumables) => { mutateDuel((draft) => { - draft.protagonist!.consumables = consumables; + draft.protagonist.consumables = consumables; }); }} /> diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Equipment.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Equipment.tsx index 2ecc5e30d..410214b55 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Equipment.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Equipment.tsx @@ -7,12 +7,12 @@ import { ConfigurationChildWrapper } from './ConfigurationChildWrapper'; export function Equipment() { const mutateDuel = Duel.useMutation(); - const protagonist = Duel.use((state) => state.protagonist!); + const protagonist = Duel.use((state) => state.protagonist); const awaitedEquipmentDefinitions = use(equipmentDefinitions); const equipmentPreset = awaitedEquipmentDefinitions.presets[protagonist.tank.equipment]; const equipmentMatrix = Duel.use( - (state) => state.protagonist!.equipmentMatrix, + (state) => state.protagonist.equipmentMatrix, ); return ( @@ -24,7 +24,7 @@ export function Equipment() { color="red" onClick={() => { mutateDuel((draft) => { - draft.protagonist!.equipmentMatrix.forEach((row) => { + draft.protagonist.equipmentMatrix.forEach((row) => { row.forEach((_, index) => { row[index] = 0; }); @@ -41,7 +41,7 @@ export function Equipment() { preset={equipmentPreset} onChange={(matrix) => { mutateDuel((draft) => { - draft.protagonist!.equipmentMatrix = matrix; + draft.protagonist.equipmentMatrix = matrix; }); }} /> diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Miscellaneous.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Miscellaneous.tsx index 102b14a09..d82594867 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Miscellaneous.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Miscellaneous.tsx @@ -8,20 +8,20 @@ import { ConfigurationChildWrapper } from './ConfigurationChildWrapper'; export function Miscellaneous() { const mutateDuel = Duel.useMutation(); - const camouflage = Duel.use((state) => state.protagonist!.camouflage); + const camouflage = Duel.use((state) => state.protagonist.camouflage); const cooldownBooster = Duel.use( - (state) => state.protagonist!.cooldownBooster, + (state) => state.protagonist.cooldownBooster, ); - const crewMastery = Duel.use((state) => state.protagonist!.crewMastery); + const crewMastery = Duel.use((state) => state.protagonist.crewMastery); const crewInput = useRef(null); const [crewMasteryDraft, setCrewMasteryDraft] = useState(crewMastery); - const { tank } = Duel.use((state) => state.protagonist!); + const { tank } = Duel.use((state) => state.protagonist); const debouncedApplyDraft = useMemo( () => debounce((value) => { mutateDuel((draft) => { - draft.protagonist!.crewMastery = value; + draft.protagonist.crewMastery = value; }); }, 500), [], @@ -51,7 +51,7 @@ export function Miscellaneous() { last onClick={() => { mutateDuel((draft) => { - draft.protagonist!.camouflage = !camouflage; + draft.protagonist.camouflage = !camouflage; }); }} /> @@ -75,9 +75,9 @@ export function Miscellaneous() { }} onClick={() => { mutateDuel((draft) => { - draft.protagonist!.cooldownBooster++; - if (draft.protagonist!.cooldownBooster === 4) - draft.protagonist!.cooldownBooster = 0; + draft.protagonist.cooldownBooster++; + if (draft.protagonist.cooldownBooster === 4) + draft.protagonist.cooldownBooster = 0; }); }} /> @@ -103,11 +103,7 @@ export function Miscellaneous() { } mutateDuel((draft) => { - draft.protagonist!.crewMastery = clamp( - newValue / 100, - 0.5, - 1, - ); + draft.protagonist.crewMastery = clamp(newValue / 100, 0.5, 1); }); }} onKeyUp={(event) => { diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Modules.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Modules.tsx index a6466cdaf..12029b36e 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Modules.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Modules.tsx @@ -118,16 +118,16 @@ function ModuleButton({ export function Modules() { const mutateDuel = Duel.useMutation(); const awaitedTankDefinitions = use(tankDefinitions); - const tank = Duel.use((state) => state.protagonist!.tank); + const tank = Duel.use((state) => state.protagonist.tank); const hasUpgrades = tank.turrets.length > 1 || tank.turrets[0].guns.length > 1 || tank.engines.length > 1 || tank.tracks.length > 1; - const turret = Duel.use((state) => state.protagonist!.turret); - const gun = Duel.use((state) => state.protagonist!.gun); - const engine = Duel.use((state) => state.protagonist!.engine); - const track = Duel.use((state) => state.protagonist!.track); + const turret = Duel.use((state) => state.protagonist.turret); + const gun = Duel.use((state) => state.protagonist.gun); + const engine = Duel.use((state) => state.protagonist.engine); + const track = Duel.use((state) => state.protagonist.track); const turret0 = tank.turrets[0]; const gun0 = turret0.guns[0]; const engine0 = tank.engines[0]; @@ -140,44 +140,44 @@ export function Modules() { function setByUnlock(unlock: Unlock) { mutateDuel((draft) => { if (unlock.type === 'turret') { - draft.protagonist!.turret = draft.protagonist!.tank.turrets.find( + draft.protagonist.turret = draft.protagonist.tank.turrets.find( (turret) => turret.id === unlock.id, )!; if ( - !draft.protagonist!.turret.guns.some( - (gun) => gun.id === draft.protagonist!.gun.id, + !draft.protagonist.turret.guns.some( + (gun) => gun.id === draft.protagonist.gun.id, ) ) { - draft.protagonist!.gun = draft.protagonist!.turret.guns.at(-1)!; - draft.protagonist!.shell = draft.protagonist!.gun.shells[0]; + draft.protagonist.gun = draft.protagonist.turret.guns.at(-1)!; + draft.protagonist.shell = draft.protagonist.gun.shells[0]; } } else if (unlock.type === 'gun') { - const gunInTurret = draft.protagonist!.turret.guns.find( + const gunInTurret = draft.protagonist.turret.guns.find( (gun) => gun.id === unlock.id, ); if (gunInTurret) { - draft.protagonist!.gun = gunInTurret; - draft.protagonist!.shell = gunInTurret.shells[0]; + draft.protagonist.gun = gunInTurret; + draft.protagonist.shell = gunInTurret.shells[0]; } else { // TODO: warn somehow? - const suitableTurret = draft.protagonist!.tank.turrets.find( - (turret) => turret.guns.some((gun) => gun.id === unlock.id), + const suitableTurret = draft.protagonist.tank.turrets.find((turret) => + turret.guns.some((gun) => gun.id === unlock.id), )!; const gunInSuitableTurret = suitableTurret.guns.find( (gun) => gun.id === unlock.id, )!; - draft.protagonist!.turret = suitableTurret; - draft.protagonist!.gun = gunInSuitableTurret; - draft.protagonist!.shell = gunInSuitableTurret.shells[0]; + draft.protagonist.turret = suitableTurret; + draft.protagonist.gun = gunInSuitableTurret; + draft.protagonist.shell = gunInSuitableTurret.shells[0]; } } else if (unlock.type === 'engine') { - draft.protagonist!.engine = draft.protagonist!.tank.engines.find( + draft.protagonist.engine = draft.protagonist.tank.engines.find( (engine) => engine.id === unlock.id, )!; } else if (unlock.type === 'chassis') { - draft.protagonist!.track = draft.protagonist!.tank.tracks.find( + draft.protagonist.track = draft.protagonist.tank.tracks.find( (track) => track.id === unlock.id, )!; } @@ -320,13 +320,11 @@ export function Modules() { color="red" onClick={() => { mutateDuel((draft) => { - draft.protagonist!.turret = - draft.protagonist!.tank.turrets[0]; - draft.protagonist!.gun = draft.protagonist!.turret.guns[0]; - draft.protagonist!.shell = draft.protagonist!.gun.shells[0]; - draft.protagonist!.engine = - draft.protagonist!.tank.engines[0]; - draft.protagonist!.track = draft.protagonist!.tank.tracks[0]; + draft.protagonist.turret = draft.protagonist.tank.turrets[0]; + draft.protagonist.gun = draft.protagonist.turret.guns[0]; + draft.protagonist.shell = draft.protagonist.gun.shells[0]; + draft.protagonist.engine = draft.protagonist.tank.engines[0]; + draft.protagonist.track = draft.protagonist.tank.tracks[0]; }); }} > @@ -336,15 +334,14 @@ export function Modules() { variant="ghost" onClick={() => { mutateDuel((draft) => { - draft.protagonist!.turret = - draft.protagonist!.tank.turrets.at(-1)!; - draft.protagonist!.gun = - draft.protagonist!.turret.guns.at(-1)!; - draft.protagonist!.shell = draft.protagonist!.gun.shells[0]; - draft.protagonist!.engine = - draft.protagonist!.tank.engines.at(-1)!; - draft.protagonist!.track = - draft.protagonist!.tank.tracks.at(-1)!; + draft.protagonist.turret = + draft.protagonist.tank.turrets.at(-1)!; + draft.protagonist.gun = draft.protagonist.turret.guns.at(-1)!; + draft.protagonist.shell = draft.protagonist.gun.shells[0]; + draft.protagonist.engine = + draft.protagonist.tank.engines.at(-1)!; + draft.protagonist.track = + draft.protagonist.tank.tracks.at(-1)!; }); }} > diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Provisions.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Provisions.tsx index 206b69269..60c8a4d5e 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/components/Provisions.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/components/Provisions.tsx @@ -8,8 +8,8 @@ import { ConfigurationChildWrapper } from './ConfigurationChildWrapper'; export function Provisions() { const mutateDuel = Duel.useMutation(); - const { tank, gun } = Duel.use((state) => state.protagonist!); - const provisions = Duel.use((state) => state.protagonist!.provisions); + const { tank, gun } = Duel.use((state) => state.protagonist); + const provisions = Duel.use((state) => state.protagonist.provisions); const awaitedProvisionDefinitions = use(provisionDefinitions); const provisionsList = availableProvisions( tank, @@ -26,7 +26,7 @@ export function Provisions() { color="red" onClick={() => { mutateDuel((draft) => { - draft.protagonist!.provisions = []; + draft.protagonist.provisions = []; }); }} > @@ -40,7 +40,7 @@ export function Provisions() { disabled={tank.provisions === provisions.length} onChange={(provisions) => { mutateDuel((draft) => { - draft.protagonist!.provisions = provisions; + draft.protagonist.provisions = provisions; }); }} /> diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx index 7c99160d5..5fd946e73 100644 --- a/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx +++ b/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx @@ -42,10 +42,10 @@ export function Characteristics() { const crewSkills = TankopediaEphemeral.use((state) => state.skills); const penetrationDistanceInput = useRef(null); const hasImprovedVentilation = useEquipment(102); - const crewMastery = Duel.use((state) => state.protagonist!.crewMastery); + const crewMastery = Duel.use((state) => state.protagonist.crewMastery); const [penetrationDistance, setPenetrationDistance] = useState(250); - const provisions = Duel.use((state) => state.protagonist!.provisions); + const provisions = Duel.use((state) => state.protagonist.provisions); const provisionCrewBonus = provisions.reduce( (total, provision) => @@ -56,13 +56,13 @@ export function Characteristics() { ) + (hasImprovedVentilation ? 0.08 : 0); const commanderMastery = crewMastery + provisionCrewBonus; const crewMemberMastery = commanderMastery * 1.1; - const consumables = Duel.use((state) => state.protagonist!.consumables); - const camouflage = Duel.use((state) => state.protagonist!.camouflage); + const consumables = Duel.use((state) => state.protagonist.consumables); + const camouflage = Duel.use((state) => state.protagonist.camouflage); const equipmentMatrix = Duel.use( - (state) => state.protagonist!.equipmentMatrix, + (state) => state.protagonist.equipmentMatrix, ); const { tank, turret, gun, engine, track, shell } = Duel.use( - (state) => state.protagonist!, + (state) => state.protagonist, ); const stockEngine = tank.engines[0]; const stockTrack = tank.tracks[0]; @@ -119,9 +119,9 @@ export function Characteristics() { }, [penetrationDistance]); useEffect(() => { mutateDuel((draft) => { - [draft.protagonist!.pitch, draft.protagonist!.yaw] = applyPitchYawLimits( - draft.protagonist!.pitch, - draft.protagonist!.yaw, + [draft.protagonist.pitch, draft.protagonist.yaw] = applyPitchYawLimits( + draft.protagonist.pitch, + draft.protagonist.yaw, gunModelDefinition.pitch, turretModelDefinition.yaw, hasImprovedVerticalStabilizer, @@ -159,7 +159,7 @@ export function Characteristics() { }} onClick={() => { mutateDuel((draft) => { - draft.protagonist!.shell = thisShell; + draft.protagonist.shell = thisShell; }); }} > diff --git a/src/app/tools/tankopedia/[id]/components/Control.tsx b/src/app/tools/tankopedia/[id]/components/Control.tsx index 44d43fe87..6c6101860 100644 --- a/src/app/tools/tankopedia/[id]/components/Control.tsx +++ b/src/app/tools/tankopedia/[id]/components/Control.tsx @@ -24,8 +24,8 @@ export function Controls() { const canvas = useThree((state) => state.gl.domElement); const orbitControls = useRef(null); const awaitedModelDefinitions = useAwait(modelDefinitions); - const protagonist = Duel.use((state) => state.protagonist!); - const antagonist = Duel.use((state) => state.antagonist!); + const protagonist = Duel.use((state) => state.protagonist); + const antagonist = Duel.use((state) => state.antagonist); const protagonistModelDefinition = awaitedModelDefinitions[protagonist.tank.id]; const protagonistTrackModelDefinition = @@ -75,8 +75,8 @@ export function Controls() { const duel = duelStore.getState(); const hasImprovedVerticalStabilizer = await hasEquipment( 122, - duel.protagonist!.tank.equipment, - duel.protagonist!.equipmentMatrix, + duel.protagonist.tank.equipment, + duel.protagonist.equipmentMatrix, ); switch (event) { diff --git a/src/app/tools/tankopedia/[id]/components/HistorySection.tsx b/src/app/tools/tankopedia/[id]/components/HistorySection.tsx index a6931cdc9..56ac43ba3 100644 --- a/src/app/tools/tankopedia/[id]/components/HistorySection.tsx +++ b/src/app/tools/tankopedia/[id]/components/HistorySection.tsx @@ -3,7 +3,7 @@ import PageWrapper from '../../../../../components/PageWrapper'; import * as Duel from '../../../../../stores/duel'; export function HistorySection() { - const tank = Duel.use((state) => state.protagonist!.tank); + const tank = Duel.use((state) => state.protagonist.tank); if (!tank.description) return null; diff --git a/src/app/tools/tankopedia/[id]/components/Lighting.tsx b/src/app/tools/tankopedia/[id]/components/Lighting.tsx index 64dadbf06..894970b48 100644 --- a/src/app/tools/tankopedia/[id]/components/Lighting.tsx +++ b/src/app/tools/tankopedia/[id]/components/Lighting.tsx @@ -12,7 +12,7 @@ export const ENVIRONMENTS = [ ] as const; export function Lighting() { - const protagonist = Duel.use((state) => state.protagonist!); + const protagonist = Duel.use((state) => state.protagonist); const { hasPbr } = useModel(protagonist.tank.id); const showEnvironment = TankopediaPersistent.use( (state) => state.model.visual.showEnvironment, diff --git a/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx b/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx index 8865ef219..6bb9ee06b 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx @@ -10,8 +10,8 @@ import { TankSandbox } from './TankSandbox'; import { Options } from './components/Options'; export function HeroSection() { - const protagonist = Duel.use((state) => state.protagonist!.tank); - const antagonist = Duel.use((state) => state.antagonist!.tank); + const protagonist = Duel.use((state) => state.protagonist.tank); + const antagonist = Duel.use((state) => state.antagonist.tank); const compareTanks = protagonist.id === antagonist.id ? [protagonist.id] diff --git a/src/app/tools/tankopedia/[id]/components/Model/TankSandbox.tsx b/src/app/tools/tankopedia/[id]/components/Model/TankSandbox.tsx index 046a75baa..b2984bb32 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/TankSandbox.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/TankSandbox.tsx @@ -20,7 +20,7 @@ export function TankSandbox() { const canvas = useRef(null); const hasImprovedVerticalStabilizer = useEquipment(122); const awaitedModelDefinitions = use(modelDefinitions); - const protagonist = Duel.use((state) => state.protagonist!); + const protagonist = Duel.use((state) => state.protagonist); const mutateDuel = Duel.useMutation(); const tankModelDefinition = awaitedModelDefinitions[protagonist.tank.id]; const turretModelDefinition = @@ -55,8 +55,8 @@ export function TankSandbox() { ); modelTransformEvent.emit({ pitch, yaw }); - draft.protagonist!.pitch = pitch; - draft.protagonist!.yaw = yaw; + draft.protagonist.pitch = pitch; + draft.protagonist.yaw = yaw; }); break; @@ -73,8 +73,8 @@ export function TankSandbox() { ); modelTransformEvent.emit({ pitch, yaw }); - draft.protagonist!.pitch = pitch; - draft.protagonist!.yaw = yaw; + draft.protagonist.pitch = pitch; + draft.protagonist.yaw = yaw; }); break; @@ -91,8 +91,8 @@ export function TankSandbox() { ); modelTransformEvent.emit({ pitch, yaw }); - draft.protagonist!.pitch = pitch; - draft.protagonist!.yaw = yaw; + draft.protagonist.pitch = pitch; + draft.protagonist.yaw = yaw; }); break; @@ -108,9 +108,9 @@ export function TankSandbox() { useEffect(() => { mutateDuel((draft) => { - [draft.protagonist!.pitch, draft.protagonist!.yaw] = applyPitchYawLimits( - draft.protagonist!.pitch, - draft.protagonist!.yaw, + [draft.protagonist.pitch, draft.protagonist.yaw] = applyPitchYawLimits( + draft.protagonist.pitch, + draft.protagonist.yaw, gunModelDefinition.pitch, turretModelDefinition.yaw, hasImprovedVerticalStabilizer, diff --git a/src/app/tools/tankopedia/[id]/components/Model/TechTreeSection.tsx b/src/app/tools/tankopedia/[id]/components/Model/TechTreeSection.tsx index 08b8c4fed..fee102b06 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/TechTreeSection.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/TechTreeSection.tsx @@ -51,7 +51,7 @@ export function TreeArrow({ export function TechTreeSection() { const awaitedTankDefinitions = use(tankDefinitions); - const tank = Duel.use((state) => state.protagonist!.tank); + const tank = Duel.use((state) => state.protagonist.tank); if (tank.treeType !== 'researchable') return null; diff --git a/src/app/tools/tankopedia/[id]/components/Model/components/Options.tsx b/src/app/tools/tankopedia/[id]/components/Model/components/Options.tsx index af03c6fe9..1aeb51054 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/components/Options.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/components/Options.tsx @@ -66,11 +66,11 @@ export function Options() { (state) => state.model.visual.environment, ); const developerMode = App.use((state) => state.developerMode); - const antagonistGun = Duel.use((state) => state.antagonist!.gun); - const antagonistShell = Duel.use((state) => state.antagonist!.shell); + const antagonistGun = Duel.use((state) => state.antagonist.gun); + const antagonistShell = Duel.use((state) => state.antagonist.shell); const [antagonistSelectorOpen, setAntagonistSelectorOpen] = useState(false); - const antagonistTank = Duel.use((state) => state.antagonist!.tank); - const antagonistTurret = Duel.use((state) => state.antagonist!.turret); + const antagonistTank = Duel.use((state) => state.antagonist.tank); + const antagonistTurret = Duel.use((state) => state.antagonist.turret); const hasCalibratedShells = useEquipment(103, true); const [tab, setTab] = useState('search'); const mutateDuel = Duel.useMutation(); @@ -151,7 +151,7 @@ export function Options() { }} onClick={() => { mutateDuel((draft) => { - draft.antagonist!.shell = thisShell; + draft.antagonist.shell = thisShell; }); mutateTankopediaEphemeral((draft) => { draft.shot = undefined; @@ -183,7 +183,7 @@ export function Options() { }} onClick={() => { mutateDuel((draft) => { - draft.antagonist!.equipmentMatrix[0][0] = hasCalibratedShells + draft.antagonist.equipmentMatrix[0][0] = hasCalibratedShells ? 0 : 1; }); @@ -215,7 +215,7 @@ export function Options() { }} onClick={() => { mutateDuel((draft) => { - draft.protagonist!.equipmentMatrix[1][1] = hasEnhancedArmor + draft.protagonist.equipmentMatrix[1][1] = hasEnhancedArmor ? 0 : -1; }); @@ -298,14 +298,14 @@ export function Options() { compact onSelect={(tank) => { mutateDuel((draft) => { - draft.antagonist!.tank = tank; - draft.antagonist!.engine = tank.engines.at(-1)!; - draft.antagonist!.track = tank.tracks.at(-1)!; - draft.antagonist!.turret = tank.turrets.at(-1)!; - draft.antagonist!.gun = - draft.antagonist!.turret.guns.at(-1)!; - draft.antagonist!.shell = - draft.antagonist!.gun.shells[0]; + draft.antagonist.tank = tank; + draft.antagonist.engine = tank.engines.at(-1)!; + draft.antagonist.track = tank.tracks.at(-1)!; + draft.antagonist.turret = tank.turrets.at(-1)!; + draft.antagonist.gun = + draft.antagonist.turret.guns.at(-1)!; + draft.antagonist.shell = + draft.antagonist.gun.shells[0]; }); setAntagonistSelectorOpen(false); }} @@ -332,11 +332,11 @@ export function Options() { key={turret.id} onClick={() => { mutateDuel((draft) => { - draft.antagonist!.turret = turret; - draft.antagonist!.gun = + draft.antagonist.turret = turret; + draft.antagonist.gun = turret.guns.at(-1)!; - draft.antagonist!.shell = - draft.antagonist!.gun.shells[0]; + draft.antagonist.shell = + draft.antagonist.gun.shells[0]; }); mutateTankopediaEphemeral((draft) => { draft.shot = undefined; @@ -361,8 +361,8 @@ export function Options() { } onClick={() => { mutateDuel((draft) => { - draft.antagonist!.gun = gun; - draft.antagonist!.shell = gun.shells[0]; + draft.antagonist.gun = gun; + draft.antagonist.shell = gun.shells[0]; }); }} selected={antagonistGun.id === gun.id} diff --git a/src/app/tools/tankopedia/[id]/components/Model/components/TankModel.tsx b/src/app/tools/tankopedia/[id]/components/Model/components/TankModel.tsx index 1c019ffa1..b0ad8c20d 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/components/TankModel.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/components/TankModel.tsx @@ -28,7 +28,7 @@ export const TankModel = memo(() => { const mutateDuel = Duel.useMutation(); const duelStore = Duel.useStore(); const awaitedModelDefinitions = useAwait(modelDefinitions); - const protagonist = Duel.use((draft) => draft.protagonist!); + const protagonist = Duel.use((draft) => draft.protagonist); const canvas = useThree((state) => state.gl.domElement); const hullContainer = useRef(null); const turretContainer = useRef(null); @@ -221,8 +221,8 @@ export const TankModel = memo(() => { const duel = duelStore.getState(); const hasImprovedVerticalStabilizer = await hasEquipment( 122, - duel.protagonist!.tank.equipment, - duel.protagonist!.equipmentMatrix, + duel.protagonist.tank.equipment, + duel.protagonist.equipmentMatrix, ); const boundingRect = canvas.getBoundingClientRect(); @@ -240,8 +240,8 @@ export const TankModel = memo(() => { } function handlePointerUp() { mutateDuel((draft) => { - draft.protagonist!.pitch = normalizeAngleRad(pitch); - draft.protagonist!.yaw = normalizeAngleRad(yaw); + draft.protagonist.pitch = normalizeAngleRad(pitch); + draft.protagonist.yaw = normalizeAngleRad(yaw); }); mutateTankopediaTemporary((draft) => { draft.controlsEnabled = true; @@ -301,8 +301,8 @@ export const TankModel = memo(() => { const duel = duelStore.getState(); const hasImprovedVerticalStabilizer = await hasEquipment( 122, - duel.protagonist!.tank.equipment, - duel.protagonist!.equipmentMatrix, + duel.protagonist.tank.equipment, + duel.protagonist.equipmentMatrix, ); const boundingRect = canvas.getBoundingClientRect(); delta.set(event.clientX, event.clientY).sub(position); @@ -322,8 +322,8 @@ export const TankModel = memo(() => { draft.controlsEnabled = true; }); mutateDuel((draft) => { - draft.protagonist!.pitch = normalizeAngleRad(pitch); - draft.protagonist!.yaw = normalizeAngleRad(yaw); + draft.protagonist.pitch = normalizeAngleRad(pitch); + draft.protagonist.yaw = normalizeAngleRad(yaw); }); window.removeEventListener('pointermove', handlePointerMove); window.removeEventListener('pointerup', handlePointerUp); diff --git a/src/app/tools/tankopedia/[id]/components/QuickInputs/index.tsx b/src/app/tools/tankopedia/[id]/components/QuickInputs/index.tsx index 69b37397f..9b54db668 100644 --- a/src/app/tools/tankopedia/[id]/components/QuickInputs/index.tsx +++ b/src/app/tools/tankopedia/[id]/components/QuickInputs/index.tsx @@ -15,7 +15,7 @@ import * as styles from './index.css'; export function RotationInputs() { const mutateDuel = Duel.useMutation(); - const protagonist = Duel.use((state) => state.protagonist!); + const protagonist = Duel.use((state) => state.protagonist); const awaitedModelDefinitions = use(modelDefinitions); const yawInput = useRef(null); const pitchInput = useRef(null); @@ -90,8 +90,8 @@ export function RotationInputs() { ); modelTransformEvent.emit({ pitch, yaw }); mutateDuel((state) => { - state.protagonist!.pitch = pitch; - state.protagonist!.yaw = yaw; + state.protagonist.pitch = pitch; + state.protagonist.yaw = yaw; }); yawInput.current!.value = radToDeg(protagonist.yaw).toFixed(1); }} @@ -137,8 +137,8 @@ export function RotationInputs() { ); modelTransformEvent.emit({ pitch, yaw }); mutateDuel((state) => { - state.protagonist!.pitch = pitch; - state.protagonist!.yaw = yaw; + state.protagonist.pitch = pitch; + state.protagonist.yaw = yaw; }); pitchInput.current!.value = ( -radToDeg(protagonist.pitch) + initialGunPitch diff --git a/src/app/tools/tankopedia/[id]/components/Title.tsx b/src/app/tools/tankopedia/[id]/components/Title.tsx index 28f8f3539..0615b829a 100644 --- a/src/app/tools/tankopedia/[id]/components/Title.tsx +++ b/src/app/tools/tankopedia/[id]/components/Title.tsx @@ -11,8 +11,8 @@ import { TankSearch } from '../../components/TankSearch'; export function Title() { const awaitedProvisionDefinitions = use(provisionDefinitions); - const protagonist = Duel.use((state) => state.protagonist!); - const antagonist = Duel.use((state) => state.antagonist!); + const protagonist = Duel.use((state) => state.protagonist); + const antagonist = Duel.use((state) => state.antagonist); const compareTanks = protagonist.tank.id === antagonist.tank.id ? [protagonist.tank.id] diff --git a/src/app/tools/tankopedia/[id]/components/VideoSection.tsx b/src/app/tools/tankopedia/[id]/components/VideoSection.tsx index e031dc46b..59edbfb3e 100644 --- a/src/app/tools/tankopedia/[id]/components/VideoSection.tsx +++ b/src/app/tools/tankopedia/[id]/components/VideoSection.tsx @@ -5,7 +5,7 @@ import { videoDefinitions } from '../../../../../core/blitzkit/videos'; import * as Duel from '../../../../../stores/duel'; export function VideoSection() { - const tank = Duel.use((state) => state.protagonist!.tank); + const tank = Duel.use((state) => state.protagonist.tank); const awaitedVideoDefinitions = use(videoDefinitions); const videos = awaitedVideoDefinitions[tank.id]?.videos ?? []; diff --git a/src/app/tools/tankopedia/[id]/page.tsx b/src/app/tools/tankopedia/[id]/page.tsx index 9f8a5195c..bb036d7f7 100644 --- a/src/app/tools/tankopedia/[id]/page.tsx +++ b/src/app/tools/tankopedia/[id]/page.tsx @@ -32,20 +32,20 @@ export default function Page() { if (event.key === '1') { wipeShot(); mutateDuel((draft) => { - draft.antagonist!.shell = draft.antagonist!.gun.shells[0]; + draft.antagonist.shell = draft.antagonist.gun.shells[0]; }); } else if (event.key === '2') { wipeShot(); mutateDuel((draft) => { - if (draft.antagonist!.gun.shells[1]) { - draft.antagonist!.shell = draft.antagonist!.gun.shells[1]; + if (draft.antagonist.gun.shells[1]) { + draft.antagonist.shell = draft.antagonist.gun.shells[1]; } }); } else if (event.key === '3') { wipeShot(); mutateDuel((draft) => { - if (draft.antagonist!.gun.shells[2]) { - draft.antagonist!.shell = draft.antagonist!.gun.shells[2]; + if (draft.antagonist.gun.shells[2]) { + draft.antagonist.shell = draft.antagonist.gun.shells[2]; } }); } diff --git a/src/components/Armor/components/CoreArmorScene.tsx b/src/components/Armor/components/CoreArmorScene.tsx index 7e89b8e1a..f46cbbba4 100644 --- a/src/components/Armor/components/CoreArmorScene.tsx +++ b/src/components/Armor/components/CoreArmorScene.tsx @@ -110,10 +110,10 @@ export const CoreArmorScene = memo(() => { return unsubscribe; }); - const tank = Duel.use((state) => state.protagonist!.tank); - const track = Duel.use((state) => state.protagonist!.track); - const turret = Duel.use((state) => state.protagonist!.turret); - const gun = Duel.use((state) => state.protagonist!.gun); + const tank = Duel.use((state) => state.protagonist.tank); + const track = Duel.use((state) => state.protagonist.track); + const turret = Duel.use((state) => state.protagonist.turret); + const gun = Duel.use((state) => state.protagonist.gun); const armorGltf = useArmor(tank.id); const armorNodes = Object.values(armorGltf.nodes); const tankModelDefinition = modelDefinitions[tank.id]; diff --git a/src/components/Armor/components/CoreArmorSceneComponent/index.tsx b/src/components/Armor/components/CoreArmorSceneComponent/index.tsx index d6b853da6..931a5ddb8 100644 --- a/src/components/Armor/components/CoreArmorSceneComponent/index.tsx +++ b/src/components/Armor/components/CoreArmorSceneComponent/index.tsx @@ -72,8 +72,8 @@ export function CoreArmorSceneComponent({ material.uniforms.explosionRadius.value = shell.explosionRadius; const duel = duelStore.getState(); - await handleProtagonistEquipmentChange(duel.protagonist!.equipmentMatrix); - await handleAntagonistEquipmentChange(duel.antagonist!.equipmentMatrix); + await handleProtagonistEquipmentChange(duel.protagonist.equipmentMatrix); + await handleAntagonistEquipmentChange(duel.antagonist.equipmentMatrix); } function handleVisualChange( visual: TankopediaPersistent.TankopediaPersistent['model']['visual'], @@ -89,7 +89,7 @@ export function CoreArmorSceneComponent({ const duel = duelStore.getState(); const hasEnhancedArmor = await hasEquipment( 110, - duel.protagonist!.tank.equipment, + duel.protagonist.tank.equipment, equipment, ); material.uniforms.thickness.value = hasEnhancedArmor @@ -100,11 +100,11 @@ export function CoreArmorSceneComponent({ equipment: Duel.EquipmentMatrix, ) { const duel = duelStore.getState(); - const shell = duel.antagonist!.shell; + const shell = duel.antagonist.shell; const penetration = resolveNearPenetration(shell.penetration); const hasCalibratedShells = await hasEquipment( 103, - duel.antagonist!.tank.equipment, + duel.antagonist.tank.equipment, equipment, ); @@ -113,30 +113,27 @@ export function CoreArmorSceneComponent({ resolvePenetrationCoefficient(hasCalibratedShells, shell.type); } - handleShellChange(duelStore.getState().antagonist!.shell); + handleShellChange(duelStore.getState().antagonist.shell); handleVisualChange(tankopediaPersistentStore.getState().model.visual); handleProtagonistEquipmentChange( - duelStore.getState().protagonist!.equipmentMatrix, + duelStore.getState().protagonist.equipmentMatrix, ); handleAntagonistEquipmentChange( - duelStore.getState().antagonist!.equipmentMatrix, + duelStore.getState().antagonist.equipmentMatrix, ); const unsubscribes = [ - duelStore.subscribe( - (state) => state.antagonist!.shell, - handleShellChange, - ), + duelStore.subscribe((state) => state.antagonist.shell, handleShellChange), tankopediaPersistentStore.subscribe( (state) => state.model.visual, handleVisualChange, ), duelStore.subscribe( - (state) => state.protagonist!.equipmentMatrix, + (state) => state.protagonist.equipmentMatrix, handleProtagonistEquipmentChange, ), duelStore.subscribe( - (state) => state.antagonist!.equipmentMatrix, + (state) => state.antagonist.equipmentMatrix, handleAntagonistEquipmentChange, ), ]; diff --git a/src/components/Armor/components/SpacedArmorScene.tsx b/src/components/Armor/components/SpacedArmorScene.tsx index b95303668..c14cb9be2 100644 --- a/src/components/Armor/components/SpacedArmorScene.tsx +++ b/src/components/Armor/components/SpacedArmorScene.tsx @@ -120,10 +120,10 @@ export const SpacedArmorScene = memo(({ scene }) => { return unsubscribe; }); - const tank = Duel.use((state) => state.protagonist!.tank); - const track = Duel.use((state) => state.protagonist!.track); - const turret = Duel.use((state) => state.protagonist!.turret); - const gun = Duel.use((state) => state.protagonist!.gun); + const tank = Duel.use((state) => state.protagonist.tank); + const track = Duel.use((state) => state.protagonist.track); + const turret = Duel.use((state) => state.protagonist.turret); + const gun = Duel.use((state) => state.protagonist.gun); const armorGltf = useArmor(tank.id); const { gltf: modelGltf } = useModel(tank.id); const armorNodes = Object.values(armorGltf.nodes); diff --git a/src/components/Armor/components/SpacedArmorSceneComponent/components/SpacedArmorSubExternal/index.tsx b/src/components/Armor/components/SpacedArmorSceneComponent/components/SpacedArmorSubExternal/index.tsx index cbba4fc77..80016de06 100644 --- a/src/components/Armor/components/SpacedArmorSceneComponent/components/SpacedArmorSubExternal/index.tsx +++ b/src/components/Armor/components/SpacedArmorSceneComponent/components/SpacedArmorSubExternal/index.tsx @@ -59,7 +59,7 @@ export function SpacedArmorSubExternal({ const duel = duelStore.getState(); const hasEnhancedArmor = await hasEquipment( 110, - duel.protagonist!.tank.equipment, + duel.protagonist.tank.equipment, equipment, ); material.uniforms.thickness.value = hasEnhancedArmor @@ -70,11 +70,11 @@ export function SpacedArmorSubExternal({ equipment: Duel.EquipmentMatrix, ) { const duel = duelStore.getState(); - const shell = duel.antagonist!.shell; + const shell = duel.antagonist.shell; const penetration = resolveNearPenetration(shell.penetration); const hasCalibratedShells = await hasEquipment( 103, - duel.antagonist!.tank.equipment, + duel.antagonist.tank.equipment, equipment, ); @@ -83,25 +83,22 @@ export function SpacedArmorSubExternal({ resolvePenetrationCoefficient(hasCalibratedShells, shell.type); } - handleShellChange(duelStore.getState().antagonist!.shell); + handleShellChange(duelStore.getState().antagonist.shell); handleProtagonistEquipmentChange( - duelStore.getState().protagonist!.equipmentMatrix, + duelStore.getState().protagonist.equipmentMatrix, ); handleAntagonistEquipmentChange( - duelStore.getState().antagonist!.equipmentMatrix, + duelStore.getState().antagonist.equipmentMatrix, ); const unsubscribes = [ + duelStore.subscribe((state) => state.antagonist.shell, handleShellChange), duelStore.subscribe( - (state) => state.antagonist!.shell, - handleShellChange, - ), - duelStore.subscribe( - (state) => state.protagonist!.equipmentMatrix, + (state) => state.protagonist.equipmentMatrix, handleProtagonistEquipmentChange, ), duelStore.subscribe( - (state) => state.antagonist!.equipmentMatrix, + (state) => state.antagonist.equipmentMatrix, handleAntagonistEquipmentChange, ), ]; diff --git a/src/components/Armor/components/SpacedArmorSceneComponent/components/SpacedArmorSubSpaced/index.tsx b/src/components/Armor/components/SpacedArmorSceneComponent/components/SpacedArmorSubSpaced/index.tsx index e6283da3c..9ca10428c 100644 --- a/src/components/Armor/components/SpacedArmorSceneComponent/components/SpacedArmorSubSpaced/index.tsx +++ b/src/components/Armor/components/SpacedArmorSceneComponent/components/SpacedArmorSubSpaced/index.tsx @@ -69,7 +69,7 @@ export function SpacedArmorSubSpaced({ const duel = duelStore.getState(); const hasEnhancedArmor = await hasEquipment( 110, - duel.protagonist!.tank.equipment, + duel.protagonist.tank.equipment, equipment, ); material.uniforms.thickness.value = hasEnhancedArmor @@ -80,11 +80,11 @@ export function SpacedArmorSubSpaced({ equipment: Duel.EquipmentMatrix, ) { const duel = duelStore.getState(); - const shell = duelStore.getState().antagonist!.shell; + const shell = duelStore.getState().antagonist.shell; const penetration = resolveNearPenetration(shell.penetration); const hasCalibratedShells = await hasEquipment( 103, - duel.antagonist!.tank.equipment, + duel.antagonist.tank.equipment, equipment, ); @@ -93,25 +93,22 @@ export function SpacedArmorSubSpaced({ resolvePenetrationCoefficient(hasCalibratedShells, shell.type); } - handleShellChange(duelStore.getState().antagonist!.shell); + handleShellChange(duelStore.getState().antagonist.shell); handleProtagonistEquipmentChange( - duelStore.getState().protagonist!.equipmentMatrix, + duelStore.getState().protagonist.equipmentMatrix, ); handleAntagonistEquipmentChange( - duelStore.getState().antagonist!.equipmentMatrix, + duelStore.getState().antagonist.equipmentMatrix, ); const unsubscribes = [ + duelStore.subscribe((state) => state.antagonist.shell, handleShellChange), duelStore.subscribe( - (state) => state.antagonist!.shell, - handleShellChange, - ), - duelStore.subscribe( - (state) => state.protagonist!.equipmentMatrix, + (state) => state.protagonist.equipmentMatrix, handleProtagonistEquipmentChange, ), duelStore.subscribe( - (state) => state.antagonist!.equipmentMatrix, + (state) => state.antagonist.equipmentMatrix, handleAntagonistEquipmentChange, ), ]; diff --git a/src/components/Armor/components/SpacedArmorSceneComponent/index.tsx b/src/components/Armor/components/SpacedArmorSceneComponent/index.tsx index e57e7f4ab..24c74d4ce 100644 --- a/src/components/Armor/components/SpacedArmorSceneComponent/index.tsx +++ b/src/components/Armor/components/SpacedArmorSceneComponent/index.tsx @@ -83,7 +83,7 @@ export function SpacedArmorSceneComponent({ remainingPenetrationInput?: number, ) { const { antagonist, protagonist } = duelStore.getState(); - const shell = antagonist!.shell; + const shell = antagonist.shell; const cameraNormal = camera.position.clone().sub(point).normalize(); const shot: TankopediaEphemeral.Shot = { damage: -1, @@ -97,13 +97,13 @@ export function SpacedArmorSceneComponent({ const hasCalibratedShells = await hasEquipment( 103, - antagonist!.tank.equipment, - antagonist!.equipmentMatrix, + antagonist.tank.equipment, + antagonist.equipmentMatrix, ); const hasEnhancedArmor = await hasEquipment( 110, - protagonist!.tank.equipment, - protagonist!.equipmentMatrix, + protagonist.tank.equipment, + protagonist.equipmentMatrix, ); const penetration = resolveNearPenetration(shell.penetration) * diff --git a/src/hooks/useEccentricity.ts b/src/hooks/useEccentricity.ts index 67c8d1580..bb0256564 100644 --- a/src/hooks/useEccentricity.ts +++ b/src/hooks/useEccentricity.ts @@ -13,7 +13,7 @@ export enum UseEccentricityMode { export function useEccentricity(mode: UseEccentricityMode) { const awaitedTankDefinitions = use(tankDefinitions); - const tank = Duel.use((state) => state.protagonist!.tank); + const tank = Duel.use((state) => state.protagonist.tank); const similarTanks = useMemo( () => Object.values(awaitedTankDefinitions).filter( diff --git a/src/hooks/useProvision.ts b/src/hooks/useProvision.ts index a7f3ff7b0..606c38f93 100644 --- a/src/hooks/useProvision.ts +++ b/src/hooks/useProvision.ts @@ -1,6 +1,6 @@ import * as Duel from '../stores/duel'; export function useProvision(id: number) { - const provisions = Duel.use((state) => state.protagonist!.provisions); + const provisions = Duel.use((state) => state.protagonist.provisions); return provisions.includes(id); }