move styles
This commit is contained in:
parent
a415278b6a
commit
1a19409645
@ -1 +1,3 @@
|
||||
import "./lib/style/index.js";
|
||||
//import "./lib/style/index.js";
|
||||
import "@picocss/pico";
|
||||
import "../static/global.css";
|
||||
|
@ -1,129 +0,0 @@
|
||||
<script>
|
||||
import "@picocss/pico";
|
||||
</script>
|
||||
|
||||
<style global>
|
||||
@font-face {
|
||||
font-family: "Faktos";
|
||||
font-style: normal;
|
||||
src: url(/fonts/Faktos.ttf) format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Dosis";
|
||||
src: url(/fonts/dosis/Dosis-VariableFont_wght.ttf) format("truetype");
|
||||
}
|
||||
|
||||
:root {
|
||||
--main-font-family: "Dosis", -apple-system, BlinkMacSystemFont, "Segoe UI",
|
||||
Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||
--font-family: "Dosis", -apple-system, BlinkMacSystemFont, "Segoe UI",
|
||||
Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||
|
||||
--font-scale-9: 0.75rem;
|
||||
--font-scale-10: 1em;
|
||||
--font-scale-11: 1.333rem;
|
||||
--font-scale-12: 1.777rem;
|
||||
--font-scale-13: 2.369rem;
|
||||
--font-scale-14: 3.157rem;
|
||||
--font-scale-15: 4.209rem;
|
||||
|
||||
--oxford-blue: hsla(226, 60%, 10%, 1);
|
||||
--royal-blue-dark: hsla(218, 100%, 16%, 1);
|
||||
--indigo-dye: hsla(209, 95%, 24%, 1);
|
||||
--cg-blue: hsla(193, 80%, 35%, 1);
|
||||
--white: hsla(20, 60%, 99%, 1);
|
||||
|
||||
--main-width: 60em;
|
||||
}
|
||||
|
||||
input.short {
|
||||
width: 5em !important;
|
||||
}
|
||||
|
||||
small {
|
||||
font-size: var(--font-scale-9);
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
font-size: var(--font-scale-14);
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: var(--font-scale-12);
|
||||
}
|
||||
|
||||
body {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: var(--white);
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 8px;
|
||||
box-sizing: border-box;
|
||||
font-family: "Dosis", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||
}
|
||||
|
||||
a {
|
||||
color: rgb(0, 100, 200);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: rgb(0, 80, 160);
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
input,
|
||||
button,
|
||||
select,
|
||||
textarea {
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
padding: 0.4em;
|
||||
margin: 0 0 0.5em 0;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
input:disabled {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
input[type="range"] {
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/* input, */
|
||||
/* select { */
|
||||
/* border: 0px; */
|
||||
/* border-bottom: 1px solid var(--indigo-dye); */
|
||||
/* } */
|
||||
|
||||
input:focus,
|
||||
select:focus {
|
||||
border: 1px solid var(--indigo-dye);
|
||||
}
|
||||
|
||||
input:not([type="checkbox"]):not([type="radio"]) {
|
||||
border: 0px;
|
||||
border-bottom: 1px solid var(--indigo-dye);
|
||||
border-radius: 0px;
|
||||
height: calc(
|
||||
1rem * var(--line-height) + var(--form-element-spacing-vertical) * 1
|
||||
);
|
||||
padding: 0 0.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
@ -14,5 +14,8 @@
|
||||
|
||||
let ship = api.getState();
|
||||
|
||||
api.subscribe(() => (ship = api.getState()));
|
||||
api.subscribe(() => {
|
||||
console.log("update!");
|
||||
ship = api.getState();
|
||||
});
|
||||
</script>
|
||||
|
@ -1,5 +1,4 @@
|
||||
<ShipItem {...reqs}>
|
||||
<!--
|
||||
<Field label={`squadron ${id}`}>
|
||||
<select bind:value={type}>
|
||||
{#each types as type (type)}
|
||||
@ -7,7 +6,6 @@
|
||||
{/each}
|
||||
</select>
|
||||
</Field>
|
||||
-->
|
||||
</ShipItem>
|
||||
|
||||
<script>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<Section label="propulsion">
|
||||
<Drive {...propulsion.drive} />
|
||||
<Ftl {...propulsion.ftl} />
|
||||
<Drive {...drive} />
|
||||
<Ftl {...ftl} />
|
||||
</Section>
|
||||
|
||||
<script lang="ts">
|
||||
@ -8,8 +8,6 @@
|
||||
import Drive from "./Propulsion/Engine.svelte";
|
||||
import Ftl from "./Propulsion/Ftl.svelte";
|
||||
|
||||
export let propulsion = {
|
||||
drive: {},
|
||||
ftl: {},
|
||||
};
|
||||
export let drive = {};
|
||||
export let ftl = {};
|
||||
</script>
|
||||
|
@ -13,5 +13,4 @@
|
||||
};
|
||||
|
||||
import Engine from "./Engine.svelte";
|
||||
import "$lib/components/GlobalStyle.svelte";
|
||||
</script>
|
||||
|
@ -25,7 +25,8 @@
|
||||
export let rating = 0;
|
||||
export let api = getContext("api");
|
||||
|
||||
$: api?.dispatch?.setEngine?.({ rating, advanced });
|
||||
console.log(api?.dispatch?.setDrive);
|
||||
$: api?.dispatch?.setDrive?.({ rating, advanced });
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
@ -13,5 +13,4 @@
|
||||
};
|
||||
|
||||
import Ftl from "./Ftl.svelte";
|
||||
import "$lib/components/GlobalStyle.svelte";
|
||||
</script>
|
||||
|
@ -1,79 +1,79 @@
|
||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
||||
import { reqs, Reqs } from "./reqs";
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { reqs, type Reqs } from "./reqs";
|
||||
|
||||
type Squadron = {
|
||||
type: string;
|
||||
reqs: Reqs;
|
||||
type: string;
|
||||
reqs: Reqs;
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
bays: 0,
|
||||
squadrons: [] as Squadron[],
|
||||
reqs,
|
||||
bays: 0,
|
||||
squadrons: [] as Squadron[],
|
||||
reqs,
|
||||
};
|
||||
|
||||
export const { actions, reducer } = createSlice({
|
||||
name: "carrier",
|
||||
initialState,
|
||||
reducers: {
|
||||
setCarrierBays: (state, action: PayloadAction<number>) => {
|
||||
state.bays = action.payload;
|
||||
state.reqs = calcBaysReqs(action.payload);
|
||||
state.squadrons = adjustSquadrons(action.payload)(state.squadrons);
|
||||
name: "carrier",
|
||||
initialState,
|
||||
reducers: {
|
||||
setCarrierBays: (state, action: PayloadAction<number>) => {
|
||||
state.bays = action.payload;
|
||||
state.reqs = calcBaysReqs(action.payload);
|
||||
state.squadrons = adjustSquadrons(action.payload)(state.squadrons);
|
||||
},
|
||||
setSquadronType: (
|
||||
state,
|
||||
action: PayloadAction<{ type: string; id: number }>
|
||||
) => {
|
||||
state.squadrons[action.payload.id - 1] = {
|
||||
type: action.payload.type,
|
||||
reqs: squadronReqs(action.payload.type),
|
||||
};
|
||||
},
|
||||
},
|
||||
setSquadronType: (
|
||||
state,
|
||||
action: PayloadAction<{ type: string; id: number }>
|
||||
) => {
|
||||
state.squadrons[action.payload.id - 1] = {
|
||||
type: action.payload.type,
|
||||
reqs: squadronReqs(action.payload.type),
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
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 },
|
||||
{ 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: string) {
|
||||
return {
|
||||
mass: 6,
|
||||
cost: 6 * squadronTypes.find((s) => s.type === type)?.cost,
|
||||
};
|
||||
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.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,
|
||||
},
|
||||
})),
|
||||
];
|
||||
}
|
||||
if (squadrons.length < bays) {
|
||||
squadrons = [
|
||||
...squadrons,
|
||||
..._.times(bays - squadrons.length, () => ({
|
||||
type: squadronTypes[0].type,
|
||||
reqs: {
|
||||
cost: 6 * squadronTypes[0].cost,
|
||||
mass: 6,
|
||||
},
|
||||
})),
|
||||
];
|
||||
}
|
||||
|
||||
return squadrons;
|
||||
return squadrons;
|
||||
};
|
||||
|
||||
function calcBaysReqs(bays) {
|
||||
return {
|
||||
mass: 9 * bays,
|
||||
cost: 18 * bays,
|
||||
};
|
||||
return {
|
||||
mass: 9 * bays,
|
||||
cost: 18 * bays,
|
||||
};
|
||||
}
|
||||
|
@ -1,42 +1,41 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { Updux } from "updux";
|
||||
import { createSlice, type PayloadAction } from "@reduxjs/toolkit";
|
||||
import u from "updeep";
|
||||
|
||||
import { Reqs, reqs } from "./reqs.js";
|
||||
import { type Reqs, reqs } from "./reqs.js";
|
||||
|
||||
const initialState = {
|
||||
rating: 1,
|
||||
advanced: false,
|
||||
reqs,
|
||||
rating: 1,
|
||||
advanced: false,
|
||||
reqs,
|
||||
};
|
||||
|
||||
const engine = createSlice({
|
||||
name: "engine",
|
||||
initialState,
|
||||
reducers: {
|
||||
setDriveRating(state, action: PayloadAction<number>) {
|
||||
state.rating = action.payload;
|
||||
name: "engine",
|
||||
initialState,
|
||||
reducers: {
|
||||
setDriveRating(state, action: PayloadAction<number>) {
|
||||
state.rating = action.payload;
|
||||
},
|
||||
setDriveAdvanced(state, action: PayloadAction<boolean>) {
|
||||
state.advanced = action.payload;
|
||||
},
|
||||
setDriverReqs(state, action: PayloadAction<Reqs>) {
|
||||
state.reqs = action.payload;
|
||||
},
|
||||
},
|
||||
setDriveAdvanced(state, action: PayloadAction<boolean>) {
|
||||
state.advanced = action.payload;
|
||||
},
|
||||
setDriverReqs(state, action: PayloadAction<Reqs>) {
|
||||
state.reqs = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { actions, reducer } = engine;
|
||||
|
||||
export function calcDriveReqs(
|
||||
shipMass: number,
|
||||
rating: number,
|
||||
advanced = false
|
||||
shipMass: number,
|
||||
rating: number,
|
||||
advanced = false
|
||||
) {
|
||||
const mass = Math.ceil(rating * 0.05 * shipMass);
|
||||
const cost = mass * (advanced ? 3 : 2);
|
||||
const mass = Math.ceil(rating * 0.05 * shipMass);
|
||||
const cost = mass * (advanced ? 3 : 2);
|
||||
|
||||
return { mass, cost };
|
||||
return { mass, cost };
|
||||
}
|
||||
|
||||
export default engine;
|
||||
|
@ -2,28 +2,28 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
||||
import { reqs, Reqs } from "../reqs";
|
||||
|
||||
type DriveProps = {
|
||||
rating: number;
|
||||
advanced: boolean;
|
||||
rating: number;
|
||||
advanced: boolean;
|
||||
};
|
||||
|
||||
export const initialState: DriveProps & { reqs: Reqs } = {
|
||||
rating: 0,
|
||||
advanced: false,
|
||||
reqs,
|
||||
rating: 0,
|
||||
advanced: false,
|
||||
reqs,
|
||||
};
|
||||
|
||||
const driveSlice = createSlice({
|
||||
initialState,
|
||||
name: "drive",
|
||||
reducers: {
|
||||
setDrive: (state, action: PayloadAction<DriveProps>) => {
|
||||
state.rating = action.payload.rating;
|
||||
state.advanced = action.payload.advanced;
|
||||
initialState,
|
||||
name: "drive",
|
||||
reducers: {
|
||||
setDrive: (state, action: PayloadAction<DriveProps>) => {
|
||||
state.rating = action.payload.rating;
|
||||
state.advanced = action.payload.advanced;
|
||||
},
|
||||
setDriveReqs: (state, action: PayloadAction<Reqs>) => {
|
||||
state.reqs = action.payload;
|
||||
},
|
||||
},
|
||||
setDriveReqs: (state, action: PayloadAction<Reqs>) => {
|
||||
state.reqs = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { actions, reducer } = driveSlice;
|
||||
@ -41,10 +41,4 @@ export const calculateDriveReqs = (store) =>
|
||||
store.dispatch.setDriveReqs(calcDriveReqs(ship_mass, rating, advanced))
|
||||
);
|
||||
|
||||
export function calcDriveReqs(shipMass, rating, advanced = false) {
|
||||
const mass = Math.ceil(rating * 0.05 * shipMass);
|
||||
const cost = mass * (advanced ? 3 : 2);
|
||||
|
||||
return { mass, cost };
|
||||
}
|
||||
*/
|
||||
|
@ -1,10 +1,14 @@
|
||||
import { test, expect } from "vitest";
|
||||
import ship from "./ship";
|
||||
|
||||
test("ftlReqs reaction", () => {
|
||||
test("misc", () => {
|
||||
const store = ship.createStore();
|
||||
store.dispatch.setFtlType("standard");
|
||||
|
||||
expect(store.getState().propulsion.ftl.reqs.mass).toEqual(1);
|
||||
expect(store.getState().identification.reqs.usedMass).toEqual(1);
|
||||
|
||||
store.dispatch.setDrive({ rating: 3, advanced: true });
|
||||
|
||||
expect(store.getState().propulsion.drive.reqs).toEqual({ mass: 2, cost: 6 });
|
||||
});
|
||||
|
@ -4,13 +4,17 @@ import * as R from "remeda";
|
||||
|
||||
import identification from "./ship/identification";
|
||||
import ftl, { calcFtlReqs } from "./ship/propulsion/ftl";
|
||||
import drive from "./ship/propulsion/drive";
|
||||
import { calcDriveReqs } from "$lib/shipDux/engine";
|
||||
|
||||
const shipDux = new Updux({
|
||||
subduxes: {
|
||||
identification,
|
||||
propulsion: new Updux({
|
||||
initial: {},
|
||||
subduxes: {
|
||||
ftl,
|
||||
drive,
|
||||
},
|
||||
}),
|
||||
},
|
||||
@ -45,4 +49,14 @@ shipDux.addReaction((api) => (state) => {
|
||||
api.dispatch.setShipReqs({ cost, usedMass: 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))
|
||||
)
|
||||
);
|
||||
|
||||
export default shipDux;
|
||||
|
38
src/lib/store/ship/propulsion/drive.ts
Normal file
38
src/lib/store/ship/propulsion/drive.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { reqs, type Reqs } from "$lib/shipDux/reqs";
|
||||
import Updux, { createPayloadAction } from "updux";
|
||||
import u from "@yanick/updeep-remeda";
|
||||
|
||||
type DriveProps = {
|
||||
rating: number;
|
||||
advanced: boolean;
|
||||
};
|
||||
|
||||
const initial: DriveProps & { reqs: Reqs } = {
|
||||
rating: 0,
|
||||
advanced: false,
|
||||
reqs,
|
||||
};
|
||||
|
||||
const setDrive = createPayloadAction<DriveProps>("setDrive");
|
||||
const setDriveReqs = createPayloadAction<Reqs>("setDriveReqs");
|
||||
|
||||
const dux = new Updux({
|
||||
initial,
|
||||
actions: { setDrive, setDriveReqs },
|
||||
});
|
||||
|
||||
export default dux;
|
||||
|
||||
dux.addMutation(setDrive, (change) => u(change));
|
||||
dux.addMutation(setDriveReqs, (reqs) => u({ reqs }));
|
||||
|
||||
export function calcDriveReqs(
|
||||
shipMass: number,
|
||||
rating: number,
|
||||
advanced = false
|
||||
) {
|
||||
const mass = Math.ceil(rating * 0.05 * shipMass);
|
||||
const cost = mass * (advanced ? 3 : 2);
|
||||
|
||||
return { mass, cost };
|
||||
}
|
Loading…
Reference in New Issue
Block a user