diff --git a/src/lib/components/MainLayout.svelte b/src/lib/components/MainLayout.svelte index 4608d7c..765d1ef 100644 --- a/src/lib/components/MainLayout.svelte +++ b/src/lib/components/MainLayout.svelte @@ -7,7 +7,7 @@
Editor - Export + import { getContext } from "svelte"; + import Identification from "./ShipEdit/Identification.svelte"; import Propulsion from "./ShipEdit/Propulsion.svelte"; import shipDux from "$lib/store/ship"; @@ -20,6 +22,8 @@ export let structure = {}; export let weaponry = {}; export let carrier = {}; + + const api = getContext("api"); diff --git a/src/lib/components/ShipEdit/Identification.svelte b/src/lib/components/ShipEdit/Identification.svelte index a697149..3e6785a 100644 --- a/src/lib/components/ShipEdit/Identification.svelte +++ b/src/lib/components/ShipEdit/Identification.svelte @@ -28,6 +28,7 @@ import Field from "$lib/components/Field.svelte"; import { candidateShipTypes } from "./Identification/shipTypes.js"; import ShipCost from "./Identification/ShipCost.svelte"; + import shipDux from "$lib/store/ship"; export let shipClass = ""; export let shipType = ""; diff --git a/src/lib/store/ship.ts b/src/lib/store/ship.ts index 969f5cb..b7ba86c 100644 --- a/src/lib/store/ship.ts +++ b/src/lib/store/ship.ts @@ -19,117 +19,121 @@ import { adfcDux } from "./ship/weaponry/adfc"; import { weaponsDux } from "./ship/weaponry/weapons"; if (typeof process !== "undefined") { - process.env.UPDEEP_MODE = "dangerously_never_freeze"; + process.env.UPDEEP_MODE = "dangerously_never_freeze"; } const structure = new Updux({ - initialState: {}, - subduxes: { - streamlining, - cargo: cargoDux, - hull: hullDux, - screens: screensDux, - armor: armorDux, - carrier: carrierDux, - }, + initialState: {}, + subduxes: { + streamlining, + cargo: cargoDux, + hull: hullDux, + screens: screensDux, + armor: armorDux, + carrier: carrierDux, + }, }); const propulsion = new Updux({ - initialState: {}, - subduxes: { - ftl, - drive, - }, + initialState: {}, + subduxes: { + ftl, + drive, + }, }); const weaponry = new Updux({ - initialState: {}, - subduxes: { - adfc: adfcDux, - firecons: fireconsDux, - weapons: weaponsDux, - }, + initialState: {}, + subduxes: { + adfc: adfcDux, + firecons: fireconsDux, + weapons: weaponsDux, + }, }); const restore = createPayloadAction("restore"); +const importShip = + createPayloadAction("importShip"); const shipDux = new Updux({ - actions: { - restore, - }, - initialState: { - schemaVersion: "1", - }, - subduxes: { - identification, - structure, - propulsion, - carrier: carrierDux, - weaponry, - }, + actions: { + restore, + importShip, + }, + initialState: { + schemaVersion: "1", + }, + subduxes: { + identification, + structure, + propulsion, + carrier: carrierDux, + weaponry, + }, }); shipDux.addMutation(restore, (state) => () => state); +shipDux.addMutation(importShip, (state) => () => state); shipDux.addReaction((api) => { - return createSelector( - api.selectors.getFtlType, - api.selectors.getShipMass, - (type, mass) => api.dispatch.setFtlReqs(calcFtlReqs(type, mass)) - ); + return createSelector( + api.selectors.getFtlType, + api.selectors.getShipMass, + (type, mass) => api.dispatch.setFtlReqs(calcFtlReqs(type, mass)) + ); }); shipDux.addReaction((api) => { - const setShipReqs = memoize((cost, usedMass) => - api.dispatch.setShipReqs({ cost, usedMass }) - ); + const setShipReqs = memoize((cost, usedMass) => + api.dispatch.setShipReqs({ cost, usedMass }) + ); - return (state) => { - let cost = 0; - let mass = 0; + return (state) => { + let cost = 0; + let mass = 0; - let subsystems = R.values(R.omit(state, ["identification"])); + let subsystems = R.values(R.omit(state, ["identification"])); - while (subsystems.length > 0) { - const subsystem = subsystems.shift(); - if (typeof subsystem !== "object") continue; + while (subsystems.length > 0) { + const subsystem = subsystems.shift(); + if (typeof subsystem !== "object") continue; - if (subsystem.reqs) { - cost += subsystem.reqs.cost ?? 0; - mass += subsystem.reqs.mass ?? 0; - } + if (subsystem.reqs) { + cost += subsystem.reqs.cost ?? 0; + mass += subsystem.reqs.mass ?? 0; + } - subsystems.push(...Object.values(subsystem)); - } + subsystems.push(...Object.values(subsystem)); + } - if (Number.isNaN(cost)) { - console.log(state.weaponry.weapons); - throw new Error(); - } + if (Number.isNaN(cost)) { + console.log(state.weaponry.weapons); + throw new Error(); + } - setShipReqs(cost, mass); - }; + setShipReqs(cost, mass); + }; }); shipDux.addReaction((api) => - createSelector( - api.selectors.getShipMass, - (state) => state.propulsion.drive.rating, - (state) => state.propulsion.drive.advanced, - (mass, rating, advanced) => - api.dispatch.setDriveReqs(calcDriveReqs(mass, rating, advanced)) - ) + createSelector( + api.selectors.getShipMass, + (state) => state.propulsion.drive.rating, + (state) => state.propulsion.drive.advanced, + (mass, rating, advanced) => + api.dispatch.setDriveReqs(calcDriveReqs(mass, rating, advanced)) + ) ); shipDux.addReaction((api) => - createSelector( - // (state) => state, - api.selectors.getShipMass, - api.selectors.getStreamlining, - (mass, type) => { - api.dispatch.setStreamliningReqs(calcStreamliningReqs(type, mass)); - } - ) + createSelector( + // (state) => state, + api.selectors.getShipMass, + api.selectors.getStreamlining, + (mass, type) => { + api.dispatch.setStreamliningReqs(calcStreamliningReqs(type, mass)); + } + ) ); shipDux.addReaction(screensReqsReaction); diff --git a/src/routes/about/+layout.svelte b/src/routes/(about)/about/+layout.svelte similarity index 100% rename from src/routes/about/+layout.svelte rename to src/routes/(about)/about/+layout.svelte diff --git a/src/routes/about/+page.svelte b/src/routes/(about)/about/+page.svelte similarity index 100% rename from src/routes/about/+page.svelte rename to src/routes/(about)/about/+page.svelte diff --git a/src/routes/about/about.test.js b/src/routes/(about)/about/about.test.js similarity index 100% rename from src/routes/about/about.test.js rename to src/routes/(about)/about/about.test.js diff --git a/src/routes/about/layout.test.js b/src/routes/(about)/about/layout.test.js similarity index 100% rename from src/routes/about/layout.test.js rename to src/routes/(about)/about/layout.test.js diff --git a/src/routes/about/see-also/+page.svelte b/src/routes/(about)/about/see-also/+page.svelte similarity index 100% rename from src/routes/about/see-also/+page.svelte rename to src/routes/(about)/about/see-also/+page.svelte diff --git a/src/routes/(editor)/+layout.svelte b/src/routes/(editor)/+layout.svelte new file mode 100644 index 0000000..5970352 --- /dev/null +++ b/src/routes/(editor)/+layout.svelte @@ -0,0 +1,42 @@ + + + + + + diff --git a/src/routes/editor/+page.svelte b/src/routes/(editor)/editor/+page.svelte similarity index 100% rename from src/routes/editor/+page.svelte rename to src/routes/(editor)/editor/+page.svelte diff --git a/src/routes/editor/page.test.js b/src/routes/(editor)/editor/page.test.js similarity index 100% rename from src/routes/editor/page.test.js rename to src/routes/(editor)/editor/page.test.js diff --git a/src/routes/(editor)/export/+page.svelte b/src/routes/(editor)/export/+page.svelte new file mode 100644 index 0000000..6ace38a --- /dev/null +++ b/src/routes/(editor)/export/+page.svelte @@ -0,0 +1,11 @@ + + + diff --git a/src/routes/export/[format=outputFormat]/Serialized.svelte b/src/routes/(editor)/export/Serialized.svelte similarity index 58% rename from src/routes/export/[format=outputFormat]/Serialized.svelte rename to src/routes/(editor)/export/Serialized.svelte index b2f5d07..866287a 100644 --- a/src/routes/export/[format=outputFormat]/Serialized.svelte +++ b/src/routes/(editor)/export/Serialized.svelte @@ -6,16 +6,25 @@ on:error={copyError}>{copyLabel} content_paste +
+ + arrow_drop_down +
-
{data}
+
{serialized}