Add Fusion Thrusters, Add Atmospheric Density Modifier

This commit is contained in:
Neshura 2024-05-21 01:49:20 +02:00
parent d081dedef9
commit 5f80ab0c88
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
4 changed files with 168 additions and 62 deletions

View file

@ -27,6 +27,8 @@
"dependencies": { "dependencies": {
"bits-ui": "^0.21.8", "bits-ui": "^0.21.8",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"cmdk-sv": "^0.0.17",
"svelte-radix": "^1.1.0",
"tailwind-merge": "^2.3.0", "tailwind-merge": "^2.3.0",
"tailwind-variants": "^0.2.1" "tailwind-variants": "^0.2.1"
} }

View file

@ -1,10 +1,34 @@
import {Map} from "svelte/reactivity";
export enum Grids { export enum Grids {
Small = "smallGrid", Small = "smallGrid",
Large = "largeGrid" Large = "largeGrid"
} }
export enum ThrusterFuel {
Electric = "electric",
Hydrogen = "hydrogen",
Deuterium = "deuterium"
}
export class ThrusterTypeDetails {
atmosphericFactor: number;
vacuumFactor: number;
fuel: ThrusterFuel;
sizes: Map<ThrusterSize, ThrusterSizeDetails>;
constructor(atmos: number, vacuum: number, fuel: ThrusterFuel, sizes: Map<ThrusterSize, ThrusterSizeDetails>) {
this.atmosphericFactor = atmos;
this.vacuumFactor = vacuum;
this.fuel = fuel;
this.sizes = sizes;
}
}
export enum ThrusterSize {
Small = "smallThruster",
Large = "largeThruster",
Huge = "hugeThruster",
}
export enum ThrusterType { export enum ThrusterType {
Ion = "ion", Ion = "ion",
Atmospheric = "atmos", Atmospheric = "atmos",
@ -12,47 +36,54 @@ export enum ThrusterType {
Fusion = "fusion" Fusion = "fusion"
} }
export enum ThrusterSize { export class ThrusterSizeDetails {
Small = "smallThruster", thrust: number;
Large = "largeThruster" maxFuelConsumption: number;
constructor(thrust: number, maxFuelConsumption = 0) {
this.thrust = thrust;
this.maxFuelConsumption = maxFuelConsumption;
}
} }
export const thrustValues = new Map([ export const thrusterDetails: Map<Grids, Map<ThrusterType, ThrusterTypeDetails>> = new Map([
[Grids.Large, new Map([ [Grids.Large, new Map([
[ThrusterType.Atmospheric, new Map([ [ThrusterType.Atmospheric, new ThrusterTypeDetails(1, 0, ThrusterFuel.Electric, new Map([
[ThrusterSize.Large, 4500000], [ThrusterSize.Large, new ThrusterSizeDetails(4500000)],
[ThrusterSize.Small, 350000] [ThrusterSize.Small, new ThrusterSizeDetails(350000)]
])], ]))],
[ThrusterType.Ion, new Map([ [ThrusterType.Ion, new ThrusterTypeDetails(0.2, 1, ThrusterFuel.Electric, new Map([
[ThrusterSize.Large, 4320000], [ThrusterSize.Large, new ThrusterSizeDetails(4320000)],
[ThrusterSize.Small, 345600] [ThrusterSize.Small, new ThrusterSizeDetails(345600)]
])], ]))],
[ThrusterType.Fusion, new Map([ [ThrusterType.Hydrogen, new ThrusterTypeDetails(1, 1, ThrusterFuel.Hydrogen, new Map([
[ThrusterSize.Large, 666], [ThrusterSize.Large, new ThrusterSizeDetails(7200000)],
[ThrusterSize.Small, 666] [ThrusterSize.Small, new ThrusterSizeDetails(1080000)]
])], ]))],
[ThrusterType.Hydrogen, new Map([ [ThrusterType.Fusion, new ThrusterTypeDetails(0.5, 1, ThrusterFuel.Deuterium, new Map([
[ThrusterSize.Large, 7200000], [ThrusterSize.Large, new ThrusterSizeDetails(33780000)],
[ThrusterSize.Small, 1080000] [ThrusterSize.Small, new ThrusterSizeDetails(9040000)]
])] ]))]
])], ])],
[Grids.Small, new Map([ [Grids.Small, new Map([
[ThrusterType.Atmospheric, new Map([ [ThrusterType.Atmospheric, new ThrusterTypeDetails(1, 0, ThrusterFuel.Electric, new Map([
[ThrusterSize.Large, 340000], [ThrusterSize.Large, new ThrusterSizeDetails(340000)],
[ThrusterSize.Small, 65000] [ThrusterSize.Small, new ThrusterSizeDetails(65000)]
])], ]))],
[ThrusterType.Ion, new Map([ [ThrusterType.Ion, new ThrusterTypeDetails(0.2, 1, ThrusterFuel.Electric, new Map([
[ThrusterSize.Large, 172800], [ThrusterSize.Large, new ThrusterSizeDetails(172800)],
[ThrusterSize.Small, 14400] [ThrusterSize.Small, new ThrusterSizeDetails(14400)]
])], ]))],
[ThrusterType.Fusion, new Map([ [ThrusterType.Hydrogen, new ThrusterTypeDetails(1, 1, ThrusterFuel.Hydrogen, new Map([
[ThrusterSize.Large, 666], [ThrusterSize.Large, new ThrusterSizeDetails(480000)],
[ThrusterSize.Small, 666] [ThrusterSize.Small, new ThrusterSizeDetails(98400)]
])], ]))],
[ThrusterType.Hydrogen, new Map([ [ThrusterType.Fusion, new ThrusterTypeDetails(0.5, 1, ThrusterFuel.Deuterium, new Map([
[ThrusterSize.Large, 480000], [ThrusterSize.Huge, new ThrusterSizeDetails(9040000)],
[ThrusterSize.Small, 98400] [ThrusterSize.Large, new ThrusterSizeDetails(1030000)],
])] [ThrusterSize.Small, new ThrusterSizeDetails(210000)]
]))]
])] ])]
]) ])
@ -159,6 +190,10 @@ export const localization = new Map([
["en-GB", "Large"], ["en-GB", "Large"],
["de-DE", "Großer"] ["de-DE", "Großer"]
])], ])],
["hugeThruster", new Map([
["en-GB", "Huge"],
["de-DE", "Rießiger"]
])],
["connector", new Map([ ["connector", new Map([
["en-GB", "Connector"], ["en-GB", "Connector"],
["de-DE", "Verbinder"] ["de-DE", "Verbinder"]
@ -251,6 +286,10 @@ export const localization = new Map([
["en-GB", "Density"], ["en-GB", "Density"],
["de-DE", "Dichte"] ["de-DE", "Dichte"]
])], ])],
["atmosDensity", new Map([
["en-GB", "Atmospheric Density"],
["de-DE", "Atmosphärendichte"]
])],
]) ])
export type Thruster = { export type Thruster = {

View file

@ -10,11 +10,12 @@
localization, metricModifiers, type Thruster, localization, metricModifiers, type Thruster,
ThrusterSize, ThrusterSize,
ThrusterType, ThrusterType,
thrustValues, Density, densityValues thrusterDetails, Density, densityValues, ThrusterTypeDetails, ThrusterSizeDetails
} from "$lib/constants"; } from "$lib/constants";
import {Input} from "$lib/components/ui/input"; import {Input} from "$lib/components/ui/input";
import {Label} from "$lib/components/ui/label"; import {Label} from "$lib/components/ui/label";
import {Separator} from "$lib/components/ui/separator"; import {Separator} from "$lib/components/ui/separator";
import * as DropdownMenu from "$lib/components/ui/dropdown-menu";
import {onMount} from "svelte"; import {onMount} from "svelte";
let locale = $state("en-GB"); let locale = $state("en-GB");
@ -61,6 +62,13 @@
} }
}) })
let atmosphericDensity: number = $state(1);
$effect(() => {
if (mounted) {
localStorage.setItem("atmosphericDensity", atmosphericDensity);
}
})
let newThruster: Thruster = $state({ let newThruster: Thruster = $state({
type: ThrusterType.Atmospheric, type: ThrusterType.Atmospheric,
size: ThrusterSize.Small, size: ThrusterSize.Small,
@ -81,7 +89,7 @@
let totalThrust: number = $derived.by(() => { let totalThrust: number = $derived.by(() => {
let thrust = 0; let thrust = 0;
thrusters.forEach((thruster) => { thrusters.forEach((thruster) => {
thrust += getThrusterPower(thruster) thrust += getThrust(thruster)
}) })
return thrust return thrust
}); });
@ -110,8 +118,19 @@
return inventorySizes.get(gridSize).get(inventory) * inventoryMultiplier return inventorySizes.get(gridSize).get(inventory) * inventoryMultiplier
} }
function getThrusterPower(thruster: Thruster): number { function getThrusterDetails(thruster: Thruster): ThrusterSizeDetails {
return thrustValues.get(gridSize).get(thruster.type).get(thruster.size) return thrusterDetails.get(gridSize).get(thruster.type).sizes.get(thruster.size)
}
function getThrust(thruster: Thruster): number {
let typeDetails = getThrusterTypeDetails(thruster);
let sizeDetails = getThrusterDetails(thruster);
let thrustEfficiency = (typeDetails.vacuumFactor * (1 - atmosphericDensity)) + (typeDetails.atmosphericFactor * atmosphericDensity);
return sizeDetails.thrust * thrustEfficiency;
}
function getThrusterTypeDetails(thruster: Thruster): ThrusterTypeDetails {
return thrusterDetails.get(gridSize).get(thruster.type)
} }
function addThruster() { function addThruster() {
@ -187,6 +206,10 @@
density = localStorage.getItem("density") density = localStorage.getItem("density")
} }
if (localStorage.getItem("atmosphericDensity") !== null) {
atmosphericDensity = localStorage.getItem("atmosphericDensity")
}
if (localStorage.getItem("inventoryMultiplier") !== null) { if (localStorage.getItem("inventoryMultiplier") !== null) {
inventoryMultiplier = localStorage.getItem("inventoryMultiplier") inventoryMultiplier = localStorage.getItem("inventoryMultiplier")
} }
@ -217,6 +240,8 @@
<Separator /> <Separator />
<Label for="gravity">{localized("gravity")}</Label> <Label for="gravity">{localized("gravity")}</Label>
<Input type="number" step="0.01" id="gravity" bind:value={gravity}/> <Input type="number" step="0.01" id="gravity" bind:value={gravity}/>
<Label for="atmosDensity">{localized("atmosDensity")}</Label>
<Input type="number" step="0.01" id="atmosDensity" bind:value={atmosphericDensity}/>
<Separator /> <Separator />
<Label for="gridSize">{localized("gridSize")}</Label> <Label for="gridSize">{localized("gridSize")}</Label>
<div id="gridSize" class="flex"> <div id="gridSize" class="flex">
@ -252,24 +277,26 @@
<Separator /> <Separator />
<Card.Root> <Card.Root>
<Card.Content class="flex flex-col gap-3 pt-6"> <Card.Content class="flex flex-col gap-3 pt-6">
<div class="flex gap-2"> <DropdownMenu.Root>
{#each Object.values(ThrusterType) as thruster} <DropdownMenu.Trigger>{localized(newThruster.type)}</DropdownMenu.Trigger>
{#if newThruster.type === thruster} <DropdownMenu.Content>
<Button variant="primary">{localized(thruster)}</Button> <DropdownMenu.RadioGroup bind:value={newThruster.type}>
{:else} {#each Object.values(ThrusterType) as thrusterType}
<Button variant="secondary" onclick={() => newThruster.type = thruster}>{localized(thruster)}</Button> <DropdownMenu.RadioItem value={thrusterType}>{localized(thrusterType)}</DropdownMenu.RadioItem>
{/if} {/each}
{/each} </DropdownMenu.RadioGroup>
</div> </DropdownMenu.Content>
<div class="flex gap-2"> </DropdownMenu.Root>
{#each Object.values(ThrusterSize) as size} <DropdownMenu.Root>
{#if newThruster.size === size} <DropdownMenu.Trigger>{localized(newThruster.size)}</DropdownMenu.Trigger>
<Button variant="primary">{localized(size)}</Button> <DropdownMenu.Content>
{:else} <DropdownMenu.RadioGroup bind:value={newThruster.size}>
<Button variant="secondary" onclick={() => newThruster.size = size}>{localized(size)}</Button> {#each getThrusterTypeDetails(newThruster).sizes.keys() as thrusterDetails}
{/if} <DropdownMenu.RadioItem value={thrusterDetails}>{localized(thrusterDetails)}</DropdownMenu.RadioItem>
{/each} {/each}
</div> </DropdownMenu.RadioGroup>
</DropdownMenu.Content>
</DropdownMenu.Root>
<Button variant="secondary" onclick={() => addThruster()}>{localized("addThruster")}</Button> <Button variant="secondary" onclick={() => addThruster()}>{localized("addThruster")}</Button>
</Card.Content> </Card.Content>
</Card.Root> </Card.Root>
@ -282,7 +309,7 @@
<div class="max-h-full overflow-y-auto"> <div class="max-h-full overflow-y-auto">
{#each thrusters as thruster, index} {#each thrusters as thruster, index}
<p class="p-1"> <p class="p-1">
- {localized(thruster.size)} {localized(thruster.type)} {localized("thruster")}: {applyUnits(getThrusterPower(thruster), "N")} - {localized(thruster.size)} {localized(thruster.type)} {localized("thruster")}: {applyUnits(getThrust(thruster), "N")}
<Button variant="destructive" onclick={() => thrusters.splice(index, 1)}>X</Button> <Button variant="destructive" onclick={() => thrusters.splice(index, 1)}>X</Button>
</p> </p>
{/each} {/each}

View file

@ -208,6 +208,18 @@
"@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14" "@jridgewell/sourcemap-codec" "^1.4.14"
"@melt-ui/svelte@0.61.2":
version "0.61.2"
resolved "https://registry.yarnpkg.com/@melt-ui/svelte/-/svelte-0.61.2.tgz#2948dd4ef47c4c5b5cf74d028c5143a5f986d239"
integrity sha512-BHkD9G31zQBToA4euDRBgTQRvWxT9scufOVCXgDO6HKTvyxFspbWT2bgiSFqAK4BbAGDn9Ao36Q8F9O71KN4OQ==
dependencies:
"@floating-ui/core" "^1.3.1"
"@floating-ui/dom" "^1.4.5"
"@internationalized/date" "^3.5.0"
dequal "^2.0.3"
focus-trap "^7.5.2"
nanoid "^4.0.2"
"@melt-ui/svelte@0.76.2": "@melt-ui/svelte@0.76.2":
version "0.76.2" version "0.76.2"
resolved "https://registry.yarnpkg.com/@melt-ui/svelte/-/svelte-0.76.2.tgz#9d6a578695ac257e34710fdeff3c8a40c8c25f31" resolved "https://registry.yarnpkg.com/@melt-ui/svelte/-/svelte-0.76.2.tgz#9d6a578695ac257e34710fdeff3c8a40c8c25f31"
@ -491,6 +503,14 @@ bits-ui@^0.21.8:
"@melt-ui/svelte" "0.76.2" "@melt-ui/svelte" "0.76.2"
nanoid "^5.0.5" nanoid "^5.0.5"
bits-ui@^0.9.0:
version "0.9.9"
resolved "https://registry.yarnpkg.com/bits-ui/-/bits-ui-0.9.9.tgz#02b20e41ad673670259aadcefe2c75d827fe3626"
integrity sha512-LkdkyTtpXdkjBzPZJVJgpcre4fut6DONoprMfadHFo82HNUhph+02CxDjYEcZcThb5z4YjSxMlCYvQPZm+YtfQ==
dependencies:
"@melt-ui/svelte" "0.61.2"
nanoid "^5.0.3"
brace-expansion@^1.1.7: brace-expansion@^1.1.7:
version "1.1.11" version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@ -563,6 +583,14 @@ clsx@^2.1.1:
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999" resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA== integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==
cmdk-sv@^0.0.17:
version "0.0.17"
resolved "https://registry.yarnpkg.com/cmdk-sv/-/cmdk-sv-0.0.17.tgz#1d915040577affc72862161318ef39ab5829f49d"
integrity sha512-28QTrK1tT1TSNoGq9MVnzjeLNNjCgjmsM8c2HJfDpRt9t+GD+9m3wX/WdAPaP9jdoNYU0SSdZVdgsGgpaSQOYQ==
dependencies:
bits-ui "^0.9.0"
nanoid "^5.0.2"
color-convert@^2.0.1: color-convert@^2.0.1:
version "2.0.1" version "2.0.1"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
@ -1035,7 +1063,12 @@ nanoid@^3.3.7:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g== integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==
nanoid@^5.0.4, nanoid@^5.0.5: nanoid@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-4.0.2.tgz#140b3c5003959adbebf521c170f282c5e7f9fb9e"
integrity sha512-7ZtY5KTCNheRGfEFxnedV5zFiORN1+Y1N6zvPTnHQd8ENUvfaDBeuJDZb2bN/oXwXxu3qkTXDzy57W5vAmDTBw==
nanoid@^5.0.2, nanoid@^5.0.3, nanoid@^5.0.4, nanoid@^5.0.5:
version "5.0.7" version "5.0.7"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.7.tgz#6452e8c5a816861fd9d2b898399f7e5fd6944cc6" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.7.tgz#6452e8c5a816861fd9d2b898399f7e5fd6944cc6"
integrity sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ== integrity sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==
@ -1423,6 +1456,11 @@ svelte-preprocess@^5.1.3:
sorcery "^0.11.0" sorcery "^0.11.0"
strip-indent "^3.0.0" strip-indent "^3.0.0"
svelte-radix@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/svelte-radix/-/svelte-radix-1.1.0.tgz#5fb0c8d37422ea4863649180f6277af2d8b70dd3"
integrity sha512-kyE9wZiJV937INGb+wiBkAjmGtQUUYRPkVL2Q+/gj+9Vog1Ewd2wNvNmpNMUd+c+euxoc5u5YZMuCUgky9EUPw==
svelte@^5.0.0-next: svelte@^5.0.0-next:
version "5.0.0-next.136" version "5.0.0-next.136"
resolved "https://registry.yarnpkg.com/svelte/-/svelte-5.0.0-next.136.tgz#13db3f1e06e92d3951e1b2133590434e765ed1c4" resolved "https://registry.yarnpkg.com/svelte/-/svelte-5.0.0-next.136.tgz#13db3f1e06e92d3951e1b2133590434e765ed1c4"