import { SceneSystem } from 'dacha';
import { EventType } from '../../../events';
import { Settings } from '../../components';
import { persistentStorage } from '../../../persistent-storage';
export class SettingsSystem extends SceneSystem {
    constructor(options) {
        super();
        this.handleSetSettingsValue = (event) => {
            const { name, value } = event;
            const settings = this.mainActor.getComponent(Settings);
            settings.data[name] = value;
            persistentStorage.set(`canvas.mainActor.settings.${name}`, value);
        };
        const { world } = options;
        this.world = world;
        this.mainActor = world.data.mainActor;
        this.world.addEventListener(EventType.SetSettingsValue, this.handleSetSettingsValue);
    }
    onSceneDestroy() {
        this.world.removeEventListener(EventType.SetSettingsValue, this.handleSetSettingsValue);
    }
}
SettingsSystem.systemName = 'SettingsSystem';
