Skip to main content

morpion_solitaire/
lib.rs

1//! Morpion Solitaire — a fast player and solver.
2//!
3//! This is the shared library behind both the native binary (GUI + headless
4//! [`cli`]) and the WebAssembly build (the `morpion-solitaire-wasm` crate). The
5//! [`game`] model and [`search`] engines are format-agnostic; the self-describing
6//! record format itself lives in the separate `morpion-solitaire-record` (`msr`)
7//! crate. See the project [README] and book for usage.
8//!
9//! [README]: https://github.com/sjourdois/morpion-solitaire
10#![forbid(unsafe_code)]
11
12pub mod app;
13#[cfg(not(target_arch = "wasm32"))]
14pub mod cli;
15pub mod game;
16pub mod i18n;
17pub mod render;
18pub mod search;
19pub mod ui;
20
21use app::MorpionApp;
22
23/// Construct the eframe application. Shared by the native binary ([`run_native`])
24/// and the WebAssembly entry point (the `morpion-solitaire-wasm` crate).
25pub fn create_app(cc: &eframe::CreationContext<'_>) -> Box<dyn eframe::App> {
26    Box::new(MorpionApp::new(cc))
27}
28
29#[cfg(not(target_arch = "wasm32"))]
30pub fn run_native() -> eframe::Result<()> {
31    env_logger::init();
32    i18n::set_language(&i18n::detect_locale());
33    let native_options = eframe::NativeOptions {
34        viewport: egui::ViewportBuilder::default()
35            .with_inner_size([1280.0, 800.0])
36            .with_min_inner_size([800.0, 600.0])
37            .with_app_id("morpion-solitaire"),
38        ..Default::default()
39    };
40    eframe::run_native(
41        "Morpion Solitaire",
42        native_options,
43        Box::new(|cc| Ok(create_app(cc))),
44    )
45}