Merge branch 'v3-preps'

This commit is contained in:
Yanick Champoux 2023-05-04 18:14:35 -04:00
commit e88f7ad503
7 changed files with 37 additions and 198 deletions

View File

@ -34,6 +34,10 @@ tasks:
cmds: cmds:
- histoire build - histoire build
build:
cmds:
- vite build
integrate: integrate:
deps: [check] deps: [check]
cmds: cmds:
@ -43,6 +47,10 @@ tasks:
- git checkout {{.PARENT_BRANCH}} - git checkout {{.PARENT_BRANCH}}
- git weld - - git weld -
sync:
cmds:
- rsync -av build/ 192.168.0.100:/home/docks
release: release:
cmds: cmds:
- standard-version -a - standard-version -a

View File

@ -29,11 +29,12 @@
"prettier-plugin-svelte": "^2.10.0", "prettier-plugin-svelte": "^2.10.0",
"showdown": "^2.1.0", "showdown": "^2.1.0",
"svelte": "^3.58.0", "svelte": "^3.58.0",
"svelte-preprocess": "^5.0.3",
"typescript": "^5.0.4", "typescript": "^5.0.4",
"vitest": "^0.30.1" "vitest": "^0.30.1"
}, },
"dependencies": { "dependencies": {
"@reduxjs/toolkit": "^1.9.5", "@reduxjs/toolkit": "==2.0.0-alpha.5 ",
"@yanick/updeep-remeda": "^2.2.0", "@yanick/updeep-remeda": "^2.2.0",
"beercss": "^3.1.3", "beercss": "^3.1.3",
"histoire": "^0.16.1", "histoire": "^0.16.1",
@ -45,7 +46,7 @@
"reselect": "^4.1.8", "reselect": "^4.1.8",
"svelte-copy-clipboard-action": "^0.0.3", "svelte-copy-clipboard-action": "^0.0.3",
"svelte-moveable": "^0.38.1", "svelte-moveable": "^0.38.1",
"updux": "link:../../updux", "updux": "file:/home/yanick/work/javascript/updux/updux-5.1.0.tgz",
"vite": "^4.3.3", "vite": "^4.3.3",
"yaml": "^2.2.2" "yaml": "^2.2.2"
}, },

View File

@ -1,168 +0,0 @@
import { combineReducers, configureStore, createSlice } from "@reduxjs/toolkit";
import R from "remeda";
import * as propulsion from "./propulsion";
import * as structure from "./structure";
import * as weaponry from "./weaponry/index.js";
import * as carrier from "./carrier";
import * as identification from "./identification.js";
import * as shipReqs from "./shipReqs";
import * as engine from "./engine";
const shipSlice = createSlice({
name: "ship",
initialState: {},
reducers: {},
extraReducers(builder) {
builder.addMatcher(
() => true,
combineReducers({
identification: identification.reducer,
propulsion: propulsion.reducer,
structure: structure.reducer,
weaponry: weaponry.reducer,
carrier: carrier.reducer,
engine: engine.reducer,
})
);
},
});
export function createStore() {
return configureStore({
reducer: shipSlice.reducer,
});
}
export const actions = {
...shipReqs.actions,
...shipSlice.actions,
...identification.actions,
...engine.actions,
...propulsion.actions,
};
/**
import * as propulsion from "./propulsion/index.js";
import { calculateDriveReqs } from "./propulsion/drive.js";
import { ftlReqsReaction } from "./propulsion/ftl.js";
import * as structure from "./structure/index.js";
import * as carrier from "./carrier.js";
import * as weaponry from "./weaponry/index.js";
import * as shipReqs from "./shipReqs.js";
import { screensReqsReaction } from "./structure/screens.js";
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
propulsion: propulsion.initialState,
identification: identification.initialState,
structure: structure.initialState,
carrier: carrier.initialState,
weaponry: weaponry.initialState,
shipReqs: shipReqs.initialState,
}
const shipSlice = createSlice({
name: "ship",
),
});
const dux = new Updux({
subduxes: {
identification,
propulsion,
structure,
carrier,
weaponry,
},
initial: {
reqs: { cost: 0, mass: 10, usedMass: 0 },
},
actions: {
setShipReqs: null,
setUITransform: null,
resetLayout: null,
resetShip: null,
},
});
function resetUITransform(thing) {
if (typeof thing !== "object") return thing;
return u.map(
(v, k) => (k === "uiTransform" ? "" : resetUITransform(v)),
thing
);
}
dux.setMutation("resetShip", () => () => dux.initial);
dux.setMutation("resetLayout", () => resetUITransform);
dux.setMutation("setUITransform", ({ system, systemId, translate }) => {
const transform = translate
? `translate(${translate[0]}px,${translate[1]}px)`
: "";
switch (system) {
case "firecons":
return u.updateIn("weaponry.firecons.uiTransform", transform);
case "weapon":
return u.updateIn(
"weaponry.weapons",
u.map(u.if(({ id }) => id === systemId, u({ uiTransform: transform })))
);
case "screens":
return u.updateIn("structure.screens.uiTransform", transform);
case "hull":
return u.updateIn("structure.hull.uiTransform", transform);
case "internalSystems":
const path = "structure.uiTransform";
return u.updateIn(path, transform);
case "ftl":
return u.updateIn("propulsion.ftl.uiTransform", transform);
case "drive":
return u.updateIn("propulsion.drive.uiTransform", transform);
default:
return (state) => state;
}
});
dux.addReaction(calculateDriveReqs);
dux.addReaction(ftlReqsReaction);
dux.addReaction(screensReqsReaction);
dux.addReaction((store) => (state) => {
let cost = 0;
let mass = 0;
let subsystems = Object.values(state);
while (subsystems.length > 0) {
const subsystem = subsystems.shift();
if (typeof subsystem !== "object") continue;
if (subsystem.reqs) {
cost += subsystem.reqs.cost;
mass += subsystem.reqs.mass;
}
subsystems.push(...Object.values(subsystem));
}
store.dispatch.setShipReqs({ cost, usedMass: mass });
});
export default dux;
*/

View File

@ -5,17 +5,17 @@ import { writable } from "svelte/store";
export type Api = ReturnType<typeof ship.createStore>; export type Api = ReturnType<typeof ship.createStore>;
export const createApi = () => { export const createApi = () => {
const state = browser const options: Partial<{ preloadedState: object }> = {};
? JSON.parse(localStorage.getItem("ship") || "null")
: undefined;
const api = ship.createStore({ const preloadedState = browser && localStorage.getItem("ship");
preloadedState: state, if (preloadedState) options.preloadedState = JSON.parse(preloadedState);
});
api.dispatch.restore(state); const api = ship.createStore(options);
const svelteStore = writable(state); const svelteStore = writable();
if (preloadedState) {
svelteStore.set(JSON.parse(preloadedState));
}
if (browser) { if (browser) {
api.subscribe(() => { api.subscribe(() => {

View File

@ -2,7 +2,6 @@ import { reqs, type Reqs } from "$lib/shipDux/reqs";
import Updux, { createPayloadAction } from "updux"; import Updux, { createPayloadAction } from "updux";
import u from "@yanick/updeep-remeda"; import u from "@yanick/updeep-remeda";
import { createSelector } from "reselect"; import { createSelector } from "reselect";
import prepare from "immer";
type Layer = number; type Layer = number;
@ -22,15 +21,12 @@ export const armorDux = new Updux({
actions: { setNbrArmorLayers, setArmorRating }, actions: { setNbrArmorLayers, setArmorRating },
}); });
armorDux.addMutation(setArmorRating, ({ index, rating }) => armorDux.addMutation(setArmorRating, ({ index, rating }) => (state) => {
prepare((state) => {
state.layers[index] = rating; state.layers[index] = rating;
state.reqs = calcArmorReqs(state.layers); state.reqs = calcArmorReqs(state.layers);
}) });
);
armorDux.addMutation(setNbrArmorLayers, (nbrLayers) => armorDux.addMutation(setNbrArmorLayers, (nbrLayers) => (state) => {
prepare((state) => {
while (state.layers.length > nbrLayers) { while (state.layers.length > nbrLayers) {
state.layers.pop(); state.layers.pop();
} }
@ -38,8 +34,7 @@ armorDux.addMutation(setNbrArmorLayers, (nbrLayers) =>
state.layers.push(0); state.layers.push(0);
} }
state.reqs = calcArmorReqs(state.layers); state.reqs = calcArmorReqs(state.layers);
}) });
);
function calcArmorReqs(layers: Layer[]): Reqs { function calcArmorReqs(layers: Layer[]): Reqs {
const mass = 2 * layers.reduce((a, b) => a + b, 0); const mass = 2 * layers.reduce((a, b) => a + b, 0);

View File

@ -1,8 +1,12 @@
import preprocess from "svelte-preprocess"; import preprocess from "svelte-preprocess";
import adapter from "@sveltejs/adapter-static";
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
preprocess: preprocess(), preprocess: preprocess(),
kit: {
adapter: adapter({}),
},
}; };
export default config; export default config;

View File

@ -12,7 +12,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */ /* Language and Environment */
"target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, "target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */ // "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@ -67,7 +67,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */ /* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */