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
//! Paddle is a framework for easy game building for the browser.
//! TODO: more description, README
//!
#![cfg_attr(feature = "const_fn", feature(const_fn))]
#![cfg_attr(feature = "const_fn", feature(const_fn_floating_point_arithmetic))]

pub use nuts;

#[macro_use]
pub(crate) mod debug;

pub(crate) mod context;
pub(crate) mod error;
pub(crate) mod frame;
pub mod graphics;
pub(crate) mod input;
pub(crate) mod js;
pub(crate) mod load;
pub mod quicksilver_compat;
pub(crate) mod view_manager;
pub mod web_integration;

mod display;
mod geometry;
pub use context::*;
pub use display::*;
pub use error::*;
pub use frame::*;
pub use geometry::*;
pub use graphics::*;
pub use input::*;
pub use load::*;
pub use view_manager::*;

// Code that currently belongs nowhere
pub fn utc_now() -> chrono::NaiveDateTime {
    let millis: f64 = js_sys::Date::now();
    let seconds = (millis / 1000.0).trunc() as i64;
    let nanos = ((millis % 1000.0) * 1_000_000.0) as u32;
    chrono::NaiveDateTime::from_timestamp(seconds, nanos)
}

pub fn init(config: PaddleConfig) -> PaddleResult<()> {
    web_integration::register_debug_hook();
    if let Some(region) = config.text_board_region {
        crate::TextBoard::init(region);
        enable_nuts_checks_to_textboard();
    } else {
        enable_nuts_checks_to_console();
    }
    Context::init(config)?;
    EventGate::init();
    FrameManipulator::init();
    Ok(())
}