/* * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/limnus * Licensed under the MIT License. See LICENSE in the project root for license information. */ use limnus_app::prelude::*; use limnus_message::prelude::Message; use limnus_resource::prelude::Resource; use limnus_system_params::{Msg, Re, ReM}; use limnus_system_runner::UpdatePhase; #[derive(Debug, Resource)] pub struct TestResource { pub value: i32, } #[derive(Debug, Resource)] pub struct AnotherTestResource { pub value: Option, } #[derive(Debug, Message)] pub struct TestMessage { pub value: i32, } fn test_system(mut res: ReM) { res.value = -1; } const VALUE_SET_BY_SYSTEM_2: i32 = 99; #[allow(clippy::needless_pass_by_value)] fn test_system_2(msg: Msg, mut res: ReM) { if msg.is_empty_current() && res.value == -1 { res.value = VALUE_SET_BY_SYSTEM_2; } } #[allow(clippy::needless_pass_by_value)] fn test_system_3(msg: Msg, mut res: ReM, res2: Re) { if let Some(v) = res2.value { if msg.is_empty_current() && res.value == VALUE_SET_BY_SYSTEM_2 { res.value = v; } } } #[test] fn test_systems() { const EXPECTED_VALUE: i32 = 42; let mut app = App::new(); app.insert_resource(TestResource { value: 0 }); app.insert_resource(AnotherTestResource { value: Some(EXPECTED_VALUE), }); app.create_message_type::(); app.add_system(UpdatePhase::Update, test_system_3); // this will run last app.add_system(UpdatePhase::First, test_system); app.add_system(UpdatePhase::First, test_system_2); app.update(); assert_eq!(app.resource::().value, EXPECTED_VALUE); }