Initial flame_lua_runtime package

This commit is contained in:
gem
2026-06-07 22:53:58 +08:00
commit 733b2fb798
262 changed files with 28439 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import '../protocol/runtime_protocol.dart';
class RuntimeCommand {
const RuntimeCommand({
required this.type,
this.target,
this.payload = const {},
});
final String type;
final String? target;
final Map<String, Object?> payload;
static RuntimeCommand fromMap(Map<String, Object?> map) {
final type = map[RuntimeProtocolField.type];
if (type is! String || type.isEmpty) {
throw const FormatException('RuntimeCommand.type must be a string');
}
if (!RuntimeCommandType.isSupported(type)) {
throw FormatException('RuntimeCommand.type is unsupported: $type');
}
RuntimeProtocolSchema.ensureKnownKeys(
map,
allowed: RuntimeProtocolSchema.allowedCommandFields(type),
context: 'RuntimeCommand.$type',
);
final targetValue = map[RuntimeProtocolField.target];
if (targetValue != null && targetValue is! String) {
throw const FormatException('RuntimeCommand.target must be a string');
}
final payload = Map<String, Object?>.from(map)
..remove(RuntimeProtocolField.type)
..remove(RuntimeProtocolField.target);
return RuntimeCommand(
type: type,
target: targetValue as String?,
payload: payload,
);
}
}