Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

24.3 KB
Raw Blame
/**
 * Two agents talking, drawn — the R3F half of `conversation.ts`.
 *
 * Everything it needs about WHERE the figures are it reads from
 * `walkerRegistry.ts`, the same per-frame map the minimap reads: positions
 * change 60 times a second and putting them through React would be absurd.
 * Everything it needs about WHO said WHAT it reads from the conversation
 * store, which changes a few times per sentence.
 *
 * What it writes back is one `SpeechPose` per participant: a heading to turn
 * toward and a flag for the `talk` clip. Never a position. A conversation
 * cannot move a figure (`world-behaviour-manual.md` §1) — the backend owns
 * where an agent is, and a figure that walked to another shop because it said
 * something would be the island inventing a third truth.
 *
 * Mounted OUTSIDE `<Shadowed>`: the ground pips are additive halos and a
 * translucent glow that casts a shadow reads as a hole in the grass.
 */
import { memo, useEffect, useMemo, useRef } from "react";
import { Html } from "@react-three/drei";
import { useFrame, useThree } from "@react-three/fiber";
import { Object3D, type Group, type InstancedMesh, type Mesh } from "three";

import { fill, useT } from "@/i18n";
import type { SocietyAgent } from "../data";
import { WORLD_HERO_SCALE } from "./WalkerFigure";
import { useKit } from "./WorldKit";
import { useCameraStore } from "./cameraStore";
import { ZOOM_WIDTHS_M } from "./worldCamera";
import { useBuildingPoses } from "./buildingPoses";
import {
  ARC_BEADS,
  CALL_MIN_S,
  CALL_SECONDS,
  MAX_CONCURRENT,
  MIN_FACE_M,
  ROOM_RING_R_M,
  arcApexFor,
  arcPoint,
  beadAlive,
  beadRadiusFor,
  beadScale,
  bubbleSeconds,
  classify,
  clamp01,
  driftedApart,
  facingBetween,
  hangupSweep,
  pingFade,
  pingScale,
  pipScale,
  tangentFacing,
  type ConvoKind,
  type TalkKind,
} from "./conversation";
import {
  clearSpeechPoses,
  orderedTalks,
  setSpeechPose,
  useConversationStore,
  type Conversation,
} from "./conversationStore";
import { buildIsland, groundY, tileToWorld } from "./islandLayout";
import { SIGNAL } from "./worldPalette";
import { walkerPins, type WalkerPin } from "./walkerRegistry";

/**
 * How high a bubble floats over a figure's own head, in metres.
 *
 * High enough to clear the nameplate: at 0.5 m the bubble sat exactly on it
 * and hid the one thing the viewer needs — WHO is speaking.
 */
const BUBBLE_LIFT_M = 1.75;
/** Stacked conversations lift their bubbles by this much each, so none overlap. */
const BUBBLE_STACK_M = 0.9;
/**
 * The listener's "…" rides lower than the speaker's line: above its nameplate,
 * well under the bubble. Two figures on one stand tile put both anchors at the
 * same screen point, and at the same height the dots sat on the words.
 */
const LISTEN_LIFT_M = 0.62;
/**
 * …and it is dropped entirely when the two stand this close, because at 64 m
 * across the stage four metres is ten pixels: the dots would sit inside the
 * speaker's own bubble whatever height they were given. Wider than
 * `MIN_FACE_M`, which only has to be wider than the lateral offset.
 */
const LISTEN_HIDE_M = 4;
/**
 * A room's sign clears the Town Hall's facade. Anything lower shares its anchor
 * with the speech bubble over the member standing there, and loses.
 */
const ROOM_SIGN_Y_M = 9.5;
/** The marker ring under a figure that is in a conversation, in metres. */
const SPEAK_RING_R_M = 1.15;
/** How wide a ping ring grows at a caller's head, in metres. */
const PING_R_M = 1.9;
/** Reused for every instance matrix; three.js wants an Object3D, not a matrix. */
const DUMMY = new Object3D();
/** Head height for a figure whose recipe carries no height. */
const DEFAULT_HEAD_M = 2.0;

/** One participant, resolved: the roster row, the live pin, the head height. */
interface Party {
  agent: SocietyAgent;
  pin: WalkerPin;
  headY: number;
}

function headHeight(agent: SocietyAgent): number {
  if (!agent.figure) return DEFAULT_HEAD_M;
  return (agent.figure.heightM ?? 1.75) * WORLD_HERO_SCALE;
}

/**
 * A conversation with both ends resolved against the live island, or null when
 * there is nothing to draw. `partner` is null for the one-sided case: a message
 * from the scheduler, or to a row that has no figure yet.
 */
interface Staged {
  talk: Conversation;
  speaker: Party;
  partner: Party | null;
  kind: ConvoKind;
  distanceM: number;
  /** Index among the live conversations — decides the bubble's stack height. */
  slot: number;
}

function stage(
  talks: Conversation[],
  byId: Map<string, SocietyAgent>,
  pins: ReadonlyMap<string, WalkerPin>,
): Staged[] {
  const out: Staged[] = [];
  talks.forEach((talk, slot) => {
    const speakerAgent = byId.get(talk.speakerId);
    const speakerPin = pins.get(talk.speakerId);
    const partnerAgent = talk.partnerId ? byId.get(talk.partnerId) : undefined;
    const partnerPin = talk.partnerId ? pins.get(talk.partnerId) : undefined;

    // Whoever we can see is the anchor. When only the partner has a figure —
    // the scheduler messaging Scout — the bubble belongs over the partner.
    const speaker: Party | null =
      speakerAgent && speakerPin
        ? { agent: speakerAgent, pin: speakerPin, headY: headHeight(speakerAgent) }
        : null;
    const partner: Party | null =
      partnerAgent && partnerPin
        ? { agent: partnerAgent, pin: partnerPin, headY: headHeight(partnerAgent) }
        : null;
    const anchor = speaker ?? partner;
    if (!anchor) return; // neither end is on the island yet: nothing to draw

    const other = anchor === speaker ? partner : null;
    const distanceM = other
      ? Math.hypot(anchor.pin.x - other.pin.x, anchor.pin.z - other.pin.z)
      : 0;
    // Decided once and cached on the row: a wandering figure must not flip a
    // running conversation from a talk into a call mid-sentence.
    const kind: ConvoKind = talk.kind ?? (other ? classify(distanceM) : "talk");
    if (talk.kind === null && other) useConversationStore.getState().setKind(talk.key, kind);
    out.push({ talk, speaker: anchor, partner: other, kind, distanceM, slot });
  });
  return out;
}

export interface ConversationSceneProps {
  agents: SocietyAgent[];
  /** Reduced motion: the island holds still and so does every conversation. */
  paused: boolean;
}

export function ConversationScene({ agents, paused }: ConversationSceneProps) {
  const talks = useConversationStore((s) => s.talks);
  const room = useConversationStore((s) => s.room);
  const byId = useMemo(() => new Map(agents.map((a) => [a.agentId, a])), [agents]);
  const live = useMemo(() => orderedTalks(talks).slice(0, MAX_CONCURRENT), [talks]);

  // A conversation whose line has run its course hands the queue on. Kept out
  // of `useFrame` on purpose: it is a state change, not an animation.
  useEffect(() => {
    if (live.length === 0) return;
    const timers = live
      .filter((t) => t.line !== null)
      .map((t) => {
        const left = t.lineStartedMs + bubbleSeconds(t.line?.chars ?? 0) * 1000 - Date.now();
        return setTimeout(
          () => useConversationStore.getState().advance(t.key),
          Math.max(0, left),
        );
      });
    return () => timers.forEach(clearTimeout);
  }, [live]);

  // A conversation left with no line and nothing queued is over.
  useEffect(() => {
    const empty = live.filter((t) => t.line === null && t.queued.length === 0);
    if (empty.length === 0) return;
    const timers = empty.map((t) =>
      setTimeout(() => useConversationStore.getState().closeTalk(t.key), 800),
    );
    return () => timers.forEach(clearTimeout);
  }, [live]);

  // The scene is going away (unmount, a lost WebGL context): every figure it
  // was driving goes back to its own sim (AP-32 — nothing survives the loss).
  useEffect(() => clearSpeechPoses, []);

  if (live.length === 0 && !room) return null;

  return (
    <group>
      {live.map((talk) => (
        <ConversationView
          key={talk.key}
          talk={talk}
          byId={byId}
          paused={paused}
          slot={live.indexOf(talk)}
        />
      ))}
      {room && <RoomSign room={room} paused={paused} />}
    </group>
  );
}

/**
 * One conversation. The heavy work is per frame and writes to refs; the only
 * React state it reads is the line, which changes once per sentence.
 */
function ConversationView({
  talk,
  byId,
  paused,
  slot,
}: {
  talk: Conversation;
  byId: Map<string, SocietyAgent>;
  paused: boolean;
  slot: number;
}) {
  const kit = useKit();
  const invalidate = useThree((s) => s.invalidate);
  const anchorRef = useRef<Group>(null);
  const pipA = useRef<Mesh>(null);
  const pipB = useRef<Mesh>(null);

  useFrame(({ clock }) => {
    const pins = walkerPins();
    const [next] = stage([talk], byId, pins);
    const anchor = anchorRef.current;
    if (!next || !anchor) {
      if (pipA.current) pipA.current.visible = false;
      if (pipB.current) pipB.current.visible = false;
      return;
    }

    const { speaker, partner } = next;
    anchor.position.set(
      speaker.pin.x,
      speaker.headY + BUBBLE_LIFT_M + slot * BUBBLE_STACK_M,
      speaker.pin.z,
    );

    if (!paused && partner) {
      // Two figures on one stand tile have no usable vector between them: the
      // heading would jitter and they would turn INTO each other. Below the
      // floor they turn along the building's front instead, across each other.
      const close = next.distanceM < MIN_FACE_M;
      const facing = close
        ? tangentFacing(speaker.pin.x <= partner.pin.x ? 0 : Math.PI, 1)
        : facingBetween(speaker.pin.x, speaker.pin.z, partner.pin.x, partner.pin.z);
      const back = close
        ? tangentFacing(speaker.pin.x <= partner.pin.x ? 0 : Math.PI, -1)
        : facingBetween(partner.pin.x, partner.pin.z, speaker.pin.x, speaker.pin.z);
      // A talk that has drifted apart keeps its bubbles and drops the facing:
      // shouting across the island should not look like a quiet word.
      const holdFacing = next.kind === "talk" && !driftedApart(next.distanceM);
      setSpeechPose(talk.speakerId, {
        heading: holdFacing ? facing : null,
        talking: talk.line !== null,
      });
      setSpeechPose(partner.agent.agentId, {
        heading: holdFacing ? back : null,
        talking: false,
      });
    } else if (!paused) {
      setSpeechPose(talk.speakerId, { heading: null, talking: talk.line !== null });
    }

    // The ground pips: a soft breathing pool under whoever is in this
    // conversation. One draw call each, and they read at any zoom where the
    // bubble text has already become unreadable.
    const t = clock.getElapsedTime();
    const scale = paused ? 1 : pipScale(t);
    const { map } = buildIsland();
    if (pipA.current) {
      pipA.current.visible = true;
      pipA.current.position.set(speaker.pin.x, groundY(map, speaker.pin.x, speaker.pin.z) + 0.03, speaker.pin.z);
      pipA.current.scale.set(SPEAK_RING_R_M * scale, SPEAK_RING_R_M * scale, 1.4);
    }
    if (pipB.current) {
      pipB.current.visible = partner !== null;
      if (partner) {
        pipB.current.position.set(partner.pin.x, groundY(map, partner.pin.x, partner.pin.z) + 0.03, partner.pin.z);
        pipB.current.scale.set(SPEAK_RING_R_M * scale, SPEAK_RING_R_M * scale, 1.4);
      }
    }
    if (paused) invalidate();
  });

  // The figures go back to their own sims the moment this conversation ends.
  useEffect(() => {
    const speakerId = talk.speakerId;
    const partnerId = talk.partnerId;
    return () => {
      setSpeechPose(speakerId, { heading: null, talking: false });
      if (partnerId) setSpeechPose(partnerId, { heading: null, talking: false });
    };
  }, [talk.speakerId, talk.partnerId]);

  const lineSpeaker = talk.line ? byId.get(talk.line.speakerId) : undefined;
  const speakerAgent =
    lineSpeaker ?? byId.get(talk.speakerId) ?? (talk.partnerId ? byId.get(talk.partnerId) : undefined);
  const accent = speakerAgent?.palette.accent ?? "#1f2a3a";
  const speakerName = speakerAgent?.name ?? talk.speakerId;

  return (
    <group>
      {/* A ring, not a filled pool: the island is already covered in soft lamp
          light and a wash under a figure vanished into it. */}
      <mesh
        ref={pipA}
        geometry={kit.g.ring}
        material={kit.m.halo(accent, 0.75)}
        rotation={[Math.PI / 2, 0, 0]}
        visible={false}
      />
      <mesh
        ref={pipB}
        geometry={kit.g.ring}
        material={kit.m.halo(accent, 0.45)}
        rotation={[Math.PI / 2, 0, 0]}
        visible={false}
      />
      <group ref={anchorRef}>
        {talk.line && (
          <Html center zIndexRange={[34, 12]} style={{ pointerEvents: "none" }}>
            <SpeechBubble
              who={speakerName}
              text={talk.line.text}
              kind={talk.line.kind}
              accent={accent}
              skipped={talk.skipped}
              truncated={talk.line.truncated}
            />
          </Html>
        )}
      </group>
      {talk.kind === "call" && talk.partnerId && (
        <CallLink talk={talk} byId={byId} paused={paused} />
      )}
      {talk.partnerId && talk.line && (
        <ListeningBubble
          byId={byId}
          partnerId={talk.partnerId}
          speakerId={talk.speakerId}
          calling={talk.kind === "call" ? speakerName : ""}
          slot={slot}
        />
      )}
    </group>
  );
}

/**
 * The signal between two figures the island cannot show side by side: a chain
 * of beads on a quadratic arc from head to head, with a wave of light running
 * from the sender to the receiver, and a ping ring at each end while it
 * connects.
 *
 * One shared `<instancedMesh>` and one shared material for the whole link. The
 * wave is animated by SCALE, never by opacity — `worldMaterials.halo()` caches
 * a material per colour and opacity, so a per-frame opacity would grow that
 * cache without bound.
 */
function CallLink({
  talk,
  byId,
  paused,
}: {
  talk: Conversation;
  byId: Map<string, SocietyAgent>;
  paused: boolean;
}) {
  const kit = useKit();
  const beads = useRef<InstancedMesh>(null);
  const pingA = useRef<Mesh>(null);
  const pingB = useRef<Mesh>(null);
  /** When the last line ENDED, so the hang-up sweep has something to run from. */
  const quietSince = useRef(0);
  /** When this call first went out — its floor, so it cannot flicker. */
  const openedAt = useRef(0);
  const dark = useRef<InstancedMesh>(null);

  useFrame(() => {
    const mesh = beads.current;
    if (!mesh) return;
    const [next] = stage([talk], byId, walkerPins());
    const partner = next?.partner ?? null;
    if (!next || !partner) {
      mesh.visible = false;
      if (pingA.current) pingA.current.visible = false;
      if (pingB.current) pingB.current.visible = false;
      return;
    }

    // The clock is the STORE's, not a local ref: `lineStartedMs` survives a
    // remount and is the same number in every open window, so two people
    // watching the same call see the same signal in the same place.
    const now = Date.now();
    if (openedAt.current === 0) openedAt.current = now;
    // A call holds the island for a moment even when the sentence is short.
    const young = (now - openedAt.current) / 1000 < CALL_MIN_S;
    const speaking = talk.line !== null || young;
    if (speaking) quietSince.current = 0;
    else if (quietSince.current === 0) quietSince.current = now;

    const age = paused
      ? CALL_SECONDS.dial + CALL_SECONDS.arc
      : (now - (speaking ? talk.lineStartedMs || openedAt.current : quietSince.current)) / 1000;

    // The head of the wave reaches across over `dial` + `arc`, the whole line
    // stays lit while the sentence is up, and it runs off on hang-up.
    const reach = CALL_SECONDS.dial + CALL_SECONDS.arc;
    const front = speaking ? clamp01(age / reach) : 1;
    const sweep = speaking ? 0 : hangupSweep(age);

    // The sender is whoever spoke last, so an answer sends the wave back.
    const from = next.speaker;
    const to = partner;
    const { map } = buildIsland();
    const head = {
      x: from.pin.x,
      y: groundY(map, from.pin.x, from.pin.z) + from.headY,
      z: from.pin.z,
    };
    const tail = {
      x: to.pin.x,
      y: groundY(map, to.pin.x, to.pin.z) + to.headY,
      z: to.pin.z,
    };
    const apex = arcApexFor(next.distanceM);
    const beadR = beadRadiusFor(ZOOM_WIDTHS_M[useCameraStore.getState().zoom]);

    mesh.visible = sweep < 1;
    let drawn = 0;
    for (let i = 0; i < ARC_BEADS; i++) {
      const scale = beadAlive(i, ARC_BEADS, sweep) ? beadScale(i, ARC_BEADS, front) : 0;
      const at = arcPoint(head, tail, i / (ARC_BEADS - 1), apex);
      DUMMY.position.set(at.x, at.y, at.z);
      DUMMY.scale.setScalar(Math.max(0.0001, scale * beadR * 2));
      DUMMY.updateMatrix();
      mesh.setMatrixAt(i, DUMMY.matrix);
      if (scale > 0) drawn += 1;
    }
    mesh.instanceMatrix.needsUpdate = true;
    if (drawn === 0) mesh.visible = false;
    // The backing: the same beads, a shade bigger and dark, so the warm core
    // has an edge on grass, on sand, on a roof and on the sea alike.
    const back = dark.current;
    if (back) {
      back.visible = mesh.visible;
      for (let i = 0; i < ARC_BEADS; i++) {
        const scale = beadAlive(i, ARC_BEADS, sweep) ? beadScale(i, ARC_BEADS, front) : 0;
        const at = arcPoint(head, tail, i / (ARC_BEADS - 1), apex);
        DUMMY.position.set(at.x, at.y, at.z);
        DUMMY.scale.setScalar(Math.max(0.0001, scale * beadR * 2.9));
        DUMMY.updateMatrix();
        back.setMatrixAt(i, DUMMY.matrix);
      }
      back.instanceMatrix.needsUpdate = true;
    }

    // The two pings: one when the call goes out, one when it lands.
    const ring = (node: Mesh | null, local: number, at: { x: number; y: number; z: number }) => {
      if (!node) return;
      const alive = local >= 0 && local <= CALL_SECONDS.dial;
      node.visible = alive && speaking;
      if (!alive) return;
      node.position.set(at.x, at.y, at.z);
      const r = Math.max(PING_R_M, beadR * 5) * (0.4 + pingScale(local));
      node.scale.set(r, r, 0.5 + pingFade(local));
    };
    ring(pingA.current, age, head);
    ring(pingB.current, age - CALL_SECONDS.dial - CALL_SECONDS.arc * 0.7, tail);
  });

  return (
    <group>
      {/* Solid and unlit, not additive. An additive bead is light ADDED to
          what is behind it, and the island is a bright green field under a
          flat, un-tonemapped pipeline — the same reason bloom is off by
          default. Over the grass the whole arc simply vanished. */}
      <instancedMesh
        ref={dark}
        args={[kit.g.sphere, kit.m.glow(SIGNAL.rim), ARC_BEADS]}
        frustumCulled={false}
        renderOrder={1}
      />
      <instancedMesh
        ref={beads}
        args={[kit.g.sphere, kit.m.glow(SIGNAL.bead), ARC_BEADS]}
        frustumCulled={false}
        renderOrder={2}
      />
      <mesh ref={pingA} geometry={kit.g.ring} material={kit.m.glow(SIGNAL.ping)} visible={false} />
      <mesh ref={pingB} geometry={kit.g.ring} material={kit.m.glow(SIGNAL.ping)} visible={false} />
    </group>
  );
}

/** The three dots over whoever is being spoken to. */
function ListeningBubble({
  byId,
  partnerId,
  speakerId,
  calling,
  slot,
}: {
  byId: Map<string, SocietyAgent>;
  partnerId: string;
  speakerId: string;
  /** The caller's name when this is a call; "" for a conversation in earshot. */
  calling: string;
  slot: number;
}) {
  const t = useT();
  const group = useRef<Group>(null);
  const agent = byId.get(partnerId);

  useFrame(() => {
    const pin = walkerPins().get(partnerId);
    const node = group.current;
    if (!node) return;
    if (!pin || !agent) {
      node.visible = false;
      return;
    }
    const speaker = walkerPins().get(speakerId);
    // Standing on the same tile the two anchors coincide: the speaker's own
    // bubble already names both ends, so a second one there is only noise.
    const together =
      speaker !== undefined && Math.hypot(speaker.x - pin.x, speaker.z - pin.z) < LISTEN_HIDE_M;
    // A call is never "together" by definition, and its badge says who is on
    // the other end — that is the whole point of drawing it.
    node.visible = calling !== "" || !together;
    node.position.set(
      pin.x,
      headHeight(agent) + LISTEN_LIFT_M + slot * BUBBLE_STACK_M,
      pin.z,
    );
  });

  if (!agent) return null;
  return (
    <group ref={group} visible={false}>
      <Html center zIndexRange={[33, 12]} style={{ pointerEvents: "none" }}>
        {calling ? (
          <div className="sw-bubble" data-calling>
            <span className="sw-bubble-kind">
              <i className="sw-bubble-dot" style={{ background: agent.palette.accent }} />
              {fill(t("society.world.talk_calling"), { name: calling }).replace("{0}", calling)}
            </span>
          </div>
        ) : (
          <div className="sw-bubble" data-listening aria-label={t("society.world.talk_listening")}>
            <span className="sw-bubble-dots" aria-hidden>
              <i />
              <i />
              <i />
            </span>
          </div>
        )}
      </Html>
    </group>
  );
}

const KIND_KEY: Record<TalkKind, string | null> = {
  say: null,
  query: "society.world.talk_kind_query",
  answer: "society.world.talk_kind_answer",
  propose: "society.world.talk_kind_propose",
};

/** The bubble itself. Memoised: it is DOM, and it changes once per sentence. */
const SpeechBubble = memo(function SpeechBubble({
  who,
  text,
  kind,
  accent,
  skipped,
  truncated,
}: {
  who: string;
  text: string;
  kind: TalkKind;
  accent: string;
  skipped: number;
  truncated: boolean;
}) {
  const t = useT();
  const label = KIND_KEY[kind];
  return (
    <div
      className="sw-bubble"
      data-kind={kind}
      data-accent=""
      style={{ ["--sw-accent" as string]: accent }}
    >
      <span className="sw-bubble-kind">
        <i className="sw-bubble-dot" style={{ background: accent }} />
        {who}
        {label && <em>{t(label)}</em>}
      </span>
      {text}
      {truncated ? t("society.world.talk_more") : ""}
      {skipped > 0 && (
        <span className="sw-bubble-digest">
          {fill(t("society.world.talk_digest"), { count: skipped }).replace("{0}", String(skipped))}
        </span>
      )}
    </div>
  );
});

/**
 * A bounded room in session: a ring on the ground at the Town Hall and a sign
 * saying which round it is on. The members are already standing there — the
 * checkpoint engine put them at `civic` — so this adds no movement of its own.
 */
function RoomSign({
  room,
  paused,
}: {
  room: NonNullable<ReturnType<typeof useConversationStore.getState>["room"]>;
  paused: boolean;
}) {
  const t = useT();
  const kit = useKit();
  const ring = useRef<Mesh>(null);
  // The viewer can turn the Town Hall; the ring follows it.
  const generation = useBuildingPoses((s) => s.generation);
  const anchor = useMemo(() => {
    const { map, content } = buildIsland();
    const [tx, tz] = content.places.civic.standTile;
    const [x, z] = tileToWorld(tx, tz);
    return { x, y: groundY(map, x, z) + 0.04, z };
    // `generation` is the island's rebuild counter, not an unused value.
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [generation]);

  useFrame(({ clock }) => {
    if (paused || !ring.current) return;
    const r = ROOM_RING_R_M * pipScale(clock.getElapsedTime() * 0.6);
    ring.current.scale.set(r, r, 1.6);
  });

  const round = fill(t("society.world.room_round"), { count: room.round })
    .replace("{0}", String(room.round))
    .replace("{1}", String(room.maxRounds));
  const reasonKey = `society.world.room_reason_${room.reason}`;
  const reason = room.reason ? t(reasonKey) : "";

  return (
    <group position={[anchor.x, anchor.y, anchor.z]}>
      <mesh
        ref={ring}
        geometry={kit.g.ring}
        material={kit.m.halo("#ffd166", room.settled ? 0.35 : 0.7)}
        rotation={[Math.PI / 2, 0, 0]}
        scale={[ROOM_RING_R_M, ROOM_RING_R_M, 1.6]}
      />
      <Html
        position={[0, ROOM_SIGN_Y_M, 0]}
        center
        zIndexRange={[32, 12]}
        style={{ pointerEvents: "none" }}
      >
        <div className="sw-roomsign">
          {room.settled ? (
            <>
              <span>{t("society.world.room_settled")}</span>
              {reason && reason !== reasonKey && (
                <span className="sw-roomsign-topic">{reason}</span>
              )}
            </>
          ) : (
            <>
              <span className="sw-roomsign-round">{round}</span>
              {room.topic && <span className="sw-roomsign-topic">{room.topic}</span>}
            </>
          )}
        </div>
      </Html>
    </group>
  );
}

export default ConversationScene;