Add string representation for player symbols

This commit is contained in:
Patrick Auernig 2023-08-08 21:33:46 +02:00
parent 659c7d4f8e
commit 8c0d37ee72
8 changed files with 358 additions and 4 deletions

View File

@ -10,3 +10,7 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.txt]
trim_trailing_whitespace = false
insert_final_newline = false

184
Cargo.lock generated
View File

@ -132,6 +132,12 @@ version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
[[package]]
name = "cassowary"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
[[package]]
name = "cc"
version = "1.0.79"
@ -231,6 +237,47 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossterm"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13"
dependencies = [
"bitflags 1.3.2",
"crossterm_winapi",
"libc",
"mio",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df"
dependencies = [
"bitflags 2.3.3",
"crossterm_winapi",
"libc",
"mio",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi",
]
[[package]]
name = "either"
version = "1.9.0"
@ -266,7 +313,7 @@ checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"redox_syscall 0.2.16",
"windows-sys 0.48.0",
]
@ -314,6 +361,12 @@ dependencies = [
"cc",
]
[[package]]
name = "indoc"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c785eefb63ebd0e33416dfcb8d6da0bf27ce752843a45632a67bf10d4d4b5c4"
[[package]]
name = "inotify"
version = "0.9.6"
@ -351,6 +404,7 @@ version = "0.1.0"
dependencies = [
"binrw",
"chrono",
"substring",
"urlencoding",
]
@ -395,6 +449,16 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0"
[[package]]
name = "lock_api"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.19"
@ -452,6 +516,35 @@ version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.3.5",
"smallvec",
"windows-targets 0.48.1",
]
[[package]]
name = "paste"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "proc-macro2"
version = "1.0.66"
@ -470,6 +563,21 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "ratatui"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8285baa38bdc9f879d92c0e37cb562ef38aa3aeefca22b3200186bc39242d3d5"
dependencies = [
"bitflags 2.3.3",
"cassowary",
"crossterm 0.26.1",
"indoc",
"paste",
"unicode-segmentation",
"unicode-width",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
@ -479,6 +587,15 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "rustix"
version = "0.38.4"
@ -501,12 +618,63 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "signal-hook"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801"
dependencies = [
"libc",
"signal-hook-registry",
]
[[package]]
name = "signal-hook-mio"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
dependencies = [
"libc",
"mio",
"signal-hook",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "smallvec"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "substring"
version = "1.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ee6433ecef213b2e72f587ef64a2f5943e7cd16fbd82dbe8bc07486c534c86"
dependencies = [
"autocfg",
]
[[package]]
name = "syn"
version = "1.0.109"
@ -546,6 +714,18 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
[[package]]
name = "unicode-segmentation"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-width"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "urlencoding"
version = "2.1.3"
@ -640,8 +820,10 @@ version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"crossterm 0.27.0",
"jrny-save",
"notify",
"ratatui",
]
[[package]]

View File

@ -13,3 +13,4 @@ crate-type = ["cdylib", "rlib"]
binrw = "0.11"
chrono = "0.4"
urlencoding = "2.1"
substring = "1.4"

View File

@ -1,6 +1,7 @@
mod companion;
mod glyphs;
mod murals;
mod symbol;
mod test;
@ -9,6 +10,7 @@ use std::io::{Read, Write};
use binrw::{until_eof, BinRead, BinReaderExt, BinWriterExt};
use chrono::{DateTime, NaiveDateTime, Utc};
use symbol::Symbol;
use crate::companion::{CompanionSymbols, CompanionWithId, Companions};
use crate::glyphs::Glyphs;
@ -56,7 +58,7 @@ pub struct Savefile {
robe: u32,
pub symbol: u32,
pub symbol: Symbol,
pub scarf_length: u32,

98
crates/save/src/symbol.rs Normal file
View File

@ -0,0 +1,98 @@
use core::fmt;
use binrw::{BinRead, BinWrite};
use substring::Substring;
const SYMBOL_PARTS: &str = include_str!("symbol_parts.txt");
const SYMBOL_PART_WIDTH: usize = 6;
const SYMBOL_PART_HEIGTH: usize = 3;
#[derive(Debug, Clone, Copy, BinRead, BinWrite)]
pub struct Symbol {
pub id: u32,
}
impl fmt::Display for Symbol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", get_symbol(self.id as usize).unwrap())
}
}
fn get_symbol(id: usize) -> Option<String> {
let (top_left, top_right, btm_left, btm_right) = symbol_part_ids(id)?;
get_symbol_with_parts(top_left, top_right, btm_left, btm_right)
}
fn symbol_part_ids(id: usize) -> Option<(usize, usize, usize, usize)> {
let ids = match id {
0 => (0, 1, 3, 2),
1 => (4, 4, 7, 7),
2 => (9, 9, 13, 2),
3 => (15, 16, 9, 9),
4 => (4, 9, 4, 9),
5 => (15, 12, 3, 9),
6 => (5, 5, 9, 12),
7 => (12, 9, 15, 15),
8 => (7, 9, 12, 8),
9 => (12, 12, 9, 9),
10 => (14, 7, 14, 7),
11 => (8, 8, 13, 13),
12 => (2, 3, 2, 3),
13 => (10, 7, 7, 12),
14 => (7, 7, 10, 12),
15 => (15, 15, 15, 15),
16 => (4, 4, 4, 4),
17 => (11, 10, 11, 10),
18 => (12, 8, 12, 8),
19 => (6, 6, 11, 10),
20 => (12, 9, 11, 10),
_ => return None,
};
Some(ids)
}
fn get_symbol_with_parts(
top_left: usize,
top_right: usize,
btm_left: usize,
btm_right: usize,
) -> Option<String> {
if top_left > 16 || top_right > 16 || btm_left > 16 || btm_right > 16 {
return None;
}
let top_left = get_symbol_part(top_left);
let top_right = get_symbol_part(top_right);
let btm_left = get_symbol_part(btm_left);
let btm_right = get_symbol_part(btm_right);
let top = top_left
.lines()
.zip(top_right.lines())
.map(|(left, right)| format!("{} {}", left, right));
let bottom = btm_left
.lines()
.zip(btm_right.lines())
.map(|(left, right)| format!("{} {}", left, right));
const EMPTY_LINE: &str = " ";
let symbol = top
.chain([EMPTY_LINE.to_string()].into_iter())
.chain(bottom)
.collect::<Vec<_>>()
.join("\n");
Some(symbol)
}
fn get_symbol_part(idx: usize) -> &'static str {
const SYMBOL_PART_SIZE: usize = SYMBOL_PART_WIDTH * SYMBOL_PART_HEIGTH + 2;
let start = (SYMBOL_PART_SIZE + 2) * idx;
let end = start + SYMBOL_PART_SIZE;
SYMBOL_PARTS.substring(start, end)
}

View File

@ -0,0 +1,67 @@
██ ██
██
██████
██ ██
██
██████
██████
██
██ ██
██████
██
██ ██
██████
██ ██
██ ██
██████
██
██████
██ ██
██ ██
██████
██ ██
██ ██
██ ██
██████
██████
██
████
██████
██████
████
██
██████
████
██
██
████
██████
██████
██ ██
██ ██
██
██ ██
██
██ ██
██████
██████
██ ██
██

View File

@ -16,7 +16,7 @@ fn general_info() {
assert_eq!(savefile.robe_color(), RobeColor::Red);
assert_eq!(savefile.robe_tier(), 4);
assert_eq!(savefile.symbol, 7);
assert_eq!(savefile.symbol.id, 7);
assert_eq!(savefile.scarf_length, 27);
assert_eq!(savefile.current_level, 1);
assert_eq!(savefile.total_collected_symbols, 107);

View File

@ -63,7 +63,7 @@ fn edit_file(cur_savefile: &Savefile, args: &Args) -> Result<Savefile> {
}
if let Some(val) = args.symbol {
savefile.symbol = val;
savefile.symbol.id = val;
}
if let Some(color) = &args.robe_color {