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
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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,
Expand Down
67 changes: 34 additions & 33 deletions src/components/BaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,16 @@ const BaseModal: React.FC<BaseModalProps> = ({
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 (
<div className="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50">
<div className={`bg-gradient-to-b from-slate-900 to-slate-950 rounded-lg p-6 border border-slate-700 shadow-lg ${
width === 'sm' ? 'w-[400px]' :
width === 'md' ? 'w-[600px]' :
width === 'lg' ? 'w-[800px]' :
width === 'xl' ? 'w-[1000px]' :
width === '2xl' ? 'w-[1200px]' :
'w-[600px]'
} max-h-[80vh] overflow-y-auto`}>
{title && (
<div className="flex justify-between items-center mb-6 border-b border-slate-700 pb-4">
<h2 className="text-2xl font-bold text-green-400">{title}</h2>
<button
onClick={onClose}
className="text-slate-400 hover:text-green-400 transition-colors"
>
<X size={24} />
</button>
</div>
)}
{children}
</div>
</div>
);
}

// Base creation/management UI code
const [name, setName] = useState(existingBase?.name || '');
const [showFacilitySelect, setShowFacilitySelect] = useState(false);
const [localFacilities, setLocalFacilities] = useState<Facility[]>(existingBase?.facilities || []);
const [powerStatus, setPowerStatus] = useState(() =>
const [powerStatus, setPowerStatus] = useState(() =>
existingBase ? calculatePowerStatus(existingBase) : { generation: 0, usage: 0, surplus: 0 }
);
const [availableFacilities, setAvailableFacilities] = useState<typeof FACILITY_TYPES[keyof typeof FACILITY_TYPES][]>([]);


// Keep state in sync with existingBase prop
useEffect(() => {
if (existingBase) {
Expand Down Expand Up @@ -127,6 +96,38 @@ const BaseModal: React.FC<BaseModalProps> = ({
}
}, [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 (
<div className="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50">
<div className={`bg-gradient-to-b from-slate-900 to-slate-950 rounded-lg p-6 border border-slate-700 shadow-lg ${
width === 'sm' ? 'w-[400px]' :
width === 'md' ? 'w-[600px]' :
width === 'lg' ? 'w-[800px]' :
width === 'xl' ? 'w-[1000px]' :
width === '2xl' ? 'w-[1200px]' :
'w-[600px]'
} max-h-[80vh] overflow-y-auto`}>
{title && (
<div className="flex justify-between items-center mb-6 border-b border-slate-700 pb-4">
<h2 className="text-2xl font-bold text-green-400">{title}</h2>
<button
onClick={onClose}
className="text-slate-400 hover:text-green-400 transition-colors"
>
<X size={24} />
</button>
</div>
)}
{children}
</div>
</div>
);
}

// Keep localFacilities in sync when upgrades happen
const handleFacilityUpgrade = (baseId: string, facilityId: string) => {
if (!onUpgrade) return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/HangarModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const HangarModal: React.FC<HangarModalProps> = ({
<div className="space-y-6">
{(['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));
Expand Down
5 changes: 3 additions & 2 deletions src/data/basePersonnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/data/vehicles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions src/utils/baseUtils.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -93,17 +93,17 @@ 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;
}

/**
* For new bases, calculate initial housing capacity from barracks
* @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;
Expand All @@ -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');
}
Expand Down