Initial flame_lua_runtime package
This commit is contained in:
47
lib/runtime/events/runtime_event_gate.dart
Normal file
47
lib/runtime/events/runtime_event_gate.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import '../lifecycle/runtime_session.dart';
|
||||
import '../models/runtime_event.dart';
|
||||
|
||||
class RuntimeEventGate {
|
||||
const RuntimeEventGate({
|
||||
required this.session,
|
||||
required bool Function(String id) isScopeAlive,
|
||||
bool Function(String id, int epoch)? isNodeEpochAlive,
|
||||
}) : _isScopeAlive = isScopeAlive,
|
||||
_isNodeEpochAlive = isNodeEpochAlive;
|
||||
|
||||
final RuntimeSession session;
|
||||
final bool Function(String id) _isScopeAlive;
|
||||
final bool Function(String id, int epoch)? _isNodeEpochAlive;
|
||||
|
||||
RuntimeEvent attachSession(RuntimeEvent event) {
|
||||
return event.withLifecycle(sessionId: event.sessionId ?? session.id);
|
||||
}
|
||||
|
||||
bool accepts(RuntimeEvent event) {
|
||||
final eventSessionId = event.sessionId;
|
||||
if (eventSessionId != null && !session.accepts(eventSessionId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final target = event.target;
|
||||
final targetEpoch = event.targetEpoch;
|
||||
final epochChecker = _isNodeEpochAlive;
|
||||
if (target != null && targetEpoch != null && epochChecker != null) {
|
||||
if (!epochChecker(target, targetEpoch)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final scope = event.scope;
|
||||
if (scope != null && !_isScopeAlive(scope)) {
|
||||
return false;
|
||||
}
|
||||
final scopeEpoch = event.scopeEpoch;
|
||||
if (scope != null && scopeEpoch != null && epochChecker != null) {
|
||||
if (!epochChecker(scope, scopeEpoch)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user