mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-14 23:53:14 +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.
143 lines
6.3 KiB
TypeScript
143 lines
6.3 KiB
TypeScript
import { spread } from "@storyteller/framework";
|
|
import { match } from "@storyteller/utility";
|
|
import { LitElement, TemplateResult, html, nothing, unsafeCSS } from "lit";
|
|
import { customElement, property } from "lit/decorators.js";
|
|
import { unsafeSVG } from "lit/directives/unsafe-svg.js";
|
|
|
|
import farCrosshairs from "@fortawesome/fontawesome-pro/svgs/regular/crosshairs.svg?raw";
|
|
import farVideo from "@fortawesome/fontawesome-pro/svgs/regular/video.svg?raw";
|
|
import fasCircleQuestion from "@fortawesome/fontawesome-pro/svgs/solid/circle-question.svg?raw";
|
|
import fasKey from "@fortawesome/fontawesome-pro/svgs/solid/key.svg?raw";
|
|
import farCube from "@fortawesome/fontawesome-pro/svgs/regular/cube.svg?raw";
|
|
import farGlobe from "@fortawesome/fontawesome-pro/svgs/regular/globe.svg?raw";
|
|
import farUpDownLeftRight from "@fortawesome/fontawesome-pro/svgs/regular/arrows-up-down-left-right.svg?raw";
|
|
import fasPlay from "@fortawesome/fontawesome-pro/svgs/solid/play.svg?raw";
|
|
import fasPause from "@fortawesome/fontawesome-pro/svgs/solid/pause.svg?raw";
|
|
import fasFwdStep from "@fortawesome/fontawesome-pro/svgs/solid/forward-step.svg?raw";
|
|
import fasFwdFast from "@fortawesome/fontawesome-pro/svgs/solid/forward-fast.svg?raw";
|
|
import fasBwdStep from "@fortawesome/fontawesome-pro/svgs/solid/backward-step.svg?raw";
|
|
import fasBwdFast from "@fortawesome/fontawesome-pro/svgs/solid/backward-fast.svg?raw";
|
|
import fasQuestion from "@fortawesome/fontawesome-pro/svgs/solid/question.svg?raw";
|
|
import farRotate from "@fortawesome/fontawesome-pro/svgs/regular/arrows-rotate.svg?raw";
|
|
import farScale from "@fortawesome/fontawesome-pro/svgs/regular/arrow-up-right-and-arrow-down-left-from-center.svg?raw";
|
|
import fasCaretRight from "@fortawesome/fontawesome-pro/svgs/solid/caret-right.svg?raw";
|
|
import fasFloppyDisk from "@fortawesome/fontawesome-pro/svgs/solid/floppy-disk.svg?raw";
|
|
import farSkeleton from "@fortawesome/fontawesome-pro/svgs/regular/skeleton.svg?raw";
|
|
import farBone from "@fortawesome/fontawesome-pro/svgs/regular/bone.svg?raw";
|
|
import fasBrightness from "@fortawesome/fontawesome-pro/svgs/solid/brightness.svg?raw";
|
|
import fasCheck from "@fortawesome/fontawesome-pro/svgs/solid/check.svg?raw";
|
|
import fasXmark from "@fortawesome/fontawesome-pro/svgs/solid/xmark.svg?raw";
|
|
import fasCircleCheck from "@fortawesome/fontawesome-pro/svgs/solid/circle-check.svg?raw";
|
|
import fasCircleXmark from "@fortawesome/fontawesome-pro/svgs/solid/circle-xmark.svg?raw";
|
|
import fasMinus from "@fortawesome/fontawesome-pro/svgs/solid/minus.svg?raw";
|
|
import fasListTree from "@fortawesome/fontawesome-pro/svgs/solid/list-tree.svg?raw";
|
|
import fasBars from "@fortawesome/fontawesome-pro/svgs/solid/bars.svg?raw";
|
|
import fasPlusLarge from "@fortawesome/fontawesome-pro/svgs/solid/plus-large.svg?raw";
|
|
import farFileImport from "@fortawesome/fontawesome-pro/svgs/regular/file-import.svg?raw";
|
|
import farPhotoFilmMusic from "@fortawesome/fontawesome-pro/svgs/regular/photo-film-music.svg?raw";
|
|
import fasChevronDown from "@fortawesome/fontawesome-pro/svgs/solid/chevron-down.svg?raw";
|
|
import farVolume from "@fortawesome/fontawesome-pro/svgs/regular/volume.svg?raw";
|
|
import farFilm from "@fortawesome/fontawesome-pro/svgs/regular/film.svg?raw";
|
|
import fasPersonRunning from "@fortawesome/fontawesome-pro/svgs/solid/person-running.svg?raw";
|
|
import farMountainSun from "@fortawesome/fontawesome-pro/svgs/regular/mountain-sun.svg?raw";
|
|
import farArrowRightToBracket from "@fortawesome/fontawesome-pro/svgs/regular/arrow-right-to-bracket.svg?raw";
|
|
import farMagnifyingGlass from "@fortawesome/fontawesome-pro/svgs/regular/magnifying-glass.svg?raw";
|
|
import fasHouse from "@fortawesome/fontawesome-pro/svgs/solid/house.svg?raw";
|
|
import fasRecord from "@fortawesome/fontawesome-pro/svgs/solid/circle.svg?raw";
|
|
import fasUpload from "@fortawesome/fontawesome-pro/svgs/solid/upload.svg?raw";
|
|
|
|
import customCylinder from "../assets/icons/cylinder.svg?raw";
|
|
import customSphere from "../assets/icons/sphere.svg?raw";
|
|
import customTorus from "../assets/icons/torus.svg?raw";
|
|
|
|
import styles from "./icon.element.scss?inline";
|
|
|
|
@customElement("sts-icon")
|
|
export class IconElement extends LitElement {
|
|
static override styles = unsafeCSS(styles);
|
|
|
|
@property() icon = "";
|
|
|
|
protected override render = () => html`
|
|
<span class="a11y-label">
|
|
<slot></slot>
|
|
</span>
|
|
<div class="svg-wrapper" role="presentation">
|
|
${renderSvg(this.icon)}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
const RENDER_RESULTS = new Map<string, TemplateResult>();
|
|
|
|
function renderSvg(iconId: string) {
|
|
if (RENDER_RESULTS.has(iconId))
|
|
return RENDER_RESULTS.get(iconId)!;
|
|
|
|
const svgSrc = match (iconId, {
|
|
"bars": () => fasBars,
|
|
"bone": () => farBone,
|
|
"bwd-fast": () => fasBwdFast,
|
|
"bwd-step": () => fasBwdStep,
|
|
"caret-right": () => fasCaretRight,
|
|
"check": () => fasCheck,
|
|
"chevron-down": () => fasChevronDown,
|
|
"circle-check": () => fasCircleCheck,
|
|
"circle-question": () => fasCircleQuestion,
|
|
"circle-xmark": () => fasCircleXmark,
|
|
"crosshairs": () => farCrosshairs,
|
|
"cube": () => farCube,
|
|
"cylinder": () => customCylinder,
|
|
"figure": () => fasPersonRunning,
|
|
"file-import": () => farFileImport,
|
|
"film": () => farFilm,
|
|
"floppy-disk": () => fasFloppyDisk,
|
|
"fwd-fast": () => fasFwdFast,
|
|
"fwd-step": () => fasFwdStep,
|
|
"home": () => fasHouse,
|
|
"import": () => farArrowRightToBracket,
|
|
"key": () => fasKey,
|
|
"light": () => fasBrightness,
|
|
"list-tree": () => fasListTree,
|
|
"minus": () => fasMinus,
|
|
"globe": () => farGlobe,
|
|
"photo-film-music": () => farPhotoFilmMusic,
|
|
"play": () => fasPlay,
|
|
"pause": () => fasPause,
|
|
"plus-large": () => fasPlusLarge,
|
|
"question": () => fasQuestion,
|
|
"record": () => fasRecord,
|
|
"rotate": () => farRotate,
|
|
"scale": () => farScale,
|
|
"scene": () => farMountainSun,
|
|
"search": () => farMagnifyingGlass,
|
|
"skeleton": () => farSkeleton,
|
|
"sphere": () => customSphere,
|
|
"torus": () => customTorus,
|
|
"up-down-left-right": () => farUpDownLeftRight,
|
|
"upload": () => fasUpload,
|
|
"video": () => farVideo,
|
|
"volume": () => farVolume,
|
|
"xmark": () => fasXmark,
|
|
_: () => null,
|
|
});
|
|
|
|
if (!svgSrc) return nothing;
|
|
|
|
const [, attrsString, body] = svgSrc.match(/<svg(.+?)>(.+?)<\/svg>/s)!;
|
|
const attrs = Object.fromEntries(
|
|
Array.from(attrsString.matchAll(/([-:_a-zA-Z0-9]+)(?:=['"]?([^'"]*)['"]?)/g))
|
|
.map(([, attr, value]) => [attr, value])
|
|
);
|
|
|
|
const result = html`
|
|
<svg ${spread(attrs)}>
|
|
${unsafeSVG(body)}
|
|
</svg>
|
|
`;
|
|
|
|
RENDER_RESULTS.set(iconId, result);
|
|
|
|
return result;
|
|
}
|