khora_core/agent/mode.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//! Engine execution modes.
16//!
17//! The base engine only knows about **Playing** mode.
18//! Plugins inject their own modes via `Custom(String)`.
19
20/// The current mode of the engine.
21///
22/// Different modes activate different agents and change rendering behavior.
23/// The base engine only defines `Playing`; other modes are injected by plugins.
24#[derive(Debug, Clone, PartialEq, Eq, Hash)]
25pub enum EngineMode {
26 /// Simulation mode — scene cameras, physics, audio, ECS snapshot.
27 Playing,
28 /// A custom mode injected by a plugin.
29 /// The string identifies the plugin's mode (e.g., `"editor"`).
30 Custom(String),
31}
32
33impl EngineMode {
34 /// Parses a mode from a string (case-insensitive).
35 pub fn from_name(name: &str) -> Option<Self> {
36 match name.to_lowercase().as_str() {
37 "playing" | "play" | "simulation" => Some(EngineMode::Playing),
38 other => Some(EngineMode::Custom(other.to_string())),
39 }
40 }
41
42 /// Returns a human-readable name for this mode.
43 pub fn name(&self) -> &str {
44 match self {
45 EngineMode::Playing => "playing",
46 EngineMode::Custom(s) => s,
47 }
48 }
49}