carrier component
This commit is contained in:
parent
7120f410a3
commit
4a69641120
@ -3,17 +3,23 @@
|
|||||||
<Structure {...structure} />
|
<Structure {...structure} />
|
||||||
<Weaponry {...weaponry} />
|
<Weaponry {...weaponry} />
|
||||||
|
|
||||||
|
{#if identification.isCarrier}
|
||||||
|
<Carrier {...carrier} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Identification from "./ShipEdit/Identification.svelte";
|
import Identification from "./ShipEdit/Identification.svelte";
|
||||||
import Propulsion from "./ShipEdit/Propulsion.svelte";
|
import Propulsion from "./ShipEdit/Propulsion.svelte";
|
||||||
import shipDux from "$lib/store/ship";
|
import shipDux from "$lib/store/ship";
|
||||||
import Structure from "./ShipEdit/Structure.svelte";
|
import Structure from "./ShipEdit/Structure.svelte";
|
||||||
import Weaponry from "./ShipEdit/Weaponry.svelte";
|
import Weaponry from "./ShipEdit/Weaponry.svelte";
|
||||||
|
import Carrier from "./ShipEdit/Carrier.svelte";
|
||||||
|
|
||||||
export let identification = {};
|
export let identification = {};
|
||||||
export let propulsion = {};
|
export let propulsion = {};
|
||||||
export let structure = {};
|
export let structure = {};
|
||||||
export let weaponry = {};
|
export let weaponry = {};
|
||||||
|
export let carrier = {};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
<Section label="carrier">
|
<Section label="carrier">
|
||||||
|
<div>
|
||||||
<ShipItem {...reqs}>
|
<ShipItem {...reqs}>
|
||||||
<Field label="bays">
|
<Field label="bays">
|
||||||
<input class="short" type="number" min="0" bind:value={bays} />
|
<input class="short" type="number" min="1" bind:value={bays} />
|
||||||
</Field>
|
</Field>
|
||||||
</ShipItem>
|
</ShipItem>
|
||||||
|
</div>
|
||||||
|
|
||||||
{#each squadrons as squadron, id (id)}
|
{#each squadrons as squadron, id (id)}
|
||||||
<Squadron {...squadron} id={id + 1} />
|
<Squadron {...squadron} id={id + 1} />
|
||||||
{/each}
|
{/each}
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
<script lang="ts">
|
<script>
|
||||||
import { getContext } from "svelte";
|
import { getContext } from "svelte";
|
||||||
|
|
||||||
import Field from "$lib/components/Field.svelte";
|
import Field from "$lib/components/Field.svelte";
|
||||||
@ -18,13 +20,15 @@
|
|||||||
import Section from "$lib/components/Section.svelte";
|
import Section from "$lib/components/Section.svelte";
|
||||||
import Squadron from "./Carrier/Squadron.svelte";
|
import Squadron from "./Carrier/Squadron.svelte";
|
||||||
|
|
||||||
export let bays = 0;
|
export let bays = 1;
|
||||||
export let reqs = { cost: 0, mass: 0 };
|
export let reqs = { cost: 0, mass: 0 };
|
||||||
export let squadrons = [];
|
export let squadrons = [];
|
||||||
|
|
||||||
|
if (bays < 1) bays = 1;
|
||||||
|
|
||||||
export let api = getContext("api");
|
export let api = getContext("api");
|
||||||
|
|
||||||
$: api?.dispatch?.setCarrierBays?.(bays);
|
$: api?.dispatch.setNbrCarrierBays(bays);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<ShipItem {...reqs}>
|
<ShipItem {...reqs}>
|
||||||
<Field label={`squadron ${id}`}>
|
<div class="field label suffix">
|
||||||
<select bind:value={type}>
|
<select bind:value={type}>
|
||||||
{#each types as type (type)}
|
{#each types as type (type)}
|
||||||
<option>{type}</option>
|
<option>{type}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
</Field>
|
<label class="active">squadron {id}</label>
|
||||||
</ShipItem>
|
<i>arrow_drop_down</i>
|
||||||
|
</div></ShipItem
|
||||||
|
>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte";
|
import { getContext } from "svelte";
|
||||||
@ -14,7 +16,7 @@
|
|||||||
import Section from "$lib/components/Section.svelte";
|
import Section from "$lib/components/Section.svelte";
|
||||||
import Field from "$lib/components/Field.svelte";
|
import Field from "$lib/components/Field.svelte";
|
||||||
import ShipItem from "$lib/components/ShipItem.svelte";
|
import ShipItem from "$lib/components/ShipItem.svelte";
|
||||||
// import { squadronTypes } from "$lib/shipDux/carrier";
|
import { squadronTypes } from "$lib/store/ship/carrier.ts";
|
||||||
|
|
||||||
const types = squadronTypes.map(({ type }) => type);
|
const types = squadronTypes.map(({ type }) => type);
|
||||||
|
|
||||||
@ -30,6 +32,9 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
select {
|
select {
|
||||||
width: inherit;
|
/* width: inherit; */
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
display: inline-block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
export let isCarrier = false;
|
export let isCarrier = false;
|
||||||
export let reqs = {};
|
export let reqs = {};
|
||||||
|
|
||||||
|
$: console.log("in the comp", isCarrier, shipClass);
|
||||||
|
|
||||||
export let api = getContext("api");
|
export let api = getContext("api");
|
||||||
|
|
||||||
$: shipTypes = candidateShipTypes(reqs.mass, isCarrier).map(
|
$: shipTypes = candidateShipTypes(reqs.mass, isCarrier).map(
|
||||||
@ -45,7 +47,6 @@
|
|||||||
|
|
||||||
$: api?.dispatch?.updateIdentification?.({ shipType, shipClass });
|
$: api?.dispatch?.updateIdentification?.({ shipType, shipClass });
|
||||||
|
|
||||||
$: console.log(isCarrier);
|
|
||||||
$: api?.dispatch.setCarrier?.(isCarrier);
|
$: api?.dispatch.setCarrier?.(isCarrier);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
<Weaponry {...$shipState.weaponry} />
|
<Weaponry {...$shipState.weaponry} />
|
||||||
|
|
||||||
|
{#if $shipState.identification.isCarrier}
|
||||||
<Carrier {...$shipState.carrier} />
|
<Carrier {...$shipState.carrier} />
|
||||||
|
{/if}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -8,10 +8,15 @@ export const createApi = () => {
|
|||||||
? JSON.parse(localStorage.getItem("ship") || "null")
|
? JSON.parse(localStorage.getItem("ship") || "null")
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const api = ship.createStore(state || undefined);
|
const api = ship.createStore({
|
||||||
|
preloadedState: state,
|
||||||
|
});
|
||||||
|
|
||||||
|
api.dispatch.restore(state);
|
||||||
|
|
||||||
if (browser) {
|
if (browser) {
|
||||||
api.subscribe(() => {
|
api.subscribe(() => {
|
||||||
|
console.log("saving...", api.getState());
|
||||||
localStorage.setItem("ship", JSON.stringify(api.getState()));
|
localStorage.setItem("ship", JSON.stringify(api.getState()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createSelector } from "@reduxjs/toolkit";
|
import { createSelector } from "@reduxjs/toolkit";
|
||||||
import Updux from "updux";
|
import Updux, { createPayloadAction } from "updux";
|
||||||
import * as R from "remeda";
|
import * as R from "remeda";
|
||||||
import memoize from "memoize-one";
|
import memoize from "memoize-one";
|
||||||
|
|
||||||
@ -51,7 +51,12 @@ const weaponry = new Updux({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const restore = createPayloadAction<typeof shipDux.initialState>("restore");
|
||||||
|
|
||||||
const shipDux = new Updux({
|
const shipDux = new Updux({
|
||||||
|
actions: {
|
||||||
|
restore,
|
||||||
|
},
|
||||||
initialState: {
|
initialState: {
|
||||||
schemaVersion: "1",
|
schemaVersion: "1",
|
||||||
},
|
},
|
||||||
@ -64,6 +69,8 @@ const shipDux = new Updux({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
shipDux.addMutation(restore, (state) => () => state);
|
||||||
|
|
||||||
shipDux.addReaction((api) => {
|
shipDux.addReaction((api) => {
|
||||||
return createSelector(
|
return createSelector(
|
||||||
api.selectors.getFtlType,
|
api.selectors.getFtlType,
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
{#if ship}
|
||||||
<ShipEdit {...ship} />
|
<ShipEdit {...ship} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte";
|
import { getContext } from "svelte";
|
||||||
@ -7,7 +9,7 @@
|
|||||||
|
|
||||||
export let api = getContext("api");
|
export let api = getContext("api");
|
||||||
|
|
||||||
let ship = {};
|
let ship = api?.getState() ?? {};
|
||||||
api?.subscribe(() => {
|
api?.subscribe(() => {
|
||||||
ship = api.getState();
|
ship = api.getState();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user