From 4d0de8419ca3e3290fca068d1d7f28402ab318a1 Mon Sep 17 00:00:00 2001 From: Alamion Date: Mon, 23 Feb 2026 21:42:25 +0300 Subject: [PATCH] fixes: - now stats, attributes, characters stats have a changeable id - now all additional promts are stacked in 2 lines --- .gitignore | 4 ++-- manifest.json | 2 +- src/systems/ui/trackerEditor.js | 29 +++++++++++++++++++++++++---- src/utils/transformations.js | 11 +++++++++++ style.css | 15 +++++++++------ 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/utils/transformations.js diff --git a/.gitignore b/.gitignore index 789b14f..1e0df72 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,5 @@ node_modules/ # Environment variables .env -# Claude -CLAUDE.md \ No newline at end of file +# Claude +CLAUDE.md diff --git a/manifest.json b/manifest.json index ff16a2a..55c1c6d 100644 --- a/manifest.json +++ b/manifest.json @@ -6,6 +6,6 @@ "js": "index.js", "css": "style.css", "author": "Marinara", - "version": "3.7.2", + "version": "3.7.3", "homePage": "https://github.com/SpicyMarinara/rpg-companion-sillytavern" } diff --git a/src/systems/ui/trackerEditor.js b/src/systems/ui/trackerEditor.js index 90718ff..7a0cabf 100644 --- a/src/systems/ui/trackerEditor.js +++ b/src/systems/ui/trackerEditor.js @@ -31,6 +31,7 @@ import { renderUserStats } from '../rendering/userStats.js'; import { renderInfoBox } from '../rendering/infoBox.js'; import { renderThoughts } from '../rendering/thoughts.js'; import { updateFabWidgets } from './mobile.js'; +import { safeToSnake } from '../../utils/transformations.js'; let $editorModal = null; let activeTab = 'userStats'; @@ -38,6 +39,18 @@ let tempConfig = null; // Temporary config for cancel functionality let tempAssociation = null; // Temporary association state: { presetId: string|null, entityKey: string|null } let originalAssociation = null; // Original association when editor opened + +function set_ids_names(list_with_stats, index, value) { + list_with_stats[index].name = value; + const ids = list_with_stats.toSpliced(index, 1).map(stat => stat.id); + const snake_value = safeToSnake(value); // new id format + if (snake_value !== value && !ids.includes(snake_value)) { // check if this id already exists + list_with_stats[index].id = snake_value; + } + return list_with_stats; +} + + /** * Initialize the tracker editor modal */ @@ -885,7 +898,9 @@ function setupUserStatsListeners() { // Rename stat $('.rpg-stat-name').off('blur').on('blur', function () { const index = $(this).data('index'); - extensionSettings.trackerConfig.userStats.customStats[index].name = $(this).val(); + const value = $(this).val(); + const list_with_stats = extensionSettings.trackerConfig.userStats.customStats + set_ids_names(list_with_stats, index, value); }); // Change stat max value @@ -943,7 +958,9 @@ function setupUserStatsListeners() { // Rename attribute $('.rpg-attr-name').off('blur').on('blur', function () { const index = $(this).data('index'); - extensionSettings.trackerConfig.userStats.rpgAttributes[index].name = $(this).val(); + const value = $(this).val(); + const list_with_stats = extensionSettings.trackerConfig.userStats.rpgAttributes + set_ids_names(list_with_stats, index, value); }); // Enable/disable RPG Attributes section toggle @@ -1394,7 +1411,9 @@ function setupPresentCharactersListeners() { // Rename field $('.rpg-field-label').off('blur').on('blur', function () { const index = $(this).data('index'); - extensionSettings.trackerConfig.presentCharacters.customFields[index].name = $(this).val(); + const value = $(this).val(); + const list_with_stats = extensionSettings.trackerConfig.presentCharacters.customFields + set_ids_names(list_with_stats, index, value); }); // Update description @@ -1443,7 +1462,9 @@ function setupPresentCharactersListeners() { // Rename character stat $('.rpg-char-stat-label').off('blur').on('blur', function () { const index = $(this).data('index'); - extensionSettings.trackerConfig.presentCharacters.characterStats.customStats[index].name = $(this).val(); + const value = $(this).val(); + const list_with_stats = extensionSettings.trackerConfig.presentCharacters.characterStats.customStats + set_ids_names(list_with_stats, index, value); }); } diff --git a/src/utils/transformations.js b/src/utils/transformations.js new file mode 100644 index 0000000..6778ebe --- /dev/null +++ b/src/utils/transformations.js @@ -0,0 +1,11 @@ +const toSnake = str => str + .replace(/[^a-zA-Z]/g, '_') + .replace(/([A-Z])/g, '_$1') + .toLowerCase() + .replace(/_+/g, '_') + .replace(/^_|_$/g, ''); + +export const safeToSnake = (str) => { + const res = toSnake(str); + return (res.length >= 2) ? res : str; // considering element with one symbol is too short to be safe +}; diff --git a/style.css b/style.css index 68b01ef..c1b22c1 100644 --- a/style.css +++ b/style.css @@ -10732,7 +10732,10 @@ body[data-theme="cyberpunk"] .rpg-music-widget-play { /* Features row container */ .rpg-features-row { - display: flex; + display: grid; + grid-template-rows: repeat(2, 1fr); + grid-auto-flow: column; + grid-auto-columns: min-content; gap: 8px; margin-bottom: 12px; overflow-x: auto; @@ -10743,11 +10746,11 @@ body[data-theme="cyberpunk"] .rpg-music-widget-play { } /* Center items when they fit, allow scrolling when they don't */ -.rpg-features-row::before, -.rpg-features-row::after { - content: ''; - margin: auto; -} +/*.rpg-features-row::before,*/ +/*.rpg-features-row::after {*/ +/* content: '';*/ +/* margin: auto;*/ +/*}*/ /* Hide scrollbar for cleaner look while maintaining functionality */ .rpg-features-row::-webkit-scrollbar {