openstranded-map-tool 0.2.0

Convert Stranded II .s2 map files to .osmap (OpenStranded MAP) format
Documentation
// openstranded-map-tool — convert Stranded II .s2 maps to .osmap format
// Copyright (C) 2026  OpenStranded contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

//! Convert Stranded II `.s2` map files to the `.osmap` (OpenStranded MAP) format.
//!
//! # Library
//!
//! ```rust
//! // Demonstrate API types — see README for full usage.
//! use openstranded_map_tool::OpenStrandedMap;
//!
//! fn _types_are_public() {
//!     let _map = OpenStrandedMap {
//!         meta: openstranded_map_tool::MapMeta {
//!             name: "test".into(),
//!             engine_version: "0.1.0".into(),
//!             map_version: "0.1.0".into(),
//!             source_file: String::new(),
//!             s2_header: None,
//!             created_at: String::new(),
//!         },
//!         terrain: openstranded_map_tool::TerrainData {
//!             size: 16,
//!             heights: vec![],
//!             seaground_level: -2.0,
//!         },
//!         entities: vec![],
//!         player_spawn: None,
//!         environment: std::collections::HashMap::new(),
//!         colormap: None,
//!         grass: None,
//!         password: String::new(),
//!         scripts: vec![],
//!     };
//! }
//! ```
//!
//! # CLI
//!
//! ```text
//! openstranded-map-tool convert <input.s2> [output.osmap]
//! openstranded-map-tool info <input.s2|.osmap>
//! ```

pub mod cli;
pub mod convert;
pub mod parser;
pub mod types;

pub use parser::{parse_s2, parse_s2_file, S2Error};
pub use convert::s2_to_osmap;
pub use types::*;

/// Save an `OpenStrandedMap` to a RON file.
pub fn save_osmap_ron(osmap: &OpenStrandedMap, path: impl AsRef<std::path::Path>) -> Result<(), anyhow::Error> {
    let ron_str = ron::ser::to_string_pretty(osmap, ron::ser::PrettyConfig::default())?;
    std::fs::write(path.as_ref(), &ron_str)?;
    Ok(())
}