gate_build/lib.rs
1// Copyright 2017-2019 Matthew D. Michelotti
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Gate-Build contains utilities for packing image atlases and other assets
16//! as part of the build script for a Gate application (see the "gate" crate).
17//!
18//! The `AssetPacker` of Gate-Build should be invoked in a build script in a Gate application.
19//! Rust enums are generated to reference the packed assets.
20//!
21//! # Example build script
22//!
23//! In the below example, the user should place sprite png files in the "sprites" directory,
24//! music ogg files in the "music" directory, and sound ogg files in the "sounds" directory.
25//!
26//! ```rust,no_run
27//! extern crate gate_build;
28//!
29//! use std::path::Path;
30//! use std::env;
31//! use gate_build::AssetPacker;
32//!
33//! fn main() {
34//! let out_dir = env::var("OUT_DIR").unwrap();
35//! let gen_code_path = Path::new(&out_dir).join("asset_id.rs");
36//!
37//! let mut packer = AssetPacker::new(Path::new("assets"));
38//! packer.cargo_rerun_if_changed();
39//! packer.sprites(Path::new("sprites"));
40//! packer.music(Path::new("music"));
41//! packer.sounds(Path::new("sounds"));
42//! packer.gen_asset_id_code(&gen_code_path);
43//! }
44//! ```
45
46extern crate image;
47extern crate byteorder;
48extern crate regex;
49#[macro_use] extern crate lazy_static;
50
51mod rect_packer;
52mod atlas;
53mod asset_packer;
54mod html;
55
56pub use crate::asset_packer::AssetPacker;
57
58use std::path::Path;
59
60fn rerun_print(check_rerun_flag: bool, path: &Path) {
61 if check_rerun_flag {
62 println!("cargo:rerun-if-changed={}", path.to_str().expect("path could not be converted to string"));
63 }
64}