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.

2.9 KB
Raw Blame
// The two pieces of page every playable has: a button that opens the store, and the end card shown when the game is
// over. Plain page elements, so a raea render draws them as the playable does.
import { useEffect, type CSSProperties, type ReactNode } from "react";
import { end, install } from "./network";

export interface InstallButtonProps {
  children?: ReactNode;
  style?: CSSProperties;
}

const BUTTON: CSSProperties = {
  border: "none",
  borderRadius: 999,
  padding: "0.7em 1.6em",
  fontFamily: "Inter, system-ui, sans-serif",
  fontWeight: 800,
  fontSize: 40,
  color: "#101422",
  background: "#ffd166",
  boxShadow: "0 6px 0 rgba(0,0,0,0.25)",
  cursor: "pointer",
};

/** Opens the store when tapped (install()). */
export function InstallButton({ children = "Install", style }: InstallButtonProps) {
  return (
    <button
      type="button"
      onPointerUp={(e) => {
        e.stopPropagation();
        install();
      }}
      style={{ ...BUTTON, ...style }}
    >
      {children}
    </button>
  );
}

export interface EndCardProps {
  /** shown once the game is over (a state the game's fold reaches); end() is called when it first shows */
  show: boolean;
  title?: string;
  subtitle?: string;
  /** the app's icon: an imported picture (`import icon from "./icon.png"`), which the export carries in the page */
  icon?: string;
  cta?: string;
  background?: string;
  /** the card's type (a brand's font, carried by importing it in an @font-face), Inter by default */
  font?: string;
  /** the text's colour, white by default */
  color?: string;
  /** the button's look over the default yellow pill: a brand's colours and type */
  button?: CSSProperties;
  children?: ReactNode;
}

/** The card the playable ends on: the whole card opens the store when tapped, as networks expect. */
export function EndCard({ show, title, subtitle, icon, cta = "Play now", background = "rgba(10, 12, 24, 0.82)", font = "Inter, system-ui, sans-serif", color = "#ffffff", button, children }: EndCardProps) {
  useEffect(() => {
    if (show) end();
  }, [show]);
  if (!show) return null;
  return (
    <div
      onPointerUp={() => install()}
      style={{
        position: "absolute",
        inset: 0,
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
        justifyContent: "center",
        gap: 28,
        background,
        color,
        fontFamily: font,
        textAlign: "center",
        cursor: "pointer",
      }}
    >
      {icon ? <img src={icon} alt="" style={{ width: 180, height: 180, borderRadius: 40 }} /> : null}
      {title ? <div style={{ fontSize: 64, fontWeight: 900, lineHeight: 1.05, padding: "0 40px" }}>{title}</div> : null}
      {subtitle ? <div style={{ fontSize: 34, opacity: 0.8, padding: "0 40px" }}>{subtitle}</div> : null}
      {children}
      <InstallButton style={button}>{cta}</InstallButton>
    </div>
  );
}