Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat(city): street network, transit loop, instanced street props, rooftop kits

[._.]/ Adam Eivya1dd4e8cd7aa
diff --git a/client/src/components/city/Borough.jsx b/client/src/components/city/Borough.jsx
index 20e6eb2795..43fd2bbe6a 100644
--- a/client/src/components/city/Borough.jsx
+++ b/client/src/components/city/Borough.jsx
@@ -46,6 +46,7 @@ export default function Borough({ app, position, agentMap, onBuildingClick, play
agentCount={agents.length}
onClick={() => onBuildingClick?.(app)}
playSfx={playSfx}
+ rooftops={(settings?.particleDensity ?? 1) > 0.5}
neonBrightness={neonBrightness}
isProximity={isProximity}
dimmed={dimmed}
diff --git a/client/src/components/city/Building.jsx b/client/src/components/city/Building.jsx
index 65bbcd4612..cc45372e71 100644
--- a/client/src/components/city/Building.jsx
+++ b/client/src/components/city/Building.jsx
@@ -6,6 +6,55 @@ import { useCityPalette } from './CityPaletteContext';
import CityLabel from './CityLabel';
import HolographicPanel from './HolographicPanel';
import BuildingHologram from './BuildingHologram';
+import { computeRooftopKit } from '../../utils/cityRooftops';
+
+// Rooftop fixture geometry/materials are module-scope singletons shared by every
+// building — fixtures are tiny set dressing, so they keep fixed colors (the antenna
+// tip is a red aviation blinker on purpose) instead of per-theme materials.
+const ROOF_METAL_MAT = new THREE.MeshStandardMaterial({ color: '#232d40', roughness: 0.6, metalness: 0.5 });
+const ROOF_TIP_MAT = new THREE.MeshBasicMaterial({ color: '#ff3344', toneMapped: false });
+const ROOF_GEOMS = {
+ antennaMast: new THREE.CylinderGeometry(0.02, 0.035, 1.2, 5),
+ antennaTip: new THREE.SphereGeometry(0.05, 6, 6),
+ tank: new THREE.CylinderGeometry(0.22, 0.22, 0.45, 10),
+ ac: new THREE.BoxGeometry(0.4, 0.22, 0.34),
+ dish: new THREE.SphereGeometry(0.24, 10, 6, 0, Math.PI * 2, 0, Math.PI / 2),
+};
+
+// 0–3 deterministic fixtures (antenna/tank/AC/dish) on the roof, seeded by app name —
+// the same determinism as the window textures, so a building keeps its roof forever.
+function RooftopKit({ name, width, y }) {
+ const kit = useMemo(() => computeRooftopKit(name, width), [name, width]);
+ if (kit.length === 0) return null;
+ return (
+ <group position={[0, y, 0]}>
+ {kit.map((f, i) => (
+ <group key={i} position={[f.x, 0, f.z]} rotation={[0, f.rotation, 0]} scale={f.scale}>
+ {f.type === 'antenna' && (
+ <>
+ <mesh geometry={ROOF_GEOMS.antennaMast} material={ROOF_METAL_MAT} position={[0, 0.6, 0]} />
+ <mesh geometry={ROOF_GEOMS.antennaTip} material={ROOF_TIP_MAT} position={[0, 1.22, 0]} />
+ </>
+ )}
+ {f.type === 'tank' && (
+ <mesh geometry={ROOF_GEOMS.tank} material={ROOF_METAL_MAT} position={[0, 0.225, 0]} />
+ )}
+ {f.type === 'ac' && (
+ <mesh geometry={ROOF_GEOMS.ac} material={ROOF_METAL_MAT} position={[0, 0.11, 0]} />
+ )}
+ {f.type === 'dish' && (
+ <mesh
+ geometry={ROOF_GEOMS.dish}
+ material={ROOF_METAL_MAT}
+ position={[0, 0.12, 0]}
+ rotation={[Math.PI / 5, 0, 0]}
+ />
+ )}
+ </group>
+ ))}
+ </group>
+ );
+}
// 7x7 pixel art icons drawn on building faces via lit office windows
const PIXEL_ICONS = [
@@ -343,7 +392,7 @@ function FloorLightBands({ width, depth, height, color, accentColor, seed, dimMu
);
}
-export default function Building({ app, position, agentCount, onClick, playSfx, neonBrightness = 1.2, isProximity = false, dimmed = false, dayMix = 0, playback = false, transitionState = null, onExited }) {
+export default function Building({ app, position, agentCount, onClick, playSfx, neonBrightness = 1.2, isProximity = false, dimmed = false, dayMix = 0, playback = false, transitionState = null, onExited, rooftops = true }) {
const meshRef = useRef();
const glowRef = useRef();
const haloRef = useRef();
@@ -537,6 +586,9 @@ export default function Building({ app, position, agentCount, onClick, playSfx,
)}
</mesh>
+ {/* Rooftop fixtures — deterministic per app name; off on the low preset */}
+ {rooftops && <RooftopKit name={app.name || app.id} width={width} y={height} />}
+
{/* Glow halo wireframe - slightly larger than building (night only) */}
{!app.archived && !daytime && (
<lineSegments ref={haloRef} position={[0, height / 2, 0]}>
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index 16252ccda9..c4573aa2c4 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -39,6 +39,9 @@ import CitySky from './CitySky';
import CityGalaxySky from './CityGalaxySky';
import CityLandscape from './CityLandscape';
import CityWater from './CityWater';
+import CityStreets from './CityStreets';
+import CityStreetProps from './CityStreetProps';
+import CityTransitLoop from './CityTransitLoop';
import CityEnergyOverlay from './CityEnergyOverlay';
import PlayerController from './PlayerController';
import CameraTransition from './CameraTransition';
@@ -226,6 +229,9 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
<CityJiraDistrict jiraTickets={jiraTickets} settings={settings} />
<CityAiCore aiActivity={aiActivity} positions={positions} apps={apps} settings={settings} />
<CityGround settings={settings} />
+ <CityStreets settings={settings} />
+ <CityStreetProps settings={settings} />
+ <CityTransitLoop settings={settings} />
<BuildingCluster
apps={apps}
diff --git a/client/src/components/city/CityStreetProps.jsx b/client/src/components/city/CityStreetProps.jsx
new file mode 100644
index 0000000000..98b06e4e83
--- /dev/null
+++ b/client/src/components/city/CityStreetProps.jsx
@@ -0,0 +1,118 @@
+import { useMemo, useLayoutEffect, useRef } from 'react';
+import * as THREE from 'three';
+import { cityDayMix, mixHex } from './cityConstants';
+import { useCityPalette } from './CityPaletteContext';
+import { computeStreets, computeStreetProps } from '../../utils/cityPlan';
+
+// Street furniture from the master plan: lamp posts pooling light along every street and
+// holo-trees ringing the AI Core plaza. Everything is instanced — four draw calls cover
+// the whole town regardless of lamp count. Lamp light pools are faked with emissive heads
+// + additive ground discs (the city's established no-real-point-lights pattern).
+// Quality-gated: the low preset renders streets only (this component returns null).
+
+const dummy = new THREE.Object3D();
+
+// One instanced mesh whose matrices are written once from `placements`.
+function Instances({ placements, geometryArgs, geometry, position, children }) {
+ const ref = useRef();
+ useLayoutEffect(() => {
+ if (!ref.current) return;
+ placements.forEach((p, i) => {
+ dummy.position.set(p.x + (position?.[0] ?? 0), position?.[1] ?? 0, p.z + (position?.[2] ?? 0));
+ dummy.rotation.set(0, p.seed != null ? (p.seed * 1.7) % (Math.PI * 2) : 0, 0);
+ dummy.scale.setScalar(p.scale ?? 1);
+ dummy.updateMatrix();
+ ref.current.setMatrixAt(i, dummy.matrix);
+ });
+ ref.current.instanceMatrix.needsUpdate = true;
+ }, [placements, position]);
+
+ return (
+ <instancedMesh ref={ref} args={[undefined, undefined, placements.length]} frustumCulled={false}>
+ {geometry === 'cylinder' && <cylinderGeometry args={geometryArgs} />}
+ {geometry === 'sphere' && <sphereGeometry args={geometryArgs} />}
+ {geometry === 'circle' && <circleGeometry args={geometryArgs} />}
+ {geometry === 'icosahedron' && <icosahedronGeometry args={geometryArgs} />}
+ {children}
+ </instancedMesh>
+ );
+}
+
+// The glow discs lie flat — they need their own matrix writer with a rotation.
+function FlatInstances({ placements, radius, children }) {
+ const ref = useRef();
+ useLayoutEffect(() => {
+ if (!ref.current) return;
+ placements.forEach((p, i) => {
+ dummy.position.set(p.x, 0.035, p.z);
+ dummy.rotation.set(-Math.PI / 2, 0, 0);
+ dummy.scale.setScalar(1);
+ dummy.updateMatrix();
+ ref.current.setMatrixAt(i, dummy.matrix);
+ });
+ ref.current.instanceMatrix.needsUpdate = true;
+ }, [placements]);
+ return (
+ <instancedMesh ref={ref} args={[undefined, undefined, placements.length]} frustumCulled={false}>
+ <circleGeometry args={[radius, 16]} />
+ {children}
+ </instancedMesh>
+ );
+}
+
+export default function CityStreetProps({ settings }) {
+ const { accent, tintStructure } = useCityPalette();
+ const dayMix = cityDayMix(settings);
+ const density = settings?.particleDensity ?? 1;
+
+ const props = useMemo(() => {
+ const streets = computeStreets();
+ return computeStreetProps(streets, density);
+ }, [density]);
+
+ // Low preset: streets only, no furniture.
+ if (density <= 0.5 || (props.lamps.length === 0 && props.trees.length === 0)) return null;
+
+ const lampGlow = mixHex(accent, '#fff7d6', 0.35);
+ const headOpacity = 0.95 * (1 - dayMix) + 0.4 * dayMix; // lamps rest by day
+ const poolOpacity = 0.1 * (1 - dayMix); // light pools are a night thing
+
+ return (
+ <group>
+ {/* Lamp poles */}
+ <Instances placements={props.lamps} geometry="cylinder" geometryArgs={[0.05, 0.08, 3.4, 6]} position={[0, 1.7, 0]}>
+ <meshStandardMaterial color={tintStructure('#141b2c')} roughness={0.7} metalness={0.45} />
+ </Instances>
+ {/* Lamp heads — emissive spheres standing in for point lights */}
+ <Instances placements={props.lamps} geometry="sphere" geometryArgs={[0.16, 10, 10]} position={[0, 3.45, 0]}>
+ <meshBasicMaterial color={lampGlow} transparent opacity={headOpacity} toneMapped={false} />
+ </Instances>
+ {/* Faked light pools on the pavement */}
+ {poolOpacity > 0.005 && (
+ <FlatInstances placements={props.lamps} radius={1.7}>
+ <meshBasicMaterial
+ color={lampGlow}
+ transparent
+ opacity={poolOpacity}
+ blending={THREE.AdditiveBlending}
+ depthWrite={false}
+ />
+ </FlatInstances>
+ )}
+ {/* Holo-tree trunks around the plaza */}
+ <Instances placements={props.trees} geometry="cylinder" geometryArgs={[0.07, 0.1, 1.1, 5]} position={[0, 0.55, 0]}>
+ <meshStandardMaterial color={tintStructure('#101626')} roughness={0.8} />
+ </Instances>
+ {/* Holo-tree canopies — wireframe polyhedra, the city's "digital foliage" */}
+ <Instances placements={props.trees} geometry="icosahedron" geometryArgs={[0.8, 1]} position={[0, 1.9, 0]}>
+ <meshBasicMaterial
+ color={mixHex(accent, '#22c55e', 0.45)}
+ wireframe
+ transparent
+ opacity={0.5 * (1 - dayMix) + 0.3 * dayMix}
+ toneMapped={false}
+ />
+ </Instances>
+ </group>
+ );
+}
diff --git a/client/src/components/city/CityStreets.jsx b/client/src/components/city/CityStreets.jsx
new file mode 100644
index 0000000000..89466fd7cd
--- /dev/null
+++ b/client/src/components/city/CityStreets.jsx
@@ -0,0 +1,114 @@
+import { useMemo, useEffect } from 'react';
+import * as THREE from 'three';
+import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
+import { cityDayMix, mixHex, getAccentColor } from './cityConstants';
+import { useCityPalette } from './CityPaletteContext';
+import { computeStreets, PARCELS } from '../../utils/cityPlan';
+
+// The street network from the master plan (cityPlan.js): an octagonal ring road around
+// downtown, spokes out to every district, the grand avenue to the harbor, a plaza
+// sidewalk ring, crosswalk bands, and a faint tinted ground pad under each district.
+// Everything merges into THREE draw calls total (asphalt / neon edge strips / paint),
+// using native merged geometry — never drei <Line> (broken in this three-stdlib combo).
+
+const STRIP_WIDTH = 0.16;
+
+// A flat rectangle at ground level: PlaneGeometry(length × width) rotated into XZ and
+// aimed along `angle` (atan2(dz,dx) convention — rotateY(-angle) maps +x onto it).
+const flatRect = (x, z, length, width, angle, y) => {
+ const geom = new THREE.PlaneGeometry(length, width);
+ geom.rotateX(-Math.PI / 2);
+ geom.rotateY(-angle);
+ geom.translate(x, y, z);
+ return geom;
+};
+
+export default function CityStreets({ settings }) {
+ const { accent, neonAccents } = useCityPalette();
+ const dayMix = cityDayMix(settings);
+
+ const streets = useMemo(() => computeStreets(), []);
+
+ // Asphalt: every street segment, one merged geometry.
+ const asphaltGeom = useMemo(() => {
+ const rects = streets.segments.map((s) => flatRect(s.x, s.z, s.length, s.width, s.angle, 0.02));
+ return mergeGeometries(rects);
+ }, [streets]);
+
+ // Neon edge strips: a thin glowing border along each side of every segment.
+ const stripGeom = useMemo(() => {
+ const rects = [];
+ for (const s of streets.segments) {
+ const off = s.width / 2 + STRIP_WIDTH;
+ const px = -Math.sin(s.angle) * off;
+ const pz = Math.cos(s.angle) * off;
+ rects.push(flatRect(s.x + px, s.z + pz, s.length, STRIP_WIDTH, s.angle, 0.025));
+ rects.push(flatRect(s.x - px, s.z - pz, s.length, STRIP_WIDTH, s.angle, 0.025));
+ }
+ return mergeGeometries(rects);
+ }, [streets]);
+
+ // Paint layer: crosswalk bands + the plaza sidewalk ring + tinted district pads,
+ // vertex-colored so one material covers all of it.
+ const paintGeom = useMemo(() => {
+ const parts = [];
+ const paintColor = new THREE.Color('#aab4c2');
+ const pushColored = (geom, color) => {
+ const count = geom.getAttribute('position').count;
+ const arr = new Float32Array(count * 3);
+ for (let i = 0; i < count; i++) {
+ arr[i * 3] = color.r;
+ arr[i * 3 + 1] = color.g;
+ arr[i * 3 + 2] = color.b;
+ }
+ geom.setAttribute('color', new THREE.BufferAttribute(arr, 3));
+ parts.push(geom);
+ };
+
+ for (const c of streets.crosswalks) {
+ pushColored(flatRect(c.x, c.z, c.length, c.width, c.angle, 0.028), paintColor);
+ }
+
+ const ring = new THREE.RingGeometry(streets.plazaRing.inner, streets.plazaRing.outer, 48);
+ ring.rotateX(-Math.PI / 2);
+ ring.translate(0, 0.018, 0);
+ pushColored(ring, paintColor.clone().multiplyScalar(0.6));
+
+ // District ground pads — a quiet color wash so each quarter reads as a zone.
+ // The pad color is each district's deterministic neon accent (same picker the
+ // buildings use), well under the labels so it never competes with them.
+ for (const [id, parcel] of Object.entries(PARCELS)) {
+ if (parcel.dynamic || parcel.water || id === 'aiCore') continue;
+ const tint = new THREE.Color(getAccentColor({ name: id }, neonAccents)).multiplyScalar(0.5);
+ pushColored(flatRect(parcel.anchor[0], parcel.anchor[2], parcel.w, parcel.d, 0, 0.012), tint);
+ }
+
+ return mergeGeometries(parts);
+ }, [streets, neonAccents]);
+
+ useEffect(() => () => {
+ asphaltGeom.dispose();
+ stripGeom.dispose();
+ paintGeom.dispose();
+ }, [asphaltGeom, stripGeom, paintGeom]);
+
+ // Night: near-black asphalt with accent-glow borders. Day: concrete gray, strips
+ // muted to painted lane edges.
+ const asphaltColor = mixHex('#0b0f18', '#566273', dayMix);
+ const stripOpacity = 0.55 * (1 - dayMix) + 0.25 * dayMix;
+ const paintOpacity = 0.12 + 0.16 * dayMix;
+
+ return (
+ <group>
+ <mesh geometry={asphaltGeom}>
+ <meshStandardMaterial color={asphaltColor} roughness={0.92} metalness={0.08} />
+ </mesh>
+ <mesh geometry={stripGeom}>
+ <meshBasicMaterial color={mixHex(accent, '#dde6ee', dayMix)} transparent opacity={stripOpacity} toneMapped={false} />
+ </mesh>
+ <mesh geometry={paintGeom}>
+ <meshBasicMaterial vertexColors transparent opacity={paintOpacity} />
+ </mesh>
+ </group>
+ );
+}
diff --git a/client/src/components/city/CityTransitLoop.jsx b/client/src/components/city/CityTransitLoop.jsx
new file mode 100644
index 0000000000..fb7bc66f99
--- /dev/null
+++ b/client/src/components/city/CityTransitLoop.jsx
@@ -0,0 +1,82 @@
+import { useMemo, useRef, useEffect } from 'react';
+import { useFrame } from '@react-three/fiber';
+import * as THREE from 'three';
+import { cityDayMix, mixHex } from './cityConstants';
+import { useCityPalette } from './CityPaletteContext';
+import { TRANSIT } from '../../utils/cityPlan';
+
+// The elevated transit loop from the master plan: a closed glowing track linking every
+// quarter, with a few trams orbiting it — the city's "alive" motion layer. Native
+// TubeGeometry along a closed CatmullRom curve (never drei <Line>); support pylons drop
+// at each district stop. Trams hide on the low preset; the track itself is one mesh.
+
+const TRAM_SIZE = [0.9, 0.5, 0.42];
+
+export default function CityTransitLoop({ settings }) {
+ const { accent, tintStructure } = useCityPalette();
+ const dayMix = cityDayMix(settings);
+ const showTrams = (settings?.particleDensity ?? 1) > 0.5;
+
+ const curve = useMemo(() => {
+ const points = TRANSIT.stops.map((s) => new THREE.Vector3(...s.point));
+ const c = new THREE.CatmullRomCurve3(points, true, 'centripetal');
+ return c;
+ }, []);
+
+ const trackGeom = useMemo(() => new THREE.TubeGeometry(curve, 220, 0.1, 6, true), [curve]);
+ useEffect(() => () => trackGeom.dispose(), [trackGeom]);
+
+ const tramRefs = useRef([]);
+ tramRefs.current = [];
+ const lookAhead = useRef(new THREE.Vector3());
+
+ useFrame(({ clock }) => {
+ const t = clock.getElapsedTime() * TRANSIT.tramSpeed;
+ tramRefs.current.forEach((tram, i) => {
+ if (!tram) return;
+ const u = (t + i / TRANSIT.tramCount) % 1;
+ curve.getPointAt(u, tram.position);
+ curve.getPointAt((u + 0.005) % 1, lookAhead.current);
+ tram.lookAt(lookAhead.current);
+ });
+ });
+
+ const trackColor = mixHex(accent, '#8b9bb0', dayMix);
+ const trackOpacity = 0.5 * (1 - dayMix) + 0.3 * dayMix;
+
+ return (
+ <group>
+ <mesh geometry={trackGeom}>
+ <meshBasicMaterial color={trackColor} transparent opacity={trackOpacity} toneMapped={false} />
+ </mesh>
+
+ {/* Support pylon + station halo at every stop */}
+ {TRANSIT.stops.map((stop) => (
+ <group key={stop.id} position={[stop.point[0], 0, stop.point[2]]}>
+ <mesh position={[0, TRANSIT.y / 2, 0]}>
+ <cylinderGeometry args={[0.12, 0.2, TRANSIT.y, 6]} />
+ <meshStandardMaterial color={tintStructure('#121a2c')} roughness={0.7} metalness={0.4} />
+ </mesh>
+ <mesh position={[0, TRANSIT.y - 0.35, 0]} rotation={[Math.PI / 2, 0, 0]}>
+ <torusGeometry args={[0.55, 0.05, 6, 20]} />
+ <meshBasicMaterial color={trackColor} transparent opacity={trackOpacity + 0.15} toneMapped={false} />
+ </mesh>
+ </group>
+ ))}
+
+ {showTrams && Array.from({ length: TRANSIT.tramCount }, (_, i) => (
+ <mesh key={i} ref={(el) => { if (el) tramRefs.current[i] = el; }}>
+ <boxGeometry args={TRAM_SIZE} />
+ <meshStandardMaterial
+ color={tintStructure('#1a2440')}
+ emissive={accent}
+ emissiveIntensity={0.5 * (1 - dayMix) + 0.15 * dayMix}
+ metalness={0.5}
+ roughness={0.3}
+ toneMapped={false}
+ />
+ </mesh>
+ ))}
+ </group>
+ );
+}
diff --git a/client/src/utils/README.md b/client/src/utils/README.md
index f8bf160c7b..e0b0b5a476 100644
--- a/client/src/utils/README.md
+++ b/client/src/utils/README.md
@@ -84,6 +84,7 @@ its tunable constants and placement helpers.
| `cityMiniMap` | Mini-map projection of building positions into 2D bounds (`computeMiniMap`, `projectPoint`). |
| `cityPhotoMode` | Photo-mode camera presets, the demand-loop fly stepper, postcard stats, and screenshot filename (`getPreset`, `cyclePreset`, `stepFly`). |
| `cityPlan` | Master town plan: district parcels, shoreline/bay, plaza, transit loop, street network (`PARCELS`, `WORLD`, `computeStreets`, `computeStreetProps`, `isInWater`). |
+| `cityRooftops` | Deterministic rooftop fixture kits (antenna/tank/AC/dish) per app name (`computeRooftopKit`). |
| `cityProductivity` | Productivity monument from streak/velocity tiers (`computeProductivityMonument`). |
| `citySeasonalDecor` | Season/holiday resolution → seasonal decoration placements (`computeSeasonalDecor`). |
| `citySoundscape` | Ambient soundscape: mood/energy classification and chord selection (`computeSoundscape`). |
diff --git a/client/src/utils/cityRooftops.js b/client/src/utils/cityRooftops.js
new file mode 100644
index 0000000000..8b28085cf7
--- /dev/null
+++ b/client/src/utils/cityRooftops.js
@@ -0,0 +1,49 @@
+// Pure, deterministic helpers for CyberCity's rooftop fixtures: small antennas, water
+// tanks, AC units, and dish arrays scattered on app-building roofs so the skyline reads
+// as a lived-in game city instead of bare boxes. Fixtures are seeded from the app name
+// (same determinism as the procedural window textures in Building.jsx) so a building
+// keeps its roof across refetches, theme switches, and installs. No three.js / React
+// imports so the kit is unit-testable (mirrors cityTaskQueue.js etc.).
+
+import { hashString } from './hashString';
+
+export const ROOFTOP_TYPES = ['antenna', 'tank', 'ac', 'dish'];
+
+const MAX_FIXTURES = 3;
+const EDGE_MARGIN = 0.45; // keep fixtures off the roof edge (relative to a width-2 roof)
+
+// Successive bit-slices of the name hash drive each pick — cheap, allocation-free
+// determinism without a generator.
+const pick = (hash, shift, mod) => Math.abs(hash >> shift) % mod;
+
+// 0–3 fixtures for a roof of `width`×`width` (buildings are square). Positions are
+// offsets from the roof center; `scale` tracks the building width so kits read
+// proportionate on the rare wider structure.
+export function computeRooftopKit(name, width = 2) {
+ const hash = hashString(String(name || ''));
+ const count = pick(hash, 0, MAX_FIXTURES + 1); // 0..3 — some roofs stay bare
+ const half = Math.max(0.2, width / 2 - EDGE_MARGIN);
+ const fixtures = [];
+ for (let i = 0; i < count; i++) {
+ const shift = 3 + i * 7;
+ const type = ROOFTOP_TYPES[pick(hash, shift, ROOFTOP_TYPES.length)];
+ // Two more slices position the fixture on a 5×5 roof grid (deterministic, clamped).
+ const gx = pick(hash, shift + 2, 5) / 4 - 0.5; // -0.5..0.5
+ const gz = pick(hash, shift + 4, 5) / 4 - 0.5;
+ fixtures.push({
+ type,
+ x: gx * 2 * half,
+ z: gz * 2 * half,
+ scale: 0.8 + pick(hash, shift + 5, 3) * 0.2, // 0.8 / 1.0 / 1.2
+ rotation: pick(hash, shift + 6, 8) * (Math.PI / 4),
+ });
+ }
+ // Two fixtures on the same grid cell read as one mangled prop — drop duplicates.
+ const seen = new Set();
+ return fixtures.filter((f) => {
+ const key = `${Math.round(f.x * 10)},${Math.round(f.z * 10)}`;
+ if (seen.has(key)) return false;
+ seen.add(key);
+ return true;
+ });
+}
diff --git a/client/src/utils/cityRooftops.test.js b/client/src/utils/cityRooftops.test.js
new file mode 100644
index 0000000000..e814aed495
--- /dev/null
+++ b/client/src/utils/cityRooftops.test.js
@@ -0,0 +1,50 @@
+import { describe, it, expect } from 'vitest';
+import { computeRooftopKit, ROOFTOP_TYPES } from './cityRooftops';
+
+describe('computeRooftopKit', () => {
+ it('is deterministic per name', () => {
+ expect(computeRooftopKit('port-os')).toEqual(computeRooftopKit('port-os'));
+ expect(computeRooftopKit('another-app', 2)).toEqual(computeRooftopKit('another-app', 2));
+ });
+
+ it('returns 0–3 fixtures of known types', () => {
+ for (const name of ['a', 'bb', 'ccc', 'port-os', 'my-app', 'svc-12', 'x9', 'zzz']) {
+ const kit = computeRooftopKit(name);
+ expect(kit.length).toBeLessThanOrEqual(3);
+ for (const f of kit) {
+ expect(ROOFTOP_TYPES).toContain(f.type);
+ expect(f.scale).toBeGreaterThan(0);
+ }
+ }
+ });
+
+ it('keeps every fixture inside the roof bounds', () => {
+ for (const width of [2, 3.5]) {
+ for (const name of ['port-os', 'another-app', 'svc-12', 'big-roof-app']) {
+ for (const f of computeRooftopKit(name, width)) {
+ expect(Math.abs(f.x), name).toBeLessThanOrEqual(width / 2);
+ expect(Math.abs(f.z), name).toBeLessThanOrEqual(width / 2);
+ }
+ }
+ }
+ });
+
+ it('varies across names (not every roof identical)', () => {
+ const kits = ['app-one', 'app-two', 'app-three', 'app-four', 'app-five', 'gamma', 'delta']
+ .map((n) => JSON.stringify(computeRooftopKit(n)));
+ expect(new Set(kits).size).toBeGreaterThan(1);
+ });
+
+ it('never stacks two fixtures on the same spot', () => {
+ for (const name of ['port-os', 'another-app', 'svc-12', 'abcdefg', 'q']) {
+ const kit = computeRooftopKit(name);
+ const keys = kit.map((f) => `${Math.round(f.x * 10)},${Math.round(f.z * 10)}`);
+ expect(new Set(keys).size).toBe(keys.length);
+ }
+ });
+
+ it('tolerates a missing name', () => {
+ expect(() => computeRooftopKit(undefined)).not.toThrow();
+ expect(() => computeRooftopKit('')).not.toThrow();
+ });
+});
diff --git a/client/src/utils/index.js b/client/src/utils/index.js
index 23f9eaa4f4..17c132b25d 100644
--- a/client/src/utils/index.js
+++ b/client/src/utils/index.js
@@ -53,6 +53,7 @@ export * from './cityMemoryDistrict.js';
export * from './cityMiniMap.js';
export * from './cityPhotoMode.js';
export * from './cityPlan.js';
+export * from './cityRooftops.js';
export * from './cityProductivity.js';
export * from './citySeasonalDecor.js';
export * from './citySoundscape.js';