This commit is contained in:
Yanick Champoux 2022-03-03 11:06:51 -05:00
parent 7ee496c7af
commit fee93ed649
6 changed files with 83 additions and 3 deletions

View File

@ -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}

View 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>

View File

@ -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>

View File

@ -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;

View 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))
);

View File

@ -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
},
});