Voir le prompt
Sur la page Accueil, dans la zone « Globe » : la Terre en 3D avec three.js (installe le paquet three si besoin ; les icônes viennent de lucide-react).
Le globe doit être IDENTIQUE au site de référence : même rotation, même zoom (molette de la souris ou pincement), mêmes étiquettes, mêmes traits qui restent collés à leur ville quand on fait glisser la Terre.
BRANCHEMENT
- Les villes viennent de la ligne WorldState (champ cities), relue toutes les 60 s directement dans la base, sans appeler la fonction bot.
- Clic sur une ville → elle devient la ville sélectionnée (selected) et le globe tourne vers elle. Le panneau de la ville arrive au jour 6.
- Exception à la règle « aucune couleur en dur » : les couleurs du globe sont écrites dans ce code, c'est voulu.
- Tant que le bot n'a placé aucun pari (avant le jour 4 ou juste après), le globe tourne sans ville : c'est normal.
Crée les fichiers du globe avec le code ci-dessous, COPIÉ TEL QUEL (mêmes valeurs, mêmes chiffres, ne simplifie rien, n'invente rien). Seuls les chemins d'import peuvent être adaptés à l'app.
DONNÉES : le composant Globe reçoit cities = liste d'objets { station, city, lat, lon, sky, open, won, lost, pnl, settled }.
- sky vaut "clear" | "partly" | "cloudy" | "rain" | "snow" | "storm" | "fog" (adapte la fonction bot si elle envoie d'autres noms : sun→clear, cloud→cloudy).
- Les villes affichées : toutes celles où le bot a au moins un pari (en cours ou réglé). La tuile VILLES compte ces villes.
- La barre de boutons est en haut à droite du globe : le code lui réserve un rectangle de 480 × 60 px où aucune étiquette ne se pose.
- Le conteneur du globe : <section className="relative lg:col-start-2 lg:row-span-2"> (ou l'équivalent de la grille actuelle) et le globe remplit tout : position absolute inset-0.
=== components/globe/objects.js ===
import * as THREE from "three";
export const COLORS = { win: 0x2cc980, loss: 0xef4444, open: 0xf5a524 };
// Green once a city made money, red if it lost, amber while only open bets.
// Orange while any bet is still open (or it was only sold early, not lost); red only when a bet
// actually lost and the city is down; green once everything is settled with a profit.
export const tone = (c) => (c.open > 0 ? "open" : c.lost > 0 && c.pnl < 0 ? "loss" : c.pnl > 0 && c.won > 0 ? "win" : "open");
const LAND = "https://unpkg.com/three-globe@2.31.0/example/img/earth-water.png";
export function toVec(lat, lon, r = 1) {
const phi = ((90 - lat) * Math.PI) / 180, th = ((lon + 180) * Math.PI) / 180;
return new THREE.Vector3(-r * Math.sin(phi) * Math.cos(th), r * Math.cos(phi), r * Math.sin(phi) * Math.sin(th));
}
const IMG = "https://unpkg.com/three-globe@2.31.0/example/img/";
// Realistic Earth: satellite colors, raised terrain (displacement + bump) and shiny oceans.
export function buildEarth() {
const tl = new THREE.TextureLoader();
tl.setCrossOrigin("anonymous");
const map = tl.load(`${IMG}earth-blue-marble.jpg`);
map.colorSpace = THREE.SRGBColorSpace;
map.anisotropy = 8;
const relief = tl.load(`${IMG}earth-topology.png`);
return new THREE.Mesh(new THREE.SphereGeometry(1, 384, 192), new THREE.MeshPhongMaterial({
map, bumpMap: relief, bumpScale: 6, displacementMap: relief, displacementScale: 0.025, displacementBias: -0.004,
specularMap: tl.load(LAND), specular: new THREE.Color(0x335577), shininess: 18,
}));
}
export function lights(scene) {
const sun = new THREE.DirectionalLight(0xffffff, 2.6);
sun.position.set(-4, 2, 3);
scene.add(new THREE.AmbientLight(0xffffff, 0.55), sun);
}
export function atmosphere() {
return new THREE.Mesh(new THREE.SphereGeometry(1.18, 64, 64), new THREE.ShaderMaterial({
vertexShader: "varying vec3 vN; void main(){ vN = normalize(normalMatrix * normal); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }",
fragmentShader: "varying vec3 vN; void main(){ float i = pow(0.62 - dot(vN, vec3(0.0, 0.0, 1.0)), 3.0); gl_FragColor = vec4(0.45, 0.55, 1.0, 1.0) * i; }",
blending: THREE.AdditiveBlending, side: THREE.BackSide, transparent: true, depthWrite: false,
}));
}
=== components/globe/markers.js ===
import * as THREE from "three";
import { COLORS, tone, toVec } from "./objects";
// One glowing dot and a pulsing ring per city; the icon floats above the dot on a straight stem.
export function buildMarkers(cities) {
const group = new THREE.Group(), rings = [], tips = [];
for (const c of cities) {
const color = COLORS[tone(c)], n = toVec(c.lat, c.lon, 1);
const dot = new THREE.Mesh(new THREE.SphereGeometry(0.014, 12, 12), new THREE.MeshBasicMaterial({ color }));
dot.position.copy(n.clone().multiplyScalar(1.006));
const ring = new THREE.Mesh(new THREE.RingGeometry(0.02, 0.027, 40),
new THREE.MeshBasicMaterial({ color, transparent: true, side: THREE.DoubleSide, depthWrite: false }));
ring.position.copy(n.clone().multiplyScalar(1.004));
ring.lookAt(n.clone().multiplyScalar(2));
const tip = new THREE.Object3D();
tip.position.copy(n.clone().multiplyScalar(1.006)); // the dot; the stem to the icon is drawn on screen
tip.userData.station = c.station;
tip.userData.color = `#${color.toString(16).padStart(6, "0")}`;
group.add(dot, ring, tip);
rings.push({ ring, phase: Math.random(), speed: 3500 });
tips.push(tip);
}
return { group, rings, tips };
}
export function disposeMarkers(m) {
m.group.traverse((o) => { o.geometry?.dispose(); o.material?.dispose(); });
}
=== components/globe/createScene.js ===
import * as THREE from "three";
import { atmosphere, buildEarth, lights, toVec } from "./objects";
import { buildMarkers, disposeMarkers } from "./markers";
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
const angDiff = (a, b) => Math.atan2(Math.sin(a - b), Math.cos(a - b));
// The spinning dotted Earth. `labels` holds the city tag elements it keeps pinned to each beam.
export function createScene(el, labels) {
const scene = new THREE.Scene(), camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
camera.position.set(0, 0, 3.05);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
const cvs = renderer.domElement;
cvs.style.cursor = "grab"; cvs.style.touchAction = "none";
el.appendChild(cvs);
const globe = new THREE.Group();
globe.rotation.set(0.35, -1.2, 0);
const earth = buildEarth();
globe.add(earth);
scene.add(globe, atmosphere());
lights(scene);
let markers = null, target = null, hold = false, drag = null, raf = 0, w = 1, h = 1;
// Zoom: 1 = whole Earth, 0.62 = close up. Wheel or pinch sets the target, the camera eases to it.
let baseZ = 3.05, zoom = 1, zoomT = 1;
const ZMIN = 0.62, ZMAX = 1;
const pts = new Map(); let pinch = 0;
// Pull the camera back on narrow (portrait) screens so the whole globe + glow fits the width.
const resize = () => {
w = el.clientWidth; h = el.clientHeight; renderer.setSize(w, h); camera.aspect = w / h;
baseZ = Math.max(3.05, 1.16 / (Math.tan((20 * Math.PI) / 180) * camera.aspect));
camera.position.z = baseZ * zoom;
camera.updateProjectionMatrix();
};
const ro = new ResizeObserver(resize); ro.observe(el); resize();
const gap = () => { const [a, b] = [...pts.values()]; return Math.hypot(a.x - b.x, a.y - b.y); };
const down = (e) => {
pts.set(e.pointerId, { x: e.clientX, y: e.clientY }); cvs.setPointerCapture(e.pointerId); target = null;
if (pts.size === 2) { drag = null; pinch = gap(); return; }
drag = { x: e.clientX, y: e.clientY }; cvs.style.cursor = "grabbing";
};
const move = (e) => {
if (pts.has(e.pointerId)) pts.set(e.pointerId, { x: e.clientX, y: e.clientY });
if (pts.size === 2 && pinch) { const g = gap(); zoomT = clamp(zoomT * (pinch / g), ZMIN, ZMAX); pinch = g; return; }
if (!drag) return;
// Turn slower when zoomed in, so the Earth follows the finger at every zoom level.
const k = 0.005 * zoom;
globe.rotation.y += (e.clientX - drag.x) * k;
globe.rotation.x = clamp(globe.rotation.x + (e.clientY - drag.y) * k, -1.2, 1.2);
drag = { x: e.clientX, y: e.clientY };
};
const up = (e) => { pts.delete(e.pointerId); if (pts.size < 2) pinch = 0; if (!pts.size) { drag = null; cvs.style.cursor = "grab"; } };
const wheel = (e) => { e.preventDefault(); zoomT = clamp(zoomT * Math.exp(e.deltaY * 0.0015), ZMIN, ZMAX); };
cvs.addEventListener("pointerdown", down); cvs.addEventListener("pointermove", move); cvs.addEventListener("pointerup", up);
// Wheel / trackpad pinch on the whole globe area (labels included), never the browser page zoom.
const area = el.parentElement || el;
cvs.addEventListener("pointercancel", up); area.addEventListener("wheel", wheel, { passive: false });
// Safari trackpad pinch sends gesture events instead of ctrl+wheel.
let g0 = 1;
const gStart = (e) => { e.preventDefault(); g0 = zoomT; };
const gChange = (e) => { e.preventDefault(); zoomT = clamp(g0 / e.scale, ZMIN, ZMAX); };
area.addEventListener("gesturestart", gStart); area.addEventListener("gesturechange", gChange);
const p = new THREE.Vector3(), cam = new THREE.Vector3();
// Thin leader lines from each city's beam to its label (labels get nudged apart when they collide).
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
Object.assign(svg.style, { position: "absolute", inset: "0", width: "100%", height: "100%", pointerEvents: "none", overflow: "visible" });
el.appendChild(svg);
const lines = {}, pos = {}, keep = {}; // keep = each label's chosen offset from its city
const GAP = 6;
function layoutLabels() {
const items = [];
markers?.tips.forEach((tip) => {
const id = tip.userData.station, tag = labels.current[id];
if (!tag) return;
tip.getWorldPosition(p);
// Cities near the rim keep only their dot; the horizon moves in when the camera zooms closer.
const vis = p.clone().normalize().dot(cam) > Math.max(0.35, 1 / camera.position.z + 0.1);
p.project(camera);
const ax = ((p.x + 1) / 2) * w, ay = ((1 - p.y) / 2) * h;
if (!lines[id]) {
lines[id] = document.createElementNS("http://www.w3.org/2000/svg", "line");
lines[id].setAttribute("stroke-width", "1.5");
svg.appendChild(lines[id]);
}
lines[id].setAttribute("stroke", tip.userData.color || "rgba(255,255,255,0.5)");
const onScreen = ax > 8 && ax < w - 8 && ay > 8 && ay < h - 8; // zoomed in: dots past the edge get no label
if (!vis || !onScreen) { tag.style.opacity = "0"; tag.style.pointerEvents = "none"; lines[id].style.opacity = "0"; return; }
items.push({ id, tag, ax, ay, bw: tag.offsetWidth, bh: tag.offsetHeight, sel: tag.dataset.selected === "1" });
});
// Selected first, then labels that already have a spot (so they keep it), then top to bottom.
items.sort((a, b) => (b.sel - a.sel) || (!!keep[b.id] - !!keep[a.id]) || (a.ay - b.ay));
// Keep the buttons bar (top right) and the legend (top left) free.
const placed = [{ x: w - 480, y: 0, bw: 480, bh: 60 }, { x: 0, y: 0, bw: 280, bh: 30 }]; // buttons, legend
const hits = (x, y, it) => placed.some((q) => x < q.x + q.bw + GAP && x + it.bw + GAP > q.x && y < q.y + q.bh + GAP && y + it.bh + GAP > q.y);
// An icon must never cover a city dot (its own or another's).
const coversDot = (x, y, it) => items.some((o) => o.ax > x - 5 && o.ax < x + it.bw + 5 && o.ay > y - 5 && o.ay < y + it.bh + 5);
const STEM = 12;
for (const it of items) {
const { ax, ay, bw, bh } = it, out = ax < w / 2 ? -1 : 1;
// Spots right next to the city, cheapest first: above, beside it toward the edge of the globe,
// below, beside it toward the middle. Only if all four are taken does it go further out.
const above = { x: ax - bw / 2, y: ay - bh - STEM }, below = { x: ax - bw / 2, y: ay + STEM };
const side = (d) => ({ x: d < 0 ? ax - STEM - bw : ax + STEM, y: ay - bh / 2 });
const near = [above, side(out), below, side(-out)];
const far = [];
for (let r = 1; r <= 1; r++) for (const q of near) {
const vx = Math.sign(q.x + bw / 2 - ax), vy = Math.sign(q.y + bh / 2 - ay);
far.push({ x: q.x + vx * r * (bw / 2 + GAP), y: q.y + vy * r * (bh / 2 + GAP) });
}
const fits = (q) => q.y >= 4 && q.y + bh <= h - 4 && q.x >= 4 && q.x + bw <= w - 4 && !hits(q.x, q.y, it) && !coversDot(q.x, q.y, it);
const prev = keep[it.id] && { x: ax + keep[it.id].dx, y: ay + keep[it.id].dy };
// Straight above whenever there's room; else keep the last spot (no jumping); else search.
// The last spot is kept only if it's one of the close spots right next to the dot.
const close = prev && near.some((q) => Math.hypot(q.x - prev.x, q.y - prev.y) < 6);
const spot = (fits(above) && above) || (close && fits(prev) && prev) || near.find(fits) || far.find(fits) || (it.sel ? above : null);
// Too crowded (or under the buttons): no icon, the city keeps just its dot until there's room.
if (!spot) { it.tag.style.opacity = "0"; it.tag.style.pointerEvents = "none"; lines[it.id].style.opacity = "0"; delete pos[it.id]; continue; }
let x = spot.x, y = spot.y;
keep[it.id] = { dx: x - ax, dy: y - ay };
x = clamp(x, 4, w - bw - 4); y = clamp(y, 4, h - bh - 4);
placed.push({ x, y, bw, bh });
// Ease only the offset from the city, so labels stay locked to their city while dragging.
const off = pos[it.id] || { dx: x - ax, dy: y - ay };
off.dx += (x - ax - off.dx) * 0.15; off.dy += (y - ay - off.dy) * 0.15;
pos[it.id] = off;
const cur = { x: ax + off.dx, y: ay + off.dy };
it.tag.style.transform = `translate(${cur.x}px, ${cur.y}px)`;
it.tag.style.opacity = "1"; it.tag.style.pointerEvents = "auto";
// One straight stem from the dot's edge to the nearest edge of the icon.
const l = lines[it.id], lx = clamp(ax, cur.x, cur.x + bw), ly = clamp(ay, cur.y, cur.y + bh);
const d = Math.hypot(lx - ax, ly - ay) || 1;
l.setAttribute("x1", ax + ((lx - ax) / d) * 5); l.setAttribute("y1", ay + ((ly - ay) / d) * 5);
l.setAttribute("x2", lx); l.setAttribute("y2", ly);
l.style.opacity = "0.85";
}
}
const tick = (t) => {
raf = requestAnimationFrame(tick);
if (target) {
globe.rotation.y += angDiff(target.y, globe.rotation.y) * 0.07;
globe.rotation.x += (target.x - globe.rotation.x) * 0.07;
} else if (!drag && !hold) globe.rotation.y += 0.0005;
// Dots keep the same size on screen when zooming in.
markers?.group.children.forEach((o) => { if (o.geometry?.type === "SphereGeometry") o.scale.setScalar(zoom); });
markers?.rings.forEach(({ ring, phase, speed }) => {
const f = (t / speed + phase) % 1;
ring.scale.setScalar((1 + f * 0.9) * zoom); ring.material.opacity = 0.45 * (1 - f);
});
if (Math.abs(zoomT - zoom) > 1e-4) { zoom += (zoomT - zoom) * 0.15; camera.position.z = baseZ * zoom; }
cam.copy(camera.position).normalize();
layoutLabels();
renderer.render(scene, camera);
};
raf = requestAnimationFrame(tick);
return {
setCities(cities) {
if (markers) { globe.remove(markers.group); disposeMarkers(markers); }
markers = buildMarkers(cities);
globe.add(markers.group);
},
// Turn the globe so the city faces the viewer; null resumes spinning.
focus(c) {
hold = !!c;
if (!c) { target = null; return; }
const v = toVec(c.lat, c.lon);
target = { y: Math.atan2(-v.x, v.z), x: clamp((c.lat * Math.PI) / 180, -1.2, 1.2) };
},
dispose() {
cancelAnimationFrame(raf); ro.disconnect();
cvs.removeEventListener("pointerdown", down); cvs.removeEventListener("pointermove", move); cvs.removeEventListener("pointerup", up);
cvs.removeEventListener("pointercancel", up); area.removeEventListener("wheel", wheel); area.removeEventListener("gesturestart", gStart); area.removeEventListener("gesturechange", gChange);
if (markers) disposeMarkers(markers);
earth.geometry.dispose(); ["map", "bumpMap", "specularMap"].forEach((k) => earth.material[k]?.dispose()); earth.material.dispose();
renderer.dispose(); cvs.remove(); svg.remove();
},
};
}
=== components/live/WeatherIcon.jsx ===
import { Cloud, CloudFog, CloudLightning, CloudRain, CloudSnow, CloudSun, Sun } from "lucide-react";
export const SKY = {
clear: { Icon: Sun, label: "Ensoleillé", cls: "text-accent" },
partly: { Icon: CloudSun, label: "Éclaircies", cls: "text-accent" },
cloudy: { Icon: Cloud, label: "Couvert", cls: "text-muted-foreground" },
rain: { Icon: CloudRain, label: "Pluie", cls: "text-chart-3" },
snow: { Icon: CloudSnow, label: "Neige", cls: "text-foreground" },
storm: { Icon: CloudLightning, label: "Orage", cls: "text-chart-4" },
fog: { Icon: CloudFog, label: "Brouillard", cls: "text-muted-foreground" },
};
export default function WeatherIcon({ sky, className = "h-4 w-4" }) {
const s = SKY[sky];
if (!s) return null;
return <s.Icon className={`${className} ${s.cls}`} aria-label={s.label} />;
}
(text-chart-3 = hsl(200 80% 60%) bleu, text-chart-4 = hsl(280 65% 65%) violet : mets --chart-3: 200 80% 60%; et --chart-4: 280 65% 65%; dans les variables CSS, en remplaçant les valeurs existantes.)
=== components/globe/Globe.jsx ===
import { useEffect, useRef } from "react";
import { createScene } from "./createScene";
import { tone } from "./objects";
import WeatherIcon, { SKY } from "../live/WeatherIcon";
const TAG = {
win: "border-primary bg-[#0d2a20]/90 text-primary shadow-[0_0_16px_rgba(22,199,132,.6)]",
loss: "border-destructive/60 bg-background/85 text-destructive",
open: "border-accent/60 bg-background/85 text-accent",
};
export default function Globe({ cities, selected, onSelect }) {
const wrap = useRef(null), labels = useRef({}), api = useRef(null);
useEffect(() => {
api.current = createScene(wrap.current, labels);
return () => api.current.dispose();
}, []);
useEffect(() => { api.current.setCities(cities); }, [cities]);
useEffect(() => { api.current.focus(cities.find((c) => c.station === selected) || null); }, [selected, cities]);
return (
<div className="absolute inset-0">
<div ref={wrap} className="absolute inset-0" />
{cities.map((c) => {
const t = tone(c);
return (
<button key={c.station} ref={(n) => { labels.current[c.station] = n; }}
data-station={c.station}
data-selected={c.station === selected ? "1" : "0"}
onClick={() => onSelect(c.station === selected ? null : c.station)}
style={{ zIndex: c.station === selected ? 20 : 10 }}
title={`${c.city}${SKY[c.sky] ? ` · ${SKY[c.sky].label}` : ""}`} aria-label={`${c.city}${SKY[c.sky] ? `, ${SKY[c.sky].label}` : ""}`}
className={`absolute left-0 top-0 flex items-center justify-center rounded-lg border-[1.5px] p-0.5 opacity-0 sm:rounded-[10px] shadow-lg backdrop-blur-md transition-opacity duration-300 hover:brightness-125 ${TAG[t]} ${c.station === selected ? "ring-2 ring-foreground/70" : ""}`}>
<span className="flex h-6 w-6 items-center justify-center rounded-md bg-foreground/5 sm:h-7 sm:w-7">
{SKY[c.sky]
? <WeatherIcon sky={c.sky} className="h-4 w-4 drop-shadow-[0_0_6px_currentColor] sm:h-5 sm:w-5" />
: <span className="font-mono text-[11px] font-semibold">{c.city.slice(0, 3).toUpperCase()}</span>}
</span>
</button>
);
})}
</div>
);
}
À LA FIN : capture à 1440 × 900 : l'Atlantique au centre, un halo bleu-violet large autour de la Terre, des étiquettes compactes (environ 34 px) qui ne se chevauchent jamais et ne passent jamais sous les boutons en haut à droite ; une ville sans place garde seulement son point.
RÈGLES POUR CETTE ÉTAPE (la personne qui colle ce prompt débute et ne sait pas programmer) :
- Ne me pose aucune question : si tu hésites, choisis l'option la plus simple qui respecte le contrat commun et continue.
- Fais toute l'étape d'un coup, vérifie toi-même que ça marche, et corrige tes propres erreurs avant de répondre.
- Ne me demande jamais de clé, de secret ni de mot de passe : l'app n'en a pas besoin.
- Si tu as besoin de mon accord (bouton Approve), dis-le en une phrase simple : « Clique sur Approve pour continuer. »
- Ne change rien de ce qui a été fait aux étapes précédentes, sauf si c'est indispensable.
- Termine par un résumé de 3 lignes maximum, en français simple, sans mot technique.