Story 3.2 done
This commit is contained in:
@@ -235,12 +235,20 @@ export class PresetImportExportManager {
|
||||
const validPresets = extractionResults.filter(r => r.error === null);
|
||||
const errors = extractionResults.filter(r => r.error !== null).map(r => r.error);
|
||||
|
||||
// Check if we would exceed max presets in merge mode
|
||||
const existingCount = this._scenePresetManager.list().length;
|
||||
const newCount = validPresets.length;
|
||||
// Get existing preset names for duplicate detection and limit checking
|
||||
const existingPresetNames = new Set(this._scenePresetManager.list().map(p => p.name));
|
||||
const existingCount = existingPresetNames.size;
|
||||
|
||||
// Count how many presets would actually be added (excluding duplicates in merge mode)
|
||||
let netNewCount = validPresets.length;
|
||||
if (mode === 'merge') {
|
||||
// Count only presets that don't already exist
|
||||
netNewCount = validPresets.filter(r => !existingPresetNames.has(r.name)).length;
|
||||
}
|
||||
|
||||
if (mode === 'merge' && existingCount + newCount > MAX_PRESETS_PER_WORLD) {
|
||||
errors.push(`Import would exceed maximum of ${MAX_PRESETS_PER_WORLD} presets (currently ${existingCount}, adding ${newCount})`);
|
||||
// Check preset limits
|
||||
if (mode === 'merge' && existingCount + netNewCount > MAX_PRESETS_PER_WORLD) {
|
||||
errors.push(`Import would exceed maximum of ${MAX_PRESETS_PER_WORLD} presets (currently ${existingCount}, adding ${netNewCount} new)`);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Import cancelled: would exceed preset limit',
|
||||
@@ -251,6 +259,18 @@ export class PresetImportExportManager {
|
||||
};
|
||||
}
|
||||
|
||||
if (mode === 'replace' && validPresets.length > MAX_PRESETS_PER_WORLD) {
|
||||
errors.push(`Import file contains ${validPresets.length} presets, exceeding maximum of ${MAX_PRESETS_PER_WORLD}`);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Import cancelled: file exceeds preset limit',
|
||||
added: 0,
|
||||
replaced: 0,
|
||||
skipped: 0,
|
||||
errors,
|
||||
};
|
||||
}
|
||||
|
||||
// Process based on mode
|
||||
if (mode === 'replace') {
|
||||
const result = await this._replacePresets(data, validPresets, existingCount);
|
||||
@@ -258,7 +278,7 @@ export class PresetImportExportManager {
|
||||
result.errors = [...errors, ...result.errors];
|
||||
return result;
|
||||
}
|
||||
const result = await this._mergePresets(data, validPresets);
|
||||
const result = await this._mergePresets(data, validPresets, existingPresetNames);
|
||||
// Merge extraction errors with merge errors
|
||||
result.errors = [...errors, ...result.errors];
|
||||
return result;
|
||||
@@ -269,11 +289,11 @@ export class PresetImportExportManager {
|
||||
*
|
||||
* @param {ExportData} data - Validated import data.
|
||||
* @param {Array<{name: string, preset: import('../contracts/scene-preset.js').ScenePreset|null, error: string|null}>} validPresets - Validated presets to import.
|
||||
* @param {Set<string>} existingPresetNames - Set of existing preset names for duplicate detection.
|
||||
* @returns {Promise<ImportResult>} Result of the merge operation.
|
||||
* @private
|
||||
*/
|
||||
async _mergePresets(data, validPresets) {
|
||||
const existingPresetNames = new Set(this._scenePresetManager.list().map(p => p.name));
|
||||
async _mergePresets(data, validPresets, existingPresetNames) {
|
||||
let added = 0;
|
||||
let skipped = 0;
|
||||
const errors = [];
|
||||
|
||||
Reference in New Issue
Block a user