Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

1.2 KB
Raw Blame
// Debug overlays (sdk/react/docs/playtest.md, "views"): drawings a game or piece keeps beside its picture (hitboxes, its
// state as text, a path) that show only in a render asked for them. A playtest view renders the same frame clean for a
// taste question and with overlays for a diagnosis; the overlays are never in the clean render, nor in live play.
// The render asks by setting globalThis.__RAEA_OVERLAYS__ (names, or "*" for all) before the bundle runs.
import type { ReactNode } from "react";

/** The overlays this render was asked for ([] in a clean render and in live play). */
export function overlays(): string[] {
  const o = (globalThis as { __RAEA_OVERLAYS__?: unknown }).__RAEA_OVERLAYS__;
  return Array.isArray(o) ? o.filter((x): x is string => typeof x === "string") : [];
}

export interface OverlayProps {
  /** the overlay's name, as the render asks for it */
  name: string;
  /** what the overlay draws */
  children?: ReactNode;
}

/** Its children only in a render asked for the overlay `name`. */
export function Overlay({ name, children }: OverlayProps) {
  const on = overlays();
  return on.includes(name) || on.includes("*") ? (children ?? null) : null;
}