Fix ownership conflicts

This commit is contained in:
Neshura 2024-05-22 23:14:05 +02:00
parent 9a63e033a1
commit 42628b6a57
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
5 changed files with 22 additions and 20 deletions

View file

@ -5,18 +5,15 @@
import {Button} from "$lib/components/ui/button/index.js"; import {Button} from "$lib/components/ui/button/index.js";
import {Grid} from "$lib/grid"; import {Grid} from "$lib/grid";
let { i18n = new Localization("en-GB"), inventories = $bindable(), grid, multiplier } = $props(); let { i18n = new Localization("en-GB"), inventories, onRemoveInventory, grid, multiplier } = $props();
let valid = $derived.by(() => { let valid = $derived.by(() => {
let valids = []; let valids = [];
valids[0] = typeof inventories !== "undefined"; valids[0] = typeof inventories !== "undefined";
valids[1] = typeof grid !== "undefined"; valids[1] = typeof grid !== "undefined";
valids[2] = typeof multiplier !== "undefined"; valids[2] = typeof multiplier !== "undefined";
valids[3] = typeof onRemoveInventory !== "undefined";
return !valids.includes(false); return !valids.includes(false);
}); });
function removeInventory(index: number) {
thrusters.splice(index, 1);
}
</script> </script>
<div class="max-h-full flex flex-col gap-2 overflow-y-auto"> <div class="max-h-full flex flex-col gap-2 overflow-y-auto">
@ -24,7 +21,7 @@
{#each inventories as inventory, index} {#each inventories as inventory, index}
<p class="flex gap-2 justify-between"> <p class="flex gap-2 justify-between">
- {i18n.localize(inventory.details.name)} {i18n.localize("volume")}: {applyUnits(i18n, inventory.getVolume(grid, multiplier), "l")} - {i18n.localize(inventory.details.name)} {i18n.localize("volume")}: {applyUnits(i18n, inventory.getVolume(grid, multiplier), "l")}
<Button variant="destructive" onclick={() => removeInventory(index)}>X</Button> <Button variant="destructive" onclick={() => onRemoveInventory(index)}>X</Button>
</p> </p>
{/each} {/each}
{:else} {:else}

View file

@ -5,18 +5,15 @@
import {applyUnits, Localization} from "$lib/constants"; import {applyUnits, Localization} from "$lib/constants";
import {Grid} from "$lib/grid"; import {Grid} from "$lib/grid";
let { i18n = new Localization("en-GB"), thrusters = $bindable(), grid, atmosphere } = $props(); let { i18n = new Localization("en-GB"), thrusters, onRemoveThruster, grid, atmosphere } = $props();
let valid = $derived.by(() => { let valid = $derived.by(() => {
let valids = []; let valids = [];
valids[0] = typeof thrusters !== "undefined"; valids[0] = typeof thrusters !== "undefined";
valids[1] = typeof grid !== "undefined"; valids[1] = typeof grid !== "undefined";
valids[2] = typeof atmosphere !== "undefined"; valids[2] = typeof atmosphere !== "undefined";
valids[3] = typeof onRemoveThruster !== "undefined";
return !valids.includes(false); return !valids.includes(false);
}); });
function removeThruster(index: number) {
thrusters.splice(index, 1);
}
</script> </script>
@ -25,7 +22,7 @@
{#each thrusters as thruster, index} {#each thrusters as thruster, index}
<p class="gap-2 flex justify-between"> <p class="gap-2 flex justify-between">
- {i18n.localize(thruster.details.size)} {i18n.localize(thruster.details.type.details.name)}: {applyUnits(i18n, thruster.getThrust(grid, atmosphere), "N")} - {i18n.localize(thruster.details.size)} {i18n.localize(thruster.details.type.details.name)}: {applyUnits(i18n, thruster.getThrust(grid, atmosphere), "N")}
<Button variant="destructive" onclick={() => removeThruster(index)}>X</Button> <Button variant="destructive" onclick={() => onRemoveThruster(index)}>X</Button>
</p> </p>
{/each} {/each}
{:else} {:else}

View file

@ -56,7 +56,6 @@ export class Inventory {
} }
getVolume(grid: Grid, multiplier: number): number { getVolume(grid: Grid, multiplier: number): number {
console.log(this.details.capacity.get(grid), multiplier);
return (this.details.capacity.get(grid) || 0) * multiplier; return (this.details.capacity.get(grid) || 0) * multiplier;
} }
} }

View file

@ -68,8 +68,12 @@ export class Ship {
return volume; return volume;
} }
spliceInventories(index: number, length: number): void { removeThruster(index: number): void {
this.inventories.splice(index, length); this.thrusters.splice(index, 1);
}
removeInventory(index: number): void {
this.inventories.splice(index, 1);
} }
getTotalThrust(atmosphere: number): number { getTotalThrust(atmosphere: number): number {

View file

@ -65,17 +65,23 @@
let maxWeight: number = $derived(ship.getTotalMaxThrust() / (gravity * 9.81)) let maxWeight: number = $derived(ship.getTotalMaxThrust() / (gravity * 9.81))
let maxVehicleWeight: number = $derived(maxWeight - ship.getTotalVolume(inventoryMultiplier) * material.density) let maxVehicleWeight: number = $derived(maxWeight - ship.getTotalVolume(inventoryMultiplier) * material.density)
$inspect(maxVehicleWeight);
$inspect(`${maxWeight} - ${ship.getTotalVolume(inventoryMultiplier)} * ${material.density} = ${maxVehicleWeight}`)
function addInventory(newInventory: Inventory) { function addInventory(newInventory: Inventory) {
ship.addInventory(newInventory); ship.addInventory(newInventory);
} }
function removeInventory(index: number) {
ship.removeInventory(index);
}
function addThruster(newThruster: Thruster) { function addThruster(newThruster: Thruster) {
ship.addThruster(newThruster); ship.addThruster(newThruster);
} }
function removeThruster(index: number) {
ship.removeThruster(index);
}
onMount(() => { onMount(() => {
if (navigator) { if (navigator) {
i18n.language = navigator.language; i18n.language = navigator.language;
@ -83,7 +89,6 @@
let ret = getFromLocalStorage("version"); let ret = getFromLocalStorage("version");
if (ret.result) { if (ret.result) {
console.log(ret);
if (ret.value !== STORAGE_VERSION) { if (ret.value !== STORAGE_VERSION) {
localStorage.clear(); localStorage.clear();
localStorage.setItem("version", STORAGE_VERSION); localStorage.setItem("version", STORAGE_VERSION);
@ -188,7 +193,7 @@
</Card.Header> </Card.Header>
<Card.Content class="flex flex-col gap-3 overflow-hidden"> <Card.Content class="flex flex-col gap-3 overflow-hidden">
<Separator /> <Separator />
<ThrusterList i18n={i18n} bind:thrusters={ship.thrusters} grid={ship.grid} atmosphere={atmosphericDensity}/> <ThrusterList i18n={i18n} thrusters={ship.thrusters} onRemoveThruster={removeThruster} grid={ship.grid} atmosphere={atmosphericDensity}/>
</Card.Content> </Card.Content>
</Card.Root> </Card.Root>
</Card.Content> </Card.Content>
@ -213,7 +218,7 @@
</Card.Header> </Card.Header>
<Card.Content class="flex flex-col gap-3 overflow-hidden"> <Card.Content class="flex flex-col gap-3 overflow-hidden">
<Separator /> <Separator />
<InventoryList i18n={i18n} bind:inventories={ship.inventories} grid={ship.grid} multiplier={inventoryMultiplier} /> <InventoryList i18n={i18n} inventories={ship.inventories} onRemoveInventory={removeInventory} grid={ship.grid} multiplier={inventoryMultiplier} />
</Card.Content> </Card.Content>
</Card.Root> </Card.Root>
</Card.Content> </Card.Content>