Spaces:
Build error
Build error
Upload components/BuildingCard.jsx with huggingface_hub
Browse files- components/BuildingCard.jsx +72 -0
components/BuildingCard.jsx
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { motion } from 'framer-motion';
|
| 2 |
+
import { useState } from 'react';
|
| 3 |
+
|
| 4 |
+
export default function BuildingCard({ building, onPurchase, resources }) {
|
| 5 |
+
const [isPurchasing, setIsPurchasing] = useState(false);
|
| 6 |
+
|
| 7 |
+
const canAfford = building.cost.every(cost => {
|
| 8 |
+
const resource = resources.find(r => r.name === cost.name);
|
| 9 |
+
return resource && resource.amount >= cost.amount;
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
const handlePurchase = () => {
|
| 13 |
+
if (canAfford && !isPurchasing) {
|
| 14 |
+
setIsPurchasing(true);
|
| 15 |
+
setTimeout(() => {
|
| 16 |
+
onPurchase(building);
|
| 17 |
+
setIsPurchasing(false);
|
| 18 |
+
}, 500);
|
| 19 |
+
}
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
return (
|
| 23 |
+
<motion.div
|
| 24 |
+
whileHover={{ scale: 1.02 }}
|
| 25 |
+
className="bg-space-dark/50 border border-space-blue/30 rounded-lg p-4 flex flex-col"
|
| 26 |
+
>
|
| 27 |
+
<div className="flex justify-between items-start mb-3">
|
| 28 |
+
<h3 className="text-lg font-semibold text-space-gold">{building.name}</h3>
|
| 29 |
+
<div className="text-right">
|
| 30 |
+
<div className="text-xs text-space-blue/70">Level {building.level}</div>
|
| 31 |
+
<div className="text-xs text-space-gold">
|
| 32 |
+
+{building.production}/s
|
| 33 |
+
</div>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<div className="mb-3">
|
| 38 |
+
<p className="text-sm text-space-blue/80 mb-2">{building.description}</p>
|
| 39 |
+
<div className="flex flex-wrap gap-2 mb-3">
|
| 40 |
+
{building.cost.map((cost, index) => {
|
| 41 |
+
const resource = resources.find(r => r.name === cost.name);
|
| 42 |
+
const hasEnough = resource && resource.amount >= cost.amount;
|
| 43 |
+
return (
|
| 44 |
+
<div
|
| 45 |
+
key={index}
|
| 46 |
+
className={`flex items-center space-x-1 px-2 py-1 rounded text-xs ${
|
| 47 |
+
hasEnough ? 'bg-green-900/50 text-green-300' : 'bg-red-900/50 text-red-300'
|
| 48 |
+
}`}
|
| 49 |
+
>
|
| 50 |
+
<cost.icon size={12} />
|
| 51 |
+
<span>{cost.amount}</span>
|
| 52 |
+
</div>
|
| 53 |
+
);
|
| 54 |
+
})}
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
<motion.button
|
| 59 |
+
whileTap={{ scale: 0.98 }}
|
| 60 |
+
onClick={handlePurchase}
|
| 61 |
+
disabled={!canAfford || isPurchasing}
|
| 62 |
+
className={`w-full py-2 rounded-lg font-medium transition-all ${
|
| 63 |
+
canAfford
|
| 64 |
+
? 'bg-space-gold text-space-dark hover:bg-yellow-400'
|
| 65 |
+
: 'bg-gray-600 text-gray-400 cursor-not-allowed'
|
| 66 |
+
} ${isPurchasing ? 'animate-pulse' : ''}`}
|
| 67 |
+
>
|
| 68 |
+
{isPurchasing ? 'Purchasing...' : `Buy (${building.cost[0].amount} ${building.cost[0].name})`}
|
| 69 |
+
</motion.button>
|
| 70 |
+
</motion.div>
|
| 71 |
+
);
|
| 72 |
+
}
|