assetActions property

  1. @override
List<AssetAction> get assetActions
override

What this module can do with a file in the Assets dock.

Implementation

@override
List<AssetAction> get assetActions => [
  AssetAction(
    id: 'graphics.cook',
    label: 'Cook',
    icon: Icons.local_fire_department_outlined,
    appliesTo: (path, {required isDirectory}) =>
        !isDirectory && ModelCooking.isModel(path) && _ownFile(path),
    run: (scope, path) async {
      try {
        final result = await cooking.cook(path);
        _reload(path);
        scope.reloadAssets([ModelImportSettings.cookedOf(path)]);
        _log(['Cooked $path.', ...result.warnings].join(' '));
      } on Object catch (error) {
        _log('Could not cook $path: $error', warn: true);
      }
    },
  ),
  AssetAction(
    id: 'graphics.uncook',
    label: 'Use the file, not its cooked copy',
    icon: Icons.restart_alt,
    appliesTo: (path, {required isDirectory}) =>
        !isDirectory &&
        ModelCooking.isModel(path) &&
        _ownFile(path) &&
        cooking.isCooked(path),
    run: (scope, path) async {
      await cooking.uncook(path);
      _reload(path);
      scope.reloadAssets([ModelImportSettings.cookedOf(path)]);
      _log('$path loads from the file again.');
    },
  ),
  AssetAction(
    id: placeId,
    label: 'Place with its lights and sockets',
    icon: Icons.account_tree_outlined,
    // Offered while a scene models go in is open.
    appliesTo: (path, {required isDirectory}) =>
        !isDirectory && ModelCooking.isModel(path) && _inModelScene,
    run: (scope, path) async {
      if (!_inModelScene) {
        _log('Models go in 3D scenes: open one to place $path.', warn: true);
        return;
      }
      try {
        final file = File('$_root/$path');
        final folder = file.parent.path;
        final data = cooking
            .settingsOf(path)
            .apply(
              await loadModelData(
                await file.readAsBytes(),
                name: path,
                fetch: (uri) => File('$folder/$uri').readAsBytes(),
              ),
            );
        ModelExpansion.place(
          scope,
          ModelExpansion.partsOf(data, path, scope.editorView.focus),
        );
      } on Object catch (error) {
        _log('Could not place $path: $error', warn: true);
      }
    },
  ),
  AssetAction(
    id: 'graphics.cookFolder',
    label: 'Cook changed models',
    icon: Icons.local_fire_department_outlined,
    appliesTo: (path, {required isDirectory}) =>
        isDirectory && _ownFile(path),
    run: (scope, path) => _cookStale(cooking.modelsUnder(path)),
  ),
];