Initial flame_lua_runtime package
This commit is contained in:
83
lib/runtime/commands/command_resources.dart
Normal file
83
lib/runtime/commands/command_resources.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
part of 'command_executor.dart';
|
||||
|
||||
extension _CommandExecutorResources on CommandExecutor {
|
||||
Future<_CommandResult> _preloadResources(
|
||||
RuntimeCommand command,
|
||||
_CommandContext context,
|
||||
RuntimeCommandHandle? handle,
|
||||
) async {
|
||||
final group = _requiredResourceGroup(command);
|
||||
final failOnError =
|
||||
_optionalBool(
|
||||
command.payload['failOnError'],
|
||||
'preload_resources.failOnError',
|
||||
) ??
|
||||
false;
|
||||
final resources = _resources;
|
||||
final audio = _audio;
|
||||
if (resources != null && resources.hasPackage) {
|
||||
await resources.preloadGroup(group, failOnError: failOnError);
|
||||
}
|
||||
if (audio != null && audio.hasPackage) {
|
||||
await audio.preloadGroup(group, failOnError: failOnError);
|
||||
}
|
||||
if (handle?.isCancelled ?? false) {
|
||||
return _CommandResult.cancelled;
|
||||
}
|
||||
_emitCommandCompletion(command, context);
|
||||
return _CommandResult.completed;
|
||||
}
|
||||
|
||||
Future<_CommandResult> _evictResources(
|
||||
RuntimeCommand command,
|
||||
_CommandContext context,
|
||||
RuntimeCommandHandle? handle,
|
||||
) async {
|
||||
final group = _requiredResourceGroup(command);
|
||||
final resources = _resources;
|
||||
final audio = _audio;
|
||||
if (resources != null && resources.hasPackage) {
|
||||
resources.evictGroup(group);
|
||||
}
|
||||
if (audio != null && audio.hasPackage) {
|
||||
audio.evictGroup(group);
|
||||
}
|
||||
if (handle?.isCancelled ?? false) {
|
||||
return _CommandResult.cancelled;
|
||||
}
|
||||
_emitCommandCompletion(command, context);
|
||||
return _CommandResult.completed;
|
||||
}
|
||||
|
||||
Future<_CommandResult> _cancelCommands(
|
||||
RuntimeCommand command,
|
||||
_CommandContext context,
|
||||
) async {
|
||||
final id = _optionalString(command.payload['id'], 'cancel_commands.id');
|
||||
final group = _optionalString(
|
||||
command.payload['group'],
|
||||
'cancel_commands.group',
|
||||
);
|
||||
final scope = _optionalString(
|
||||
command.payload['scope'],
|
||||
'cancel_commands.scope',
|
||||
);
|
||||
if (id == null && group == null && scope == null) {
|
||||
throw const FormatException(
|
||||
'cancel_commands requires id, group or scope',
|
||||
);
|
||||
}
|
||||
if (id != null) {
|
||||
_commandRegistry.cancelId(id);
|
||||
}
|
||||
if (group != null) {
|
||||
_commandRegistry.cancelGroup(group);
|
||||
}
|
||||
if (scope != null) {
|
||||
_commandRegistry.cancelScope(scope);
|
||||
_tasks.cancelScope(scope);
|
||||
}
|
||||
_emitCommandCompletion(command, context);
|
||||
return _CommandResult.completed;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user