Add Component Density Toggle
This commit is contained in:
parent
cebb36a76f
commit
d081dedef9
2 changed files with 60 additions and 15 deletions
|
@ -79,13 +79,21 @@ export const inventorySizes = new Map([
|
|||
]);
|
||||
|
||||
export const metricModifiers: Map<number, string> = 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<Density, number> = 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 = {
|
||||
|
|
|
@ -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<InventoryType> = $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}
|
||||
</div>
|
||||
<Separator />
|
||||
<Label for="density">{localized("density")}</Label>
|
||||
<div id="density" class="flex">
|
||||
{#each Object.values(Density) as value}
|
||||
{#if density === value}
|
||||
<Button variant="primary">{localized(value)}</Button>
|
||||
{:else}
|
||||
<Button variant="secondary" onclick={() => density = value}>{localized(value)}</Button>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
<Separator />
|
||||
<p>{localized("liftableVehcileWeight")}: {weightConversion(maxVehicleWeight)}</p>
|
||||
<p>{localized("liftableWeight")}: {weightConversion(maxWeight)}</p>
|
||||
</Card.Content>
|
||||
|
|
Loading…
Reference in a new issue