import * as studio from "@storyteller/studio"; import { match } from "@storyteller/utility"; import { LitElement, html, unsafeCSS } from "lit"; import { customElement, property } from "lit/decorators.js"; import { v4 as uuid } from "uuid"; import { type Rgba } from "./inspector.types"; import styles from "./material-inspector.element.scss?inline"; @customElement("sts-material-inspector") export class MaterialInspectorElement extends LitElement { static override styles = unsafeCSS(styles); @property({ attribute: false }) baseColor: Rgba = { red: 1, green: 1, blue: 1, alpha: 1 }; @property() inputColorSpace: "linear"|"srgb" = "linear"; #baseColorId = uuid(); onBaseColorInput(event: InputEvent): void { const hex = (event.target as HTMLInputElement).value; const value = match (this.inputColorSpace, { "linear": () => RgbaLinear.fromHexSrgb(hex, this.baseColor.alpha), "srgb": () => Srgba.fromHex(hex, this.baseColor.alpha), }); studio.updateComponentField({ component: "bevy_pbr::pbr_material::StandardMaterial", reflectPath: "base_color", value, }); } protected override render() { const [rgb, _] = match (this.inputColorSpace, { "linear": () => RgbaLinear.toHexSrgb(this.baseColor), "srgb": () => Srgba.toHex(this.baseColor), }); return html`