Skip to content

Commit

Permalink
Make separate terminal and wasm binary setup
Browse files Browse the repository at this point in the history
  • Loading branch information
knzai committed Jul 17, 2024
1 parent cbbaf35 commit 2052128
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 24 deletions.
27 changes: 17 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,35 @@ readme = "README.md"
keywords = ["gamedev", "graphics"]
categories = ["command-line-utilities"]
exclude = [".rusty-hook.toml", ".gitignore"]
default-run = 'cega'

[[bin]]
name = 'cega'
path = "src/main.rs"
path = "src/terminal/main.rs"
required-features = ["terminal"]

[[bin]]
name = 'cega-wasm'
path = "src/wasm/main.rs"
required-features = ["wasm"]

[features]
default = ["terminal", "png"]
terminal = ["clap"]
png = ["image"]
terminal = ["dep:clap"]
png = ["dep:image"]
wasm = ["dep:yew", "png", "dep:gloo"]
#sdl2 = ["dep:sdl2"]

[dev-dependencies]
rusty-hook = "^0.11.2"

[dependencies]
bitvec = "1"
factor = "0.4.0"
image = { version = "0.25.1", optional = true }
clap = { version = "4.5.7", features = ["derive"], optional = true }

[dependencies.sdl2]
version = "0.37.0"
optional = true
default-features = false
features = ["gfx"]
#optional deps
clap = { optional = true, version = "4.5.7", features = ["derive"] }
gloo = { optional = true, version = "0.10" }
image = { optional = true, version = "0.25.1" }
sdl2 = { optional = true, version = "0.37.0", default-features = false, features = ["gfx"] }
yew = { optional = true, git = "https://github.com/yewstack/yew/", features = ["csr"] }
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ This is currently very much in an alpha state: apis and CLI arguments may still

If you use feature `sdl2` you must install the sdl2 libraries first

## MacOS
### MacOS
`brew install sdl2 sdl2_gfx sdl2_image`

## Linux
### Linux
`[sudo] apt-get install libsdl2-dev libsdl2-gfx-dev libsdl2-image-dev`

### Features/conditional compilation and related dependencies
```toml
[features]
default = ["terminal", "png"]
terminal = ["dep:clap"]
png = ["dep:image"]
wasm = ["dep:yew"]
#sdl2 = ["dep:sdl2"]
```
Including terminal or wasm produces the corresponding binary

## Roadmap/Upcoming

### Priority
Expand Down Expand Up @@ -97,17 +108,6 @@ cega will ouput in different preview formats, such as colored ASCII or a gui win

<img width="650" alt="cega ../../assets/game/CGATILES.BIN -w 16 -r 16 -i cga -t c -c 1234 -s" src="https://github.com/knzconnor/cega/assets/53/593e9c9f-2780-4201-af93-7073155e876c">

## Cargo features and library usage

```toml
default = ["terminal", "sdl2", "png"]
terminal = ["clap"]
png = ["image"]
```

Disabling terminal will skip the binary target
Png feature is handled via [image](https://crates.io/crates/image) so includes that dep

## Acknowledgements & References
- [The DOS Game Modding Wiki](https://moddingwiki.shikadi.net/wiki/Main_Page), particularly [User:TheAlmightyGuru](https://moddingwiki.shikadi.net/wiki/User:TheAlmightyGuru)
- [Raw_EGA_data](https://moddingwiki.shikadi.net/wiki/Raw_EGA_data)
Expand Down
3 changes: 3 additions & 0 deletions Trunk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
target = "src/wasm/index.html"
dist = "target/dist"
2 changes: 1 addition & 1 deletion src/main.rs → src/terminal/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cega::sdl::render_sdl;
use cega::terminal::{self, args, *};
use cega::ImageType;

fn main() -> Result<(), Box<dyn std::error::Error>> {
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = args::Args::parse();

let reader = std::fs::read(Path::new(&args.image))?;
Expand Down
11 changes: 11 additions & 0 deletions src/wasm/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
</head>
<body><link
data-trunk
rel="rust" href="../../Cargo.toml"
data-bin="cega-wasm"
data-cargo-no-default-features
data-cargo-features="wasm" /></body>
</html>
26 changes: 26 additions & 0 deletions src/wasm/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![cfg(feature = "wasm")]
use yew::prelude::*;

#[function_component]
fn App() -> Html {
let counter = use_state(|| 0);
let onclick = {
let counter = counter.clone();
move |_| {
let value = *counter + 1;
counter.set(value);
}
};

html! {
<div>
<button {onclick}>{ "+1" }</button>
<p>{ *counter }</p>
</div>
}
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
yew::Renderer::<App>::new().render();
Ok(())
}

0 comments on commit 2052128

Please sign in to comment.