Drive UI
This commit is contained in:
parent
c08b70dc9f
commit
31d48d0926
@ -1,6 +1,6 @@
|
|||||||
<Meta
|
<Meta
|
||||||
title="Engine"
|
title="ShipEdit/Propulsion/Drive"
|
||||||
component={Engine}
|
component={Drive}
|
||||||
argTypes={{
|
argTypes={{
|
||||||
rating: { type: "number", defaultValue: 6 },
|
rating: { type: "number", defaultValue: 6 },
|
||||||
advanced: { type: "boolean", defaultValue: false },
|
advanced: { type: "boolean", defaultValue: false },
|
||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<Template let:args>
|
<Template let:args>
|
||||||
<div style="width: 50em">
|
<div style="width: 50em">
|
||||||
<Engine {...args} />
|
<Drive {...args} />
|
||||||
</div>
|
</div>
|
||||||
</Template>
|
</Template>
|
||||||
|
|
||||||
@ -22,10 +22,12 @@
|
|||||||
|
|
||||||
import { setContext } from "svelte";
|
import { setContext } from "svelte";
|
||||||
|
|
||||||
import Engine from "./index.svelte";
|
import Drive from "./index.svelte";
|
||||||
|
|
||||||
setContext("ship", {
|
setContext("ship", {
|
||||||
dispatch: (type, detail) => action(type)(detail),
|
dispatch: {
|
||||||
|
setDrive: action('setDrive')
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let advanced = false;
|
let advanced = false;
|
@ -17,11 +17,10 @@
|
|||||||
export let advanced = false;
|
export let advanced = false;
|
||||||
export let rating = 0;
|
export let rating = 0;
|
||||||
|
|
||||||
const ship = getContext("ship") || {
|
const ship = getContext("ship");
|
||||||
dispatch: (...args) => console.log(args),
|
|
||||||
};
|
|
||||||
|
|
||||||
$: ship.dispatch("setEngine", { rating, advanced });
|
console.log( ship.dispatch )
|
||||||
|
$: ship.dispatch.setDrive({ rating, advanced });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
11
src/lib/components/ShipEdit/Propulsion/index.svelte
Normal file
11
src/lib/components/ShipEdit/Propulsion/index.svelte
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<Section label="propulsion">
|
||||||
|
<Drive { ...propulsion.drive } />
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Section from "$lib/components/Section/index.svelte";
|
||||||
|
import Drive from './Drive/index.svelte';
|
||||||
|
|
||||||
|
export let propulsion = {};
|
||||||
|
$: console.log(propulsion)
|
||||||
|
</script>
|
@ -4,11 +4,14 @@
|
|||||||
<ShipCost {...$shipState.reqs} />
|
<ShipCost {...$shipState.reqs} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Propulsion propulsion={$shipState.propulsion}/>
|
||||||
|
|
||||||
<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";
|
||||||
|
|
||||||
const { state: shipState } = getContext("ship");
|
const { state: shipState } = getContext("ship");
|
||||||
</script>
|
</script>
|
||||||
|
@ -10,13 +10,13 @@ const dux = new Updux({
|
|||||||
advanced: false,
|
advanced: false,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setEngine: null,
|
setDrive: null,
|
||||||
setEngineReqs: null,
|
setDriveReqs: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
dux.setMutation("setEngine", (changes) => u(changes));
|
dux.setMutation("setDrive", (changes) => u(changes));
|
||||||
dux.setMutation("setEngineReqs", (reqs) => u({ reqs }));
|
dux.setMutation("setDriveReqs", (reqs) => u({ reqs }));
|
||||||
|
|
||||||
export function calcDriveReqs(shipMass, rating, advanced = false) {
|
export function calcDriveReqs(shipMass, rating, advanced = false) {
|
||||||
const mass = Math.ceil(rating * 0.05 * shipMass);
|
const mass = Math.ceil(rating * 0.05 * shipMass);
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import { Updux } from "updux";
|
import { Updux } from "updux";
|
||||||
import u from 'updeep';
|
import u from 'updeep';
|
||||||
|
|
||||||
import engine from "./engine.js";
|
import propulsion from "./propulsion/index.js";
|
||||||
import identification from "./identification.js";
|
import identification from "./identification.js";
|
||||||
import reqs from "./reqs.js";
|
|
||||||
|
|
||||||
const dux = new Updux({
|
const dux = new Updux({
|
||||||
subduxes: {
|
subduxes: {
|
||||||
identification,
|
identification,
|
||||||
engine,
|
propulsion
|
||||||
},
|
},
|
||||||
initial: {
|
initial: {
|
||||||
reqs: { cost: 0, mass: 10, usedMass: 0 },
|
reqs: { cost: 0, mass: 10, usedMass: 0 },
|
||||||
|
28
src/lib/shipDux/propulsion/drive.js
Normal file
28
src/lib/shipDux/propulsion/drive.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { Updux } from "updux";
|
||||||
|
import u from "updeep";
|
||||||
|
|
||||||
|
import reqs from "../reqs.js";
|
||||||
|
|
||||||
|
const dux = new Updux({
|
||||||
|
subduxes: { reqs },
|
||||||
|
initial: {
|
||||||
|
rating: 1,
|
||||||
|
advanced: false,
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
setDrive: null,
|
||||||
|
setDriveReqs: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
dux.setMutation("setDrive", (changes) => u(changes));
|
||||||
|
dux.setMutation("setDriveReqs", (reqs) => u({ reqs }));
|
||||||
|
|
||||||
|
export function calcDriveReqs(shipMass, rating, advanced = false) {
|
||||||
|
const mass = Math.ceil(rating * 0.05 * shipMass);
|
||||||
|
const cost = mass * (advanced ? 3 : 2);
|
||||||
|
|
||||||
|
return { mass, cost };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default dux;
|
12
src/lib/shipDux/propulsion/index.js
Normal file
12
src/lib/shipDux/propulsion/index.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Updux } from "updux";
|
||||||
|
import u from 'updeep';
|
||||||
|
|
||||||
|
import drive from './drive.js';
|
||||||
|
|
||||||
|
const dux = new Updux({
|
||||||
|
subduxes: {
|
||||||
|
drive
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default dux;
|
Loading…
Reference in New Issue
Block a user