"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { adminFetch } from "@/lib/admin-fetch"; export function NitroScale32Generator({ classname, disabled, onChanged, }: { classname: string; disabled: boolean; onChanged: (metadata: Record) => void; }) { const [preview, setPreview] = useState<{ hash: string; before: string; after: string; count: number; skipped?: number; } | null>(null), [undo, setUndo] = useState<{ hash: string; backupHash: string } | null>( null, ), [busy, setBusy] = useState(false), [error, setError] = useState(""); async function run(action: "preview" | "apply" | "restore") { setBusy(true); setError(""); try { const response = await adminFetch("/api/admin/studio/nitro-scale32", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ classname, action, expectedHash: action === "restore" ? undo?.hash : preview?.hash, backupHash: undo?.backupHash, }), }); const data = await response.json(); if (!response.ok) throw Error(data.error || "Generation failed"); if (action === "preview") setPreview(data); else { setPreview(null); setUndo( action === "apply" ? { hash: data.hash, backupHash: data.backupHash } : null, ); onChanged(data.metadata); } } catch (e) { setError(e instanceof Error ? e.message : "Generation failed"); } finally { setBusy(false); } } return (

Generate scale 32 from 64

Adds derived artwork using nearest-neighbor reduction. Existing scale 32 is preserved. Preview uses the saved bundle and shows one sprite at its original pixel size.

{disabled && (

Save or reset your pending edits first.

)} {preview && ( <>

{preview.count} sprite entries will be added. Check positioning and animations in the client after saving.

{preview.skipped ? (

{preview.skipped} sprite(s) were skipped because the source bundle has no usable artwork for them.

) : null}
{[ ["Original 64", preview.before], ["Derived 32", preview.after], ].map(([label, src]) => (
{label}
{label}
))}
)} {undo && (

Saved. A copy of the original bundle is preserved.

)} {error && (

{error}

)}
); }