Merge branch 'graser'
56
.histoire/dist/histoire.json
vendored
@ -293,6 +293,62 @@
|
||||
],
|
||||
"virtual": false,
|
||||
"markdownFile": null
|
||||
},
|
||||
{
|
||||
"id": "src-lib-components-shipedit-weaponry-weapon-graser-index-story-svelte",
|
||||
"title": "Graser",
|
||||
"group": null,
|
||||
"layout": {
|
||||
"type": "single",
|
||||
"iframe": true
|
||||
},
|
||||
"icon": null,
|
||||
"iconColor": null,
|
||||
"docsOnly": false,
|
||||
"variants": [
|
||||
{
|
||||
"id": "_default",
|
||||
"title": "default"
|
||||
}
|
||||
],
|
||||
"relativePath": "src/lib/components/ShipEdit/Weaponry/Weapon/Graser/index.story.svelte",
|
||||
"supportPluginId": "svelte3",
|
||||
"treePath": [
|
||||
"ShipEdit",
|
||||
"Weaponry",
|
||||
"Weapon",
|
||||
"Graser"
|
||||
],
|
||||
"virtual": false,
|
||||
"markdownFile": null
|
||||
},
|
||||
{
|
||||
"id": "src-routes-export-print-printship-weapons-graser-index-story-svelte",
|
||||
"title": "Graser",
|
||||
"group": null,
|
||||
"layout": {
|
||||
"type": "single",
|
||||
"iframe": true
|
||||
},
|
||||
"icon": null,
|
||||
"iconColor": null,
|
||||
"docsOnly": false,
|
||||
"variants": [
|
||||
{
|
||||
"id": "_default",
|
||||
"title": "default"
|
||||
}
|
||||
],
|
||||
"relativePath": "src/routes/export/print/PrintShip/Weapons/Graser/index.story.svelte",
|
||||
"supportPluginId": "svelte3",
|
||||
"treePath": [
|
||||
"Export",
|
||||
"PrintShip",
|
||||
"Weapons",
|
||||
"Graser"
|
||||
],
|
||||
"virtual": false,
|
||||
"markdownFile": null
|
||||
}
|
||||
],
|
||||
"markdownFiles": []
|
||||
|
After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 24 KiB |
@ -60,7 +60,6 @@
|
||||
const broadside = ["FS", "FP", "AP", "AS"];
|
||||
|
||||
function setArcs(firstArc) {
|
||||
console.log(firstArc);
|
||||
let newArcs;
|
||||
if (nbrArcs === "broadside") {
|
||||
newArcs = broadside;
|
||||
|
@ -0,0 +1,13 @@
|
||||
<Hst.Story title="ShipEdit/Weaponry/Weapon/Graser">
|
||||
<Graser {api} />
|
||||
</Hst.Story>
|
||||
|
||||
<script>
|
||||
export let Hst;
|
||||
import { logEvent } from "histoire/client";
|
||||
import Graser from "./index.svelte";
|
||||
|
||||
const api = {
|
||||
dispatch: {},
|
||||
};
|
||||
</script>
|
100
src/lib/components/ShipEdit/Weaponry/Weapon/Graser/index.svelte
Normal file
@ -0,0 +1,100 @@
|
||||
<span>graser</span>
|
||||
|
||||
<Field label="graser class" suffix>
|
||||
<select bind:value={weaponClass}>
|
||||
{#each weaponClasses as value}
|
||||
<option {value}>{value}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<i>arrow_drop_down</i>
|
||||
</Field>
|
||||
|
||||
<Field label="arcs" suffix>
|
||||
<select bind:value={nbrArcs}>
|
||||
{#each nbrArcsOptions as value}
|
||||
<option {value}>{value}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<i>arrow_drop_down</i>
|
||||
</Field>
|
||||
|
||||
<div class="arcs">
|
||||
<Arcs
|
||||
size={48}
|
||||
selected={arcs}
|
||||
on:clickArc={({ detail }) => setFirstArc(detail)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<script lang="ts">
|
||||
import * as R from "remeda";
|
||||
import u from "@yanick/updeep-remeda";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
import memoize from "memoize-one";
|
||||
|
||||
import Arcs from "../Arcs.svelte";
|
||||
import ShipItem from "$lib/components/ShipItem.svelte";
|
||||
import Field from "$lib/components/Field.svelte";
|
||||
import {
|
||||
weaponTypes,
|
||||
broadsideArcs,
|
||||
arcs as allArcs,
|
||||
isBroadside,
|
||||
} from "$lib/store/ship/weaponry/rules.ts";
|
||||
|
||||
const options = weaponTypes.find(u.matches({ type: "graser" })).options;
|
||||
|
||||
const weaponClasses = options.map(R.prop("weaponClass"));
|
||||
|
||||
export let weaponClass = weaponClasses[0];
|
||||
|
||||
export let arcs = ["F"];
|
||||
|
||||
let nbrArcs = isBroadside(arcs) ? "broadside" : arcs.length;
|
||||
|
||||
$: classOptions = options.find(u.matches({ weaponClass }));
|
||||
|
||||
$: nbrArcsOptions = classOptions.nbrArcs;
|
||||
$: broadside = classOptions.broadside;
|
||||
|
||||
$: if (!nbrArcsOptions.includes(nbrArcs)) nbrArcs = nbrArcsOptions[0];
|
||||
|
||||
function allowedArcs(arcs, options) {
|
||||
if (options.broadside && isBroadside(arcs)) return true;
|
||||
|
||||
return options.nbrArcs.includes(arcs.length);
|
||||
}
|
||||
|
||||
let firstArc = allArcs[0];
|
||||
const setFirstArc = (a) => (firstArc = a);
|
||||
|
||||
$: arcs = setArcs(firstArc, nbrArcs);
|
||||
|
||||
function setArcs(firstArc, nbrArcs) {
|
||||
if (nbrArcs === "broadside") return broadsideArcs;
|
||||
|
||||
let first_index = allArcs.findIndex((arc) => arc === firstArc);
|
||||
if (first_index === -1) first_index = 0;
|
||||
|
||||
return Array.from({ length: nbrArcs }).map(
|
||||
(_dummy, i) => allArcs[(first_index + i) % allArcs.length]
|
||||
);
|
||||
}
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
const memoChange = memoize((weaponClass, ...arcs) =>
|
||||
dispatch("change", {
|
||||
weaponClass,
|
||||
arcs,
|
||||
})
|
||||
);
|
||||
|
||||
$: memoChange(weaponClass, ...arcs);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.arcs {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
</style>
|
@ -17,6 +17,7 @@
|
||||
import PointDefenceSystem from "./PDS.svelte";
|
||||
import Scattergun from "./Scattergun.svelte";
|
||||
import Needle from "./Needle.svelte";
|
||||
import Graser from "./Graser/index.svelte";
|
||||
|
||||
const component = {
|
||||
beam: Beam,
|
||||
@ -24,6 +25,7 @@
|
||||
pds: PointDefenceSystem,
|
||||
scattergun: Scattergun,
|
||||
needle: Needle,
|
||||
graser: Graser,
|
||||
};
|
||||
|
||||
export let reqs = {};
|
||||
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 22 KiB |
@ -2,125 +2,186 @@ import type { Reqs } from "$lib/shipDux/reqs";
|
||||
|
||||
export const arcs = ["FS", "F", "FP", "AP", "A", "AS"] as const;
|
||||
|
||||
export const broadsideArcs = ["FP", "AP", "AS", "FS"];
|
||||
|
||||
export type Arc = (typeof arcs)[number];
|
||||
|
||||
export type WeaponType = "beam";
|
||||
|
||||
type Beam = {
|
||||
type: "beam";
|
||||
weaponClass: 1 | 2 | 3 | 4;
|
||||
arcs: Arc[];
|
||||
type: "beam";
|
||||
weaponClass: 1 | 2 | 3 | 4;
|
||||
arcs: Arc[];
|
||||
};
|
||||
|
||||
type Submunition = {
|
||||
type: "submunition";
|
||||
arc: Arc;
|
||||
type: "submunition";
|
||||
arc: Arc;
|
||||
};
|
||||
|
||||
type PDS = {
|
||||
type: "pds";
|
||||
type: "pds";
|
||||
};
|
||||
|
||||
type Scattergun = { type: "scattergun" };
|
||||
|
||||
type Needle = { type: "needle"; arc: Arc };
|
||||
|
||||
export type Weapon = Beam | Submunition | PDS | Scattergun | Needle;
|
||||
type Graser = {
|
||||
type: "graser";
|
||||
weaponClass: 1 | 2 | 3;
|
||||
arcs: Arc[];
|
||||
};
|
||||
|
||||
export type Weapon = Beam | Submunition | PDS | Scattergun | Needle | Graser;
|
||||
|
||||
export const weaponTypes = [
|
||||
{
|
||||
type: "beam",
|
||||
name: "beam",
|
||||
reqs: beamReqs,
|
||||
initial: {
|
||||
type: "beam",
|
||||
weaponClass: 1,
|
||||
arcs,
|
||||
} as any as Beam,
|
||||
},
|
||||
{
|
||||
type: "submunition",
|
||||
name: "submunition pack",
|
||||
reqs: { mass: 1, cost: 3 },
|
||||
initial: { type: "submunition", arc: "F" } as Submunition,
|
||||
},
|
||||
{
|
||||
name: "point defence system",
|
||||
type: "pds",
|
||||
reqs: { mass: 1, cost: 3 },
|
||||
initial: {
|
||||
type: "pds",
|
||||
{
|
||||
type: "beam",
|
||||
name: "beam",
|
||||
reqs: beamReqs,
|
||||
initial: {
|
||||
type: "beam",
|
||||
weaponClass: 1,
|
||||
arcs,
|
||||
} as any as Beam,
|
||||
},
|
||||
{
|
||||
type: "graser",
|
||||
name: "graser",
|
||||
reqs: graserReqs,
|
||||
initial: {
|
||||
type: "graser",
|
||||
weaponClass: 1,
|
||||
arcs: ["F"],
|
||||
} as any as Graser,
|
||||
options: [
|
||||
{ weaponClass: 1, nbrArcs: [1, 3, 6, "broadside"] },
|
||||
{
|
||||
weaponClass: 2,
|
||||
nbrArcs: [1, 2, 3, 4, 5, 6, "broadside"],
|
||||
},
|
||||
{
|
||||
weaponClass: 3,
|
||||
nbrArcs: [1, 2, 3, 4, 5, 6, "broadside"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "submunition",
|
||||
name: "submunition pack",
|
||||
reqs: { mass: 1, cost: 3 },
|
||||
initial: { type: "submunition", arc: "F" } as Submunition,
|
||||
},
|
||||
{
|
||||
name: "point defence system",
|
||||
type: "pds",
|
||||
reqs: { mass: 1, cost: 3 },
|
||||
initial: {
|
||||
type: "pds",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "scattergun",
|
||||
type: "scattergun",
|
||||
reqs: { mass: 1, cost: 4 },
|
||||
initial: { type: "scattergun" },
|
||||
},
|
||||
{
|
||||
name: "needle beam",
|
||||
type: "needle",
|
||||
reqs: { mass: 2, cost: 6 },
|
||||
initial: { arc: "F", type: "needle" },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "scattergun",
|
||||
type: "scattergun",
|
||||
reqs: { mass: 1, cost: 4 },
|
||||
initial: { type: "scattergun" },
|
||||
},
|
||||
{
|
||||
name: "needle beam",
|
||||
type: "needle",
|
||||
reqs: { mass: 2, cost: 6 },
|
||||
initial: { arc: "F", type: "needle" },
|
||||
},
|
||||
];
|
||||
|
||||
export function weaponReqs(weapon): Reqs {
|
||||
const { reqs } = weaponTypes.find((wt) => wt.type === weapon.type) || {};
|
||||
const { reqs } = weaponTypes.find((wt) => wt.type === weapon.type) || {};
|
||||
|
||||
if (!reqs)
|
||||
return {
|
||||
cost: 0,
|
||||
mass: 0,
|
||||
};
|
||||
if (!reqs)
|
||||
return {
|
||||
cost: 0,
|
||||
mass: 0,
|
||||
};
|
||||
|
||||
if (typeof reqs === "function") return reqs(weapon);
|
||||
if (typeof reqs === "function") return reqs(weapon);
|
||||
|
||||
return reqs;
|
||||
return reqs;
|
||||
}
|
||||
|
||||
const isBroadside = (arcs: Arc[]) => {
|
||||
if (arcs.length !== 4) return false;
|
||||
export const isBroadside = (arcs: Arc[]) => {
|
||||
if (arcs.length !== 4) return false;
|
||||
|
||||
// that'd be A or F
|
||||
return !arcs.some((a) => a.length === 1);
|
||||
// that'd be A or F
|
||||
return !arcs.some((a) => a.length === 1);
|
||||
};
|
||||
|
||||
function beamReqs({ weaponClass, arcs }: Beam) {
|
||||
console.log(weaponClass, arcs);
|
||||
let mass;
|
||||
let mass;
|
||||
|
||||
if (weaponClass === 1) {
|
||||
mass = 1;
|
||||
}
|
||||
|
||||
if (weaponClass === 2) {
|
||||
mass = 2 + (arcs.length > 3 ? 1 : 0);
|
||||
}
|
||||
|
||||
if (weaponClass == 3) {
|
||||
mass = 4;
|
||||
|
||||
if (isBroadside(arcs)) {
|
||||
mass += 2;
|
||||
} else {
|
||||
mass += arcs.length - 1;
|
||||
if (weaponClass === 1) {
|
||||
mass = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (weaponClass == 4) {
|
||||
mass = 8;
|
||||
|
||||
if (isBroadside(arcs)) {
|
||||
mass += 4;
|
||||
} else {
|
||||
mass += 2 * (arcs.length - 1);
|
||||
if (weaponClass === 2) {
|
||||
mass = 2 + (arcs.length > 3 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
mass,
|
||||
cost: 3 * mass,
|
||||
};
|
||||
if (weaponClass == 3) {
|
||||
mass = 4;
|
||||
|
||||
if (isBroadside(arcs)) {
|
||||
mass += 2;
|
||||
} else {
|
||||
mass += arcs.length - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (weaponClass == 4) {
|
||||
mass = 8;
|
||||
|
||||
if (isBroadside(arcs)) {
|
||||
mass += 4;
|
||||
} else {
|
||||
mass += 2 * (arcs.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
mass,
|
||||
cost: 3 * mass,
|
||||
};
|
||||
}
|
||||
|
||||
function graserReqs({ weaponClass, arcs }: Beam) {
|
||||
let mass: number;
|
||||
|
||||
if (weaponClass === 1) {
|
||||
if (arcs.length === 1) {
|
||||
mass = 2;
|
||||
} else if (arcs.length === 3) {
|
||||
mass = 3;
|
||||
} else {
|
||||
mass = 4;
|
||||
}
|
||||
} else if (weaponClass === 2) {
|
||||
mass = 9;
|
||||
if (isBroadside(arcs)) {
|
||||
mass += 6;
|
||||
} else {
|
||||
mass += 3 * (arcs.length - 1);
|
||||
}
|
||||
} else if (weaponClass === 3) {
|
||||
mass = 24;
|
||||
if (isBroadside(arcs)) {
|
||||
mass += 12;
|
||||
} else {
|
||||
mass += 6 * (arcs.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
mass,
|
||||
cost: 4 * mass,
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div>
|
||||
<Arcs selected={arcs} size="40">
|
||||
<Arcs selected={arcs} size={40}>
|
||||
<text x="50%" y="50%">
|
||||
{weaponClass}
|
||||
</text>
|
||||
|
@ -0,0 +1,9 @@
|
||||
<Hst.Story title="Export/PrintShip/Weapons/Graser">
|
||||
<Graser arcs={["F", "FS"]} weaponClass={2} />
|
||||
</Hst.Story>
|
||||
|
||||
<script>
|
||||
import Graser from "./index.svelte";
|
||||
|
||||
export let Hst;
|
||||
</script>
|
@ -0,0 +1,35 @@
|
||||
<div>
|
||||
<Arcs selected={arcs} size={40}>
|
||||
<polygon
|
||||
points="0,30 30,30 15,4"
|
||||
style="fill:black"
|
||||
transform="translate(7,2) scale(0.85)"
|
||||
/>
|
||||
<text x="50%" y="50%" style="color: white">
|
||||
{weaponClass}
|
||||
</text>
|
||||
</Arcs>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
import Arcs from "$lib/components/ShipEdit/Weaponry/Weapon/Arcs.svelte";
|
||||
export let weaponClass = 1;
|
||||
export let arcs = [];
|
||||
</script>
|
||||
|
||||
<style>
|
||||
div {
|
||||
margin: 0px 0.5rem;
|
||||
}
|
||||
div :global(path:hover) {
|
||||
fill: white;
|
||||
}
|
||||
div :global(path.active:hover) {
|
||||
fill: black;
|
||||
}
|
||||
text {
|
||||
text-anchor: middle;
|
||||
dominant-baseline: central;
|
||||
font-size: var(--font-scale-10);
|
||||
}
|
||||
</style>
|
@ -3,11 +3,13 @@ import Submunition from "./Submunition.svelte";
|
||||
import PDS from "./PDS.svelte";
|
||||
import Scattergun from "./Scattergun.svelte";
|
||||
import Needlebeam from "./Needlebeam.svelte";
|
||||
import Graser from "./Graser/index.svelte";
|
||||
|
||||
export default {
|
||||
beam: Beam,
|
||||
submunition: Submunition,
|
||||
pds: PDS,
|
||||
scattergun: Scattergun,
|
||||
needle: Needlebeam,
|
||||
graser: Graser,
|
||||
beam: Beam,
|
||||
submunition: Submunition,
|
||||
pds: PDS,
|
||||
scattergun: Scattergun,
|
||||
needle: Needlebeam,
|
||||
};
|
||||
|