aotds-docks/src/lib/components/Output/Print/Hull/Integrity/index.svelte

84 lines
1.6 KiB
Svelte
Raw Normal View History

<div
use:movable={{
disabled: !isMovable,
}}
on:translate={({ detail: translate }) => {
ship.dispatch.setUITransform({ system: "hull", translate });
}}
style:transform={hull?.uiTransform}
>
2022-03-01 17:42:33 +00:00
{#each rows as row, i (i)}
2020-07-29 19:56:19 +00:00
<div class="row">
2022-03-26 16:37:43 +00:00
{#each row as threshold, j (j)}
2020-07-29 19:56:19 +00:00
<div class="cell">
2022-03-26 16:37:43 +00:00
{#if threshold}
2022-04-05 23:58:32 +00:00
<img src="{base}/icons/crew-star.svg" alt="crew loss threshold" />
2020-07-29 19:56:19 +00:00
{/if}
</div>
{/each}
</div>
{/each}
</div>
<script>
import { base } from "$app/paths";
import { getContext } from "svelte";
import { movable } from "../../MainSystems/movable.js";
2022-03-26 16:37:43 +00:00
export let shipMass = 0;
2020-07-29 19:56:19 +00:00
export let rating = 0;
export let advanced = false;
export let hull = {};
export let isMovable = false;
const ship = getContext("ship");
2020-07-29 19:56:19 +00:00
let nbr_rows;
$: nbr_rows = advanced ? 3 : 4;
let cells;
$: cells = Array(rating).fill(false);
let dcp;
2022-03-26 16:37:43 +00:00
$: dcp = Math.ceil(shipMass / 20);
2020-07-29 19:56:19 +00:00
2022-03-01 17:42:33 +00:00
$: cells = divide(cells, dcp)
.map((g) => {
g[g.length - 1] = true;
2020-07-29 19:56:19 +00:00
return g;
2022-03-01 17:42:33 +00:00
})
.flat();
2020-07-29 19:56:19 +00:00
function divide(list, divider) {
2022-03-01 17:42:33 +00:00
if (divider <= 1) return [list];
2020-07-29 19:56:19 +00:00
let div = list.length / divider;
const mod = list.length % divider;
2022-03-01 17:42:33 +00:00
if (mod) div++;
2020-07-29 19:56:19 +00:00
2022-03-01 17:42:33 +00:00
return [list.slice(0, div), ...divide(list.slice(div), divider - 1)];
2020-07-29 19:56:19 +00:00
}
let rows = [];
2022-03-01 17:42:33 +00:00
$: rows = divide(cells, nbr_rows);
2020-07-29 19:56:19 +00:00
</script>
<style>
.row {
2022-03-26 16:37:43 +00:00
margin-bottom: 0.5em;
}
2022-03-01 17:42:33 +00:00
.cell {
display: inline-block;
margin-right: 0.5em;
2022-03-26 16:37:43 +00:00
width: 1.5em;
height: 1.5em;
2022-03-01 17:42:33 +00:00
border: 1px solid black;
}
2020-07-29 19:56:19 +00:00
img {
width: 1em;
2022-03-26 16:37:43 +00:00
margin-left: 0.2em;
2020-07-29 19:56:19 +00:00
}
</style>