1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! ISSUN-CORE: Engine-Agnostic Game Mechanics Library
//!
//! This crate provides a policy-based design for composable game mechanics.
//! It uses Rust's generic type system to enable zero-cost abstractions while
//! maintaining complete separation from any specific game engine.
//!
//! # Architecture
//!
//! ISSUN-CORE follows a **Policy-Based Design** pattern:
//!
//! 1. **Mechanics**: High-level game systems (e.g., contagion, economy)
//! 2. **Policies**: Trait-based "slots" for customizable behavior
//! 3. **Strategies**: Concrete implementations of policies
//! 4. **Composition**: Combine strategies via generics to create custom mechanics
//!
//! # Design Principles
//!
//! - **Zero-Cost Abstraction**: All composition happens at compile time
//! - **Engine-Agnostic**: No dependencies on Bevy, Unity, Godot, etc.
//! - **Static Dispatch**: No `dyn Trait` - everything is monomorphized
//! - **Composability**: Mix and match strategies to create custom behaviors
//!
//! # Quick Start
//!
//! ```
//! use issun_core::mechanics::contagion::prelude::*;
//! use issun_core::mechanics::{Mechanic, EventEmitter};
//!
//! // Option 1: Use a preset
//! type MyVirus = ZombieVirus; // Explosive spread + hard to resist
//!
//! // Option 2: Use default generics
//! type SimpleVirus = ContagionMechanic; // LinearSpread + ThresholdProgression<10>
//!
//! // Option 3: Fully customize
//! type CustomVirus = ContagionMechanic<ExponentialSpread, ThresholdProgression<50>>;
//!
//! // 2. Create configuration (shared across all entities)
//! let config = ContagionConfig { base_rate: 0.15 };
//!
//! // 3. Create per-entity state
//! let mut state = SimpleSeverity::default();
//!
//! // 4. Prepare input for this frame
//! let input = ContagionInput {
//! density: 0.7, // Population density
//! resistance: 8, // Entity's resistance
//! rng: 0.04, // Random value
//! };
//!
//! // 5. Create an event emitter
//! # struct TestEmitter { events: Vec<ContagionEvent> }
//! # impl EventEmitter<ContagionEvent> for TestEmitter {
//! # fn emit(&mut self, event: ContagionEvent) { self.events.push(event); }
//! # }
//! let mut emitter = TestEmitter { events: vec![] };
//!
//! // 6. Execute the mechanic
//! MyVirus::step(&config, &mut state, input, &mut emitter);
//!
//! // 7. Check results
//! if state.severity > 0 {
//! println!("Entity is infected! Severity: {}", state.severity);
//! }
//! ```
//!
//! # Module Organization
//!
//! - [`mechanics`]: Core trait definitions and mechanic implementations
//! - [`mechanics::contagion`]: Disease/infection spreading system
//! - [`prelude`]: Convenient re-exports of commonly used items
//!
//! # For Engine Adapters
//!
//! If you're building an engine adapter (e.g., `issun-bevy`), you'll typically:
//!
//! 1. Query ECS data to construct `Input` structs
//! 2. Call `Mechanic::step()` with that input
//! 3. Listen to emitted events and update the game world
//!
//! See the `issun-bevy` crate for a complete example.