Skip to content

Commit af05e91

Browse files
authored
mvp: Merge pull request #6 from mwln/examples-lib
first draft mvp
2 parents 5ea9a55 + 25a67f9 commit af05e91

17 files changed

+536
-291
lines changed

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# will have compiled files and executables
33
/target/
44

5-
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6-
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7-
Cargo.lock
5+
# wasm default directory
6+
/pkg/
7+
*.json
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk

Cargo.lock

+247
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
[package]
2-
name = "noclue"
2+
name = "puz"
33
version = "0.1.0"
44
edition = "2021"
55

6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
6+
[lib]
7+
crate-type = ["cdylib", "rlib"]
78

89
[dependencies]
9-
byteorder = "1.3.1"
10+
wasm-bindgen-futures = "0.4.37"
11+
wasm-bindgen = "0.2.87"
12+
gloo-file = {version = "0.3.0", features = ['futures'] }
13+
js-sys = "0.3.64"
14+
web-sys = { version = "0.3.64", features = ['File', 'FileReader', 'Blob', 'console'] }
15+
byteorder = "1.4.3"
16+
serde_json = "1.0.107"

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 mert!
3+
Copyright (c) 2022 mwln
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# noclue
1+
# puz.rs
2+
23
A .puz file parser
34

45
## Usage
56

6-
* Takes in one or more `.puz` files and parses them to TOML format on stdout
7-
* assigns a "smartId", as a means of identifying unique puzzles based on
7+
- Takes in one or more `.puz` files and parses them to TOML format on stdout
8+
- assigns a "smartId", as a means of identifying unique puzzles based on
89
solution grid.
9-
* Can return the following to stdout / file(s) / or through a module function via
10+
- Can return the following to stdout / file(s) / or through a module function via
1011
crate import:
1112

1213
```toml
@@ -28,8 +29,8 @@ solution = [
2829
]
2930
extensions = [
3031
# nothing here means puzzle is standard
31-
# circled squares = o
32-
# tile contents are given = g
32+
# circled squares = o
33+
# tile contents are given = g
3334
# tile has rebus @ index n = n (`u16`)
3435
"og3", # circled, contents given, rebus.options[3]
3536
"...",
@@ -54,11 +55,10 @@ options = [ "CLUB", "DIAMOND", "SPADE", "HEARTS"]
5455

5556
## Thoughts
5657

57-
* Think of ways to handle multiple files when outputting to stdout
58+
- Think of ways to handle multiple files when outputting to stdout
5859

5960
## Considerations
6061

61-
* How do scrambled puzzles get read?
62-
* Assigning rebus's properly
63-
* GEXT analysis for board setup
64-
62+
- How do scrambled puzzles get read?
63+
- Assigning rebus's properly
64+
- GEXT analysis for board setup

examples/data/circled.puz

2.45 KB
Binary file not shown.

examples/data/circled2.puz

2.59 KB
Binary file not shown.

examples/data/circled3.puz

2.71 KB
Binary file not shown.

examples/data/rebus.puz

2.68 KB
Binary file not shown.

examples/data/rebus1.puz

2.7 KB
Binary file not shown.
File renamed without changes.

examples/data/standard2.puz

2.44 KB
Binary file not shown.

examples/read-with-file.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use puz::parse_puz;
2+
use std::{
3+
fs::File,
4+
io::{ErrorKind, Write},
5+
};
6+
fn main() -> std::io::Result<()> {
7+
let path = "examples/data/rebus.puz";
8+
let file = match File::open(&path) {
9+
Err(err) => match err.kind() {
10+
ErrorKind::NotFound => panic!("File not found at path: {}", &path),
11+
other_error => panic!("Problem opening the file: {:?}", other_error),
12+
},
13+
Ok(file) => file,
14+
};
15+
16+
let puzzle = parse_puz(&file).expect("Error while parsing the file.");
17+
let file_path = "examples/output.json";
18+
let mut file = File::create(file_path)?;
19+
file.write_all(puzzle.to_string().as_bytes())?;
20+
21+
Ok(())
22+
}

0 commit comments

Comments
 (0)