63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
type Layer = {
|
|
id: string;
|
|
name: string;
|
|
visible: boolean;
|
|
locked: boolean;
|
|
};
|
|
|
|
export class LayerManager {
|
|
private layers: Layer[] = [];
|
|
|
|
public addLayer(layer: Layer): void {
|
|
this.layers.push(layer);
|
|
}
|
|
|
|
public removeLayer(id: string): void {
|
|
const index = this.layers.findIndex(layer => layer.id === id);
|
|
if (index !== -1) {
|
|
this.layers.splice(index, 1);
|
|
}
|
|
}
|
|
|
|
public updateLayer(layer: Layer): void {
|
|
const index = this.layers.findIndex(l => l.id === layer.id);
|
|
if (index !== -1) {
|
|
this.layers[index] = layer;
|
|
}
|
|
}
|
|
|
|
public getLayer(id: string): Layer | undefined {
|
|
return this.layers.find(layer => layer.id === id);
|
|
}
|
|
|
|
public getLayers(): Layer[] {
|
|
return this.layers;
|
|
}
|
|
|
|
public getVisibleLayers(): Layer[] {
|
|
return this.layers.filter(layer => layer.visible && !layer.locked);
|
|
}
|
|
|
|
public setVisible(id: string, visible: boolean): void {
|
|
const layer = this.getLayer(id);
|
|
if (layer) {
|
|
layer.visible = visible;
|
|
}
|
|
}
|
|
|
|
public setLocked(id: string, locked: boolean): void {
|
|
const layer = this.getLayer(id);
|
|
if (layer) {
|
|
layer.locked = locked;
|
|
}
|
|
}
|
|
|
|
public moveLayer(id: string, newIndex: number): void {
|
|
const index = this.layers.findIndex(layer => layer.id === id);
|
|
if (index !== -1) {
|
|
const [layer] = this.layers.splice(index, 1);
|
|
this.layers.splice(newIndex, 0, layer);
|
|
}
|
|
}
|
|
}
|