tts-voice-creator-clone-and.../static/js/character-columns.js

50 lines
2.3 KiB
JavaScript

// Character-table metadata and the persisted column-visibility controller.
// Kept separate from the character renderer so table layout can evolve
// without making library-characters.js responsible for every table concern.
const _CHAR_PROFILE_COMPLETENESS_FIELDS = [
'gender', 'age_estimate', 'race_species', 'languages', 'nationality_background',
'social_class', 'profession', 'title', 'archetype', 'physical', 'clothing',
'alignment', 'arc_direction', 'arc_note', 'attribute_high', 'attribute_low',
'skills', 'capabilities', 'backstory', 'relationships', 'motivation', 'fears',
'mannerisms', 'communication_style', 'voice_pattern', 'secret', 'conflict_style',
'win_condition', 'reputation', 'religious_beliefs', 'notes', 'inventory',
];
// Stable read-only metadata for diagnostics and browser regression tests.
window._CHAR_PROFILE_COMPLETENESS_FIELDS = _CHAR_PROFILE_COMPLETENESS_FIELDS;
const _CHAR_TABLE_COLUMN_DEFS = [
['select', 'Select'], ['avatar', 'Avatar'], ['name', 'Name'], ['gender', 'Gender'],
['age', 'Age'], ['lines', 'Lines'], ['language', 'Language'], ['alignment', 'Good / Evil'],
['profile', 'Profile'], ['voice', 'Voice'], ['rating', 'Rating'], ['prompt', 'Voice Design Prompt'],
['notes', 'Notes'], ['tags', 'Tags'], ['book', 'Book / Script'], ['export', 'Export'],
];
function _charTableHiddenColumns() {
try {
const saved = JSON.parse(localStorage.getItem('ttsvc_libchars_columns') || '{}');
return saved && typeof saved === 'object' ? saved : {};
} catch (_) { return {}; }
}
function _applyCharTableColumns(table, hidden) {
if (!table) return;
_CHAR_TABLE_COLUMN_DEFS.forEach(function (def, index) {
const isHidden = hidden[def[0]] === false;
table.querySelectorAll('tr').forEach(function (row) {
const cell = row.children[index];
if (cell) cell.classList.toggle('lib-chars-col-hidden', isHidden);
});
const col = table.querySelector('colgroup')?.children[index];
if (col) col.classList.toggle('lib-chars-col-hidden', isHidden);
});
}
function _charProfileCompleteness(sheet) {
const sh = sheet || {};
const filled = _CHAR_PROFILE_COMPLETENESS_FIELDS.filter(function (key) {
return _libStr(sh[key]).trim().length > 0;
}).length;
return { filled: filled, total: _CHAR_PROFILE_COMPLETENESS_FIELDS.length };
}