Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
charredUtensil committed Jun 25, 2024
1 parent 02bdae6 commit 5407e5d
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 88 deletions.
10 changes: 6 additions & 4 deletions src/core/architects/nomads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
TUNNEL_SCOUT,
Vehicle,
} from "../models/vehicle";
import { Loadout } from "../models/miner";
import { Loadout, Miner } from "../models/miner";
import { filterTruthy, pairEach } from "../common/utils";
import { plotLine } from "../common/geometry";
import { gFoundHq } from "./established_hq";
Expand Down Expand Up @@ -126,6 +126,7 @@ const BASE: PartialArchitect<Metadata> = {
template,
});
});
const placedMiners: Miner[] = [];
for (let i = 0; i < plan.metadata.minersCount; i++) {
const driving = placedVehicles[i] as Vehicle | undefined;
const pos = driving ? position(driving) : randomlyInTile({ x, y, rng });
Expand All @@ -141,12 +142,13 @@ const BASE: PartialArchitect<Metadata> = {
if (placedVehicles[i]) {
placedVehicles[i] = { ...placedVehicles[i], driverId: miner.id };
}
miners.push(miner);
placedMiners.push(miner);
}
vehicles.push(...placedVehicles);
miners.push(...placedMiners);
setCameraPosition(position({
x: miners[0].x,
y: miners[0].y,
x: placedMiners[0].x,
y: placedMiners[0].y,
aimedAt: plan.path.baseplates[0].center,
pitch: Math.PI / 4,
}));
Expand Down
4 changes: 3 additions & 1 deletion src/core/lore/graphs/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ const ORDERS = phraseGraph<State>(({ pg, state, start, end, cut, skip }) => {
"and",
"and use it to",
", and when you are ready,",
state("hasMonsters")
pg(
state("hasMonsters").then(state("hasSlugs"), skip),
state("hasSlugs"))
.then("and keep it safe.", "and make sure it is heavily defended.")
.then("Then,", we_need.then(cut)),
),
Expand Down
1 change: 1 addition & 0 deletions src/webui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import styles from "./App.module.scss";
import { TILE_STYLE_VARS } from "../core/models/tiles";

const MAP_OVERLAY_BUTTONS: readonly { of: MapOverlay; label: String }[] = [
{ of: "overview", label: "Overview" },
{ of: "tiles", label: "Tiles" },
{ of: "crystals", label: "Crystals" },
{ of: "ore", label: "Ore" },
Expand Down
13 changes: 13 additions & 0 deletions src/webui/components/map_preview/entity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { Miner } from "../../../core/models/miner";
import { radsToDegrees } from "../../../core/common/geometry";
import styles from "./style.module.scss";
import { Vehicle } from "../../../core/models/vehicle";
import { MapOverlay } from ".";
import { Cavern } from "../../../core/models/cavern";

const SCALE = 6;

type Params = {
mapOverlay: MapOverlay;
cavern: Cavern;
building?: true;
creature?: true;
miner?: true;
Expand All @@ -34,11 +38,20 @@ type Params = {

export default function EntityPreview({
entity,
cavern,
mapOverlay,
building,
creature,
miner,
vehicle,
}: Params) {
if (mapOverlay === "overview") {
if (!cavern.discoveryZones?.get(Math.floor(entity.x), Math.floor(entity.y))?.openOnSpawn) {
return null
}
} else if (mapOverlay !== "entities") {
return null;
}
if (building) {
}
const v = building ? SCALE / 3 : SCALE / 4;
Expand Down
69 changes: 34 additions & 35 deletions src/webui/components/map_preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ export type MapOverlay =
| "landslides"
| "lore"
| "ore"
| "overview"
| "tiles"
| null;

function getTransform(cavern: Cavern, mapOverlay: MapOverlay) {
if (mapOverlay !== "overview" || !cavern.cameraPosition) {
return undefined;
}
const {x, y, yaw, pitch} = cavern.cameraPosition;
return `scale(5) rotate3d(1, 0, 0, ${pitch}rad) rotate(${Math.PI / -2 - yaw}rad) translate(${-x * 6}px, ${-y * 6}px)`
}

export default function CavernPreview({
cavern,
error,
Expand All @@ -39,26 +48,20 @@ export default function CavernPreview({
showPearls: boolean;
}) {
const holder = createRef<HTMLDivElement>();
const [width, setWidth] = useState(600);
const [height, setHeight] = useState(600);
useLayoutEffect(() => {
const onResize = () => {
if (holder.current) {
setWidth(holder.current.clientWidth);
setHeight(holder.current.clientHeight);
}
};
onResize();
window.addEventListener("resize", onResize);
return () => window.removeEventListener("resize", onResize);
}, [holder]);
const size = cavern.context.targetSize * 2 * 6;

return (
<div ref={holder} className={styles.cavernPreview}>
<svg
className={styles.map}
style={{ width: width, height: height }}
viewBox={`${width / -2} ${height / -2} ${width} ${height}`}
style={{
top: `calc(50% - ${size / 2}px)`,
left: `calc(50% - ${size / 2}px)`,
width: size,
height: size,
transform: getTransform(cavern, mapOverlay)
}}
viewBox={`${size / -2} ${size / -2} ${size} ${size}`}
xmlns="http://www.w3.org/2000/svg"
>
{<TilesPreview cavern={cavern} mapOverlay={mapOverlay} />}
Expand All @@ -71,6 +74,22 @@ export default function CavernPreview({
))}
{showOutlines &&
cavern.paths?.map((pa) => <PathPreview key={pa.id} path={pa} />)}
{cavern.buildings?.map((b, i) => (
<EntityPreview key={i} entity={b} mapOverlay={mapOverlay} cavern={cavern} building />
))}
{cavern.creatures?.map((c) => (
<EntityPreview key={c.id} entity={c} mapOverlay={mapOverlay} cavern={cavern} creature />
))}
{cavern.miners?.map((m) => (
<EntityPreview key={m.id} entity={m} mapOverlay={mapOverlay} cavern={cavern} miner />
))}
{cavern.vehicles?.map((v) => (
<EntityPreview key={v.id} entity={v} mapOverlay={mapOverlay} cavern={cavern} vehicle />
))}
{mapOverlay === "discovery" &&
cavern.openCaveFlags?.map((_, x, y) => (
<OpenCaveFlagPreview key={`${x},${y}`} x={x} y={y} />
))}
{showOutlines &&
cavern.plans?.map((pl) => <PlanPreview key={pl.id} plan={pl} />)}
{showPearls &&
Expand All @@ -93,26 +112,6 @@ export default function CavernPreview({
pearl={"innerPearl"}
/>
))}
{mapOverlay === "entities" && (
<>
{cavern.buildings?.map((b, i) => (
<EntityPreview key={i} entity={b} building />
))}
{cavern.creatures?.map((c) => (
<EntityPreview key={c.id} entity={c} creature />
))}
{cavern.miners?.map((m) => (
<EntityPreview key={m.id} entity={m} miner />
))}
{cavern.vehicles?.map((v) => (
<EntityPreview key={v.id} entity={v} vehicle />
))}
</>
)}
{mapOverlay === "discovery" &&
cavern.openCaveFlags?.map((_, x, y) => (
<OpenCaveFlagPreview key={`${x},${y}`} x={x} y={y} />
))}
</svg>
<Stats cavern={cavern} mapOverlay={mapOverlay} />
{error && <div className={styles.error}>{error.message}</div>}
Expand Down
43 changes: 12 additions & 31 deletions src/webui/components/map_preview/plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@ function caveWithOneBaseplate(plan: Partial<Plan>) {
cy={y * SCALE}
r={drawRadius(plan.pearlRadius!) * SCALE}
/>
<text className={styles.fg} x={x * SCALE} y={y * SCALE}>
{plan.id}
<text
className={styles.fg}
x={x * SCALE}
y={y * SCALE}
>
{plan.architect?.name} {plan.id}
</text>
{plan.architect && (
<text
className={`${styles.fg} ${styles.architect}`}
x={x * SCALE}
y={y * SCALE}
>
{plan.architect.name}
</text>
)}
</>
);
}
Expand Down Expand Up @@ -110,21 +105,12 @@ function caveWithTwoBaseplates(plan: Partial<Plan>) {
<>
<path className={styles.bg} d={dWrapping(a, b)} />
<text
className={`${styles.fg} ${styles.id}`}
className={styles.fg}
x={x0 * SCALE}
y={y0 * SCALE}
>
{plan.id}
{plan.architect?.name} {plan.id}
</text>
{plan.architect && (
<text
className={`${styles.fg} ${styles.architect}`}
x={x0 * SCALE}
y={y0 * SCALE}
>
{plan.architect.name}
</text>
)}
</>
);
}
Expand All @@ -145,19 +131,14 @@ function hall(plan: Partial<Plan>) {
d={d}
fill="none"
strokeWidth={drawRadius(plan.pearlRadius!) * 2 * SCALE}
/>
>
<title>{plan.architect?.name} {plan.id}</title>
</path>
<text className={styles.fg}>
<textPath href={`#plan${plan.id}`} startOffset="50%">
{plan.id}
{plan.architect?.name} {plan.id}
</textPath>
</text>
{plan.architect && (
<text className={`${styles.fg} ${styles.architect}`}>
<textPath href={`#plan${plan.id}`} startOffset="50%">
{plan.architect.name}
</textPath>
</text>
)}
</>
);
}
Expand Down
22 changes: 5 additions & 17 deletions src/webui/components/map_preview/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

.map {
position: absolute;
left: 0;
top: 0;

.baseplate {
font-family: var(--font-tiny);
Expand Down Expand Up @@ -62,23 +60,17 @@
opacity: var(--fg-opacity);
font-family: var(--font-tiny);
font-size: 12px;
baseline-shift: 4px;
}
}

.plan {
--color-bg: #444444;
--color-fg: white;

&.caveKind {
.bg {
stroke: var(--color-bg);
stroke-width: 2px;
fill: none;
}
.fg {
font-size: 18px;
}
&.caveKind .bg {
stroke: var(--color-bg);
stroke-width: 2px;
fill: none;
}
&.hallKind .bg {
stroke: var(--color-bg);
Expand All @@ -95,13 +87,9 @@
text-anchor: middle;
fill: var(--color-fg);
font-family: "Silkscreen";
font-size: 12px;
font-size: 8px;
stroke: black;
stroke-width: 0.2;
&.architect {
font-size: 8px;
baseline-shift: -100%;
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/webui/components/map_preview/tiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,22 @@ function getFill(
y: number,
): string | null {
switch (mapOverlay) {
case "overview":
{
for (let ox = -1; ox <= 1; ox++) {
for (let oy = -1; oy <= 1; oy++) {
if (cavern.discoveryZones?.get(x + ox, y + oy)?.openOnSpawn) {
return t.inspectColor;
}
}
}
return null;
}
case "entities":
if (t === Tile.FOUNDATION) {
return t.inspectColor;
}
break;
case "tiles":
return t.inspectColor;
case "crystals":
Expand Down

0 comments on commit 5407e5d

Please sign in to comment.