FTL dux
This commit is contained in:
parent
7ee496c7af
commit
fee93ed649
@ -2,7 +2,7 @@
|
||||
<Field label="FTL drive">
|
||||
{#each types as t (t)}
|
||||
<label
|
||||
><input type="radio" bind:group={type} value={t} on:change={change} />
|
||||
><input type="radio" bind:group={type} value={t} />
|
||||
{t}
|
||||
</label>
|
||||
{/each}
|
||||
|
32
src/lib/components/ShipEdit/Propulsion/Ftl.svelte
Normal file
32
src/lib/components/ShipEdit/Propulsion/Ftl.svelte
Normal file
@ -0,0 +1,32 @@
|
||||
<ShipItem {...reqs}>
|
||||
<Field label="FTL drive">
|
||||
{#each types as t (t)}
|
||||
<label
|
||||
><input type="radio" bind:group={type} value={t} />
|
||||
{t}
|
||||
</label>
|
||||
{/each}
|
||||
</Field>
|
||||
</ShipItem>
|
||||
|
||||
<script>
|
||||
import { getContext } from "svelte";
|
||||
import Field from "$lib/components/Field/index.svelte";
|
||||
import ShipItem from "$lib/components/ShipItem/index.svelte";
|
||||
|
||||
const types = ["none", "standard", "advanced"];
|
||||
|
||||
export let reqs = {};
|
||||
export let type = types[0];
|
||||
|
||||
const ship = getContext("ship");
|
||||
|
||||
$: ship.dispatch.setFtl(type);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
label {
|
||||
display: inline;
|
||||
margin-right: 1em;
|
||||
}
|
||||
</style>
|
@ -1,11 +1,12 @@
|
||||
<Section label="propulsion">
|
||||
<Drive { ...propulsion.drive } />
|
||||
<Ftl { ...propulsion.ftl } />
|
||||
</Section>
|
||||
|
||||
<script>
|
||||
import Section from "$lib/components/Section/index.svelte";
|
||||
import Drive from './Drive/index.svelte';
|
||||
import Ftl from './Ftl.svelte';
|
||||
|
||||
export let propulsion = {};
|
||||
$: console.log(propulsion)
|
||||
</script>
|
||||
|
@ -4,6 +4,7 @@ import u from 'updeep';
|
||||
import propulsion from "./propulsion/index.js";
|
||||
import identification from "./identification.js";
|
||||
import { calculateDriveReqs } from './propulsion/drive.js';
|
||||
import { ftlReqsReaction } from './propulsion/ftl.js';
|
||||
|
||||
const dux = new Updux({
|
||||
subduxes: {
|
||||
@ -21,5 +22,6 @@ const dux = new Updux({
|
||||
dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) );
|
||||
|
||||
dux.addReaction( calculateDriveReqs );
|
||||
dux.addReaction( ftlReqsReaction );
|
||||
|
||||
export default dux;
|
||||
|
44
src/lib/shipDux/propulsion/ftl.js
Normal file
44
src/lib/shipDux/propulsion/ftl.js
Normal file
@ -0,0 +1,44 @@
|
||||
import { Updux } from "updux";
|
||||
import u from "updeep";
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
import reqs from "../reqs.js";
|
||||
|
||||
export const ftlTypes = ["none", "standard", "advanced"];
|
||||
|
||||
const dux = new Updux({
|
||||
subduxes: { reqs },
|
||||
initial: {
|
||||
type: "none",
|
||||
},
|
||||
actions: {
|
||||
setFtl: null,
|
||||
setFtlReqs: null,
|
||||
},
|
||||
});
|
||||
export default dux;
|
||||
|
||||
dux.setMutation( 'setFtl', type => u({type}) );
|
||||
dux.setMutation( 'setFtlReqs', reqs => u({reqs}) );
|
||||
|
||||
export function calcFtlReqs(type,shipMass) {
|
||||
if(type==="none") return { cost: 0, mass: 0 };
|
||||
|
||||
const mass = Math.ceil(shipMass / 10);
|
||||
|
||||
return {
|
||||
mass,
|
||||
cost: mass * ( type === 'advanced' ? 3 : 2 ),
|
||||
}
|
||||
}
|
||||
|
||||
// needs to be at the top level
|
||||
export const ftlReqsReaction = store =>
|
||||
createSelector(
|
||||
[
|
||||
(ship) => ship.propulsion.ftl.type,
|
||||
(ship) => ship.reqs.mass,
|
||||
],
|
||||
(type,shipMass) =>
|
||||
store.dispatch.setFtlReqs(calcFtlReqs(type,shipMass))
|
||||
);
|
@ -2,10 +2,11 @@ import { Updux } from "updux";
|
||||
import u from 'updeep';
|
||||
|
||||
import drive from './drive.js';
|
||||
import ftl from './ftl.js';
|
||||
|
||||
const dux = new Updux({
|
||||
subduxes: {
|
||||
drive
|
||||
drive, ftl
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user