mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-18 07:35:19 +00:00
1163192d24
This PR updates the Media Library feature to implement asset imports
from the local file system, and spawning assets from the library into
the scene. Additionally, some placeholder functionality has been
scaffolded for adding animations onto existing characters in the scene.
### Additional Changes
* Dialogs can be set to `nonBlocking` to allow interaction with
background elements (note: this is fraught for accessibility and likely
temporary, to facilitate testing while the UI/UX redesign is in
progress)
* Dialogs can be moved around the screen by dragging their title-bars
* The `scene` module has been moved into a folder with a separate
`wasm.rs` file for its submodule. (`scene/mod.rs` remains one of our
largest single Rust files and could probably stand to be partitioned
further.)
### To-Do
* Support for adding animations is not yet fully implemented, though
some prerequisite functionality has been scaffolded. Namely, the "Add to
Scene" button will be disabled if:
- There is a mix of animations and non-animations selected in the Media
Library
- There is more than one animation selected in the Media Library
- There is one animation selected in the Media Library, but no
animatable character selected in the scene
* Adding full Storyteller-format scenes to the existing scene is not a
use case that has been tested, and may not be a use case we wish to
support in the long-term, as some of the data stored in Storyteller
scenes are intended to be "singleton" resources that may conflict with
existing data in the scene.
**Attempting to spawn a Storyteller scene through the Media Library has
not been explicitly blocked for now, but may cause unexpected
behavior.** This needs additional UX consideration and grooming.
162 lines
4.0 KiB
TypeScript
162 lines
4.0 KiB
TypeScript
import { on } from "@storyteller/framework";
|
|
import { LitElement, PropertyValues, TemplateResult, html, unsafeCSS } from "lit";
|
|
import { customElement, property, queryAssignedElements, state } from "lit/decorators.js";
|
|
import { classMap } from "lit/directives/class-map.js";
|
|
import { v4 as uuid } from "uuid";
|
|
|
|
import { type DialogHeaderElement } from "./dialog-header.element";
|
|
|
|
import styles from "./dialog-base.element.scss?inline";
|
|
|
|
/**
|
|
* A base template for building custom dialogs. Can be extended via inheritance
|
|
* or customized with [named slots](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot)
|
|
* and [CSS parts](https://developer.mozilla.org/en-US/docs/Web/CSS/::part).
|
|
*
|
|
* @slot `dialog-header`
|
|
*
|
|
* Insert a custom header. Can alternatively be configured via the
|
|
* {@linkcode heading} and {@linkcode icon} properties. See also
|
|
* {@linkcode DialogHeaderElement}.
|
|
*
|
|
* @slot `sidebar`
|
|
*
|
|
* Insert a custom sidebar (empty by default).
|
|
*
|
|
* @slot `footer`
|
|
*
|
|
* Insert a custom footer (empty by default and not currently styled).
|
|
*
|
|
* @slot (default)
|
|
*
|
|
* Projected content without a named `slot` attribute will appear in the main
|
|
* content area.
|
|
*
|
|
* @part `header`
|
|
*
|
|
* A CSS part for styling the default dialog header. Has no effect if a custom
|
|
* `sts-dialog-header` or `[part="dialog-header"]` is inserted.
|
|
*
|
|
* @part `main`
|
|
*
|
|
* A CSS part for styling the wrapper around the `sidebar` and `content` areas.
|
|
*
|
|
* @part `content`
|
|
*
|
|
* A CSS part to style the wrapper around the main content area.
|
|
*/
|
|
@customElement("sts-dialog-base")
|
|
export class DialogBaseElement extends LitElement {
|
|
static override styles = unsafeCSS(styles);
|
|
|
|
@property({ reflect: true })
|
|
override role = "dialog";
|
|
|
|
@property({
|
|
attribute: "aria-label",
|
|
reflect: true,
|
|
})
|
|
heading?: string;
|
|
|
|
@property() icon?: string;
|
|
|
|
override ariaModal = "true";
|
|
override tabIndex = -1;
|
|
|
|
@state() _hasFooter = false;
|
|
|
|
@queryAssignedElements({ slot: "dialog-header" })
|
|
dialogHeaders!: Element[];
|
|
|
|
@queryAssignedElements({ slot: "footer" })
|
|
dialogFooters!: Element[];
|
|
|
|
@state() _translateX?: number;
|
|
@state() _translateY?: number;
|
|
|
|
override connectedCallback(): void {
|
|
this.focus();
|
|
super.connectedCallback();
|
|
}
|
|
|
|
protected override update(changes: PropertyValues<this>): void {
|
|
if (
|
|
changes.has("_translateX") || changes.has("_translateY")
|
|
&& (this._translateX != null || this._translateY != null)
|
|
) {
|
|
this.style.setProperty(
|
|
"transform",
|
|
`translateX(${this._translateX ?? 0}px) ` +
|
|
`translateY(${this._translateY ?? 0}px)`
|
|
);
|
|
}
|
|
|
|
super.update(changes);
|
|
}
|
|
|
|
@on("keydown")
|
|
onKeydown(event: KeyboardEvent): void {
|
|
if (/^(Escape|Shift)$/.test(event.key))
|
|
event.stopPropagation();
|
|
|
|
if (event.key === "Escape")
|
|
this.dispatchEvent(new CustomEvent("close"));
|
|
}
|
|
|
|
@on("translate", { capture: true })
|
|
onTranslate({ detail: { x, y }}: CustomEvent<{ x: number; y: number }>): void {
|
|
this._translateX = x;
|
|
this._translateY = y;
|
|
}
|
|
|
|
onDialogHeaderChanged(): void {
|
|
if (this.dialogHeaders.length && !this.ariaLabel) {
|
|
const header = this.dialogHeaders[0];
|
|
header.id = uuid();
|
|
this.setAttribute("aria-labelledby", header.id);
|
|
}
|
|
else if (!this.dialogHeaders.length && this.hasAttribute("aria-labelledby")) {
|
|
this.removeAttribute("aria-labelledby");
|
|
}
|
|
}
|
|
|
|
onFooterChanged(): void {
|
|
this._hasFooter = this.dialogFooters.length > 0;
|
|
}
|
|
|
|
protected override render(): TemplateResult {
|
|
return html`
|
|
<slot
|
|
name="dialog-header"
|
|
@slotchange=${this.onDialogHeaderChanged}
|
|
>
|
|
<sts-dialog-header
|
|
part="header"
|
|
.icon=${this.icon}
|
|
>
|
|
${this.heading}
|
|
</sts-dialog-header>
|
|
</slot>
|
|
|
|
<section class="main" part="main">
|
|
<slot name="sidebar" part="sidebar"></slot>
|
|
|
|
<section
|
|
class=${classMap({
|
|
"content": true,
|
|
"with-footer": this._hasFooter,
|
|
})}
|
|
part="content"
|
|
>
|
|
<slot></slot>
|
|
</section>
|
|
</section>
|
|
|
|
<slot
|
|
name="footer"
|
|
@slotchange=${this.onFooterChanged}
|
|
></slot>
|
|
`;
|
|
}
|
|
}
|