Enhance preset saving and loading to include historyPersistence
This commit is contained in:
+21
-3
@@ -740,7 +740,10 @@ export function createPreset(name) {
|
||||
extensionSettings.presetManager.presets[presetId] = {
|
||||
id: presetId,
|
||||
name: name,
|
||||
trackerConfig: JSON.parse(JSON.stringify(extensionSettings.trackerConfig))
|
||||
trackerConfig: JSON.parse(JSON.stringify(extensionSettings.trackerConfig)),
|
||||
historyPersistence: extensionSettings.historyPersistence
|
||||
? JSON.parse(JSON.stringify(extensionSettings.historyPersistence))
|
||||
: null
|
||||
};
|
||||
// Also set it as the active preset so edits go to the new preset
|
||||
extensionSettings.presetManager.activePresetId = presetId;
|
||||
@@ -750,20 +753,23 @@ export function createPreset(name) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the current trackerConfig to the specified preset
|
||||
* Saves the current trackerConfig and historyPersistence to the specified preset
|
||||
* @param {string} presetId - The preset ID to save to
|
||||
*/
|
||||
export function saveToPreset(presetId) {
|
||||
const preset = extensionSettings.presetManager.presets[presetId];
|
||||
if (preset) {
|
||||
preset.trackerConfig = JSON.parse(JSON.stringify(extensionSettings.trackerConfig));
|
||||
preset.historyPersistence = extensionSettings.historyPersistence
|
||||
? JSON.parse(JSON.stringify(extensionSettings.historyPersistence))
|
||||
: null;
|
||||
saveSettings();
|
||||
// console.log(`[RPG Companion] Saved current config to preset "${preset.name}"`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a preset's trackerConfig as the active configuration
|
||||
* Loads a preset's trackerConfig and historyPersistence as the active configuration
|
||||
* @param {string} presetId - The preset ID to load
|
||||
* @returns {boolean} True if loaded successfully, false otherwise
|
||||
*/
|
||||
@@ -771,6 +777,18 @@ export function loadPreset(presetId) {
|
||||
const preset = extensionSettings.presetManager.presets[presetId];
|
||||
if (preset && preset.trackerConfig) {
|
||||
extensionSettings.trackerConfig = JSON.parse(JSON.stringify(preset.trackerConfig));
|
||||
// Load historyPersistence if present, otherwise use defaults
|
||||
if (preset.historyPersistence) {
|
||||
extensionSettings.historyPersistence = JSON.parse(JSON.stringify(preset.historyPersistence));
|
||||
} else {
|
||||
// Default values for presets that don't have historyPersistence yet
|
||||
extensionSettings.historyPersistence = {
|
||||
enabled: false,
|
||||
messageCount: 5,
|
||||
injectionPosition: 'assistant_message_end',
|
||||
contextPreamble: ''
|
||||
};
|
||||
}
|
||||
extensionSettings.presetManager.activePresetId = presetId;
|
||||
saveSettings();
|
||||
// console.log(`[RPG Companion] Loaded preset "${preset.name}"`);
|
||||
|
||||
@@ -490,18 +490,10 @@ function migrateTrackerPreset(config) {
|
||||
|
||||
// Add persistInHistory to infoBox widgets if missing (v3.4.0)
|
||||
if (migrated.infoBox && migrated.infoBox.widgets) {
|
||||
const defaultPersistence = {
|
||||
date: true,
|
||||
weather: true,
|
||||
temperature: false,
|
||||
time: true,
|
||||
location: true,
|
||||
recentEvents: false
|
||||
};
|
||||
|
||||
for (const [widgetId, widget] of Object.entries(migrated.infoBox.widgets)) {
|
||||
if (widget.persistInHistory === undefined) {
|
||||
widget.persistInHistory = defaultPersistence[widgetId] ?? false;
|
||||
// Default to false for backwards compatibility - user must explicitly enable
|
||||
widget.persistInHistory = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user