Merge branch 'hull-integrity' into version-2
This commit is contained in:
commit
7c17b90d70
27
src/lib/components/ShipEdit/Structure/Hull.svelte
Normal file
27
src/lib/components/ShipEdit/Structure/Hull.svelte
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<ShipItem {...reqs}>
|
||||||
|
<Field label="hull">
|
||||||
|
<input bind:value={rating} type="number" {min} {max} />
|
||||||
|
</Field>
|
||||||
|
</ShipItem>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getContext } from "svelte";
|
||||||
|
|
||||||
|
import ShipItem from '$lib/components/ShipItem/index.svelte';
|
||||||
|
import Field from '$lib/components/Field/index.svelte';
|
||||||
|
|
||||||
|
export let rating = 0;
|
||||||
|
export let reqs = {};
|
||||||
|
export let min = 0;
|
||||||
|
export let max = 1;
|
||||||
|
|
||||||
|
const ship = getContext('ship');
|
||||||
|
|
||||||
|
$: ship.dispatch.setHull(rating);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
input {
|
||||||
|
width: 5em;
|
||||||
|
}
|
||||||
|
</style>
|
16
src/lib/components/ShipEdit/Structure/index.svelte
Normal file
16
src/lib/components/ShipEdit/Structure/index.svelte
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<Section label="structure">
|
||||||
|
<Hull {...hull}/>
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Section from "$lib/components/Section/index.svelte";
|
||||||
|
import Hull from './Hull.svelte';
|
||||||
|
|
||||||
|
export let hull = {};
|
||||||
|
|
||||||
|
$: console.log(hull);
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
</style>
|
@ -6,12 +6,15 @@
|
|||||||
|
|
||||||
<Propulsion propulsion={$shipState.propulsion}/>
|
<Propulsion propulsion={$shipState.propulsion}/>
|
||||||
|
|
||||||
|
<Structure {...$shipState.structure} />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte";
|
import { getContext } from "svelte";
|
||||||
|
|
||||||
import Identification from "./Identification/index.svelte";
|
import Identification from "./Identification/index.svelte";
|
||||||
import ShipCost from "./ShipCost.svelte";
|
import ShipCost from "./ShipCost.svelte";
|
||||||
import Propulsion from "./Propulsion/index.svelte";
|
import Propulsion from "./Propulsion/index.svelte";
|
||||||
|
import Structure from "./Structure/index.svelte";
|
||||||
|
|
||||||
const { state: shipState } = getContext("ship");
|
const { state: shipState } = getContext("ship");
|
||||||
</script>
|
</script>
|
||||||
|
@ -5,17 +5,18 @@ 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';
|
import { ftlReqsReaction } from './propulsion/ftl.js';
|
||||||
|
import structure from './structure/index.js';
|
||||||
|
|
||||||
const dux = new Updux({
|
const dux = new Updux({
|
||||||
subduxes: {
|
subduxes: {
|
||||||
identification,
|
identification,
|
||||||
propulsion
|
propulsion,
|
||||||
|
structure
|
||||||
},
|
},
|
||||||
initial: {
|
initial: {
|
||||||
reqs: { cost: 0, mass: 10, usedMass: 0 },
|
reqs: { cost: 0, mass: 10, usedMass: 0 },
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setShipMass: null,
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
31
src/lib/shipDux/structure/hull.js
Normal file
31
src/lib/shipDux/structure/hull.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { Updux } from "updux";
|
||||||
|
import u from 'updeep';
|
||||||
|
|
||||||
|
import reqs from '../reqs.js';
|
||||||
|
|
||||||
|
const dux = new Updux({
|
||||||
|
subduxes: {
|
||||||
|
reqs
|
||||||
|
},
|
||||||
|
initial: {
|
||||||
|
rating: 0, min: 0, max: 0,
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
setShipMass: null,
|
||||||
|
setHull: null,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
export default dux;
|
||||||
|
|
||||||
|
dux.setMutation( 'setHull', rating => u({rating,
|
||||||
|
reqs: {
|
||||||
|
mass: rating, cost: 2 * rating
|
||||||
|
}}) );
|
||||||
|
|
||||||
|
dux.setMutation( 'setShipMass', mass => state => {
|
||||||
|
let {rating} = state;
|
||||||
|
if(rating > mass) rating = mass;
|
||||||
|
const min = Math.ceil(mass/10);
|
||||||
|
if(rating < min) rating = min;
|
||||||
|
return u({max: mass, min, rating}, state);
|
||||||
|
})
|
8
src/lib/shipDux/structure/index.js
Normal file
8
src/lib/shipDux/structure/index.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Updux } from 'updux';
|
||||||
|
|
||||||
|
import hull from './hull.js';
|
||||||
|
|
||||||
|
const dux = new Updux({
|
||||||
|
subduxes: { hull }
|
||||||
|
});
|
||||||
|
export default dux;
|
Loading…
Reference in New Issue
Block a user