Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RON formatting for Amethyst #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions sheep/src/format/amethyst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ pub struct SerializedSpriteSheet {
pub sprites: Vec<SpritePosition>,
}

#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum Wrapper<T> {
List(T),
}

impl Format for AmethystFormat {
type Data = SerializedSpriteSheet;
type Data = Wrapper<SerializedSpriteSheet>;
type Options = ();

fn encode(
Expand All @@ -39,10 +44,10 @@ impl Format for AmethystFormat {
})
.collect::<Vec<SpritePosition>>();

SerializedSpriteSheet {
Wrapper::List(SerializedSpriteSheet {
texture_width: dimensions.0 as f32,
texture_height: dimensions.1 as f32,
sprites: sprite_positions,
}
})
}
}
1 change: 1 addition & 0 deletions sheep_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ clap = "2.32"
ron = "0.4"
oxipng = "2.2"
png = "0.15"
glob = "0.3"

[[bin]]
name = "sheep"
Expand Down
24 changes: 19 additions & 5 deletions sheep_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
extern crate clap;
extern crate glob;
extern crate image;
extern crate ron;
extern crate serde;
extern crate sheep;

use clap::{App, AppSettings, Arg, SubCommand};
use glob::glob;
use serde::Serialize;
use sheep::{
AmethystFormat, AmethystNamedFormat, InputSprite, MaxrectsOptions, MaxrectsPacker,
SimplePacker, SpriteSheet,
};
use std::path::{PathBuf, Path};
use std::str::FromStr;
use std::{fs::File, io::prelude::*};

Expand Down Expand Up @@ -93,7 +96,16 @@ fn main() {
("pack", Some(matches)) => {
let input = matches
.values_of("INPUT")
.map(|values| values.map(|it| String::from(it)).collect::<Vec<String>>())
.map(|values| {
values
.flat_map(|path_pattern| {
glob(path_pattern)
.expect("Invalid path pattern")
.map(|path| path.expect("Invalid path"))
.collect::<Vec<PathBuf>>()
})
.collect::<Vec<PathBuf>>()
})
.unwrap_or(Vec::new());

let out = matches
Expand Down Expand Up @@ -171,20 +183,22 @@ fn main() {
}
}

fn get_filenames(input: &[String]) -> Vec<String> {
fn get_filenames(input: &[PathBuf]) -> Vec<String> {
input
.iter()
.map(|path| {
std::path::PathBuf::from(&path)
.file_stem()
path.file_stem()
.and_then(|name| name.to_str())
.map(|name| String::from_str(name).expect("could not parse string from file name"))
.expect("Failed to extract file name")
})
.collect()
}

fn load_images(input: &[String]) -> Vec<InputSprite> {
fn load_images<T>(input: &[T]) -> Vec<InputSprite>
where
T: AsRef<Path>,
{
input
.iter()
.map(|path| {
Expand Down