From 9596ae99226193bb580c39d4d91ea5fb45e76d94 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 4 Mar 2022 16:17:57 -0500 Subject: [PATCH 01/15] cargo --- .../ShipEdit/Structure/Cargo.svelte | 25 +++++++++++++++++++ .../ShipEdit/Structure/index.svelte | 3 +++ src/lib/shipDux/structure/cargo.js | 24 ++++++++++++++++++ src/lib/shipDux/structure/index.js | 3 ++- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/lib/components/ShipEdit/Structure/Cargo.svelte create mode 100644 src/lib/shipDux/structure/cargo.js diff --git a/src/lib/components/ShipEdit/Structure/Cargo.svelte b/src/lib/components/ShipEdit/Structure/Cargo.svelte new file mode 100644 index 0000000..6bb00eb --- /dev/null +++ b/src/lib/components/ShipEdit/Structure/Cargo.svelte @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/src/lib/components/ShipEdit/Structure/index.svelte b/src/lib/components/ShipEdit/Structure/index.svelte index 0bfd6bf..8276ea1 100644 --- a/src/lib/components/ShipEdit/Structure/index.svelte +++ b/src/lib/components/ShipEdit/Structure/index.svelte @@ -1,15 +1,18 @@
+
diff --git a/src/lib/shipDux/structure/cargo.js b/src/lib/shipDux/structure/cargo.js new file mode 100644 index 0000000..204d94b --- /dev/null +++ b/src/lib/shipDux/structure/cargo.js @@ -0,0 +1,24 @@ +import { Updux } from "updux"; +import u from 'updeep'; +import { createSelector } from 'reselect'; + +import reqs from '../reqs.js'; + +const dux = new Updux({ + subduxes: { + reqs + }, + initial: { + space: 0, + }, + actions: { + setCargo: null, + } +}); +export default dux; + +dux.setMutation('setCargo', space => u({ + space, + reqs: { mass: space } +})); + diff --git a/src/lib/shipDux/structure/index.js b/src/lib/shipDux/structure/index.js index a2f8b4d..cffeeae 100644 --- a/src/lib/shipDux/structure/index.js +++ b/src/lib/shipDux/structure/index.js @@ -2,8 +2,9 @@ import { Updux } from 'updux'; import hull from './hull.js'; import screens from './screens.js'; +import cargo from './cargo.js'; const dux = new Updux({ - subduxes: { hull, screens } + subduxes: { hull, screens, cargo } }); export default dux; From 15495ee84387c0382ddc6aabd8ac96877dea6781 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 4 Mar 2022 16:31:05 -0500 Subject: [PATCH 02/15] streamlining --- src/dux/index.js | 16 -------- .../ShipEdit/Structure/Streamlining.svelte | 41 +++++++++++++++++++ .../ShipEdit/Structure/index.svelte | 3 ++ src/lib/shipDux/structure/index.js | 4 +- src/lib/shipDux/structure/streamlining.js | 33 +++++++++++++++ src/lib/store/ship.js | 3 +- 6 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 src/lib/components/ShipEdit/Structure/Streamlining.svelte create mode 100644 src/lib/shipDux/structure/streamlining.js diff --git a/src/dux/index.js b/src/dux/index.js index 9d83cb5..86acdde 100644 --- a/src/dux/index.js +++ b/src/dux/index.js @@ -66,22 +66,6 @@ dux.addSubscription((store) => createSelector(calc_ship_req, (reqs) => store.dispatch(set_ship_reqs(reqs))) ); -dux.addSubscription((store) => - createSelector( - (store) => store.general.mass, - (store) => store.streamlining.type, - (ship_mass, streamlining) => { - const mass = ceil( - (ship_mass * - (streamlining === "none" ? 0 : streamlining === "partial" ? 5 : 10)) / - 100 - ); - const cost = 2 * mass; - - store.dispatch(dux.actions.set_streamlining_cost_mass({ cost, mass })); - } - ) -); dux.addSubscription((store) => createSelector( diff --git a/src/lib/components/ShipEdit/Structure/Streamlining.svelte b/src/lib/components/ShipEdit/Structure/Streamlining.svelte new file mode 100644 index 0000000..f610be3 --- /dev/null +++ b/src/lib/components/ShipEdit/Structure/Streamlining.svelte @@ -0,0 +1,41 @@ + + +
+ + + +
+
+
+ + + + diff --git a/src/lib/components/ShipEdit/Structure/index.svelte b/src/lib/components/ShipEdit/Structure/index.svelte index 8276ea1..b627975 100644 --- a/src/lib/components/ShipEdit/Structure/index.svelte +++ b/src/lib/components/ShipEdit/Structure/index.svelte @@ -2,6 +2,7 @@ + diff --git a/src/lib/shipDux/structure/index.js b/src/lib/shipDux/structure/index.js index cffeeae..4311ec4 100644 --- a/src/lib/shipDux/structure/index.js +++ b/src/lib/shipDux/structure/index.js @@ -3,8 +3,10 @@ import { Updux } from 'updux'; import hull from './hull.js'; import screens from './screens.js'; import cargo from './cargo.js'; +import streamlining from './streamlining.js'; const dux = new Updux({ - subduxes: { hull, screens, cargo } + subduxes: { hull, screens, cargo, streamlining } }); export default dux; + diff --git a/src/lib/shipDux/structure/streamlining.js b/src/lib/shipDux/structure/streamlining.js new file mode 100644 index 0000000..f05f09f --- /dev/null +++ b/src/lib/shipDux/structure/streamlining.js @@ -0,0 +1,33 @@ +import { Updux } from "updux"; +import u from "updeep"; + +import reqs from "../reqs.js"; +import { calculateDriveReqs } from "../propulsion/drive.js"; + +const dux = new Updux({ + subduxes: { + reqs, + }, + initial: { + type: "none", + }, + actions: { + setStreamlining: null, + }, +}); +export default dux; + +dux.setMutation("setStreamlining", ({ shipMass, type }) => + u({ + type, + reqs: calcStreamliningReqs({ shipMass, type }), + }) +); + +function calcStreamliningReqs({ shipMass, type }) { + const mass = Math.ceil( + (shipMass * (type === "none" ? 0 : type === "partial" ? 5 : 10)) / 100 + ); + + return { mass, cost: 2 * mass }; +} diff --git a/src/lib/store/ship.js b/src/lib/store/ship.js index dcfbe80..7f459d2 100644 --- a/src/lib/store/ship.js +++ b/src/lib/store/ship.js @@ -1,5 +1,5 @@ import { browser } from "$app/env"; -import { readable, get } from "svelte/store"; +import { readable, get, derived } from "svelte/store"; import { compose, applyMiddleware } from "redux"; import shipDux from "../shipDux/index.js"; @@ -28,5 +28,6 @@ export default () => { return { dispatch: duxStore.dispatch, state, + shipMass: derived( state, state => state.reqs.mass ) }; }; From 9afbd45419229faaa0f62f82830dc2bb5fe42ec5 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 4 Mar 2022 19:10:51 -0500 Subject: [PATCH 03/15] armor --- .../ShipEdit/Structure/Armor.svelte | 41 +++++++++++++++ .../ShipEdit/Structure/Armor/Layer.svelte | 22 ++++++++ .../ShipEdit/Structure/index.svelte | 3 ++ src/lib/shipDux/structure/armor.js | 50 +++++++++++++++++++ src/lib/shipDux/structure/index.js | 3 +- src/lib/shipDux/structure/streamlining.js | 1 - 6 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/lib/components/ShipEdit/Structure/Armor.svelte create mode 100644 src/lib/components/ShipEdit/Structure/Armor/Layer.svelte create mode 100644 src/lib/shipDux/structure/armor.js diff --git a/src/lib/components/ShipEdit/Structure/Armor.svelte b/src/lib/components/ShipEdit/Structure/Armor.svelte new file mode 100644 index 0000000..de581f2 --- /dev/null +++ b/src/lib/components/ShipEdit/Structure/Armor.svelte @@ -0,0 +1,41 @@ + +
+
+ + + +
+ +
+ {#each layers as rating,i (i)} + + {/each} +
+
+
+ + + + diff --git a/src/lib/components/ShipEdit/Structure/Armor/Layer.svelte b/src/lib/components/ShipEdit/Structure/Armor/Layer.svelte new file mode 100644 index 0000000..b6dab9e --- /dev/null +++ b/src/lib/components/ShipEdit/Structure/Armor/Layer.svelte @@ -0,0 +1,22 @@ + + + + + + + diff --git a/src/lib/components/ShipEdit/Structure/index.svelte b/src/lib/components/ShipEdit/Structure/index.svelte index b627975..f6c583e 100644 --- a/src/lib/components/ShipEdit/Structure/index.svelte +++ b/src/lib/components/ShipEdit/Structure/index.svelte @@ -1,6 +1,7 @@
+
@@ -10,12 +11,14 @@ import Hull from './Hull.svelte'; import Screens from './Screens.svelte'; import Cargo from './Cargo.svelte'; + import Armor from './Armor.svelte'; import Streamlining from './Streamlining.svelte'; export let hull = {}; export let screens = {}; export let cargo = {}; export let streamlining = {}; + export let armor = {}; diff --git a/src/lib/shipDux/structure/armor.js b/src/lib/shipDux/structure/armor.js new file mode 100644 index 0000000..9b43574 --- /dev/null +++ b/src/lib/shipDux/structure/armor.js @@ -0,0 +1,50 @@ +import { Updux } from "updux"; +import u from "updeep"; + +import reqs from "../reqs.js"; + +const dux = new Updux({ + subduxes: { + reqs, + }, + initial: { + layers: [], + }, + actions: { + setArmorLayers: null, + setArmorRating: null, + }, +}); +export default dux; + +dux.setMutation('setArmorRating', ({layer, rating}) => state => { + let layers = [ ...state.layers ].map( (v,k) => k === layer-1 ? rating : v ); + + return { layers, reqs: calcArmorReqs(layers) } +} ); + +dux.setMutation( 'setArmorLayers', nbrLayers => state => { + + let layers = [...state.layers]; + + if( nbrLayers < state.layers.length ) + layers = [ ...state.layers ].slice(0,nbrLayers); + + while( layers.length < nbrLayers ) { + layers.push(0); + } + + return { + layers, + reqs: calcArmorReqs(layers), + } +}); + +function calcArmorReqs(layers) { + const mass = 2* layers.reduce( (a,b) => a+ b,0 ); + const cost = 2* layers.map( (v,k) => v * (k+1) ).reduce( (a,b) => a+ b,0 ); + + return { + mass, cost + } +} diff --git a/src/lib/shipDux/structure/index.js b/src/lib/shipDux/structure/index.js index 4311ec4..c5fe3cb 100644 --- a/src/lib/shipDux/structure/index.js +++ b/src/lib/shipDux/structure/index.js @@ -3,10 +3,11 @@ import { Updux } from 'updux'; import hull from './hull.js'; import screens from './screens.js'; import cargo from './cargo.js'; +import armor from './armor.js'; import streamlining from './streamlining.js'; const dux = new Updux({ - subduxes: { hull, screens, cargo, streamlining } + subduxes: { hull, screens, cargo, streamlining, armor } }); export default dux; diff --git a/src/lib/shipDux/structure/streamlining.js b/src/lib/shipDux/structure/streamlining.js index f05f09f..aca39e6 100644 --- a/src/lib/shipDux/structure/streamlining.js +++ b/src/lib/shipDux/structure/streamlining.js @@ -2,7 +2,6 @@ import { Updux } from "updux"; import u from "updeep"; import reqs from "../reqs.js"; -import { calculateDriveReqs } from "../propulsion/drive.js"; const dux = new Updux({ subduxes: { From c8454ed792a444afe97619258dd338378c5673ad Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sat, 5 Mar 2022 13:41:30 -0500 Subject: [PATCH 04/15] carrier --- .../ShipEdit/Carrier/Carrier.stories.svelte | 33 ++++++++ .../Carrier/Squadron.svelte} | 22 +++--- .../components/ShipEdit/Carrier/index.svelte | 35 +++++++++ .../Identification.stories.svelte | 2 +- src/lib/shipDux/carrier.js | 76 +++++++++++++++++++ src/lib/store/ship.js | 1 - 6 files changed, 154 insertions(+), 15 deletions(-) create mode 100644 src/lib/components/ShipEdit/Carrier/Carrier.stories.svelte rename src/lib/components/{Carrier/Squadron/index.svelte => ShipEdit/Carrier/Squadron.svelte} (52%) create mode 100644 src/lib/components/ShipEdit/Carrier/index.svelte create mode 100644 src/lib/shipDux/carrier.js diff --git a/src/lib/components/ShipEdit/Carrier/Carrier.stories.svelte b/src/lib/components/ShipEdit/Carrier/Carrier.stories.svelte new file mode 100644 index 0000000..b17359f --- /dev/null +++ b/src/lib/components/ShipEdit/Carrier/Carrier.stories.svelte @@ -0,0 +1,33 @@ + + + + + + + diff --git a/src/lib/components/Carrier/Squadron/index.svelte b/src/lib/components/ShipEdit/Carrier/Squadron.svelte similarity index 52% rename from src/lib/components/Carrier/Squadron/index.svelte rename to src/lib/components/ShipEdit/Carrier/Squadron.svelte index 7eb17ac..6f46f46 100644 --- a/src/lib/components/Carrier/Squadron/index.svelte +++ b/src/lib/components/ShipEdit/Carrier/Squadron.svelte @@ -1,4 +1,4 @@ - + + + + + {#each squadrons as squadron,id (id)} + + {/each} + + + + + diff --git a/src/lib/components/ShipEdit/Identification/Identification.stories.svelte b/src/lib/components/ShipEdit/Identification/Identification.stories.svelte index 67ecb68..a3d01ab 100644 --- a/src/lib/components/ShipEdit/Identification/Identification.stories.svelte +++ b/src/lib/components/ShipEdit/Identification/Identification.stories.svelte @@ -1,4 +1,4 @@ - + diff --git a/src/lib/shipDux/carrier.js b/src/lib/shipDux/carrier.js new file mode 100644 index 0000000..6d8d145 --- /dev/null +++ b/src/lib/shipDux/carrier.js @@ -0,0 +1,76 @@ +import { Updux } from "updux"; +import u from "updeep"; +import _ from 'lodash'; + +import reqs from "./reqs.js"; + +const dux = new Updux({ + subduxes: { reqs }, + initial: { + bays: 0, + squadrons: [], + }, + actions: { + setCarrierBays: null, + setSquadronType: null, + } +}); + +dux.setMutation( 'setCarrierBays', bays => u({bays, reqs: + calcBaysReqs(bays), + squadrons: adjustSquadrons(bays), +}) ); + +dux.setMutation('setSquadronType', ({type, id}) => state => { + + return u.updateIn(['squadrons', id-1], { + type, + reqs: squadronReqs(type) + }, state ) + +} ); + +export const squadronTypes= [ + { type: "standard", cost: 3 }, + { type: "fast", cost: 4 }, + { type: "heavy", cost: 5 }, + { type: "interceptor", cost: 3 }, + { type: "attack", cost: 4 }, + { type: "long range", cost: 4 }, + { type: "torpedo", cost: 6 }, +]; + +function squadronReqs(type) { + return { mass: 6, cost: 6 * squadronTypes.find( s => s.type === type )?.cost } +} + + +const adjustSquadrons = bays => squadrons => { + if( squadrons.length > bays ) { + squadrons = squadrons.slice(0,bays); + } + + if( squadrons.length < bays ) { + squadrons = [ ...squadrons, ..._.times( + bays - squadrons.length, () => ({ + type: squadronTypes[0].type, + reqs: { + cost: 6 * squadronTypes[0].cost, + mass: 6, + }, + }) + )]; + } + + return squadrons; + +} + +function calcBaysReqs(bays) { + return { + mass: 9 * bays, + cost: 18 * bays, + } +} + +export default dux; diff --git a/src/lib/store/ship.js b/src/lib/store/ship.js index 7f459d2..2e507f1 100644 --- a/src/lib/store/ship.js +++ b/src/lib/store/ship.js @@ -20,7 +20,6 @@ export default () => { duxStore.subscribe(() => { if (previous === duxStore.getState()) return; previous = duxStore.getState(); - console.log("Setting!", previous); set(previous); }); }); From f207fa3d3c29a0b1765c6d0e5775049f8a2da8bc Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 6 Mar 2022 14:10:44 -0500 Subject: [PATCH 05/15] carrier --- src/lib/components/ShipEdit/Identification/shipTypes.js | 4 ++-- src/lib/components/ShipEdit/index.svelte | 3 +++ src/lib/shipDux/identification.js | 6 ++++++ src/lib/shipDux/index.js | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib/components/ShipEdit/Identification/shipTypes.js b/src/lib/components/ShipEdit/Identification/shipTypes.js index be32552..19ad819 100644 --- a/src/lib/components/ShipEdit/Identification/shipTypes.js +++ b/src/lib/components/ShipEdit/Identification/shipTypes.js @@ -1,5 +1,5 @@ const ship_types = [ - { name: "Scout", mass: [4, 10], abbrev: "SC" }, + { name: "Scout", mass: [0, 10], abbrev: "SC" }, { name: "Courier", mass: [4, 10], abbrev: "SC" }, { name: "Corvette", mass: [8, 16], abbrev: "CT" }, { name: "Frigate", mass: [14, 28], abbrev: "FF" }, @@ -14,7 +14,7 @@ const ship_types = [ { name: "Heavy Battleship", mass: [120, 160], abbrev: "BDN" }, { name: "Dreadnought", mass: [140, 180], abbrev: "DN" }, { name: "Superdreadnought", mass: [160, 300], abbrev: "SDN" }, - { name: "Escort Carrier", mass: [60, 140], abbrev: "CVE", carrier: true }, + { name: "Escort Carrier", mass: [0, 140], abbrev: "CVE", carrier: true }, { name: "Light Carrier", mass: [120, 180], abbrev: "CVL", carrier: true }, { name: "Heavy Carrier", mass: [160, 300], abbrev: "CVH", carrier: true }, { name: "Attack Carrier", mass: [150, 300], abbrev: "CVA", carrier: true }, diff --git a/src/lib/components/ShipEdit/index.svelte b/src/lib/components/ShipEdit/index.svelte index 89dec7a..ecfa2fd 100644 --- a/src/lib/components/ShipEdit/index.svelte +++ b/src/lib/components/ShipEdit/index.svelte @@ -8,6 +8,8 @@ + + diff --git a/src/lib/shipDux/identification.js b/src/lib/shipDux/identification.js index 50abc17..71e4085 100644 --- a/src/lib/shipDux/identification.js +++ b/src/lib/shipDux/identification.js @@ -1,10 +1,13 @@ import { Updux } from "updux"; import u from "updeep"; +import carrier from './carrier.js'; + const dux = new Updux({ actions: { setShipType: null, setShipClass: null, + setCarrierBays: carrier.actions.setCarrierBays, }, initial: { shipType: "", @@ -16,5 +19,8 @@ const dux = new Updux({ dux.setMutation("setShipType", (shipType) => u({ shipType })); dux.setMutation("setShipClass", (shipClass) => u({ shipClass })); +dux.setMutation('setCarrierBays', (bays) => u({ + isCarrier: bays > 0, +})) export default dux; diff --git a/src/lib/shipDux/index.js b/src/lib/shipDux/index.js index 4b74aab..d2a8f25 100644 --- a/src/lib/shipDux/index.js +++ b/src/lib/shipDux/index.js @@ -6,13 +6,14 @@ import identification from "./identification.js"; import { calculateDriveReqs } from './propulsion/drive.js'; import { ftlReqsReaction } from './propulsion/ftl.js'; import structure from './structure/index.js'; +import carrier from './carrier.js'; import { screenReqsReaction, screensReqsReaction } from './structure/screens.js' const dux = new Updux({ subduxes: { identification, propulsion, - structure + structure, carrier }, initial: { reqs: { cost: 0, mass: 10, usedMass: 0 }, From 161175c3c942abbefe8b3600ccad948d59ba9d09 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 6 Mar 2022 14:29:40 -0500 Subject: [PATCH 06/15] firecons --- src/dux/index.js | 12 ------- .../ShipEdit/Weaponry/Firecons.svelte | 21 ++++++++++++ .../ShipEdit/Weaponry/Weaponry.stories.svelte | 33 +++++++++++++++++++ .../components/ShipEdit/Weaponry/index.svelte | 16 +++++++++ src/lib/shipDux/weaponry/index.js | 30 +++++++++++++++++ 5 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 src/lib/components/ShipEdit/Weaponry/Firecons.svelte create mode 100644 src/lib/components/ShipEdit/Weaponry/Weaponry.stories.svelte create mode 100644 src/lib/components/ShipEdit/Weaponry/index.svelte create mode 100644 src/lib/shipDux/weaponry/index.js diff --git a/src/dux/index.js b/src/dux/index.js index 86acdde..2c234ca 100644 --- a/src/dux/index.js +++ b/src/dux/index.js @@ -129,18 +129,6 @@ dux.addSubscription((store) => ) ); -const calc_firecons_reqs = (nbr) => ({ - cost: 4 * nbr, - mass: nbr, -}); - -const set_firecons = action("set_firecons", payload()); -dux.addMutation(set_firecons, (nbr) => - u.updateIn("weaponry.firecons", { - nbr, - ...calc_firecons_reqs(nbr), - }) -); export default dux.asDux; diff --git a/src/lib/components/ShipEdit/Weaponry/Firecons.svelte b/src/lib/components/ShipEdit/Weaponry/Firecons.svelte new file mode 100644 index 0000000..24ffc9c --- /dev/null +++ b/src/lib/components/ShipEdit/Weaponry/Firecons.svelte @@ -0,0 +1,21 @@ + + + + + + + + + diff --git a/src/lib/components/ShipEdit/Weaponry/Weaponry.stories.svelte b/src/lib/components/ShipEdit/Weaponry/Weaponry.stories.svelte new file mode 100644 index 0000000..35be883 --- /dev/null +++ b/src/lib/components/ShipEdit/Weaponry/Weaponry.stories.svelte @@ -0,0 +1,33 @@ + + + + + + + diff --git a/src/lib/components/ShipEdit/Weaponry/index.svelte b/src/lib/components/ShipEdit/Weaponry/index.svelte new file mode 100644 index 0000000..18bd2c5 --- /dev/null +++ b/src/lib/components/ShipEdit/Weaponry/index.svelte @@ -0,0 +1,16 @@ +
+ +
+ + + + diff --git a/src/lib/shipDux/weaponry/index.js b/src/lib/shipDux/weaponry/index.js new file mode 100644 index 0000000..7c97c15 --- /dev/null +++ b/src/lib/shipDux/weaponry/index.js @@ -0,0 +1,30 @@ +import { Updux } from "updux"; +import u from "updeep"; + +const reqs = { cost: 0, mass: 0 }; + +const dux = new Updux({ + initial: { + firecons: { + stations: 0, + reqs, + }, + }, + actions: { + setFirecons: null, + }, +}); + +dux.setMutation("setFirecons", (stations) => + u({ + firecons: { + stations, + reqs: { + cost: 4 * stations, + mass: stations, + }, + }, + }) +); + +export default dux; From 55a9a17dc1232f66747ea8731a8d87d0f18f1056 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 6 Mar 2022 14:49:20 -0500 Subject: [PATCH 07/15] adfc component --- src/dux/weaponry/adfc/index.js | 17 ----------------- .../components/ShipEdit/Weaponry/ADFC.svelte | 18 ++++++++++++++++++ .../components/ShipEdit/Weaponry/index.svelte | 9 ++++++++- src/lib/shipDux/weaponry/index.js | 13 +++++++++++++ 4 files changed, 39 insertions(+), 18 deletions(-) delete mode 100644 src/dux/weaponry/adfc/index.js create mode 100644 src/lib/components/ShipEdit/Weaponry/ADFC.svelte diff --git a/src/dux/weaponry/adfc/index.js b/src/dux/weaponry/adfc/index.js deleted file mode 100644 index 485557a..0000000 --- a/src/dux/weaponry/adfc/index.js +++ /dev/null @@ -1,17 +0,0 @@ -import Updux from "updux"; -import { action, payload } from "ts-action"; -import u from "@yanick/updeep"; - -const dux = new Updux({ - initial: { - rating: 0, - cost: 0, - mass: 0, - }, -}) - -dux.addMutation( action( 'set_adfc', payload() ), rating => - u.update({ rating, mass: 2 * rating, cost: 8 * rating }) -); - -export default dux.asDux; diff --git a/src/lib/components/ShipEdit/Weaponry/ADFC.svelte b/src/lib/components/ShipEdit/Weaponry/ADFC.svelte new file mode 100644 index 0000000..93da8e6 --- /dev/null +++ b/src/lib/components/ShipEdit/Weaponry/ADFC.svelte @@ -0,0 +1,18 @@ + + + + + + + diff --git a/src/lib/components/ShipEdit/Weaponry/index.svelte b/src/lib/components/ShipEdit/Weaponry/index.svelte index 18bd2c5..5167466 100644 --- a/src/lib/components/ShipEdit/Weaponry/index.svelte +++ b/src/lib/components/ShipEdit/Weaponry/index.svelte @@ -1,14 +1,21 @@
+ +
diff --git a/src/lib/shipDux/weaponry/index.js b/src/lib/shipDux/weaponry/index.js index 7c97c15..7dbf3f1 100644 --- a/src/lib/shipDux/weaponry/index.js +++ b/src/lib/shipDux/weaponry/index.js @@ -9,8 +9,10 @@ const dux = new Updux({ stations: 0, reqs, }, + adfc: { rating: 0, reqs }, }, actions: { + setADFC: null, setFirecons: null, }, }); @@ -26,5 +28,16 @@ dux.setMutation("setFirecons", (stations) => }, }) ); +dux.setMutation("setADFC", (rating) => + u({ + adfc: { + rating, + reqs: { + cost: 8 * rating, + mass: 2 * rating, + }, + }, + }) +); export default dux; From fd72aafec02e7a3a4d5b65956dea5d7508344300 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 6 Mar 2022 17:09:01 -0500 Subject: [PATCH 08/15] trying vite for storybook... again --- .storybook/main.js | 10 +++++++++- package.json | 3 +-- src/lib/shipDux/index.js | 4 ++-- src/lib/shipDux/structure/screens.js | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.storybook/main.js b/.storybook/main.js index 1a51bb1..9fa12a9 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -2,6 +2,7 @@ const path = require("path"); const preprocess = require("svelte-preprocess"); module.exports = { + // core: { builder: "storybook-builder-vite" }, staticDirs: ["../static", "../pictures"], stories: [ "../src/**/*.stories.mdx", @@ -9,13 +10,20 @@ module.exports = { "../src/**/stories.svelte", ], addons: [ - "@storybook/addon-links", "@storybook/addon-essentials", "@storybook/addon-svelte-csf", ], framework: "@storybook/svelte", svelteOptions: { preprocess: preprocess(), + }, + async viteFinal(config, { configType }) { + // customize the Vite config here + config.resolve.alias.$lib = path.resolve(__dirname, "../src/lib/"); + config.resolve.alias.$app = path.resolve(__dirname, "../fake/app/"); + + // return the customized config + return config; }, webpackFinal: async (config) => { return { diff --git a/package.json b/package.json index e40e34c..422941b 100644 --- a/package.json +++ b/package.json @@ -24,14 +24,13 @@ "eslint-plugin-svelte3": "^3.4.1", "prettier": "~2.5.1", "prettier-plugin-svelte": "^2.6.0", + "storybook-builder-vite": "0.1.17", "svelte": "^3.46.4", "vite": "^2.7.0" }, "type": "module", "dependencies": { - "@storybook/addon-actions": "^6.4.19", "@storybook/addon-essentials": "^6.4.19", - "@storybook/addon-links": "6.4.19", "@storybook/addon-svelte-csf": "^1.1.0", "@storybook/svelte": "^6.4.19", "@sveltejs/adapter-node": "^1.0.0-next.0", diff --git a/src/lib/shipDux/index.js b/src/lib/shipDux/index.js index d2a8f25..ede0f8c 100644 --- a/src/lib/shipDux/index.js +++ b/src/lib/shipDux/index.js @@ -7,7 +7,7 @@ import { calculateDriveReqs } from './propulsion/drive.js'; import { ftlReqsReaction } from './propulsion/ftl.js'; import structure from './structure/index.js'; import carrier from './carrier.js'; -import { screenReqsReaction, screensReqsReaction } from './structure/screens.js' +import { screensReqsReaction } from './structure/screens.js' const dux = new Updux({ subduxes: { @@ -26,6 +26,6 @@ dux.setMutation( 'setShipMass', mass => u({reqs: {mass}}) ); dux.addReaction( calculateDriveReqs ); dux.addReaction( ftlReqsReaction ); -dux.addReaction( screenReqsReaction ); +dux.addReaction( screensReqsReaction ); export default dux; diff --git a/src/lib/shipDux/structure/screens.js b/src/lib/shipDux/structure/screens.js index 49e3ed4..068e653 100644 --- a/src/lib/shipDux/structure/screens.js +++ b/src/lib/shipDux/structure/screens.js @@ -21,7 +21,7 @@ export default dux; dux.setMutation('setScreens', payload => u(payload)); dux.setMutation('setScreensReqs', reqs => u({reqs})); -export const screenReqsReaction = store => createSelector( +export const screensReqsReaction = store => createSelector( (ship) => ship.reqs.mass, (ship) => ship.structure.screens.standard, (ship) => ship.structure.screens.advanced, From b40efe242ea8405efad60c47363297f0155f5724 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 6 Mar 2022 17:36:50 -0500 Subject: [PATCH 09/15] new weapon --- src/dux/weapons/rules.js | 65 -------------- .../ShipEdit/Weaponry/AddWeapon.svelte | 22 +++++ .../components/ShipEdit/Weaponry/index.svelte | 5 ++ src/lib/shipDux/weaponry/index.js | 3 + src/lib/shipDux/weaponry/weapons.js | 84 +++++++++++++++++++ 5 files changed, 114 insertions(+), 65 deletions(-) create mode 100644 src/lib/components/ShipEdit/Weaponry/AddWeapon.svelte create mode 100644 src/lib/shipDux/weaponry/weapons.js diff --git a/src/dux/weapons/rules.js b/src/dux/weapons/rules.js index 77d5c4d..52d0633 100644 --- a/src/dux/weapons/rules.js +++ b/src/dux/weapons/rules.js @@ -1,30 +1,4 @@ -export function weapon_cost_mass(weapon){ - let cost = 0; - let mass = 0; - - if( weapon.weapon_type === 'beam' ) { - return beam_cost_mass(weapon); - } - - if( weapon.weapon_type == 'submunition' ) { - return { mass: 1, cost: 3 }; - } - - if( weapon.weapon_type === 'pds' ) { - return { mass: 1, cost: 3 }; - } - - if( weapon.weapon_type === 'scattergun' ) { - return { mass: 1, cost: 4 }; - } - - if( weapon.weapon_type === 'needle' ) { - return { mass: 2, cost: 6 }; - } - - return { cost, mass }; -} const is_broadside = arcs => { if( arcs.length !== 4 ) return false; @@ -33,42 +7,3 @@ const is_broadside = arcs => { return !arcs.some( a => a.length === 1 ); } -function beam_cost_mass({weapon_class, arcs}) { - let mass; - if( weapon_class === 1 ) { - mass = 1; - } - - if( weapon_class == 2 ) { - mass = 2 + (arcs.length > 3 ? 1 : 0); - } - - - if( weapon_class == 3 ) { - mass = 4; - - if( is_broadside(arcs) ) { - mass += 2; - } - else { - mass += arcs.length - 1; - } - } - - if( weapon_class == 4 ) { - mass = 8; - - if( is_broadside(arcs) ) { - mass += 4; - } - else { - mass += 2*(arcs.length - 1); - } - } - - return { - mass, cost: 3 * mass - } - - -} diff --git a/src/lib/components/ShipEdit/Weaponry/AddWeapon.svelte b/src/lib/components/ShipEdit/Weaponry/AddWeapon.svelte new file mode 100644 index 0000000..b84e43a --- /dev/null +++ b/src/lib/components/ShipEdit/Weaponry/AddWeapon.svelte @@ -0,0 +1,22 @@ + + + + + + + diff --git a/src/lib/components/ShipEdit/Weaponry/index.svelte b/src/lib/components/ShipEdit/Weaponry/index.svelte index 5167466..2e5af0b 100644 --- a/src/lib/components/ShipEdit/Weaponry/index.svelte +++ b/src/lib/components/ShipEdit/Weaponry/index.svelte @@ -2,6 +2,8 @@ + + diff --git a/src/lib/components/ShipEdit/Weaponry/index.svelte b/src/lib/components/ShipEdit/Weaponry/index.svelte index 2e5af0b..d9b168b 100644 --- a/src/lib/components/ShipEdit/Weaponry/index.svelte +++ b/src/lib/components/ShipEdit/Weaponry/index.svelte @@ -4,6 +4,11 @@ + + {#each weapons as weapon (weapon.id)} + + {/each} +