minified version

This commit is contained in:
Vomitblood 2024-03-25 15:06:57 +08:00
parent 28c9d43f01
commit ceb9133740
7 changed files with 41 additions and 67 deletions

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./Cargo.toml"
]
}

59
Cargo.lock generated
View file

@ -11,12 +11,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "anyhow"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@ -114,12 +108,6 @@ dependencies = [
"wasi", "wasi",
] ]
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.19" version = "0.1.19"
@ -129,30 +117,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "include_dir"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24b56e147e6187d61e9d0f039f10e070d0c0a887e24fe0bb9ca3f29bfde62cab"
dependencies = [
"glob",
"include_dir_impl",
"proc-macro-hack",
]
[[package]]
name = "include_dir_impl"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a0c890c85da4bab7bce4204c707396bbd3c6c8a681716a51c8814cfc2b682df"
dependencies = [
"anyhow",
"proc-macro-hack",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.10" version = "1.0.10"
@ -176,11 +140,9 @@ name = "pokerust"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"include_dir",
"once_cell", "once_cell",
"rand", "rand",
"rust-embed", "rust-embed",
"serde",
"serde_json", "serde_json",
] ]
@ -190,12 +152,6 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro-hack"
version = "0.5.20+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.79" version = "1.0.79"
@ -264,7 +220,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"rust-embed-utils", "rust-embed-utils",
"syn 2.0.55", "syn",
"walkdir", "walkdir",
] ]
@ -310,7 +266,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.55", "syn",
] ]
[[package]] [[package]]
@ -341,17 +297,6 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.55" version = "2.0.55"

View file

@ -3,14 +3,10 @@ name = "pokerust"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
clap = "2.0.0"
rand = "0.8" rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
once_cell = "1.8.0" once_cell = "1.8.0"
clap = { version = "2" }
include_dir = "0.6.0"
rust-embed = "8.3.0" rust-embed = "8.3.0"

View file

@ -1,10 +1,9 @@
# PokeRust # PokeRust
*For educational purposes*
A simple colorscript written in Rust. A simple colorscript written in Rust.
Inspired by [phoneybadger's pokemon-coloscripts](https://gitlab.com/phoneybadger/pokemon-colorscripts) Inspired by [phoneybadger's pokemon-coloscripts](https://gitlab.com/phoneybadger/pokemon-colorscripts).
*For educational purposes*
## Performance ## Performance
@ -16,3 +15,9 @@ This is the Python implementation:
This is the Rust implementation: This is the Rust implementation:
![rust implementation](img/screenshot_250324_132205.png) ![rust implementation](img/screenshot_250324_132205.png)
## Credits
- [phoneybadger](https://gitlab.com/phoneybadger) for the original colorscripts and inspiration.
- [talwat](https://github.com/talwat/pokeget-rs) for Rust code reference. (fast af implementation at ~1ms)
- [msikma](https://github.com/msikma/pokesprite/) for the colorscripts' sprites.

View file

@ -1,7 +1,7 @@
pkgname=pokerust-git pkgname=pokerust-git
pkgdesc="Pokemon Colorscripts written in Rust" pkgdesc="Pokemon Colorscripts written in Rust"
_gitname=pokerust _gitname=pokerust
pkgver=r8.c1e2b64 pkgver=r21.28c9d43
pkgrel=1 pkgrel=1
arch=('x86_64') arch=('x86_64')
url="https://github.com/Vomitblood/$_gitname" url="https://github.com/Vomitblood/$_gitname"
@ -21,10 +21,14 @@ pkgver() {
build() { build() {
cd "$srcdir/$_gitname" cd "$srcdir/$_gitname"
# build main program
cargo build --release cargo build --release
# build mini program
cargo build --release --bin minimon
} }
package() { package() {
cd "$srcdir/$_gitname" cd "$srcdir/$_gitname"
install -Dm755 target/release/$_gitname "$pkgdir/usr/bin/$_gitname" install -Dm755 target/release/$_gitname "$pkgdir/usr/bin/$_gitname"
install -Dm755 target/release/minimon "$pkgdir/usr/bin/minimon"
} }

19
src/bin/minimon.rs Normal file
View file

@ -0,0 +1,19 @@
use rand::prelude::SliceRandom;
use rust_embed::RustEmbed;
use std::str;
#[derive(RustEmbed)]
#[folder = "colorscripts/small/regular/"]
struct ColorScriptsDir;
fn main() {
let files: Vec<_> = ColorScriptsDir::iter().collect();
let mut rng = rand::thread_rng();
if let Some(random_file) = files.choose(&mut rng) {
println!("Random Pokémon Sprite: {}", random_file);
if let Some(file_data) = ColorScriptsDir::get(random_file) {
println!("{}", std::str::from_utf8(file_data.data.as_ref()).unwrap());
}
}
}

View file

@ -3,7 +3,7 @@ use rand::Rng;
// set global constants // set global constants
#[derive(rust_embed::RustEmbed)] #[derive(rust_embed::RustEmbed)]
#[folder = "colorscripts/"] #[folder = "colorscripts/"]
pub struct ColorScriptsDir; struct ColorScriptsDir;
const POKEMON_JSON: &str = std::include_str!("../pokemon.json"); const POKEMON_JSON: &str = std::include_str!("../pokemon.json");