Skip to content

Commit

Permalink
chore: remove once_cell dependency (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus authored Jul 27, 2024
1 parent e00fc05 commit affefb3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
- name: build
run: |
cd docs
npm install
npm run docs:build
- uses: actions/configure-pages@v3
- uses: actions/upload-pages-artifact@v2
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
- uses: actions/deploy-pages@v2
- uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: lint editorconfig
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: editorconfig
run: |
docker run --rm --volume=$PWD:/check mstruebing/editorconfig-checker ec --exclude ".git|\.meta$|\.anim$|\.dds$|\.controller$|\.asset$|\.unity$|\.asmdef$|ProjectSettings"
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
- uses: actions/stale@v9
id: stale
with:
stale-issue-label: stale
Expand Down
12 changes: 1 addition & 11 deletions crates/Cargo.lock

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

7 changes: 1 addition & 6 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sprite_dicing"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
description = "Cross-engine tool for lossless compression of sprite textures with identical areas."
license = "MIT"
Expand All @@ -11,8 +11,3 @@ repository = "https://github.com/elringus/sprite-dicing"
readme = "../../README.md"
keywords = ["gamedev", "graphics", "sprite", "texture", "atlas"]
categories = ["game-development", "graphics", "compression"]

[dev-dependencies]
# TODO: Replace with std::sync::LazyLock when stabilized.
# https://github.com/rust-lang/rust/issues/109736
once_cell = "1.19"
42 changes: 21 additions & 21 deletions crates/lib/src/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![cfg(test)]

use crate::models::*;
use once_cell::sync::Lazy;
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::LazyLock;

pub const R: Pixel = Pixel::new(255, 0, 0, 255);
pub const G: Pixel = Pixel::new(0, 255, 0, 255);
Expand All @@ -13,70 +13,70 @@ pub const C: Pixel = Pixel::new(0, 255, 255, 255);
pub const M: Pixel = Pixel::new(255, 0, 255, 255);
pub const Y: Pixel = Pixel::new(255, 255, 0, 255);

pub static R1X1: Lazy<Texture> = Lazy::new(|| tex(1, 1, vec![R]));
pub static G1X1: Lazy<Texture> = Lazy::new(|| tex(1, 1, vec![G]));
pub static B1X1: Lazy<Texture> = Lazy::new(|| tex(1, 1, vec![B]));
pub static C1X1: Lazy<Texture> = Lazy::new(|| tex(1, 1, vec![C]));
pub static M1X1: Lazy<Texture> = Lazy::new(|| tex(1, 1, vec![M]));
pub static Y1X1: Lazy<Texture> = Lazy::new(|| tex(1, 1, vec![Y]));
pub static R1X1: LazyLock<Texture> = LazyLock::new(|| tex(1, 1, vec![R]));
pub static G1X1: LazyLock<Texture> = LazyLock::new(|| tex(1, 1, vec![G]));
pub static B1X1: LazyLock<Texture> = LazyLock::new(|| tex(1, 1, vec![B]));
pub static C1X1: LazyLock<Texture> = LazyLock::new(|| tex(1, 1, vec![C]));
pub static M1X1: LazyLock<Texture> = LazyLock::new(|| tex(1, 1, vec![M]));
pub static Y1X1: LazyLock<Texture> = LazyLock::new(|| tex(1, 1, vec![Y]));
#[rustfmt::skip]
pub static RGBY: Lazy<Texture> = Lazy::new(|| tex(2, 2, vec![
pub static RGBY: LazyLock<Texture> = LazyLock::new(|| tex(2, 2, vec![
R, G,
B, Y
]));
#[rustfmt::skip]
pub static BGRT: Lazy<Texture> = Lazy::new(|| tex(2, 2, vec![
pub static BGRT: LazyLock<Texture> = LazyLock::new(|| tex(2, 2, vec![
B, G,
R, T
]));
#[rustfmt::skip]
pub static BTGR: Lazy<Texture> = Lazy::new(|| tex(2, 2, vec![
pub static BTGR: LazyLock<Texture> = LazyLock::new(|| tex(2, 2, vec![
B, T,
G, R
]));
#[rustfmt::skip]
pub static BTGT: Lazy<Texture> = Lazy::new(|| tex(2, 2, vec![
pub static BTGT: LazyLock<Texture> = LazyLock::new(|| tex(2, 2, vec![
B, T,
G, T
]));
#[rustfmt::skip]
pub static TTTM: Lazy<Texture> = Lazy::new(|| tex(2, 2, vec![
pub static TTTM: LazyLock<Texture> = LazyLock::new(|| tex(2, 2, vec![
T, T,
T, M
]));
#[rustfmt::skip]
pub static MTTT: Lazy<Texture> = Lazy::new(|| tex(2, 2, vec![
pub static MTTT: LazyLock<Texture> = LazyLock::new(|| tex(2, 2, vec![
M, T,
T, T
]));
#[rustfmt::skip]
pub static TTMT: Lazy<Texture> = Lazy::new(|| tex(2, 2, vec![
pub static TTMT: LazyLock<Texture> = LazyLock::new(|| tex(2, 2, vec![
T, T,
M, T
]));
#[rustfmt::skip]
pub static TTTT: Lazy<Texture> = Lazy::new(|| tex(2, 2, vec![
pub static TTTT: LazyLock<Texture> = LazyLock::new(|| tex(2, 2, vec![
T, T,
T, T
]));
#[rustfmt::skip]
pub static RGB1X3: Lazy<Texture> = Lazy::new(|| tex(1, 3, vec![
pub static RGB1X3: LazyLock<Texture> = LazyLock::new(|| tex(1, 3, vec![
G,
R,
B
]));
#[rustfmt::skip]
pub static RGB3X1: Lazy<Texture> = Lazy::new(|| tex(3, 1, vec![
pub static RGB3X1: LazyLock<Texture> = LazyLock::new(|| tex(3, 1, vec![
G, R, B
]));
#[rustfmt::skip]
pub static RGB4X4: Lazy<Texture> = Lazy::new(|| tex(4, 4, vec![
pub static RGB4X4: LazyLock<Texture> = LazyLock::new(|| tex(4, 4, vec![
B, G, G, G,
R, R, G, B,
R, G, B, R,
B, B, R, G,
]));
pub static PLT4X4: Lazy<Texture> = Lazy::new(|| palette(4, 4));
pub static PLT4X4: LazyLock<Texture> = LazyLock::new(|| palette(4, 4));

pub fn sample_progress(act: impl Fn(Prefs)) -> Progress {
let progress = Rc::new(RefCell::new(None));
Expand All @@ -101,7 +101,7 @@ pub trait AnySource {
}
}

impl AnySource for Lazy<Texture> {
impl AnySource for LazyLock<Texture> {
fn texture(&self) -> Texture {
(self as &Texture).to_owned()
}
Expand All @@ -110,7 +110,7 @@ impl AnySource for Lazy<Texture> {
}
}

impl AnySource for (&Lazy<Texture>, (f32, f32)) {
impl AnySource for (&LazyLock<Texture>, (f32, f32)) {
fn texture(&self) -> Texture {
(self.0 as &Texture).to_owned()
}
Expand Down
3 changes: 0 additions & 3 deletions crates/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ cli = { path = "../cli" }
image = { version = "0.25", default-features = false, features = ["png", "webp"] }
serde_json = "1.0"
rand = "0.8"
# TODO: Replace with std::sync::LazyLock when stabilized.
# https://github.com/rust-lang/rust/issues/109736
once_cell = "1.19"
8 changes: 4 additions & 4 deletions crates/tests/src/common/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::common::img;
use image::RgbaImage;
use once_cell::sync::Lazy;
use sprite_dicing::SourceSprite;
use std::collections::HashMap;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;

pub const MONO: &str = "mono";
pub const ICONS: &str = "icons";
Expand All @@ -14,9 +14,9 @@ pub const NESTED: &str = "nested";
pub const EXOTIC: &str = "exotic";
pub const INVALID: &str = "invalid";

pub static SRC: Lazy<SourcesByFixture> = Lazy::new(cache_sources);
pub static DIR: Lazy<DirByFixture> = Lazy::new(cache_dirs);
pub static RAW: Lazy<RawsByFixture> = Lazy::new(cache_raws);
pub static SRC: LazyLock<SourcesByFixture> = LazyLock::new(cache_sources);
pub static DIR: LazyLock<DirByFixture> = LazyLock::new(cache_dirs);
pub static RAW: LazyLock<RawsByFixture> = LazyLock::new(cache_raws);

pub type SourcesByFixture = HashMap<String, Vec<SourceSprite>>;
pub type DirByFixture = HashMap<String, PathBuf>;
Expand Down

0 comments on commit affefb3

Please sign in to comment.