Files
gods-eye-view/src/ui/scenePresentation.js
T
Sameh Khamis ec4c55e78c feat(scenes): render the Scene panel's controls from the store
SceneControls no longer takes element handles or writes the Scene panel's
button states, PLAY label, status line, progress bar or runtime chip: it
presents them to the gev-scenes store, and the panel's buttons, scene
select and IMPORT chooser call its actions there. The chooser opens only
while an owner presents the panel and is cleared once its import settles.
On destroy the panel keeps its last status and buttons, without shots or
the runtime chip, as before.
2026-10-31 23:04:31 -07:00

92 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** The Scene panel's text and button presentation; the panel views render
* it. */
import { formatNumber, msg, t } from '../i18n/index.js';
// Labels for what a shot stores; anything else shows as stored. Style names
// match STYLE_STATUS_LABELS in visualPresets.js, which this package cannot
// import (it pulls in the shaders).
const STYLE_LABELS = Object.freeze({
normal: msg('NORMAL'),
retro: msg('CRT'),
surveillance: msg('NVG'),
thermal: msg('FLIR'),
anime: msg('ANIME'),
noir: msg('NOIR'),
});
const DETECTION_MODE_LABELS = Object.freeze({
OFF: msg('OFF'),
SPARSE: msg('SPARSE'),
BALANCED: msg('BALANCED'),
DENSE: msg('DENSE'),
});
/**
* A shot's summary line: its style, detection mode and timing.
* @param {object} shot
* @returns {string}
*/
export function describeShot(shot) {
const mode = shot.visual?.detection?.mode || 'OFF';
const style = shot.visual?.style || 'normal';
const styleLabel = STYLE_LABELS[style]
? t(STYLE_LABELS[style])
: style.toUpperCase();
const modeLabel = DETECTION_MODE_LABELS[mode]
? t(DETECTION_MODE_LABELS[mode])
: mode;
const seconds = (value) =>
formatNumber(value, {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
});
// English keeps its compact "4.0s + 0.9s"; other languages space the unit.
const timing = t('{duration}s + {hold}s', {
duration: seconds(shot.durationSec),
hold: seconds(shot.holdSec),
});
return `${styleLabel} · ${modeLabel} · ${timing}`;
}
/**
* While a scene plays, the authoring and file actions here are off and STOP
* is on. Otherwise a button is off when it would do nothing: DELETE and
* CAPTURE SHOT without a scene, UPDATE SHOT without a selected shot, PLAY and
* NEXT when no scene in the project has a shot (both continue into the
* following scenes).
*/
export function sceneButtonsDisabled(
running,
hasRun,
{ hasScene = true, playableShots = 1, hasSelectedShot = true } = {},
) {
const idleOff = {
delete: !hasScene,
capture: !hasScene,
update: !hasSelectedShot,
start: playableShots === 0,
next: playableShots === 0,
};
const disabled = {};
for (const name of [
'start',
'next',
'select',
'new',
'delete',
'capture',
'update',
'export',
'import',
])
disabled[name] = running || !!idleOff[name];
disabled.stop = !running;
disabled.download = !hasRun;
return disabled;
}
/** @returns {number} Whole percent, 0–100. */
export function scenePercent(progress) {
return Math.round(Math.max(0, Math.min(1, progress)) * 100);
}