121 lines
2.9 KiB
TypeScript
121 lines
2.9 KiB
TypeScript
import { ActionDefinition } from '../actions/ActionDefinition';
|
|
import { IActionDefinition } from '../actions/IActionDefinition';
|
|
import { IFigureSetData } from './IFigureSetData';
|
|
import { ActivePartSet } from './parts/ActivePartSet';
|
|
import { PartDefinition } from './parts/PartDefinition';
|
|
|
|
export class PartSetsData implements IFigureSetData
|
|
{
|
|
private _parts: Map<string, PartDefinition>;
|
|
private _activePartSets: Map<string, ActivePartSet>;
|
|
|
|
constructor()
|
|
{
|
|
this._parts = new Map();
|
|
this._activePartSets = new Map();
|
|
}
|
|
|
|
public parse(data: any): boolean
|
|
{
|
|
if(data.partSet && (data.partSet.length > 0))
|
|
{
|
|
for(const part of data.partSet)
|
|
{
|
|
if(!part) continue;
|
|
|
|
this._parts.set(part.setType, new PartDefinition(part));
|
|
}
|
|
}
|
|
|
|
if(data.activePartSets && (data.activePartSets.length > 0))
|
|
{
|
|
for(const activePart of data.activePartSets)
|
|
{
|
|
if(!activePart) continue;
|
|
|
|
this._activePartSets.set(activePart.id, new ActivePartSet(activePart));
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public appendJSON(data: any): boolean
|
|
{
|
|
if(data.partSet && (data.partSet.length > 0))
|
|
{
|
|
for(const part of data.partSet)
|
|
{
|
|
if(!part) continue;
|
|
|
|
this._parts.set(part.setType, new PartDefinition(part));
|
|
}
|
|
}
|
|
|
|
if(data.activePartSets && (data.activePartSets.length > 0))
|
|
{
|
|
for(const activePart of data.activePartSets)
|
|
{
|
|
if(!activePart) continue;
|
|
|
|
this._activePartSets.set(activePart.id, new ActivePartSet(activePart));
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public getActiveParts(k:IActionDefinition): string[]
|
|
{
|
|
const activePartSet = this._activePartSets.get(k.activePartSet);
|
|
|
|
if(!activePartSet) return [];
|
|
|
|
return activePartSet.parts;
|
|
}
|
|
|
|
public getPartDefinition(part: string): PartDefinition
|
|
{
|
|
const existing = this._parts.get(part);
|
|
|
|
if(!existing) return null;
|
|
|
|
return existing;
|
|
}
|
|
|
|
public addPartDefinition(k: any): PartDefinition
|
|
{
|
|
const _local_2 = k.setType as string;
|
|
|
|
let existing = this._parts.get(_local_2);
|
|
|
|
if(!existing)
|
|
{
|
|
existing = new PartDefinition(k);
|
|
|
|
this._parts.set(_local_2, existing);
|
|
}
|
|
|
|
return existing;
|
|
}
|
|
|
|
public getActivePartSet(k: ActionDefinition): ActivePartSet
|
|
{
|
|
const existing = this._activePartSets.get(k.activePartSet);
|
|
|
|
if(!existing) return null;
|
|
|
|
return existing;
|
|
}
|
|
|
|
public get parts(): Map<string, PartDefinition>
|
|
{
|
|
return this._parts;
|
|
}
|
|
|
|
public get activePartSets(): Map<string, ActivePartSet>
|
|
{
|
|
return this._activePartSets;
|
|
}
|
|
}
|