gled-ui 2.32.1

gled's egui interface, shared by the desktop app and the browser
Documentation
//! Editing assets from an interface: the change shows in the interface's own
//! copy of the assets right away and goes to the engine, which stores it in
//! the repository and sends it to every other interface.

use std::sync::Arc;

use gled_model::{asset::Asset, collection::Collections};
use gled_protocol::{assets::KnownAsset, state::ClientInput};

pub(crate) trait AssetEdits {
    /// Stores the asset here and in the engine.
    fn save(self, collections: &mut Collections);
    /// Removes the asset here and in the engine.
    fn delete(&self, collections: &mut Collections);
}

impl<T: KnownAsset> AssetEdits for Asset<T> {
    fn save(self, collections: &mut Collections) {
        let asset = Arc::new(self);
        collections.get_mut::<T>().insert_shared(asset.clone());
        ClientInput::SaveAsset(T::wrap(asset)).enqueue();
    }

    fn delete(&self, collections: &mut Collections) {
        collections.get_mut::<T>().delete_asset(self.id);
        ClientInput::DeleteAsset(T::wrap_id(self.id)).enqueue();
    }
}