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
//! # Rust Chess Library
//!
//! This is a chess library for rust with Gui.
//!
//! ## Examples
//!
//! ```no_run
//! use chess::{run, ChessGui};
//!
//! fn main() {
//!     // Create and run the Gui game
//!     run(ChessGui::default());
//! }
//! ```

#![allow(clippy::needless_doctest_main, clippy::collapsible_if)]
#![deny(
    // missing_docs, // This lint ask to document all variants/fields of enum/struct.
    missing_debug_implementations,
    missing_copy_implementations,
    trivial_casts,
    trivial_numeric_casts,
    // unsafe_code,
    unstable_features,
    unused_import_braces,
    unused_qualifications
)]

// Core

mod board;
pub use crate::board::*;

mod chess;
pub use crate::chess::*;

mod piece;
pub use crate::piece::*;

mod color;
pub use crate::color::*;

mod castle_rights;
pub use crate::castle_rights::*;

mod error;
pub use crate::error::*;

mod config;
pub use crate::config::*;

mod square;
pub use crate::square::*;

mod file;
pub use crate::file::*;

mod rank;
pub use crate::rank::*;

mod chess_move;
pub use crate::chess_move::*;

mod direction;
pub use crate::direction::*;

// Gui

mod chess_gui;
pub use crate::chess_gui::*;

mod button;
pub use crate::button::*;

mod theme;
pub use crate::theme::*;

// Function

/// Run the GUI.
pub fn run(game: ChessGui) {
    let default_conf = ggez::conf::Conf {
        window_mode: ggez::conf::WindowMode::default()
            .dimensions(SCREEN_PX_SIZE.0, SCREEN_PX_SIZE.1),
        window_setup: ggez::conf::WindowSetup::default()
            .title("Chess")
            .icon("/images/icon.png"),
        backend: ggez::conf::Backend::default(),
        modules: ggez::conf::ModuleConf {
            gamepad: false,
            audio: false,
        },
    };
    let (ctx, event_loop) =
        ggez::ContextBuilder::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_AUTHORS"))
            .add_resource_path::<std::path::PathBuf>(
                [env!("CARGO_MANIFEST_DIR"), "resources"].iter().collect(),
            )
            .default_conf(default_conf)
            .build()
            .expect("Failed to build ggez context");

    ggez::event::run(ctx, event_loop, game)
}