Skip to content

Commit

Permalink
prettier and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
charredUtensil committed Jul 17, 2024
1 parent b6c61e1 commit d6824bd
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 98 deletions.
36 changes: 20 additions & 16 deletions src/webui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ const MAP_OVERLAY_BUTTONS: readonly {
label: String;
enabled: (cavern: Cavern | undefined) => boolean;
}[] = [
{ of: "overview", label: "Overview", enabled: c => true},
{ of: "tiles", label: "Tiles", enabled: c => !!c?.tiles},
{ of: "crystals", label: "Crystals", enabled: c => !!c?.crystals},
{ of: "ore", label: "Ore", enabled: c => !!c?.ore},
{ of: "entities", label: "Entities", enabled: c => !!c?.buildings},
{ of: "discovery", label: "Discovery", enabled: c => !!c?.discoveryZones},
{ of: "height", label: "Height", enabled: c => !!c?.height},
{ of: "landslides", label: "Landslides", enabled: c => !!c?.landslides},
{ of: "erosion", label: "Erosion", enabled: c => !!c?.erosion},
{ of: "oxygen", label: "Oxygen", enabled: c => c?.oxygen !== undefined},
{ of: "lore", label: "Lore", enabled: c => !!c?.lore},
{ of: "about", label: "About", enabled: c => true},
{ of: "overview", label: "Overview", enabled: (c) => true },
{ of: "tiles", label: "Tiles", enabled: (c) => !!c?.tiles },
{ of: "crystals", label: "Crystals", enabled: (c) => !!c?.crystals },
{ of: "ore", label: "Ore", enabled: (c) => !!c?.ore },
{ of: "entities", label: "Entities", enabled: (c) => !!c?.buildings },
{ of: "discovery", label: "Discovery", enabled: (c) => !!c?.discoveryZones },
{ of: "height", label: "Height", enabled: (c) => !!c?.height },
{ of: "landslides", label: "Landslides", enabled: (c) => !!c?.landslides },
{ of: "erosion", label: "Erosion", enabled: (c) => !!c?.erosion },
{ of: "oxygen", label: "Oxygen", enabled: (c) => c?.oxygen !== undefined },
{ of: "lore", label: "Lore", enabled: (c) => !!c?.lore },
{ of: "about", label: "About", enabled: (c) => true },
];

function getDownloadLink(serializedData: string) {
Expand Down Expand Up @@ -119,9 +119,7 @@ function App() {
}, [state]);

return (
<div
className={`${styles.App} ${styles[`${biome}Biome`]}`}
>
<div className={`${styles.App} ${styles[`${biome}Biome`]}`}>
<div className={styles.settingsPanel}>
<CavernContextInput dispatchState={dispatchState} />
</div>
Expand Down Expand Up @@ -193,7 +191,13 @@ function App() {
{MAP_OVERLAY_BUTTONS.map(({ of, label, enabled }) => (
<button
key={of}
className={mapOverlay === of ? styles.active : (enabled(state.cavern) ? styles.inactive : styles.disabled)}
className={
mapOverlay === of
? styles.active
: enabled(state.cavern)
? styles.inactive
: styles.disabled
}
onClick={() => setMapOverlay((v) => (v === of ? "overview" : of))}
>
{label}
Expand Down
66 changes: 39 additions & 27 deletions src/webui/components/map_preview/plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SCALE = 6;
function getGClassName(plan: Partial<Plan>) {
const r = [styles.plan];
plan.kind && r.push(styles[`${plan.kind}Kind`]);
plan.path?.kind && r.push(styles[`${plan.path.kind}PathKind`])
plan.path?.kind && r.push(styles[`${plan.path.kind}PathKind`]);
plan.fluid && r.push(styles[`fluid${plan.fluid.id}`]);
plan.hasErosion && r.push("hasErosion");
return r.join(" ");
Expand Down Expand Up @@ -95,10 +95,7 @@ function caveWithTwoBaseplates(plan: Partial<Plan>) {
};
});

const [x0, y0] = plan.path!.baseplates[0].center;
return (
<path className={styles.bg} d={dWrapping(a, b)} />
);
return <path className={styles.bg} d={dWrapping(a, b)} />;
}

function hall(plan: Partial<Plan>) {
Expand Down Expand Up @@ -126,56 +123,71 @@ export default function PlansPreview({ cavern }: { cavern: Cavern }) {
}

const planCoords: Point[] = [];
cavern.plans.forEach(plan => {
cavern.plans.forEach((plan) => {
const bp = plan.path.baseplates;

const i = Math.floor((bp.length - 1) / 2);
const j = Math.floor((bp.length) / 2);
const j = Math.floor(bp.length / 2);
if (i === j) {
planCoords[plan.id] = bp[i].center;
} else {
const [ix, iy] = bp[i].center;
const [jx, jy] = bp[j].center;
planCoords[plan.id] = [(ix + jx) / 2, (iy + jy) / 2];
}
})
});

const right = [...cavern.plans];
right.sort((a, b) => planCoords[b.id][0] - planCoords[a.id][0]);
const left = right.splice(Math.floor(right.length / 2));
right.sort((a, b) => planCoords[a.id][1] - planCoords[b.id][1]);
left.sort((a, b) => (planCoords[a.id][1] - planCoords[b.id][1]) || (planCoords[a.id][0] - planCoords[b.id][0]));
left.sort(
(a, b) =>
planCoords[a.id][1] - planCoords[b.id][1] ||
planCoords[a.id][0] - planCoords[b.id][0],
);

function drawLabels(plans: NonNullable<Cavern['plans']>, sign: -1 | 1, className: string): ReactNode {
function drawLabels(
plans: NonNullable<Cavern["plans"]>,
sign: -1 | 1,
className: string,
): ReactNode {
let py = -Infinity;
return plans.map((plan, i) => {
const px = SCALE * planCoords[plan.id][0];
py = Math.max(SCALE * planCoords[plan.id][1], py + 4);
const lx = (SCALE * cavern.context.targetSize / 2 + 50) * sign;
const ly = SCALE * cavern.context.targetSize * ((i + 1) / plans.length - 0.5);
const bx = lx - Math.abs(py - ly) * 0.56 * sign
const lx = ((SCALE * cavern.context.targetSize) / 2 + 50) * sign;
const ly =
SCALE * cavern.context.targetSize * ((i + 1) / plans.length - 0.5);
const bx = lx - Math.abs(py - ly) * 0.56 * sign;
const d = filterTruthy([
`M ${lx + 25 * sign} ${ly}`,
`L ${lx} ${ly}`,
(bx * sign > px * sign) && `L ${bx} ${py}`,
bx * sign > px * sign && `L ${bx} ${py}`,
`L ${px} ${py}`,
]).join('');
return (<g key={plan.id} className={`${className} ${getGClassName(plan)}`}>
<path className={styles.pointer} d={d} />
<text className={styles.label} x={lx + 25 * sign} y={ly}>
{'architect' in plan
? <>{plan.architect.name}{!plan.hops.length && '*'} {plan.id}</>
: <>{plan.id}</>
}
</text>
</g>);
]).join("");
return (
<g key={plan.id} className={`${className} ${getGClassName(plan)}`}>
<path className={styles.pointer} d={d} />
<text className={styles.label} x={lx + 25 * sign} y={ly}>
{"architect" in plan ? (
<>
{plan.architect.name}
{!plan.hops.length && "*"} {plan.id}
</>
) : (
<>{plan.id}</>
)}
</text>
</g>
);
});
}

return (
<>
{cavern.plans.map(plan => {
if ('pearlRadius' in plan) {
{cavern.plans.map((plan) => {
if ("pearlRadius" in plan) {
return (
<g key={plan.id} className={getGClassName(plan)}>
{plan.kind === "cave"
Expand All @@ -194,5 +206,5 @@ export default function PlansPreview({ cavern }: { cavern: Cavern }) {
{drawLabels(left, -1, styles.left)}
{drawLabels(right, 1, styles.right)}
</>
)
);
}
29 changes: 15 additions & 14 deletions src/webui/components/map_preview/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
height: 100%;

--pvw-bpak: #222222;
--pvw-bpck: #2D004B;
--pvw-bpck: #2d004b;
--pvw-bphk: #166921;
--pvw-pathspan: yellow;
--pvw-pathaux: #24b136;
--pvw-entfriend: yellow;
--pvw-entenemy: red;
--pvw-dfluid: #080022;
--pvw-dfloor: #180032;
--pvw-dwall: #2D004B;
--pvw-dwall: #2d004b;
--pvw-scale0: #555544;
--pvw-scale1: #777744;
--pvw-scale2: #999944;
Expand All @@ -22,23 +22,23 @@
--pvw-scale5: #ffff44;
--pvw-scale6: #ffff66;
--pvw-scale7: #ffff88;
--pvw-tile1: #2D004B;
--pvw-tile1: #2d004b;
--pvw-tile2: #180032;
--pvw-tile3: #180032;
--pvw-tile4: #180032;
--pvw-tile5: #180032;
--pvw-tile6: #FF5A00;
--pvw-tile11: #002FB5;
--pvw-tile6: #ff5a00;
--pvw-tile11: #002fb5;
--pvw-tile12: #166921;
--pvw-tile14: #BFBFBF;
--pvw-tile24: #9D9B00;
--pvw-tile26: #AD59EF;
--pvw-tile30: #943CC3;
--pvw-tile34: #731CAD;
--pvw-tile14: #bfbfbf;
--pvw-tile24: #9d9b00;
--pvw-tile26: #ad59ef;
--pvw-tile30: #943cc3;
--pvw-tile34: #731cad;
--pvw-tile38: #800080;
--pvw-tile42: #B5FF00;
--pvw-tile46: #9C4108;
--pvw-tile50: #FFFF00;
--pvw-tile42: #b5ff00;
--pvw-tile46: #9c4108;
--pvw-tile50: #ffff00;
--pvw-tile60: #180032;
--pvw-tile61: #180032;
--pvw-tile62: #180032;
Expand Down Expand Up @@ -191,7 +191,8 @@
fill: none;
}

&.oly-entities, &.oly-tiles {
&.oly-entities,
&.oly-tiles {
.bounds {
fill: var(--pvw-tile38);
}
Expand Down
78 changes: 37 additions & 41 deletions src/webui/components/map_preview/tiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styles from "./style.module.scss";

const SCALE = 6;

const SCALE_COLORS = 8
const SCALE_COLORS = 8;

const MAX_COOLDOWN = {
landslides: 300,
Expand All @@ -19,13 +19,13 @@ function tk(t: Tile) {

function dk(t: Tile) {
if (t === Tile.WATER || t === Tile.LAVA) {
return 'dfluid';
return "dfluid";
}
return t.isWall ? 'dwall' : 'dfloor';
return t.isWall ? "dwall" : "dfloor";
}

function sk(s: number) {
return `scale${Math.min(Math.floor(s), SCALE_COLORS - 1)}`
return `scale${Math.min(Math.floor(s), SCALE_COLORS - 1)}`;
}

function getFill(
Expand Down Expand Up @@ -53,36 +53,33 @@ function getFill(
return dk(t);
case "tiles":
return tk(t);
case "crystals":
{
if (t.crystalYield > 0) {
return tk(t);
}
const c = cavern.crystals?.get(x, y) ?? 0;
if (c > 0) {
return sk(c - 1);
}
return dk(t)
case "crystals": {
if (t.crystalYield > 0) {
return tk(t);
}
case "ore":
{
if (t.oreYield > 4) {
return tk(t);
}
const o = (cavern.ore?.get(x, y) ?? 0) + t.oreYield;
if (o > 0) {
return sk(o - 1);
}
return dk(t)
const c = cavern.crystals?.get(x, y) ?? 0;
if (c > 0) {
return sk(c - 1);
}
case "discovery":
{
const dz = cavern.discoveryZones?.get(x, y);
if (dz) {
return dz.openOnSpawn ? 'disco0' : 'disco1';
}
return dk(t);
return dk(t);
}
case "ore": {
if (t.oreYield > 4) {
return tk(t);
}
const o = (cavern.ore?.get(x, y) ?? 0) + t.oreYield;
if (o > 0) {
return sk(o - 1);
}
return dk(t);
}
case "discovery": {
const dz = cavern.discoveryZones?.get(x, y);
if (dz) {
return dz.openOnSpawn ? "disco0" : "disco1";
}
return dk(t);
}
case "erosion":
if (t === Tile.WATER || t === Tile.LAVA) {
return tk(t);
Expand All @@ -97,17 +94,16 @@ function getFill(
);
}
return dk(t);
case "oxygen":
{
const aeration = cavern.aerationLog?.get(x, y);
if (!aeration) {
return dk(t);
}
if (cavern.crystals?.get(x, y)) {
return 'oxhc';
}
return t.isWall ? tk(t) : 'oxex';
case "oxygen": {
const aeration = cavern.aerationLog?.get(x, y);
if (!aeration) {
return dk(t);
}
if (cavern.crystals?.get(x, y)) {
return "oxhc";
}
return t.isWall ? tk(t) : "oxex";
}
}
return null;
}
Expand Down

0 comments on commit d6824bd

Please sign in to comment.