Skip to content

Commit

Permalink
#234 : Big commit. Separates embedding into bracket-embedding crate, …
Browse files Browse the repository at this point in the history
…and REX loading/saving/color into bracket-rex crate. Passes all local unit testing and examples run, will need integration testing with Hands-on Rust and Roguelike Tutorial.
  • Loading branch information
thebracket committed Nov 5, 2021
1 parent 1bf31b9 commit aaeecb7
Show file tree
Hide file tree
Showing 23 changed files with 407 additions and 307 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Expand Up @@ -36,7 +36,7 @@ webgpu = [ "bracket-terminal/webgpu" ]

[dependencies]
bracket-algorithm-traits = { path = "./bracket-algorithm-traits", version = "~0.8.2" }
bracket-color = { path = "./bracket-color", version = "~0.8.2", features = [ "rex", "palette" ] }
bracket-color = { path = "./bracket-color", version = "~0.8.2", features = [ "palette" ] }
bracket-geometry = { path = "./bracket-geometry", version = "~0.8.2" }
bracket-noise = { path = "./bracket-noise", version = "~0.8.2" }
bracket-pathfinding = { path = "./bracket-pathfinding", version = "~0.8.2" }
Expand All @@ -52,7 +52,9 @@ members = [
"bracket-pathfinding",
"bracket-random",
"bracket-terminal",
"rltk"
"rltk",
"bracket-rex",
"bracket-embedding",
]

# Comment this out for releases
Expand Down
2 changes: 0 additions & 2 deletions bracket-color/Cargo.toml
Expand Up @@ -13,12 +13,10 @@ categories = ["game-engines", "graphics"]
license = "MIT"

[features]
rex = [ "byteorder" ]
palette = [ "lazy_static", "parking_lot" ]

[dependencies]
serde = { version = "~1.0.110", features = ["derive"], optional = true }
byteorder = { version = "1.4.2", optional = true }
crossterm = { version = "~0.19", optional = true }
lazy_static = { version = "1.4.0", optional = true }
parking_lot = { version = "~0.11.1", optional = true }
Expand Down
5 changes: 0 additions & 5 deletions bracket-color/src/lib.rs
Expand Up @@ -45,9 +45,6 @@ mod palette;
mod rgb;
/// Import RGBA color support
mod rgba;
/// Import REX Paint Support
#[cfg(feature = "rex")]
mod xpcolor;

/// Exports the color functions/types in the `prelude` namespace.
pub mod prelude {
Expand All @@ -59,6 +56,4 @@ pub mod prelude {
pub use crate::palette::*;
pub use crate::rgb::*;
pub use crate::rgba::*;
#[cfg(feature = "rex")]
pub use crate::xpcolor::*;
}
22 changes: 0 additions & 22 deletions bracket-color/src/rgb.rs
@@ -1,5 +1,3 @@
#[cfg(feature = "rex")]
use crate::prelude::XpColor;
use crate::prelude::{HSV, RGBA};
use std::convert::From;
use std::ops;
Expand Down Expand Up @@ -230,26 +228,6 @@ impl RGB {
})
}

/// Converts an xp file color component to an RGB
#[cfg(feature = "rex")]
#[must_use]
pub fn from_xp(col: XpColor) -> Self {
Self::from_u8(col.r, col.g, col.b)
}

/// Converts an RGB to an xp file color component
#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_truncation)]
#[cfg(feature = "rex")]
#[must_use]
pub fn to_xp(&self) -> XpColor {
XpColor::new(
(self.r * 255.0) as u8,
(self.g * 255.0) as u8,
(self.b * 255.0) as u8,
)
}

/// Converts an RGB triple to an HSV triple.
#[allow(clippy::many_single_char_names)]
#[must_use]
Expand Down
15 changes: 0 additions & 15 deletions bracket-color/src/rgba.rs
@@ -1,5 +1,3 @@
#[cfg(feature = "rex")]
use crate::prelude::XpColor;
use crate::prelude::{HtmlColorConversionError, HSV, RGB};
use std::convert::From;
use std::ops;
Expand Down Expand Up @@ -282,19 +280,6 @@ impl RGBA {
a: self.a + range * percent,
}
}

/// Converts an RGB to an xp file color component
#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_truncation)]
#[cfg(feature = "rex")]
#[must_use]
pub fn to_xp(&self) -> XpColor {
XpColor::new(
(self.r * 255.0) as u8,
(self.g * 255.0) as u8,
(self.b * 255.0) as u8,
)
}
}

/// Support conversion from RGB
Expand Down
16 changes: 16 additions & 0 deletions bracket-embedding/Cargo.toml
@@ -0,0 +1,16 @@
[package]
name = "bracket-embedding"
version = "0.8.0"
edition = "2018"
publish = false
description = "Provides resource embedding services for bracket-lib"
homepage = "https://github.com/thebracket/bracket-lib"
repository = "https://github.com/thebracket/bracket-lib"
readme = "README.md"
keywords = ["roguelike", "gamedev", "terminal", "ascii", "cp437"]
categories = ["game-engines"]
license = "MIT"

[dependencies]
parking_lot = { version = "~0.11.1" }
lazy_static = "1.4.0"
6 changes: 3 additions & 3 deletions bracket-terminal/src/embedding.rs → bracket-embedding/src/embedding.rs 100755 → 100644
@@ -1,9 +1,9 @@
use std::collections::HashMap;

use parking_lot::Mutex;
use lazy_static::*;

const TERMINAL_8_8_BYTES: &[u8] = include_bytes!("../resources/terminal8x8.png");
const TERMINAL_8_16_BYTES: &[u8] = include_bytes!("../resources/vga8x16.png");
const TERMINAL_8_8_BYTES: &[u8] = include_bytes!("../../bracket-terminal/resources/terminal8x8.png");
const TERMINAL_8_16_BYTES: &[u8] = include_bytes!("../../bracket-terminal/resources/vga8x16.png");

lazy_static! {
pub static ref EMBED: Mutex<Dictionary> = Mutex::new(Dictionary::new());
Expand Down
22 changes: 22 additions & 0 deletions bracket-embedding/src/lib.rs
@@ -0,0 +1,22 @@
mod embedding;

pub mod prelude {
pub use crate::embedding::*;
pub use crate::{embedded_resource, link_resource};
}

#[macro_export]
macro_rules! embedded_resource {
($resource_name : ident, $filename : expr) => {
const $resource_name: &'static [u8] = include_bytes!($filename);
};
}

#[macro_export]
macro_rules! link_resource {
($resource_name : ident, $filename : expr) => {
EMBED
.lock()
.add_resource($filename.to_string(), $resource_name);
};
}
2 changes: 1 addition & 1 deletion bracket-noise/Cargo.toml
Expand Up @@ -19,4 +19,4 @@ bracket-random = { path = "../bracket-random", version = "~0.8.2" }

[dev-dependencies]
crossterm = "~0.19"
bracket-color = { path = "../bracket-color", version = "~0.8.2", features = [ "rex", "palette" ] }
bracket-color = { path = "../bracket-color", version = "~0.8.2", features = [ "palette" ] }
2 changes: 1 addition & 1 deletion bracket-pathfinding/Cargo.toml
Expand Up @@ -27,7 +27,7 @@ smallvec = "~1"
[dev-dependencies]
crossterm = "~0.19"
bracket-random = { path = "../bracket-random", version = "0.8.2" }
bracket-color = { path = "../bracket-color", version = "~0.8.2", features = [ "rex", "palette" ] }
bracket-color = { path = "../bracket-color", version = "~0.8.2", features = [ "palette" ] }
criterion = "0.3.4"

[[bench]]
Expand Down
18 changes: 18 additions & 0 deletions bracket-rex/Cargo.toml
@@ -0,0 +1,18 @@
[package]
name = "bracket-rex"
version = "0.8.0"
edition = "2018"
publish = false
description = "Load/save REX Paint files and utilize them in bracket-terminal projects."
homepage = "https://github.com/thebracket/bracket-lib"
repository = "https://github.com/thebracket/bracket-lib"
readme = "README.md"
keywords = ["roguelike", "gamedev", "terminal", "ascii", "cp437"]
categories = ["game-engines"]
license = "MIT"

[dependencies]
byteorder = "1.4.2"
flate2 = "1.0.20"
bracket-color = { path = "../bracket-color", version = "~0.8.2", features = [ "palette" ] }
bracket-embedding = { path = "../bracket-embedding", version = "~0.8" }
7 changes: 7 additions & 0 deletions bracket-rex/src/lib.rs
@@ -0,0 +1,7 @@
mod rex;
mod xpcolor;

pub mod prelude {
pub use crate::rex::*;
pub use crate::xpcolor::*;
}

0 comments on commit aaeecb7

Please sign in to comment.