openstranded_map_tool/lib.rs
1// openstranded-map-tool — convert Stranded II .s2 maps to .osmap format
2// Copyright (C) 2026 OpenStranded contributors
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17//! Convert Stranded II `.s2` map files to the `.osmap` (OpenStranded MAP) format.
18//!
19//! # Library
20//!
21//! ```rust
22//! // Demonstrate API types — see README for full usage.
23//! use openstranded_map_tool::OpenStrandedMap;
24//!
25//! fn _types_are_public() {
26//! let _map = OpenStrandedMap {
27//! meta: openstranded_map_tool::MapMeta {
28//! name: "test".into(),
29//! engine_version: "0.1.0".into(),
30//! map_version: "0.1.0".into(),
31//! source_file: String::new(),
32//! s2_header: None,
33//! created_at: String::new(),
34//! },
35//! terrain: openstranded_map_tool::TerrainData {
36//! size: 16,
37//! heights: vec![],
38//! seaground_level: -2.0,
39//! },
40//! entities: vec![],
41//! player_spawn: None,
42//! environment: std::collections::HashMap::new(),
43//! colormap: None,
44//! grass: None,
45//! password: String::new(),
46//! scripts: vec![],
47//! };
48//! }
49//! ```
50//!
51//! # CLI
52//!
53//! ```text
54//! openstranded-map-tool convert <input.s2> [output.osmap]
55//! openstranded-map-tool info <input.s2|.osmap>
56//! ```
57
58pub mod cli;
59pub mod convert;
60pub mod parser;
61pub mod types;
62
63pub use parser::{parse_s2, parse_s2_file, S2Error};
64pub use convert::s2_to_osmap;
65pub use types::*;
66
67/// Save an `OpenStrandedMap` to a RON file.
68pub fn save_osmap_ron(osmap: &OpenStrandedMap, path: impl AsRef<std::path::Path>) -> Result<(), anyhow::Error> {
69 let ron_str = ron::ser::to_string_pretty(osmap, ron::ser::PrettyConfig::default())?;
70 std::fs::write(path.as_ref(), &ron_str)?;
71 Ok(())
72}