From 42628b6a57f3840878dd0642c2361b839e53e9bf Mon Sep 17 00:00:00 2001 From: Neshura Date: Wed, 22 May 2024 23:14:05 +0200 Subject: [PATCH] Fix ownership conflicts --- src/lib/components/InventoryList.svelte | 9 +++------ src/lib/components/ThrusterList.svelte | 9 +++------ src/lib/containers.svelte.ts | 1 - src/lib/ship.svelte.ts | 8 ++++++-- src/routes/+page.svelte | 15 ++++++++++----- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/lib/components/InventoryList.svelte b/src/lib/components/InventoryList.svelte index 0c20798..456e701 100644 --- a/src/lib/components/InventoryList.svelte +++ b/src/lib/components/InventoryList.svelte @@ -5,18 +5,15 @@ import {Button} from "$lib/components/ui/button/index.js"; 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 valids = []; valids[0] = typeof inventories !== "undefined"; valids[1] = typeof grid !== "undefined"; valids[2] = typeof multiplier !== "undefined"; + valids[3] = typeof onRemoveInventory !== "undefined"; return !valids.includes(false); }); - - function removeInventory(index: number) { - thrusters.splice(index, 1); - }
@@ -24,7 +21,7 @@ {#each inventories as inventory, index}

- {i18n.localize(inventory.details.name)} {i18n.localize("volume")}: {applyUnits(i18n, inventory.getVolume(grid, multiplier), "l")} - +

{/each} {:else} diff --git a/src/lib/components/ThrusterList.svelte b/src/lib/components/ThrusterList.svelte index 5356fbc..c59c275 100644 --- a/src/lib/components/ThrusterList.svelte +++ b/src/lib/components/ThrusterList.svelte @@ -5,18 +5,15 @@ import {applyUnits, Localization} from "$lib/constants"; 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 valids = []; valids[0] = typeof thrusters !== "undefined"; valids[1] = typeof grid !== "undefined"; valids[2] = typeof atmosphere !== "undefined"; + valids[3] = typeof onRemoveThruster !== "undefined"; return !valids.includes(false); }); - - function removeThruster(index: number) { - thrusters.splice(index, 1); - } @@ -25,7 +22,7 @@ {#each thrusters as thruster, index}

- {i18n.localize(thruster.details.size)} {i18n.localize(thruster.details.type.details.name)}: {applyUnits(i18n, thruster.getThrust(grid, atmosphere), "N")} - +

{/each} {:else} diff --git a/src/lib/containers.svelte.ts b/src/lib/containers.svelte.ts index b3dff58..a52a67e 100644 --- a/src/lib/containers.svelte.ts +++ b/src/lib/containers.svelte.ts @@ -56,7 +56,6 @@ export class Inventory { } getVolume(grid: Grid, multiplier: number): number { - console.log(this.details.capacity.get(grid), multiplier); return (this.details.capacity.get(grid) || 0) * multiplier; } } \ No newline at end of file diff --git a/src/lib/ship.svelte.ts b/src/lib/ship.svelte.ts index 380ad80..d745a92 100644 --- a/src/lib/ship.svelte.ts +++ b/src/lib/ship.svelte.ts @@ -68,8 +68,12 @@ export class Ship { return volume; } - spliceInventories(index: number, length: number): void { - this.inventories.splice(index, length); + removeThruster(index: number): void { + this.thrusters.splice(index, 1); + } + + removeInventory(index: number): void { + this.inventories.splice(index, 1); } getTotalThrust(atmosphere: number): number { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 89b1581..6a91941 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -65,17 +65,23 @@ let maxWeight: number = $derived(ship.getTotalMaxThrust() / (gravity * 9.81)) let maxVehicleWeight: number = $derived(maxWeight - ship.getTotalVolume(inventoryMultiplier) * material.density) - $inspect(maxVehicleWeight); - $inspect(`${maxWeight} - ${ship.getTotalVolume(inventoryMultiplier)} * ${material.density} = ${maxVehicleWeight}`) function addInventory(newInventory: Inventory) { ship.addInventory(newInventory); } + function removeInventory(index: number) { + ship.removeInventory(index); + } + function addThruster(newThruster: Thruster) { ship.addThruster(newThruster); } + function removeThruster(index: number) { + ship.removeThruster(index); + } + onMount(() => { if (navigator) { i18n.language = navigator.language; @@ -83,7 +89,6 @@ let ret = getFromLocalStorage("version"); if (ret.result) { - console.log(ret); if (ret.value !== STORAGE_VERSION) { localStorage.clear(); localStorage.setItem("version", STORAGE_VERSION); @@ -188,7 +193,7 @@ - + @@ -213,7 +218,7 @@ - +