diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 11158c6..e688d52 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -79,13 +79,21 @@ export const inventorySizes = new Map([ ]); export const metricModifiers: Map = new Map([ - /*[1000000000, "G"],*/ + [1000000000, "G"], [1000000, "M"], [1000, "k"], [1, ""] -]) +]); -export const weightPerVolume = 1/0.37; +export enum Density { + Ore = "ore", + Component = "component", +} + +export const densityValues: Map = new Map([ + [Density.Ore, 1/0.37], + [Density.Component, 1/0.047], +]) export const localization = new Map([ ["space engineers", new Map([ @@ -230,7 +238,19 @@ export const localization = new Map([ ["separator", new Map([ ["en-GB", ","], ["de-DE", "."] - ])] + ])], + ["ore", new Map([ + ["en-GB", "Ore"], + ["de-DE", "Erz"] + ])], + ["component", new Map([ + ["en-GB", "Component"], + ["de-DE", "Komponente"] + ])], + ["density", new Map([ + ["en-GB", "Density"], + ["de-DE", "Dichte"] + ])], ]) export type Thruster = { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index f16ce2b..03ff8dc 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -10,7 +10,7 @@ localization, metricModifiers, type Thruster, ThrusterSize, ThrusterType, - thrustValues, weightPerVolume + thrustValues, Density, densityValues } from "$lib/constants"; import {Input} from "$lib/components/ui/input"; import {Label} from "$lib/components/ui/label"; @@ -26,6 +26,7 @@ localStorage.setItem("thrusters", JSON.stringify(thrusters)); } }) + let inventories: Array = $state([]) $effect(() => { if (mounted) { @@ -33,28 +34,34 @@ } }) - let inventoryMultiplier = $state(1); + let inventoryMultiplier: number = $state(3); $effect(() => { if (mounted) { localStorage.setItem("inventoryMultiplier", inventoryMultiplier); } }) - let gridSize = $state(Grids.Small); + let gridSize: Grids = $state(Grids.Small); $effect(() => { if (mounted) { localStorage.setItem("gridSize", gridSize); } }) - let gravity = $state(1); + let gravity: number = $state(1); $effect(() => { if (mounted) { localStorage.setItem("gravity", gravity); } }) + let density: Density = $state(Density.Ore); + $effect(() => { + if (mounted) { + localStorage.setItem("density", density); + } + }) - let newThruster = $state({ + let newThruster: Thruster = $state({ type: ThrusterType.Atmospheric, size: ThrusterSize.Small, }) @@ -64,21 +71,21 @@ } }) - let newInventory = $state(InventoryType.CargoSmall) + let newInventory: InventoryType = $state(InventoryType.CargoMedium) $effect(() => { if (mounted) { localStorage.setItem("newInventory", JSON.stringify(newInventory)) } }) - let totalThrust = $derived.by(() => { + let totalThrust: number = $derived.by(() => { let thrust = 0; thrusters.forEach((thruster) => { thrust += getThrusterPower(thruster) }) return thrust }); - let totalVolume = $derived.by(() => { + let totalVolume: number = $derived.by(() => { let volume = 0; inventories.forEach((inventory) => { volume += getInventoryVolume(inventory); @@ -86,12 +93,12 @@ return volume; }) - let maxWeight = $derived(totalThrust / (gravity * 9.81)) + let maxWeight: number = $derived(totalThrust / (gravity * 9.81)) - let maxVehicleWeight = $derived(maxWeight - totalVolume * weightPerVolume) + let maxVehicleWeight: number = $derived(maxWeight - totalVolume * densityValues.get(density)) function weightConversion(weight: number): string { - if (weight > 1000) { + if (weight > 1000 || weight < -1000) { return applyUnits(weight/1000, "t") } else { @@ -148,6 +155,9 @@ } } } + if (value < 0) { + return `-${applyUnits(value * -1, unit)}` + } let rounded = Math.round(((value + Number.EPSILON) * 100) / 100) return `${rounded}${unit}` } @@ -173,6 +183,10 @@ gravity = localStorage.getItem("gravity") } + if (localStorage.getItem("density") !== null) { + density = localStorage.getItem("density") + } + if (localStorage.getItem("inventoryMultiplier") !== null) { inventoryMultiplier = localStorage.getItem("inventoryMultiplier") } @@ -215,6 +229,17 @@ {/each} + +
+ {#each Object.values(Density) as value} + {#if density === value} + + {:else} + + {/if} + {/each} +
+

{localized("liftableVehcileWeight")}: {weightConversion(maxVehicleWeight)}

{localized("liftableWeight")}: {weightConversion(maxWeight)}