Skip to main content

khora_data/flow/
selection.rs

1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Per-frame selection produced by [`Flow::select`](super::Flow::select).
16
17use khora_core::ecs::entity::EntityId;
18
19/// A snapshot of entities selected by a `Flow` for the current tick.
20///
21/// Passed from `Flow::select` to `Flow::adapt` and `Flow::project`. The Flow
22/// is free to attach its own per-domain payload by extending this struct, or
23/// to keep it as just an entity list.
24#[derive(Debug, Default, Clone)]
25pub struct Selection {
26    /// Entity IDs deemed relevant for this domain this tick.
27    pub entities: Vec<EntityId>,
28}
29
30impl Selection {
31    /// Creates an empty selection.
32    pub fn new() -> Self {
33        Self::default()
34    }
35
36    /// Creates a selection from a pre-built entity list.
37    pub fn from_entities(entities: Vec<EntityId>) -> Self {
38        Self { entities }
39    }
40
41    /// Number of selected entities.
42    pub fn len(&self) -> usize {
43        self.entities.len()
44    }
45
46    /// Whether the selection is empty.
47    pub fn is_empty(&self) -> bool {
48        self.entities.is_empty()
49    }
50}