Skip to content

Commit 1ac49b4

Browse files
committed
add colors for planets
1 parent 477f870 commit 1ac49b4

File tree

8 files changed

+75
-26
lines changed

8 files changed

+75
-26
lines changed
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
2-
"settings": {
3-
"editor.formatOnSave": true,
4-
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
5-
"editor.codeActionsOnSave": {
6-
"source.fixAll.eslint": true
7-
}
8-
}
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll.eslint": "always"
6+
},
97
}

hackathon/spacecraft/src/screens/ExploreScreen.tsx

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Text, TouchableOpacity, View } from "react-native";
1+
import { FlatList, TouchableOpacity, View } from "react-native";
2+
import { Text } from "react-native-paper";
23

34
import { ScreenContainer } from "~/components/ScreenContainer";
45
import { usePlanets } from "~/hooks/usePlanets";
56
import { Routes } from "~/navigation/Routes";
7+
import { getTerrainColor } from "~/utils/getTerrainColor";
68

79
interface ExploreScreenProps {}
810

@@ -25,20 +27,46 @@ export function ExploreScreen({ navigation }: ExploreScreenProps) {
2527
);
2628
}
2729

30+
const renderItem = ({ item }) => {
31+
if (!item || item.name === "Bespin") {
32+
return null;
33+
}
34+
35+
const backgroundColor = getTerrainColor(item.terrain);
36+
const size = item.diameter / 100;
37+
38+
return (
39+
<View style={{ padding: 64 }}>
40+
<TouchableOpacity
41+
onPress={() =>
42+
navigation.navigate(Routes.PLANET_DETAILS_SCREEN, { planet: item })
43+
}
44+
>
45+
<Text variant="headlineMedium" style={{ textAlign: "center" }}>
46+
{item.name}
47+
</Text>
48+
</TouchableOpacity>
49+
<View
50+
style={{
51+
width: size,
52+
height: size,
53+
backgroundColor: backgroundColor,
54+
borderRadius: "100%",
55+
margin: 8,
56+
}}
57+
/>
58+
</View>
59+
);
60+
};
61+
2862
return (
2963
<ScreenContainer title={"Explore"}>
30-
<View>
31-
{data?.results.map((planet) => (
32-
<TouchableOpacity
33-
key={planet.name}
34-
onPress={() =>
35-
navigation.navigate(Routes.PLANET_DETAILS_SCREEN, { planet })
36-
}
37-
>
38-
<Text>{planet.name}</Text>
39-
</TouchableOpacity>
40-
))}
41-
</View>
64+
<FlatList
65+
data={data.results}
66+
renderItem={renderItem}
67+
keyExtractor={(ship) => ship.model}
68+
horizontal={true}
69+
/>
4270
</ScreenContainer>
4371
);
4472
}

hackathon/spacecraft/src/screens/PlanetDetailsScreen.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ export interface PlanetDetailsScreenProps {
3737
}
3838

3939
export function PlanetDetailsScreen(props: PlanetDetailsScreenProps) {
40-
console.log(
41-
"🚀 ~ file: PlanetDetailsScreen.tsx:6 ~ PlanetDetailsScreen ~ props:",
42-
props.route
43-
);
44-
45-
4640
return (
4741
<ScreenContainer title={props.route.params.planet.name} withGoBack>
4842
<Text>PlanetDetailsScreen</Text>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const terrainColorMap = {
2+
desert: "#EDC9AF",
3+
grasslands: "#7CFC00",
4+
mountains: "#8B4513",
5+
jungle: "#228B22",
6+
rainforests: "#006400",
7+
tundra: "#D3D3D3",
8+
"ice caves": "#ADD8E6",
9+
"mountain ranges": "#8B4513",
10+
swamp: "#556B2F",
11+
jungles: "#228B22",
12+
"gas giant": "#FFD700",
13+
forests: "#228B22",
14+
lakes: "#0000FF",
15+
"grassy hills": "#7CFC00",
16+
cityscape: "#A9A9A9",
17+
ocean: "#0000FF",
18+
};
19+
20+
export function getTerrainColor(terrain: string) {
21+
console.log("🚀 ~ terrain:", terrain);
22+
for (const [key, color] of Object.entries(terrainColorMap)) {
23+
if (terrain.includes(key)) {
24+
return color;
25+
}
26+
}
27+
28+
return "#000000"; // default color if no match
29+
}

0 commit comments

Comments
 (0)