Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | <svelte:options customElement="st-system" /> <script lang="ts"> import { onMount } from "svelte"; import type { Waypoint } from "$models/waypoint"; import Loader from "$ui/loader/src/loader.svelte"; import Button from "$ui/button/src/button.svelte"; // eslint-disable-next-line import/no-mutable-exports export let waypoint: Partial<Waypoint>; let systemWaypoints: Waypoint[] = []; let isLoading = true; function isShipyard(waypointToCheck: Partial<Waypoint>) { return waypointToCheck.traits.map((trait) => trait.name).includes("Shipyard"); } async function availableShips(waypointShips: Partial<Waypoint>) { const options = { headers: { // eslint-disable-next-line sonarjs/no-duplicate-string "Content-Type": "application/json", Authorization: `Bearer ${import.meta.env.VITE_API_TOKEN}`, }, }; const result = await fetch( `${import.meta.env.VITE_API_URL}/systems/${waypointShips.system}/waypoints/${ waypointShips.symbol }/shipyard`, options, ); const { data } = await result.json(); return data.shipTypes; } onMount(async () => { const options = { headers: { // eslint-disable-next-line sonarjs/no-duplicate-string "Content-Type": "application/json", Authorization: `Bearer ${import.meta.env.VITE_API_TOKEN}`, }, }; const result = await fetch(`${import.meta.env.VITE_API_URL}/systems/${waypoint.system}/waypoints`, options); const { data } = await result.json(); systemWaypoints = await Promise.all( data.map(async (systemWaypoint: Waypoint) => { const shipTypes = isShipyard({ traits: systemWaypoint.traits }) ? await availableShips({ symbol: systemWaypoint.symbol, system: systemWaypoint.systemSymbol }) : []; return { symbol: systemWaypoint.symbol, system: systemWaypoint.systemSymbol, faction: systemWaypoint.faction, type: systemWaypoint.type, coordinates: { x: systemWaypoint.x, y: systemWaypoint.y, }, orbitals: systemWaypoint.orbitals.map((orbital) => { return { symbol: orbital.symbol, }; }), traits: systemWaypoint.traits, shipTypes, }; }), ); isLoading = false; }); async function purchaseShip(location: Partial<Waypoint>, type: string) { // eslint-disable-next-line no-console console.log(`purchase ship ${type} at ${location.symbol}`); const options = { method: "POST", headers: { // eslint-disable-next-line sonarjs/no-duplicate-string "Content-Type": "application/json", Authorization: `Bearer ${import.meta.env.VITE_API_TOKEN}`, }, body: JSON.stringify({ shipType: type, waypointSymbol: location.symbol, }), }; await fetch(`${import.meta.env.VITE_API_URL}/my/ships`, options) .then((response) => response.json()) .then((response) => { // eslint-disable-next-line no-console console.log(response); }) // eslint-disable-next-line no-console .catch((error) => console.error(error)); return null; } </script> {#if isLoading} <Loader /> {:else} <h2>System</h2> <table> <thead> <tr> <th>Symbol</th> <th>Faction</th> <th>Type</th> <th>Coordinates</th> <th>Traits</th> <th>Available ships</th> </tr> </thead> <tbody> {#each systemWaypoints as systemWaypoint} <tr> <td>{systemWaypoint.symbol}</td> <td>{systemWaypoint.faction.symbol}</td> <td>{systemWaypoint.type}</td> <td>{systemWaypoint.coordinates.x}, {systemWaypoint.coordinates.y}</td> <td> <ul> {#each systemWaypoint.traits as trait} <li>{trait.name}</li> {/each} </ul> </td> <td> {#if systemWaypoint.shipTypes.length > 0} <ul> {#each systemWaypoint.shipTypes as ship} <li> {ship.type} </li> <Button label="purchase" on:buttonClicked="{purchaseShip(systemWaypoint, ship.type)}" /> {/each} </ul> {:else} No ships available {/if} </td> </tr> {/each} </tbody> </table> {/if} |