kon/lib.rs
1//! # Kon Engine
2//!
3//! A modular 2D game engine for Rust, built with a focus on ECS performance and simplicity.
4//!
5//! # Example
6//! ```ignore
7//! use kon::prelude::*;
8//!
9//! #[component]
10//! struct Position { x: f32, y: f32 }
11//!
12//! #[system]
13//! fn setup(ctx: &mut Context) {
14//! ctx.world()
15//! .spawn()
16//! .insert(Position { x: 0.0, y: 0.0 })
17//! .tag("player")
18//! .id();
19//! }
20//!
21//! #[system]
22//! fn update(ctx: &mut Context) {
23//! if ctx.input().just_key_pressed(KeyCode::Escape) {
24//! ctx.quit();
25//! }
26//!
27//! ctx.on::<WindowCloseRequested>(|_, context| {
28//! context.quit();
29//! });
30//! }
31//!
32//! fn main() {
33//! Kon::new()
34//! .add_plugin(DefaultPlugins)
35//! .add_startup_system(setup)
36//! .add_system(update)
37//! .run();
38//! }
39//! ```
40
41pub use kon_core;
42pub use kon_ecs;
43pub use kon_macros::{component, system};
44pub use kon_window;
45pub use kon_input;
46pub use log;
47
48use kon_core::Plugin;
49
50pub mod prelude {
51 //! Common imports for Kon Engine
52 pub use crate::DefaultPlugins;
53 pub use crate::{component, system};
54 pub use kon_core::{App, Context, Event, Events, Globals, Kon, Plugin, Time, Driver, events::*};
55 pub use kon_ecs::{ContextEcsExt, EcsPlugin, Entity, EntityBuilder, Query, World};
56 pub use kon_window::{KonWindow, WindowConfig, WindowPlugin, ContextWindowExt, types::*};
57 pub use kon_input::{InputPlugin, ContextInputExt, InputSource, Input};
58}
59
60/// Engine version
61pub const VERSION: &str = env!("CARGO_PKG_VERSION");
62
63/// Default plugins bundle
64///
65/// Includes:
66/// - `EcsPlugin` - Entity Component System
67/// - `WindowPlugin` - Window management
68/// - `InputPlugin` - Input handling
69pub struct DefaultPlugins;
70
71impl Plugin for DefaultPlugins {
72 fn build(&self, app: &mut kon_core::App) {
73 app.add_plugin(kon_ecs::EcsPlugin);
74 app.add_plugin(kon_window::WindowPlugin);
75 app.add_plugin(kon_input::InputPlugin);
76 }
77
78 fn is_plugin_group(&self) -> bool {
79 true
80 }
81}