mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-03-25 00:27:24 +01:00
style: improve code formatting in draw-markers.ts for better readability
This commit is contained in:
parent
74952a1071
commit
df56e188db
1 changed files with 19 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import {rn} from "../utils";
|
import { rn } from "../utils";
|
||||||
|
|
||||||
interface Marker {
|
interface Marker {
|
||||||
i: number;
|
i: number;
|
||||||
|
|
@ -22,7 +22,7 @@ declare global {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PinShapeFunction = (fill: string, stroke: string) => string;
|
type PinShapeFunction = (fill: string, stroke: string) => string;
|
||||||
type PinShapes = {[key: string]: PinShapeFunction};
|
type PinShapes = { [key: string]: PinShapeFunction };
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const pinShapes: PinShapes = {
|
const pinShapes: PinShapes = {
|
||||||
|
|
@ -59,7 +59,19 @@ const getPin = (shape = "bubble", fill = "#fff", stroke = "#000"): string => {
|
||||||
};
|
};
|
||||||
|
|
||||||
function markerRenderer(marker: Marker, rescale = 1): string {
|
function markerRenderer(marker: Marker, rescale = 1): string {
|
||||||
const {i, icon, x, y, dx = 50, dy = 50, px = 12, size = 30, pin, fill, stroke} = marker;
|
const {
|
||||||
|
i,
|
||||||
|
icon,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
dx = 50,
|
||||||
|
dy = 50,
|
||||||
|
px = 12,
|
||||||
|
size = 30,
|
||||||
|
pin,
|
||||||
|
fill,
|
||||||
|
stroke,
|
||||||
|
} = marker;
|
||||||
const id = `marker${i}`;
|
const id = `marker${i}`;
|
||||||
const zoomSize = rescale ? Math.max(rn(size / 5 + 24 / scale, 2), 1) : size;
|
const zoomSize = rescale ? Math.max(rn(size / 5 + 24 / scale, 2), 1) : size;
|
||||||
const viewX = rn(x - zoomSize / 2, 1);
|
const viewX = rn(x - zoomSize / 2, 1);
|
||||||
|
|
@ -81,8 +93,10 @@ const markersRenderer = (): void => {
|
||||||
const rescale = +markers.attr("rescale");
|
const rescale = +markers.attr("rescale");
|
||||||
const pinned = +markers.attr("pinned");
|
const pinned = +markers.attr("pinned");
|
||||||
|
|
||||||
const markersData: Marker[] = pinned ? pack.markers.filter((m: Marker) => m.pinned) : pack.markers;
|
const markersData: Marker[] = pinned
|
||||||
const html = markersData.map(marker => markerRenderer(marker, rescale));
|
? pack.markers.filter((m: Marker) => m.pinned)
|
||||||
|
: pack.markers;
|
||||||
|
const html = markersData.map((marker) => markerRenderer(marker, rescale));
|
||||||
markers.html(html.join(""));
|
markers.html(html.join(""));
|
||||||
|
|
||||||
TIME && console.timeEnd("drawMarkers");
|
TIME && console.timeEnd("drawMarkers");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue