Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎗️❄️ ↝ [SSG-141 SSG-125]: Making worlds (Part 2) #176

Merged
merged 10 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
🦛🏥 ↝ [SSG-147]: Fixed controller issues for advanced ph generator
  • Loading branch information
Gizmotronn committed Feb 22, 2025
commit 5f02fef31914b305e50c2824fe9ac2aa900cdfcd
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,40 @@ export function FullPlanetControls({
min={0.1}
max={10}
step={0.1}
onChange={onMassChange}
onChange={(value) => {
onMassChange(value)
if (value > 7.5) {
onTypeOverride("gaseous")
} else {
onTypeOverride(null) // Let the physics determine type
}
}}
/>
<SliderControl
label="Radius (R⊕)"
value={stats.radius}
min={0.1}
max={3}
step={0.1}
onChange={onRadiusChange}
onChange={(value) => {
onRadiusChange(value)
if (value > 2) {
onTypeOverride("gaseous")
} else {
onTypeOverride(null) // Let the physics determine type
}
}}
/>
<div className="space-y-2">
<Label className="text-sm text-[#5FCBC3]">Planet Type</Label>
<div className="flex gap-2">
<Button
size="sm"
onClick={() => onTypeOverride("terrestrial")}
onClick={() => {
onTypeOverride("terrestrial")
onMassChange(1) // Earth-like mass
onRadiusChange(1) // Earth-like radius
}}
variant={stats.type === "terrestrial" ? "default" : "outline"}
className={
stats.type === "terrestrial"
Expand All @@ -150,7 +168,11 @@ export function FullPlanetControls({
</Button>
<Button
size="sm"
onClick={() => onTypeOverride("gaseous")}
onClick={() => {
onTypeOverride("gaseous")
onMassChange(8) // Gas giant mass
onRadiusChange(2.5) // Gas giant radius
}}
variant={stats.type === "gaseous" ? "default" : "outline"}
className={
stats.type === "gaseous"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

import { useState } from "react"
import { Button } from "@/components/ui/button"
import { Textarea } from "@/components/ui/textarea"
import type { PlanetStats } from "@/utils/planet-physics"
import { Textarea } from "@/components/ui/textarea";
import type { PlanetStats } from "@/utils/planet-physics";

interface FullPlanetImportExportProps {
stats: PlanetStats
onImport: (importedStats: Partial<PlanetStats>) => void
}

// Type guard to check if a string is a valid key of PlanetStats
function isPlanetStatsKey(key: string): key is keyof PlanetStats {
return key in ({} as PlanetStats)
}

export function FullPlanetImportExport({ stats, onImport }: FullPlanetImportExportProps) {
const [importExportText, setImportExportText] = useState("")

const handleExport = () => {
const exportText = `mass: ${stats.mass.toFixed(2)}
radius: ${stats.radius.toFixed(2)}
temperature: ${stats.temperature?.toFixed(2) ?? "N/A"}
orbitalPeriod: ${stats.orbitalPeriod?.toFixed(2) ?? "N/A"}
atmosphereStrength: ${stats.atmosphereStrength?.toFixed(2) ?? "N/A"}
cloudCount: ${stats.cloudCount ?? "N/A"}
waterLevel: ${stats.waterLevel?.toFixed(2) ?? "N/A"}
density: ${stats.density?.toFixed(2) ?? "N/A"}`
const exportText = Object.entries(stats)
.map(([key, value]) => `${key}: ${typeof value === "number" ? value.toFixed(2) : JSON.stringify(value)}`)
.join("\n")
setImportExportText(exportText)
}

Expand All @@ -31,20 +31,55 @@ density: ${stats.density?.toFixed(2) ?? "N/A"}`

lines.forEach((line) => {
const [key, value] = line.split(":").map((part) => part.trim())
if (
value !== "N/A" &&
["mass", "radius", "temperature", "orbitalPeriod", "atmosphereStrength", "cloudCount", "waterLevel"].includes(
key,
)
) {
const parsedValue = Number.parseFloat(value)
if (!isNaN(parsedValue)) {
;(importedStats as any)[key] = parsedValue

if (key && value && isPlanetStatsKey(key)) {
try {
// Handle different types of values
if (key === "type") {
const typeValue = value.replace(/"/g, "") as "terrestrial" | "gaseous"
if (typeValue === "terrestrial" || typeValue === "gaseous") {
importedStats.type = typeValue
}
} else if (key === "biome") {
importedStats.biome = value.replace(/"/g, "")
} else if (key === "cloudTypes") {
try {
const cloudTypes = JSON.parse(value)
if (Array.isArray(cloudTypes)) {
importedStats.cloudTypes = cloudTypes
}
} catch (e) {
console.warn(`Failed to parse cloud types: ${value}`)
}
} else if (key === "soilType") {
const soilValue = value.replace(/"/g, "") as PlanetStats["soilType"]
if (["rocky", "sandy", "volcanic", "organic", "dusty", "frozen", "muddy"].includes(soilValue)) {
importedStats.soilType = soilValue
}
} else if (key === "terrainVariation") {
const terrainValue = value.replace(/"/g, "") as PlanetStats["terrainVariation"]
if (["flat", "moderate", "chaotic"].includes(terrainValue)) {
importedStats.terrainVariation = terrainValue
}
} else {
// Handle numeric values
const numValue = Number.parseFloat(value)
if (!isNaN(numValue)) {
importedStats[key] = numValue
}
}
} catch (e) {
console.warn(`Failed to parse value for ${key}: ${value}`)
}
}
})

if (Object.keys(importedStats).length > 0) {
// Ensure minimum required inputs are present
if (!importedStats.mass) importedStats.mass = 1
if (!importedStats.radius) importedStats.radius = 1
if (!importedStats.biome) importedStats.biome = "Rocky Highlands"

onImport(importedStats)
}
}
Expand All @@ -55,7 +90,7 @@ density: ${stats.density?.toFixed(2) ?? "N/A"}`
value={importExportText}
onChange={(e) => setImportExportText(e.target.value)}
placeholder="Paste settings here to import, or click Export to get current settings"
rows={8}
rows={12}
className="font-mono text-white bg-[#2A2A2A] border-[#3A3A3A]"
/>
<div className="flex justify-between gap-4">
Expand All @@ -71,6 +106,5 @@ density: ${stats.density?.toFixed(2) ?? "N/A"}`
</Button>
</div>
</div>
)
}

);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { determineLiquidType } from "@/utils/planet-physics";
import type { PlanetStats } from "@/utils/planet-physics";

interface PlanetControlsProps {
stats: PlanetStats;
onMassChange: (value: number) => void;
onRadiusChange: (value: number) => void;
onTemperatureChange: (value: number) => void;
onOrbitalPeriodChange: (value: number) => void;
onTypeOverride: (type: "terrestrial" | "gaseous" | null) => void;
onAtmosphereStrengthChange: (value: number) => void;
onCloudCountChange: (value: number) => void;
onWaterLevelChange: (value: number) => void;
onSurfaceRoughnessChange: (value: number) => void;
showExtendedControls: boolean;
stats: PlanetStats
onMassChange: (value: number) => void
onRadiusChange: (value: number) => void
onTemperatureChange: (value: number) => void
onOrbitalPeriodChange: (value: number) => void
onTypeOverride: (type: "terrestrial" | "gaseous" | null) => void
onAtmosphereStrengthChange: (value: number) => void
onCloudCountChange: (value: number) => void
onWaterLevelChange: (value: number) => void
onSurfaceRoughnessChange: (value: number) => void
showExtendedControls: boolean
};

export function PlanetControls({
Expand All @@ -33,7 +33,7 @@ export function PlanetControls({
onSurfaceRoughnessChange,
showExtendedControls,
}: PlanetControlsProps) {
const liquidInfo = determineLiquidType(stats.temperature);
const liquidInfo = determineLiquidType(stats.temperature)

return (
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
Expand Down
Loading