beam weapons
This commit is contained in:
parent
70a3c76cde
commit
1cac278c7c
@ -1,9 +0,0 @@
|
||||
|
||||
|
||||
const is_broadside = arcs => {
|
||||
if( arcs.length !== 4 ) return false;
|
||||
|
||||
// that'd be A or F
|
||||
return !arcs.some( a => a.length === 1 );
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
<label>beam</label>
|
||||
|
||||
<Field label="beam class">
|
||||
<select bind:value={weaponClass}>
|
||||
<option value={1}>1</option>
|
||||
<option value={2}>2</option>
|
||||
<option value={3}>3</option>
|
||||
<option value={4}>4</option>
|
||||
</select>
|
||||
</Field>
|
||||
|
||||
<Field label="arcs">
|
||||
<select bind:value={nbrArcs}>
|
||||
{#each arc_options[weaponClass] || [] as nbrArcs (nbrArcs)}
|
||||
<option>{nbrArcs}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</Field>
|
||||
|
||||
<Arcs selected={arcs} on:click_arc={({ detail }) => setArcs(detail)} />
|
||||
|
||||
<script>
|
||||
import { getContext } from "svelte";
|
||||
|
||||
import Arcs from "../Arcs.svelte";
|
||||
import ShipItem from "$lib/components/ShipItem/index.svelte";
|
||||
import Field from "$lib/components/Field/index.svelte";
|
||||
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
const all_arcs = ["FS", "F", "FP", "AP", "A", "AS"];
|
||||
|
||||
export let weaponClass = 1;
|
||||
export let arcs = ["F"];
|
||||
|
||||
let arc_options = {
|
||||
1: [6],
|
||||
2: [3, 6],
|
||||
3: [1, 2, 3, 4, 5, 6, "broadside"],
|
||||
4: [1, 2, 3, 4, 5, 6, "broadside"],
|
||||
};
|
||||
|
||||
$: arcsCaches = arcs.join(',');
|
||||
|
||||
let nbrArcs = arcs.length;
|
||||
|
||||
$: if (!arc_options[weaponClass].includes(nbrArcs)) {
|
||||
nbrArcs = arc_options[weaponClass][0];
|
||||
console.log({nbrArcs, label:"in if"})
|
||||
}
|
||||
|
||||
const broadside = ["FS", "FP", "AP", "AS"];
|
||||
|
||||
|
||||
function setArcs(firstArc) {
|
||||
console.log(firstArc);
|
||||
if (nbrArcs === "broadside") {
|
||||
arcs = broadside;
|
||||
return;
|
||||
}
|
||||
let first_index = all_arcs.findIndex((arc) => arc === firstArc);
|
||||
if (first_index === -1) first_index = 0;
|
||||
|
||||
console.log({arcs, label:"before"});
|
||||
arcs = _.range(nbrArcs).map(
|
||||
(i) => all_arcs[(first_index + i) % all_arcs.length]
|
||||
);
|
||||
arcsCaches = arcs.join(',');
|
||||
console.log({arcs, label:"after"});
|
||||
}
|
||||
|
||||
$: if (arcs.length !== nbrArcs) setArcs(arcs[0]);
|
||||
|
||||
$: console.log("it changed!", arcs)
|
||||
$: console.log("it changed!", arcsCaches)
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
$: dispatch("change", {
|
||||
weaponClass,
|
||||
arcs: arcsCaches.split(','),
|
||||
});
|
||||
</script>
|
@ -19,14 +19,14 @@
|
||||
import Arc from "./Arc.svelte";
|
||||
import ShipItem from "$lib/components/ShipItem/index.svelte";
|
||||
import Field from "$lib/components/Field/index.svelte";
|
||||
/* import Beam from "./Beam/index.svelte"; */
|
||||
import Beam from "./Beam/index.svelte";
|
||||
import Submunition from "./Submunition.svelte";
|
||||
import PointDefenceSystem from "./PDS.svelte";
|
||||
import Scattergun from "./Scattergun.svelte";
|
||||
import Needle from "./Needle.svelte";
|
||||
|
||||
const component = {
|
||||
/* beam: Beam, */
|
||||
beam: Beam,
|
||||
submunition: Submunition,
|
||||
pds: PointDefenceSystem,
|
||||
scattergun: Scattergun,
|
||||
@ -41,10 +41,10 @@
|
||||
|
||||
$: type = weapon.type;
|
||||
|
||||
$: console.log(weapon);
|
||||
const remove = () => ship.dispatch.removeWeapon(id);
|
||||
|
||||
const update = ({ detail }) => {
|
||||
console.log({id,type})
|
||||
ship.dispatch.setWeapon({
|
||||
id,
|
||||
type,
|
||||
|
@ -21,6 +21,7 @@ import { readable, get, derived } from "svelte/store";
|
||||
const store = weaponryDux.createStore();
|
||||
const state = readable(store.getState(), (set) => {
|
||||
store.subscribe(() => {
|
||||
console.log(store.getState());
|
||||
set(store.getState());
|
||||
});
|
||||
});
|
||||
|
@ -4,7 +4,9 @@ import u from "updeep";
|
||||
const reqs = { cost: 0, mass: 0 };
|
||||
|
||||
export const weaponTypes = [
|
||||
{ name: 'beam', type: 'beam', reqs: beam_cost_mass },
|
||||
{ name: 'beam', type: 'beam', reqs: beam_cost_mass, initial: {
|
||||
weaponClass: 1
|
||||
}},
|
||||
{ name: 'submunition pack', type: 'submunition', reqs: { mass:1, cost:3 },
|
||||
initial: { arc: 'F' }
|
||||
},
|
||||
@ -23,8 +25,20 @@ const dux = new Updux({
|
||||
},
|
||||
});
|
||||
|
||||
dux.setMutation('setWeapon', ({id,...rest}) =>
|
||||
u.map( u.if( (w) => w.id === id, { ...rest }))
|
||||
dux.setMutation('setWeapon', ({id,...rest}) => state => {
|
||||
console.log(id,rest,state);
|
||||
state = u.map( u.if( (w) => w.id === id,
|
||||
weapon => {
|
||||
return {
|
||||
id,
|
||||
...rest,
|
||||
reqs: weaponReqs(rest),
|
||||
}
|
||||
} ), state );
|
||||
console.log(state);
|
||||
return state;
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
dux.setMutation('removeWeapon', id => state => [
|
||||
@ -32,13 +46,14 @@ dux.setMutation('removeWeapon', id => state => [
|
||||
]);
|
||||
|
||||
dux.setMutation('addWeapon', type => state => {
|
||||
const initial = weaponTypes.find(w => w.type === type ).initial;
|
||||
return [
|
||||
...state,
|
||||
{
|
||||
id: state.length === 0 ? 1 : state[state.length -1]+1,
|
||||
type,
|
||||
reqs: weaponReqs({type}),
|
||||
...weaponTypes.find(w => w.type === type ).initial,
|
||||
reqs: weaponReqs({type,...initial}),
|
||||
...initial,
|
||||
}
|
||||
]
|
||||
});
|
||||
@ -54,21 +69,30 @@ function weaponReqs(weapon) {
|
||||
return reqs;
|
||||
}
|
||||
|
||||
function beam_cost_mass({weapon_class, arcs}) {
|
||||
const isBroadside = arcs => {
|
||||
if( arcs.length !== 4 ) return false;
|
||||
|
||||
// that'd be A or F
|
||||
return !arcs.some( a => a.length === 1 );
|
||||
}
|
||||
|
||||
function beam_cost_mass({weaponClass, arcs}) {
|
||||
console.log({weaponClass,arcs})
|
||||
let mass;
|
||||
if( weapon_class === 1 ) {
|
||||
|
||||
if( weaponClass === 1 ) {
|
||||
mass = 1;
|
||||
}
|
||||
|
||||
if( weapon_class == 2 ) {
|
||||
if( weaponClass === 2 ) {
|
||||
mass = 2 + (arcs.length > 3 ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
if( weapon_class == 3 ) {
|
||||
if( weaponClass == 3 ) {
|
||||
mass = 4;
|
||||
|
||||
if( is_broadside(arcs) ) {
|
||||
if( isBroadside(arcs) ) {
|
||||
mass += 2;
|
||||
}
|
||||
else {
|
||||
@ -76,10 +100,10 @@ function beam_cost_mass({weapon_class, arcs}) {
|
||||
}
|
||||
}
|
||||
|
||||
if( weapon_class == 4 ) {
|
||||
if( weaponClass == 4 ) {
|
||||
mass = 8;
|
||||
|
||||
if( is_broadside(arcs) ) {
|
||||
if( isBroadside(arcs) ) {
|
||||
mass += 4;
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user