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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
//! Welcome!  
//!   
//! The goal of this crate is to help you to make great 2d games running in web browsers.
//! This crate is very similar to SFML.
//! 
//! # How to use
//! 
//! Please follow these instructions to save yourself a lot of pain.
//! To use this crate, you will need wasm-pack. You can install wasm-pack with:
//! 
//! ```text
//! cargo install wasm-pack
//! ```
//!   
//! To create your game crate, the best way is to use:
//! ```text
//! wasm-pack new
//! ```
//! 
//! Then, **put this crate and the wasm-bindgen-futures crate in Cargo.toml** as usual.
//! Here is the template you may want to use in lib.rs:
//! 
//! ```rust
//! #[allow(unused_imports)]
//! 
//! use wasm_bindgen::{prelude::*, JsCast};
//! use wasm_game_lib::graphics::image::Image;
//! use wasm_game_lib::graphics::sprite::Sprite;
//! use wasm_game_lib::inputs::event::Event;
//! use wasm_game_lib::graphics::window::Window;
//! use wasm_game_lib::system::log;
//! use wasm_game_lib::inputs::event::types::*;
//! use wasm_game_lib::system::sleep;
//! use std::time::Duration;
//! use console_error_panic_hook::set_once;
//! 
//! #[wasm_bindgen(start)]
//! pub async fn start() -> Result<(), JsValue> {
//!     set_once(); // needed to see panic messages in the console of your web browser
//! 
//!     let (mut window, mut canvas) = Window::init_with_events(MOUSE_EVENT + KEYBOARD_EVENT + RESIZE_EVENT + FOCUS_EVENT);
//! 
//!     // load images and fonts here
//!     // you could make a progress bar
//! 
//!     loop {
//!         for event in window.poll_events() {
//!             // do something with events
//!             log(&format!("{:?}", event));
//!         }
//! 
//!         canvas.clear();
//!         // canvas.draw(&object);
//! 
//!         sleep(Duration::from_millis(16)).await;
//!     }
//! 
//!     Ok(())
//! }
//! ```
//! 
//! You can compile your crate using:
//! ```text
//! wasm-pack build --target=web
//! ```
//! 
//! A folder named pkg has been created in the folder of your project.
//! Only two files are important: project_name.js and project_name_bg.wasm.
//! 
//! To use these files on a web page, I recommend you to put the file index.html in the pkg folder, with this content:
//! 
//! ```html
//! <html>
//! <head>
//!     <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
//!     <style>
//!         * {
//!             padding: 0;
//!             margin: 0;
//!         }
//!         canvas {
//!             width: 100%;
//!             height: 100%;
//!         }
//!     </style>
//! </head>
//! <body>
//!     <script type="module">
//!         import init from './project_name.js';
//!
//!         async function run() {
//!             await init();
//!         }
//!         run();
//!     </script>
//! </body>
//! </html>
//! ```
//! 
//! Make sure to modify the js file name in index.html depending on your project name.
//! Now, you should be able to run your game by opening index.html in a web browser.
//! In case this does not work, make sure you followed every instruction and [contact me](mailto:mubelotix@gmail.com).

#![warn(missing_docs)]

pub mod graphics;
pub mod inputs;
/// You will need this module for various things.
pub mod system;