813 lines
24 KiB
HTML
813 lines
24 KiB
HTML
<!doctype html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>LED Volume Control</title>
|
|
<style>
|
|
:root {
|
|
color-scheme: dark;
|
|
--bg: #101112;
|
|
--panel: #191b1d;
|
|
--panel-2: #222529;
|
|
--line: #34383d;
|
|
--text: #f3f1e8;
|
|
--muted: #a9adb3;
|
|
--accent: #12c7d8;
|
|
--accent-2: #f7c744;
|
|
--danger: #ff5b5b;
|
|
--ok: #4bd377;
|
|
--radius: 8px;
|
|
font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
|
|
}
|
|
|
|
* { box-sizing: border-box; }
|
|
body {
|
|
margin: 0;
|
|
min-height: 100vh;
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
letter-spacing: 0;
|
|
}
|
|
|
|
.shell {
|
|
display: grid;
|
|
grid-template-columns: 260px minmax(0, 1fr);
|
|
min-height: 100vh;
|
|
}
|
|
|
|
aside {
|
|
border-right: 1px solid var(--line);
|
|
background: #141618;
|
|
padding: 18px 14px;
|
|
position: sticky;
|
|
top: 0;
|
|
height: 100vh;
|
|
overflow: auto;
|
|
}
|
|
|
|
main {
|
|
padding: 18px 22px 40px;
|
|
overflow: auto;
|
|
}
|
|
|
|
.brand {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 12px;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
h1 {
|
|
font-size: 18px;
|
|
line-height: 1.2;
|
|
margin: 0;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.status-dot {
|
|
width: 10px;
|
|
height: 10px;
|
|
border-radius: 50%;
|
|
background: var(--danger);
|
|
flex: 0 0 auto;
|
|
box-shadow: 0 0 16px currentColor;
|
|
}
|
|
|
|
.status-dot.ok { background: var(--ok); color: var(--ok); }
|
|
|
|
.meta {
|
|
display: grid;
|
|
gap: 8px;
|
|
margin: 14px 0 18px;
|
|
font-size: 12px;
|
|
color: var(--muted);
|
|
}
|
|
|
|
.meta strong { color: var(--text); font-weight: 600; }
|
|
|
|
.nav {
|
|
display: grid;
|
|
gap: 6px;
|
|
}
|
|
|
|
.nav button,
|
|
.toolbar button,
|
|
.command {
|
|
border: 1px solid var(--line);
|
|
background: transparent;
|
|
color: var(--text);
|
|
border-radius: var(--radius);
|
|
min-height: 36px;
|
|
padding: 8px 10px;
|
|
text-align: left;
|
|
cursor: pointer;
|
|
font: inherit;
|
|
}
|
|
|
|
.nav button {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
gap: 8px;
|
|
color: var(--muted);
|
|
}
|
|
|
|
.nav button.active {
|
|
color: var(--text);
|
|
background: #202427;
|
|
border-color: #4a5056;
|
|
}
|
|
|
|
.count {
|
|
font-size: 11px;
|
|
color: var(--muted);
|
|
min-width: 24px;
|
|
text-align: right;
|
|
}
|
|
|
|
.topbar {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 10px;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 18px;
|
|
}
|
|
|
|
.search {
|
|
flex: 1 1 300px;
|
|
min-width: 220px;
|
|
height: 38px;
|
|
border: 1px solid var(--line);
|
|
border-radius: var(--radius);
|
|
background: #151719;
|
|
color: var(--text);
|
|
padding: 0 12px;
|
|
font: inherit;
|
|
}
|
|
|
|
.toolbar {
|
|
display: flex;
|
|
gap: 8px;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.toolbar button {
|
|
text-align: center;
|
|
background: var(--panel-2);
|
|
}
|
|
|
|
.toolbar button.primary {
|
|
border-color: #198e98;
|
|
background: #123438;
|
|
}
|
|
|
|
.groups {
|
|
display: grid;
|
|
gap: 16px;
|
|
}
|
|
|
|
section {
|
|
border-top: 1px solid var(--line);
|
|
padding-top: 14px;
|
|
}
|
|
|
|
section h2 {
|
|
font-size: 15px;
|
|
margin: 0 0 12px;
|
|
font-weight: 700;
|
|
color: var(--text);
|
|
}
|
|
|
|
.grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
|
gap: 10px;
|
|
}
|
|
|
|
.control {
|
|
border: 1px solid var(--line);
|
|
border-radius: var(--radius);
|
|
background: var(--panel);
|
|
min-height: 84px;
|
|
padding: 12px;
|
|
display: grid;
|
|
gap: 10px;
|
|
align-content: start;
|
|
}
|
|
|
|
.label-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
font-size: 13px;
|
|
line-height: 1.25;
|
|
font-weight: 650;
|
|
color: var(--text);
|
|
overflow-wrap: anywhere;
|
|
}
|
|
|
|
.type {
|
|
font-size: 11px;
|
|
color: var(--muted);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
input,
|
|
select,
|
|
textarea {
|
|
width: 100%;
|
|
min-height: 34px;
|
|
border-radius: 6px;
|
|
border: 1px solid #3b4046;
|
|
background: #101214;
|
|
color: var(--text);
|
|
padding: 6px 8px;
|
|
font: inherit;
|
|
font-size: 13px;
|
|
}
|
|
|
|
input[type="range"] {
|
|
padding: 0;
|
|
accent-color: var(--accent);
|
|
}
|
|
|
|
input[type="checkbox"] {
|
|
width: 20px;
|
|
height: 20px;
|
|
min-height: 20px;
|
|
accent-color: var(--accent);
|
|
}
|
|
|
|
input[type="color"] {
|
|
padding: 2px;
|
|
height: 36px;
|
|
}
|
|
|
|
textarea {
|
|
min-height: 72px;
|
|
resize: vertical;
|
|
font-family: Consolas, monospace;
|
|
}
|
|
|
|
.number-row,
|
|
.vector-row,
|
|
.color-row {
|
|
display: grid;
|
|
gap: 8px;
|
|
}
|
|
|
|
.number-row {
|
|
grid-template-columns: minmax(0, 1fr) 96px;
|
|
align-items: center;
|
|
}
|
|
|
|
.vector-row {
|
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
}
|
|
|
|
.rgba-row {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
gap: 8px;
|
|
}
|
|
|
|
.read-only {
|
|
color: var(--accent-2);
|
|
font-variant-numeric: tabular-nums;
|
|
word-break: break-word;
|
|
}
|
|
|
|
.commands {
|
|
display: flex;
|
|
gap: 8px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.command {
|
|
background: #202427;
|
|
text-align: center;
|
|
min-width: 132px;
|
|
}
|
|
|
|
.toast {
|
|
position: fixed;
|
|
right: 18px;
|
|
bottom: 18px;
|
|
max-width: min(420px, calc(100vw - 36px));
|
|
background: #202427;
|
|
border: 1px solid var(--line);
|
|
border-radius: var(--radius);
|
|
color: var(--text);
|
|
padding: 10px 12px;
|
|
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
|
|
opacity: 0;
|
|
transform: translateY(12px);
|
|
pointer-events: none;
|
|
transition: 160ms ease;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.toast.show {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.toast.error { border-color: #8f3434; color: #ffd9d9; }
|
|
|
|
@media (max-width: 860px) {
|
|
.shell { grid-template-columns: 1fr; }
|
|
aside {
|
|
position: static;
|
|
height: auto;
|
|
border-right: 0;
|
|
border-bottom: 1px solid var(--line);
|
|
}
|
|
.nav { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
|
|
main { padding: 16px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="shell">
|
|
<aside>
|
|
<div class="brand">
|
|
<h1>LED Volume Control</h1>
|
|
<span id="statusDot" class="status-dot" title="API status"></span>
|
|
</div>
|
|
<div class="meta">
|
|
<div>Preset: <strong id="presetName">...</strong></div>
|
|
<div>API: <strong id="apiState">connecting</strong></div>
|
|
<div>Last update: <strong id="lastUpdate">never</strong></div>
|
|
</div>
|
|
<div id="nav" class="nav"></div>
|
|
</aside>
|
|
|
|
<main>
|
|
<div class="topbar">
|
|
<input id="search" class="search" type="search" placeholder="Search parameter">
|
|
<div class="toolbar">
|
|
<button id="refreshButton" type="button">Refresh</button>
|
|
<button id="syncButton" class="primary" type="button">Sync</button>
|
|
<button id="applyButton" class="primary" type="button">Apply</button>
|
|
<button id="rebuildButton" type="button">Rebuild</button>
|
|
</div>
|
|
</div>
|
|
<div id="groups" class="groups"></div>
|
|
</main>
|
|
</div>
|
|
|
|
<div id="toast" class="toast"></div>
|
|
|
|
<script>
|
|
const API = 'http://127.0.0.1:30010';
|
|
const PREFERRED_PRESET = 'RCP_LedVolumeLive';
|
|
const state = {
|
|
presetId: '',
|
|
preset: null,
|
|
values: new Map(),
|
|
activeGroup: 'all',
|
|
search: '',
|
|
pending: new Map(),
|
|
polling: false
|
|
};
|
|
|
|
const el = {
|
|
nav: document.getElementById('nav'),
|
|
groups: document.getElementById('groups'),
|
|
statusDot: document.getElementById('statusDot'),
|
|
presetName: document.getElementById('presetName'),
|
|
apiState: document.getElementById('apiState'),
|
|
lastUpdate: document.getElementById('lastUpdate'),
|
|
search: document.getElementById('search'),
|
|
toast: document.getElementById('toast'),
|
|
refreshButton: document.getElementById('refreshButton'),
|
|
syncButton: document.getElementById('syncButton'),
|
|
applyButton: document.getElementById('applyButton'),
|
|
rebuildButton: document.getElementById('rebuildButton')
|
|
};
|
|
|
|
function showToast(message, isError = false) {
|
|
el.toast.textContent = message;
|
|
el.toast.classList.toggle('error', isError);
|
|
el.toast.classList.add('show');
|
|
clearTimeout(showToast.timer);
|
|
showToast.timer = setTimeout(() => el.toast.classList.remove('show'), 2200);
|
|
}
|
|
|
|
function setApiState(ok, text) {
|
|
el.statusDot.classList.toggle('ok', ok);
|
|
el.apiState.textContent = text;
|
|
}
|
|
|
|
async function api(path, options = {}) {
|
|
const response = await fetch(API + path, {
|
|
...options,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(options.headers || {})
|
|
}
|
|
});
|
|
if (!response.ok) {
|
|
const text = await response.text();
|
|
throw new Error(text || `${response.status} ${response.statusText}`);
|
|
}
|
|
const text = await response.text();
|
|
return text ? JSON.parse(text) : null;
|
|
}
|
|
|
|
function uniqueName(name) {
|
|
return String(name || '').replace(/\s+\(\d+\)$/u, '');
|
|
}
|
|
|
|
function propertyName(property) {
|
|
return property?.UnderlyingProperty?.Name || uniqueName(property.DisplayName);
|
|
}
|
|
|
|
function propertyType(property) {
|
|
return property?.UnderlyingProperty?.Type || '';
|
|
}
|
|
|
|
function enumValues(property) {
|
|
const raw = property?.UnderlyingProperty?.Metadata?.EnumValues || '';
|
|
return raw.split(',').map(item => item.trim()).filter(Boolean);
|
|
}
|
|
|
|
function minMax(property) {
|
|
const meta = property.Metadata || {};
|
|
const under = property.UnderlyingProperty?.Metadata || {};
|
|
const minRaw = meta.Min || under.ClampMin || '';
|
|
const maxRaw = meta.Max || under.ClampMax || '';
|
|
const min = minRaw !== '' && Number.isFinite(Number(minRaw)) ? Number(minRaw) : null;
|
|
const max = maxRaw !== '' && Number.isFinite(Number(maxRaw)) ? Number(maxRaw) : null;
|
|
return { min, max };
|
|
}
|
|
|
|
function getGroups() {
|
|
if (!state.preset) return [];
|
|
return (state.preset.Groups || [])
|
|
.filter(group => group.Name !== 'All')
|
|
.map(group => {
|
|
const seen = new Set();
|
|
const props = (group.ExposedProperties || []).filter(prop => {
|
|
const name = propertyName(prop);
|
|
if (seen.has(name)) return false;
|
|
seen.add(name);
|
|
return true;
|
|
});
|
|
const funcs = (group.ExposedFunctions || []).filter(func => !/\(\d+\)$/u.test(func.DisplayName || ''));
|
|
return { ...group, ExposedProperties: props, ExposedFunctions: funcs };
|
|
})
|
|
.filter(group => group.ExposedProperties.length || group.ExposedFunctions.length);
|
|
}
|
|
|
|
function allProperties() {
|
|
return getGroups().flatMap(group => group.ExposedProperties || []);
|
|
}
|
|
|
|
async function loadPreset() {
|
|
const presets = await api('/remote/presets');
|
|
const presetInfo = (presets.Presets || []).find(item => item.Name === PREFERRED_PRESET) || (presets.Presets || [])[0];
|
|
if (!presetInfo) throw new Error('Remote Control preset not found');
|
|
state.presetId = presetInfo.ID;
|
|
const presetResponse = await api(`/remote/preset/${state.presetId}`);
|
|
state.preset = presetResponse.Preset;
|
|
el.presetName.textContent = state.preset.Name || presetInfo.Name;
|
|
}
|
|
|
|
async function loadValues() {
|
|
const props = allProperties();
|
|
await Promise.all(props.map(async prop => {
|
|
const name = propertyName(prop);
|
|
try {
|
|
const data = await api(`/remote/preset/${state.presetId}/property/${encodeURIComponent(name)}`);
|
|
state.values.set(name, data.PropertyValues?.[0]?.PropertyValue);
|
|
} catch (error) {
|
|
state.values.set(name, undefined);
|
|
}
|
|
}));
|
|
el.lastUpdate.textContent = new Date().toLocaleTimeString();
|
|
}
|
|
|
|
function renderNav(groups) {
|
|
const total = groups.reduce((sum, group) => sum + group.ExposedProperties.length, 0);
|
|
const buttons = [`<button data-group="all" class="${state.activeGroup === 'all' ? 'active' : ''}">All parameters <span class="count">${total}</span></button>`];
|
|
for (const group of groups) {
|
|
const active = state.activeGroup === group.Name ? 'active' : '';
|
|
const count = group.ExposedProperties.length + group.ExposedFunctions.length;
|
|
buttons.push(`<button data-group="${escapeHtml(group.Name)}" class="${active}">${escapeHtml(group.Name)} <span class="count">${count}</span></button>`);
|
|
}
|
|
el.nav.innerHTML = buttons.join('');
|
|
el.nav.querySelectorAll('button').forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
state.activeGroup = button.dataset.group;
|
|
render();
|
|
});
|
|
});
|
|
}
|
|
|
|
function shouldShowProperty(prop) {
|
|
if (!state.search) return true;
|
|
const haystack = `${propertyName(prop)} ${prop.DisplayName || ''} ${propertyType(prop)}`.toLowerCase();
|
|
return haystack.includes(state.search.toLowerCase());
|
|
}
|
|
|
|
function render() {
|
|
const groups = getGroups();
|
|
renderNav(groups);
|
|
const visibleGroups = groups
|
|
.filter(group => state.activeGroup === 'all' || group.Name === state.activeGroup)
|
|
.map(group => ({
|
|
...group,
|
|
ExposedProperties: group.ExposedProperties.filter(shouldShowProperty)
|
|
}))
|
|
.filter(group => group.ExposedProperties.length || (!state.search && group.ExposedFunctions.length));
|
|
|
|
el.groups.innerHTML = visibleGroups.map(renderGroup).join('');
|
|
bindControls();
|
|
}
|
|
|
|
function renderGroup(group) {
|
|
const props = group.ExposedProperties.map(renderProperty).join('');
|
|
const funcs = group.ExposedFunctions.length && !state.search ? renderFunctions(group.ExposedFunctions) : '';
|
|
return `
|
|
<section id="${escapeHtml(group.Name)}">
|
|
<h2>${escapeHtml(group.Name)}</h2>
|
|
${props ? `<div class="grid">${props}</div>` : ''}
|
|
${funcs}
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
function renderFunctions(functions) {
|
|
const allowed = new Set(['ApplyToTarget', 'RebuildTarget', 'SyncFromTarget', 'GetTargetDisplay']);
|
|
const buttons = functions
|
|
.filter(fn => allowed.has(uniqueName(fn.DisplayName)))
|
|
.map(fn => `<button class="command" data-function="${escapeHtml(uniqueName(fn.DisplayName))}" type="button">${escapeHtml(uniqueName(fn.DisplayName))}</button>`)
|
|
.join('');
|
|
return buttons ? `<div class="commands">${buttons}</div>` : '';
|
|
}
|
|
|
|
function renderProperty(prop) {
|
|
const name = propertyName(prop);
|
|
const type = propertyType(prop);
|
|
const value = state.values.get(name);
|
|
return `
|
|
<div class="control" data-property="${escapeHtml(name)}" data-type="${escapeHtml(type)}">
|
|
<div class="label-row">
|
|
<label>${escapeHtml(prop.DisplayName || name)}</label>
|
|
<span class="type">${escapeHtml(type)}</span>
|
|
</div>
|
|
${renderEditor(prop, value)}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
function renderEditor(prop, value) {
|
|
const name = propertyName(prop);
|
|
const type = propertyType(prop);
|
|
if (name === 'RenderedInstanceCount' || name === 'RequestedVoxelCount') {
|
|
return `<div class="read-only">${escapeHtml(formatValue(value))}</div>`;
|
|
}
|
|
if (type === 'bool') {
|
|
return `<input type="checkbox" data-kind="bool" ${value ? 'checked' : ''}>`;
|
|
}
|
|
if (type === 'int32' || type === 'int64' || type === 'float' || type === 'double') {
|
|
const { min, max } = minMax(prop);
|
|
const step = type.startsWith('int') ? '1' : '0.01';
|
|
const val = Number.isFinite(Number(value)) ? Number(value) : 0;
|
|
const hasRange = min !== null && max !== null;
|
|
return `
|
|
<div class="number-row">
|
|
${hasRange ? `<input type="range" data-kind="number" min="${min}" max="${max}" step="${step}" value="${val}">` : '<span></span>'}
|
|
<input type="number" data-kind="number" step="${step}" ${min !== null ? `min="${min}"` : ''} ${max !== null ? `max="${max}"` : ''} value="${val}">
|
|
</div>
|
|
`;
|
|
}
|
|
if (enumValues(prop).length) {
|
|
const options = enumValues(prop).map(option => `<option value="${escapeHtml(option)}" ${option === value ? 'selected' : ''}>${escapeHtml(option)}</option>`).join('');
|
|
return `<select data-kind="enum">${options}</select>`;
|
|
}
|
|
if (type === 'FLinearColor') {
|
|
const c = normalizeColor(value);
|
|
return `
|
|
<div class="color-row">
|
|
<input type="color" data-kind="color-picker" value="${rgbToHex(c)}">
|
|
<div class="rgba-row">
|
|
${['R', 'G', 'B', 'A'].map(key => `<input type="number" data-kind="color-number" data-channel="${key}" min="0" max="16" step="0.01" value="${Number(c[key]).toFixed(2)}">`).join('')}
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
if (type === 'FVector') {
|
|
const v = normalizeVector(value);
|
|
return `
|
|
<div class="vector-row">
|
|
${['X', 'Y', 'Z'].map(key => `<input type="number" data-kind="vector" data-channel="${key}" step="0.1" value="${Number(v[key]).toFixed(2)}">`).join('')}
|
|
</div>
|
|
`;
|
|
}
|
|
if (typeof value === 'object' && value !== null) {
|
|
return `<textarea data-kind="json">${escapeHtml(JSON.stringify(value, null, 2))}</textarea>`;
|
|
}
|
|
return `<input type="text" data-kind="text" value="${escapeHtml(value ?? '')}">`;
|
|
}
|
|
|
|
function bindControls() {
|
|
el.groups.querySelectorAll('.control').forEach(control => {
|
|
const name = control.dataset.property;
|
|
const type = control.dataset.type;
|
|
control.querySelectorAll('input, select, textarea').forEach(input => {
|
|
const eventName = input.type === 'range' || input.type === 'checkbox' || input.tagName === 'SELECT' ? 'input' : 'change';
|
|
input.addEventListener(eventName, () => {
|
|
const value = readControlValue(control, type);
|
|
state.values.set(name, value);
|
|
scheduleSet(name, value);
|
|
mirrorControl(control, input, value);
|
|
});
|
|
});
|
|
});
|
|
|
|
el.groups.querySelectorAll('[data-function]').forEach(button => {
|
|
button.addEventListener('click', () => callFunction(button.dataset.function));
|
|
});
|
|
}
|
|
|
|
function mirrorControl(control, changedInput, value) {
|
|
if (changedInput.dataset.kind === 'number') {
|
|
control.querySelectorAll('[data-kind="number"]').forEach(input => {
|
|
if (input !== changedInput) input.value = value;
|
|
});
|
|
}
|
|
if (changedInput.dataset.kind === 'color-picker') {
|
|
const c = normalizeColor(value);
|
|
control.querySelectorAll('[data-kind="color-number"]').forEach(input => {
|
|
input.value = Number(c[input.dataset.channel]).toFixed(2);
|
|
});
|
|
}
|
|
if (changedInput.dataset.kind === 'color-number') {
|
|
const picker = control.querySelector('[data-kind="color-picker"]');
|
|
if (picker) picker.value = rgbToHex(normalizeColor(value));
|
|
}
|
|
}
|
|
|
|
function readControlValue(control, type) {
|
|
if (type === 'bool') return Boolean(control.querySelector('[data-kind="bool"]').checked);
|
|
if (type === 'int32' || type === 'int64') return parseInt(control.querySelector('[data-kind="number"]').value || '0', 10);
|
|
if (type === 'float' || type === 'double') return parseFloat(control.querySelector('[data-kind="number"]').value || '0');
|
|
if (control.querySelector('[data-kind="enum"]')) return control.querySelector('[data-kind="enum"]').value;
|
|
if (type === 'FLinearColor') {
|
|
const picker = control.querySelector('[data-kind="color-picker"]');
|
|
if (document.activeElement === picker) {
|
|
const rgb = hexToRgb(picker.value);
|
|
const old = normalizeColor(state.values.get(control.dataset.property));
|
|
return { R: rgb.R, G: rgb.G, B: rgb.B, A: old.A };
|
|
}
|
|
const out = {};
|
|
control.querySelectorAll('[data-kind="color-number"]').forEach(input => {
|
|
out[input.dataset.channel] = parseFloat(input.value || '0');
|
|
});
|
|
return out;
|
|
}
|
|
if (type === 'FVector') {
|
|
const out = {};
|
|
control.querySelectorAll('[data-kind="vector"]').forEach(input => {
|
|
out[input.dataset.channel] = parseFloat(input.value || '0');
|
|
});
|
|
return out;
|
|
}
|
|
const json = control.querySelector('[data-kind="json"]');
|
|
if (json) {
|
|
try { return JSON.parse(json.value); } catch (_) { return state.values.get(control.dataset.property); }
|
|
}
|
|
return control.querySelector('[data-kind="text"]')?.value ?? '';
|
|
}
|
|
|
|
function scheduleSet(name, value) {
|
|
clearTimeout(state.pending.get(name));
|
|
const timer = setTimeout(() => setProperty(name, value), 180);
|
|
state.pending.set(name, timer);
|
|
}
|
|
|
|
async function setProperty(name, value) {
|
|
try {
|
|
await api(`/remote/preset/${state.presetId}/property/${encodeURIComponent(name)}`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify({ PropertyValue: value })
|
|
});
|
|
setApiState(true, 'connected');
|
|
} catch (error) {
|
|
setApiState(false, 'error');
|
|
showToast(`${name}: ${error.message}`, true);
|
|
}
|
|
}
|
|
|
|
async function callFunction(name) {
|
|
try {
|
|
await api(`/remote/preset/${state.presetId}/function/${encodeURIComponent(name)}`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify({ Parameters: {} })
|
|
});
|
|
showToast(`${name} done`);
|
|
await refreshValues();
|
|
} catch (error) {
|
|
showToast(`${name}: ${error.message}`, true);
|
|
}
|
|
}
|
|
|
|
async function refreshValues() {
|
|
await loadValues();
|
|
render();
|
|
}
|
|
|
|
async function boot() {
|
|
try {
|
|
await loadPreset();
|
|
await loadValues();
|
|
setApiState(true, 'connected');
|
|
render();
|
|
} catch (error) {
|
|
setApiState(false, 'error');
|
|
showToast(error.message, true);
|
|
}
|
|
}
|
|
|
|
function normalizeColor(value) {
|
|
return {
|
|
R: Number(value?.R ?? 1),
|
|
G: Number(value?.G ?? 1),
|
|
B: Number(value?.B ?? 1),
|
|
A: Number(value?.A ?? 1)
|
|
};
|
|
}
|
|
|
|
function normalizeVector(value) {
|
|
return {
|
|
X: Number(value?.X ?? 0),
|
|
Y: Number(value?.Y ?? 0),
|
|
Z: Number(value?.Z ?? 0)
|
|
};
|
|
}
|
|
|
|
function rgbToHex(c) {
|
|
const toHex = value => Math.max(0, Math.min(255, Math.round(Number(value) * 255))).toString(16).padStart(2, '0');
|
|
return `#${toHex(c.R)}${toHex(c.G)}${toHex(c.B)}`;
|
|
}
|
|
|
|
function hexToRgb(hex) {
|
|
const n = parseInt(hex.replace('#', ''), 16);
|
|
return {
|
|
R: ((n >> 16) & 255) / 255,
|
|
G: ((n >> 8) & 255) / 255,
|
|
B: (n & 255) / 255
|
|
};
|
|
}
|
|
|
|
function formatValue(value) {
|
|
if (typeof value === 'object' && value !== null) return JSON.stringify(value);
|
|
return String(value ?? '');
|
|
}
|
|
|
|
function escapeHtml(value) {
|
|
return String(value)
|
|
.replaceAll('&', '&')
|
|
.replaceAll('<', '<')
|
|
.replaceAll('>', '>')
|
|
.replaceAll('"', '"')
|
|
.replaceAll("'", ''');
|
|
}
|
|
|
|
el.search.addEventListener('input', () => {
|
|
state.search = el.search.value.trim();
|
|
render();
|
|
});
|
|
el.refreshButton.addEventListener('click', refreshValues);
|
|
el.syncButton.addEventListener('click', () => callFunction('SyncFromTarget'));
|
|
el.applyButton.addEventListener('click', () => callFunction('ApplyToTarget'));
|
|
el.rebuildButton.addEventListener('click', () => callFunction('RebuildTarget'));
|
|
|
|
setInterval(async () => {
|
|
if (state.polling || document.hidden) return;
|
|
state.polling = true;
|
|
try {
|
|
await loadValues();
|
|
setApiState(true, 'connected');
|
|
} catch (_) {
|
|
setApiState(false, 'error');
|
|
} finally {
|
|
state.polling = false;
|
|
}
|
|
}, 2500);
|
|
|
|
boot();
|
|
</script>
|
|
</body>
|
|
</html>
|