FTL dux
This commit is contained in:
parent
7ee496c7af
commit
fee93ed649
@ -2,7 +2,7 @@
|
|||||||
<Field label="FTL drive">
|
<Field label="FTL drive">
|
||||||
{#each types as t (t)}
|
{#each types as t (t)}
|
||||||
<label
|
<label
|
||||||
><input type="radio" bind:group={type} value={t} on:change={change} />
|
><input type="radio" bind:group={type} value={t} />
|
||||||
{t}
|
{t}
|
||||||
</label>
|
</label>
|
||||||
{/each}
|
{/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">
|
<Section label="propulsion">
|
||||||
<Drive { ...propulsion.drive } />
|
<Drive { ...propulsion.drive } />
|
||||||
|
<Ftl { ...propulsion.ftl } />
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Section from "$lib/components/Section/index.svelte";
|
import Section from "$lib/components/Section/index.svelte";
|
||||||
import Drive from './Drive/index.svelte';
|
import Drive from './Drive/index.svelte';
|
||||||
|
import Ftl from './Ftl.svelte';
|
||||||
|
|
||||||
export let propulsion = {};
|
export let propulsion = {};
|
||||||
$: console.log(propulsion)
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -4,6 +4,7 @@ import u from 'updeep';
|
|||||||
import propulsion from "./propulsion/index.js";
|
import propulsion from "./propulsion/index.js";
|
||||||
import identification from "./identification.js";
|
import identification from "./identification.js";
|
||||||
import { calculateDriveReqs } from './propulsion/drive.js';
|
import { calculateDriveReqs } from './propulsion/drive.js';
|
||||||
|
import { ftlReqsReaction } from './propulsion/ftl.js';
|
||||||
|
|
||||||
const dux = new Updux({
|
const dux = new Updux({
|
||||||
subduxes: {
|
subduxes: {
|
||||||
@ -21,5 +22,6 @@ const dux = new Updux({
|
|||||||
dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) );
|
dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) );
|
||||||
|
|
||||||
dux.addReaction( calculateDriveReqs );
|
dux.addReaction( calculateDriveReqs );
|
||||||
|
dux.addReaction( ftlReqsReaction );
|
||||||
|
|
||||||
export default dux;
|
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 u from 'updeep';
|
||||||
|
|
||||||
import drive from './drive.js';
|
import drive from './drive.js';
|
||||||
|
import ftl from './ftl.js';
|
||||||
|
|
||||||
const dux = new Updux({
|
const dux = new Updux({
|
||||||
subduxes: {
|
subduxes: {
|
||||||
drive
|
drive, ftl
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user