diff --git a/src/mappings_editor/src/assets/scripts/MappingFile/MappingFile.ts b/src/mappings_editor/src/assets/scripts/MappingFile/MappingFile.ts index 68d1b25..ece1d7b 100644 --- a/src/mappings_editor/src/assets/scripts/MappingFile/MappingFile.ts +++ b/src/mappings_editor/src/assets/scripts/MappingFile/MappingFile.ts @@ -96,14 +96,14 @@ export class MappingFile { public readonly scoreValues: ListProperty; /** - * The file's internal mapping objects. + * The file's mapping object template. */ - private _mappingObjects: Map; + public readonly mappingObjectTemplate: MappingObject; /** - * The file's mapping object template. + * The file's internal mapping objects. */ - private readonly _mappingObjectTemplate: MappingObject; + private _mappingObjects: Map; /** @@ -113,20 +113,6 @@ export class MappingFile { return this._mappingObjects; } - /** - * The file's default mapping type. - */ - public get defaultMappingType(): string | null { - return this._mappingObjectTemplate.mappingType.exportValue; - } - - /** - * The file's default mapping status. - */ - public get defaultMappingStatus(): string | null { - return this._mappingObjectTemplate.mappingStatus.exportValue; - } - /** * Creates a new {@link MappingFile}. @@ -157,8 +143,8 @@ export class MappingFile { this.mappingStatuses = template.mappingStatus.options; this.scoreCategories = template.scoreCategory.options; this.scoreValues = template.scoreValue.options; + this.mappingObjectTemplate = template; this._mappingObjects = new Map(); - this._mappingObjectTemplate = template; // Configure source information const sourceListing = template.sourceObject.framework; this.sourceFrameworkListing = sourceListing; @@ -186,7 +172,7 @@ export class MappingFile { * The new mapping object. */ public createMappingObject(): MappingObject { - return this._mappingObjectTemplate.duplicate(); + return this.mappingObjectTemplate.duplicate(); } /** @@ -228,6 +214,9 @@ export class MappingFile { * The mapping object to insert. */ public insertMappingObject(object: MappingObject) { + if(object.id === this.mappingObjectTemplate.id) { + throw new Error(`Mapping file cannot contain the mapping object template.`); + } if(this._mappingObjects.has(object.id)) { throw new Error(`Mapping file already contains object '${ object.id }'.`); } @@ -259,6 +248,9 @@ export class MappingFile { public insertMappingObjectAfter(object: MappingObject, destination?: string): void; public insertMappingObjectAfter(object: MappingObject, destination?: MappingObject | string) { const id = typeof destination === "string" ? destination : (destination?.id ?? null) + if(object.id === this.mappingObjectTemplate.id) { + throw new Error(`Mapping file cannot contain the mapping object template.`); + } if(this._mappingObjects.has(object.id)) { throw new Error(`Mapping file already contains object '${ object.id }'.`); } @@ -295,6 +287,9 @@ export class MappingFile { const id = typeof destination === "string" ? destination : (destination?.id ?? null) const newEntries: [string, MappingObject][] = []; for(const obj of objects){ + if(obj.id === this.mappingObjectTemplate.id) { + throw new Error(`Mapping file cannot contain the mapping object template.`); + } if(this._mappingObjects.has(obj.id)) { throw new Error(`Mapping file already contains object '${ obj.id }'.`); } diff --git a/src/mappings_editor/src/assets/scripts/MappingFileAuthority/MappingFileAuthority.ts b/src/mappings_editor/src/assets/scripts/MappingFileAuthority/MappingFileAuthority.ts index 76f52b4..303abe0 100644 --- a/src/mappings_editor/src/assets/scripts/MappingFileAuthority/MappingFileAuthority.ts +++ b/src/mappings_editor/src/assets/scripts/MappingFileAuthority/MappingFileAuthority.ts @@ -368,6 +368,7 @@ export class MappingFileAuthority { } // Compile file + const defaultObject = file.mappingObjectTemplate; return { version : file.version, source_framework : file.sourceFramework, @@ -385,8 +386,8 @@ export class MappingFileAuthority { score_categories : Object.fromEntries(score_categories), score_values : Object.fromEntries(score_values), mapping_objects, - default_mapping_type : file.defaultMappingType, - default_mapping_status : file.defaultMappingStatus + default_mapping_type : defaultObject.mappingType.exportValue, + default_mapping_status : defaultObject.mappingStatus.exportValue } }