From c10e88e42b26637e3c48ed781ced1382fb20fa26 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 17 Aug 2022 17:49:08 +0200 Subject: Revert "modularize interfaces" This reverts commit 9856b281b429fa3ba13b64f6c6cd99b3d05d1a2f. --- karld/src/main.rs | 101 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 11 deletions(-) (limited to 'karld/src/main.rs') diff --git a/karld/src/main.rs b/karld/src/main.rs index 2b95cb7..22a12f7 100644 --- a/karld/src/main.rs +++ b/karld/src/main.rs @@ -2,7 +2,6 @@ #![feature(fs_try_exists)] pub mod condition; -pub mod demo; pub mod helper; pub mod interface; pub mod savestate; @@ -12,14 +11,12 @@ use chrono::NaiveDateTime; use condition::ConditionFind; use crossbeam_channel::Sender; use helper::Overlaps; +use interface::network_loop; use karlcommon::{ ClientboundPacket, Condition, Property, ProtoError, Schedule, ServerboundPacket, Task, }; use log::{debug, error, info}; -use std::{ - collections::HashMap, - sync::{atomic::AtomicU32, RwLock}, -}; +use std::{collections::HashMap, sync::RwLock}; use crate::schedule::schedule_dynamic; @@ -29,22 +26,104 @@ fn main() { if let Err(e) = savestate::load() { error!("load failed: {}", e); } + TASKS.write().unwrap().insert( + 0, + Task { + id: 0, + name: "Mittagessen im Februar".to_string(), + description: None, + tags: vec!["Essen".to_string(), "Unwichtig".to_string()], + schedule: Schedule::Condition(Condition::And(vec![ + Condition::Equal { + modulus: None, + prop: Property::Monthofyear, + value: 1, + }, + Condition::Equal { + modulus: None, + prop: Property::Hour, + value: 12, + }, + ])), + }, + ); + TASKS.write().unwrap().insert( + 1, + Task { + id: 1, + name: "Abendessen oder Frühstück".to_string(), + description: Some("Nom nom nom".to_string()), + tags: vec!["Essen".to_string()], + schedule: Schedule::Condition(Condition::Or(vec![ + Condition::Equal { + modulus: None, + prop: Property::Hour, + value: 18, + }, + Condition::Equal { + modulus: None, + prop: Property::Hour, + value: 7, + }, + ])), + }, + ); + TASKS.write().unwrap().insert( + 2, + Task { + id: 2, + description: None, + name: "Wichtiger termin™".to_string(), + tags: vec![], + schedule: Schedule::Static(1654997366..1655007366), + }, + ); + + TASKS.write().unwrap().insert( + 3, + Task { + id: 3, + description: None, + name: "Staubsaugen".to_string(), + tags: vec!["Unwichtig".to_string()], + schedule: Schedule::Dynamic { + scheduled: None, + duration: 15 * 60, + priority: 2.0, + condition: Condition::Equal { + prop: Property::Monthofyear, + value: 6, + modulus: None, + }, + }, + }, + ); + TASKS.write().unwrap().insert( + 4, + Task { + id: 4, + description: Some("sollte ich wirklich mal machen".to_string()), + name: "Geschirrspüler ausräumen".to_string(), + tags: vec!["Unwichtig".to_string()], + schedule: Schedule::Dynamic { + scheduled: None, + duration: 15 * 60, + priority: 5.0, + condition: Condition::Never, + }, + }, + ); std::thread::spawn(move || { std::thread::sleep(std::time::Duration::from_secs_f64(0.1)); schedule_dynamic(); }); - interface::start(); - - loop { - std::thread::sleep(std::time::Duration::from_secs_f64(100.0)); - } + network_loop(); } lazy_static::lazy_static! { static ref TASKS: RwLock> = RwLock::new(HashMap::new()); - static ref CLIENT_ID_COUNTER: AtomicU32 = AtomicU32::new(0); } pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender) { -- cgit v1.2.3-70-g09d2