overlord_event_system/
lib.rs1pub use event_system::event::EventRhaiEnum;
2pub use event_system::event::LogicalTimestamp;
3pub use event_system::net;
4pub use event_system::net::EventTimestamped;
5pub use event_system::random::Seed;
6pub use event_system::script::types::ConditionalProgress;
7pub use event_system::system::{
8 EventHandleResult, SyncEventHandler, SyncEventHandlerContext, SyncEventMeta, SystemConfig,
9};
10pub use script::ScriptRunner;
11
12pub mod async_handler;
13pub mod attributes;
14pub mod bundles;
15pub mod cases;
16pub mod entities;
17pub mod event;
18pub mod gacha;
19pub mod game_config_helpers;
20pub mod party;
21pub mod quests;
22pub mod script;
23pub mod state;
24
25pub struct NoopSyncEventHandler;
26
27impl SyncEventHandler<event::OverlordEvent, state::OverlordState> for NoopSyncEventHandler {
28 type Context = ();
29
30 fn handles_event(&self, _event: &event::OverlordEvent) -> bool {
31 false
32 }
33
34 async fn create_context_for_batch(
35 &self,
36 _state: &state::OverlordState,
37 ) -> anyhow::Result<Self::Context> {
38 Ok(())
39 }
40
41 async fn handle_event(
42 &self,
43 _context: &Self::Context,
44 _event: &event::OverlordEvent,
45 _meta: SyncEventMeta,
46 state: state::OverlordState,
47 ) -> anyhow::Result<EventHandleResult<event::OverlordEvent, state::OverlordState>> {
48 Ok(EventHandleResult::ok(state))
49 }
50
51 async fn handle_side_effect_event(
52 &self,
53 _context: &Self::Context,
54 _event: &event::OverlordEvent,
55 _output_events: &[event::OverlordEvent],
56 _new_state: &state::OverlordState,
57 ) -> anyhow::Result<()> {
58 Ok(())
59 }
60
61 async fn finalize_state(
62 &self,
63 _context: &Self::Context,
64 _state: &mut state::OverlordState,
65 ) -> anyhow::Result<()> {
66 Ok(())
67 }
68
69 async fn persist_in_memory_state(
70 &self,
71 _context: &Self::Context,
72 _state: &state::OverlordState,
73 ) -> anyhow::Result<()> {
74 Ok(())
75 }
76}
77
78pub type System<SEH> = event_system::system::System<
79 event::OverlordEvent,
80 state::OverlordState,
81 async_handler::handler::OverlordAsyncEventHandler,
82 SEH,
83 event_system::plugin::delayed::RealDelayedPlugin<event::OverlordEvent>,
84 event_system::plugin::cron::RealCronPlugin<event::OverlordEvent, state::OverlordState>,
85>;
86
87pub const TICKER_UNIT_DURATION_MS: u128 = 1;
88
89pub fn new_system<SEH>(
90 game_config: configs::SharedGameConfig,
91 sync_event_handler: SEH,
92 frontend: bool,
93 zero_tick: bool,
94) -> System<SEH>
95where
96 SEH: SyncEventHandler<event::OverlordEvent, state::OverlordState>,
97{
98 System::new(
99 SystemConfig {
100 ticker_unit_duration_ms: if zero_tick {
101 0
102 } else {
103 TICKER_UNIT_DURATION_MS
104 },
105 ..Default::default()
106 },
107 async_handler::handler::OverlordAsyncEventHandler::new(game_config, frontend),
108 sync_event_handler,
109 state::OverlordState::default(),
110 Seed::new(69),
111 frontend,
112 )
113}