diff --git a/src/App.tsx b/src/App.tsx index 974765c..3e5a028 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -247,7 +247,7 @@ function App() { }); }, [addTransaction]); - const handleAddFacility = useCallback((baseId: string, facilityType: string) => { + const handleAddFacility = useCallback((baseId: string, facilityType: keyof typeof FACILITY_TYPES) => { if (!FACILITY_TYPES[facilityType]) return; setGameState(prev => { @@ -299,7 +299,7 @@ function App() { // Regular facility newFacility = { id: crypto.randomUUID(), - type: facilityType as any, + type: facilityType as Facility['type'], level: 1, personnel: [], powerUsage: facilityTypeData.basePowerUsage, diff --git a/src/components/BaseModal.tsx b/src/components/BaseModal.tsx index 92ed490..6aadd97 100644 --- a/src/components/BaseModal.tsx +++ b/src/components/BaseModal.tsx @@ -40,47 +40,16 @@ const BaseModal: React.FC = ({ title, children }) => { - // If component is not open, don't render anything - if (!isOpen) return null; - - // If this is being used as a generic modal with children - if (children) { - return ( -
-
- {title && ( -
-

{title}

- -
- )} - {children} -
-
- ); - } - // Base creation/management UI code const [name, setName] = useState(existingBase?.name || ''); const [showFacilitySelect, setShowFacilitySelect] = useState(false); const [localFacilities, setLocalFacilities] = useState(existingBase?.facilities || []); - const [powerStatus, setPowerStatus] = useState(() => + const [powerStatus, setPowerStatus] = useState(() => existingBase ? calculatePowerStatus(existingBase) : { generation: 0, usage: 0, surplus: 0 } ); const [availableFacilities, setAvailableFacilities] = useState([]); + // Keep state in sync with existingBase prop useEffect(() => { if (existingBase) { @@ -127,6 +96,38 @@ const BaseModal: React.FC = ({ } }, [localFacilities, existingBase, showFacilitySelect]); + // If component is not open, don't render anything + if (!isOpen) return null; + + // If this is being used as a generic modal with children + if (children) { + return ( +
+
+ {title && ( +
+

{title}

+ +
+ )} + {children} +
+
+ ); + } + // Keep localFacilities in sync when upgrades happen const handleFacilityUpgrade = (baseId: string, facilityId: string) => { if (!onUpgrade) return; diff --git a/src/components/HangarModal.tsx b/src/components/HangarModal.tsx index 731f89d..c21dfc3 100644 --- a/src/components/HangarModal.tsx +++ b/src/components/HangarModal.tsx @@ -263,7 +263,7 @@ const HangarModal: React.FC = ({
{(['interceptor', 'transport', 'scout'] as VehicleType[]).map((type) => { const variants = Object.entries(VEHICLE_TYPES) - .filter(([_, variant]) => { + .filter(([, variant]) => { if (variant.type !== type) return false; if (!variant.researchRequired) return true; return variant.researchRequired.every(r => completedResearch.includes(r)); diff --git a/src/data/basePersonnel.ts b/src/data/basePersonnel.ts index 1c0ee62..29d1ef5 100644 --- a/src/data/basePersonnel.ts +++ b/src/data/basePersonnel.ts @@ -177,7 +177,7 @@ export function calculateFacilityPersonnelCapacity(facility: Facility): number { case 'powerPlant': case 'radar': case 'defense': - case 'hangar': + case 'hangar': { // For other facilities, capacity depends on their basePersonnel value times level const facilityType = facility.type; // Assuming we have a constant for basePersonnel values @@ -188,8 +188,9 @@ export function calculateFacilityPersonnelCapacity(facility: Facility): number { defense: 6, hangar: 5 // Changed from 8 to 5 as per requirements }[facilityType] || 3; - + return baseCapacity * facility.level; + } default: return 0; diff --git a/src/data/vehicles.ts b/src/data/vehicles.ts index 62a3b91..0249cca 100644 --- a/src/data/vehicles.ts +++ b/src/data/vehicles.ts @@ -81,7 +81,7 @@ export function getBaseVehicleType(variantKey: string): VehicleType { // Get a list of all variants for a specific vehicle type export function getVariantsByType(vehicleType: VehicleType): string[] { return Object.entries(VEHICLE_TYPES) - .filter(([_, variant]) => variant.type === vehicleType) + .filter(([, variant]) => variant.type === vehicleType) .map(([key]) => key); } diff --git a/src/utils/baseUtils.ts b/src/utils/baseUtils.ts index df51c33..7467b64 100644 --- a/src/utils/baseUtils.ts +++ b/src/utils/baseUtils.ts @@ -1,4 +1,4 @@ -import { Base, ResearchProject, GameState } from '../types'; // Added GameState +import { Base, ResearchProject, GameState, Continent, ContinentSelection, Facility } from '../types'; import { FACILITY_TYPES } from '../data/facilities'; /** @@ -83,8 +83,8 @@ export function calculatePowerStatus(base: Base) { * @param selected Continent or ContinentSelection object * @returns Continent object */ -export function getContinent(selected: any): any { - if (!selected) return {}; +export function getContinent(selected: Continent | ContinentSelection | null | undefined): Continent | null { + if (!selected) return null; return 'continent' in selected ? selected.continent : selected; } @@ -93,9 +93,9 @@ export function getContinent(selected: any): any { * @param selectedContinent The selected continent * @returns Personnel multiplier value */ -export function getPersonnelMultiplier(selectedContinent: any) { +export function getPersonnelMultiplier(selectedContinent: Continent | ContinentSelection | null | undefined): number { const continent = getContinent(selectedContinent); - return continent?.personnelMultiplier || 1; + return continent?.personnelMultiplier ?? 1; } /** @@ -103,7 +103,7 @@ export function getPersonnelMultiplier(selectedContinent: any) { * @param selectedContinent The selected continent * @returns Initial personnel capacity value */ -export function getInitialPersonnelCapacity(selectedContinent: any) { +export function getInitialPersonnelCapacity(selectedContinent: Continent | ContinentSelection | null | undefined): number { // Initial facilities include a level 1 barracks // Level 1 barracks provides 15 personnel housing capacity const baseCapacity = 15; @@ -116,7 +116,7 @@ export function getInitialPersonnelCapacity(selectedContinent: any) { * @param facility The facility to calculate upgrade cost for * @returns The cost to upgrade the facility */ -export function calculateUpgradeCost(facility: any) { +export function calculateUpgradeCost(facility: Facility) { if (!facility || !facility.type) { throw new Error('Invalid facility provided'); }