From f5e043c981b123c0057d690ad705c55c5498b3c4 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 15 Aug 2023 10:21:49 -0700 Subject: [PATCH] Make Key an enum --- dyesub-tool/src/key/mod.rs | 28 +++++------- dyesub-tool/src/key/oyayubi.rs | 69 +++++++++++++++++------------- dyesub-tool/templates/document.xml | 25 ++++++----- 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/dyesub-tool/src/key/mod.rs b/dyesub-tool/src/key/mod.rs index 52f710f..6a10d6b 100644 --- a/dyesub-tool/src/key/mod.rs +++ b/dyesub-tool/src/key/mod.rs @@ -3,26 +3,20 @@ pub use oyayubi::OYAYUBI; use std::fmt::{Display, self}; -pub struct Key { - pub latin: char, - pub normal: char, - pub shift: char, - pub alt_shift: Option, +pub enum Key { + Oyayubi { + latin: char, + normal: char, + shift: char, + alt_shift: Option, + } } impl Display for Key { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.latin) - } -} - -impl Key { - const fn new(latin: char, normal: char, shift: char, alt_shift: Option) -> Self { - Self { - latin, - normal, - shift, - alt_shift, - } + use Key::*; + write!(f, "{}", match self { + Oyayubi { latin, .. } => latin, + }) } } \ No newline at end of file diff --git a/dyesub-tool/src/key/oyayubi.rs b/dyesub-tool/src/key/oyayubi.rs index d94a77c..5bbac60 100644 --- a/dyesub-tool/src/key/oyayubi.rs +++ b/dyesub-tool/src/key/oyayubi.rs @@ -1,34 +1,43 @@ use super::Key; +const fn k(latin: char, normal: char, shift: char, alt_shift: Option) -> Key { + Key::Oyayubi { + latin, + normal, + shift, + alt_shift, + } +} + pub const OYAYUBI: [Key; 30] = [ - Key::new('Q', '。', 'ぁ', None), - Key::new('W', 'か', 'え', None), - Key::new('E', 'た', 'り', None), - Key::new('R', 'こ', 'ゃ', None), - Key::new('T', 'さ', 'れ', None), - Key::new('Y', 'ら', 'よ', Some('ぱ')), - Key::new('U', 'ち', 'に', None), - Key::new('I', 'く', 'る', None), - Key::new('O', 'つ', 'ま', None), - Key::new('P', ',', 'ぇ', Some('ぴ')), - Key::new('A', 'う', 'を', None), - Key::new('S', 'し', 'あ', None), - Key::new('D', 'て', 'な', None), - Key::new('F', 'け', 'ゅ', None), - Key::new('G', 'せ', 'も', None), - Key::new('H', 'は', 'み', None), - Key::new('J', 'と', 'お', None), - Key::new('K', 'き', 'の', None), - Key::new('L', 'い', 'ょ', Some('ぽ')), - Key::new(';', 'ん', 'っ', None), // Missing + - Key::new('Z', '.', 'ぅ', None), - Key::new('X', 'ひ', 'ー', None), - Key::new('C', 'す', 'ろ', None), - Key::new('V', 'ふ', 'や', None), - Key::new('B', 'へ', 'ぃ', None), - Key::new('N', 'め', 'ぬ', Some('ぷ')), - Key::new('M', 'そ', 'ゆ', None), - Key::new(',', 'ね', 'む', Some('ぺ')), // Missing < - Key::new('.', 'ほ', 'わ', None), // Missing > - Key::new('?', '・', 'ぉ', Some('ゎ')) // Missing / + k('Q', '。', 'ぁ', None), + k('W', 'か', 'え', None), + k('E', 'た', 'り', None), + k('R', 'こ', 'ゃ', None), + k('T', 'さ', 'れ', None), + k('Y', 'ら', 'よ', Some('ぱ')), + k('U', 'ち', 'に', None), + k('I', 'く', 'る', None), + k('O', 'つ', 'ま', None), + k('P', ',', 'ぇ', Some('ぴ')), + k('A', 'う', 'を', None), + k('S', 'し', 'あ', None), + k('D', 'て', 'な', None), + k('F', 'け', 'ゅ', None), + k('G', 'せ', 'も', None), + k('H', 'は', 'み', None), + k('J', 'と', 'お', None), + k('K', 'き', 'の', None), + k('L', 'い', 'ょ', Some('ぽ')), + k(';', 'ん', 'っ', None), // Missing + + k('Z', '.', 'ぅ', None), + k('X', 'ひ', 'ー', None), + k('C', 'す', 'ろ', None), + k('V', 'ふ', 'や', None), + k('B', 'へ', 'ぃ', None), + k('N', 'め', 'ぬ', Some('ぷ')), + k('M', 'そ', 'ゆ', None), + k(',', 'ね', 'む', Some('ぺ')), // Missing < + k('.', 'ほ', 'わ', None), // Missing > + k('?', '・', 'ぉ', Some('ゎ')) // Missing / ]; \ No newline at end of file diff --git a/dyesub-tool/templates/document.xml b/dyesub-tool/templates/document.xml index 7f7d4cb..a905954 100644 --- a/dyesub-tool/templates/document.xml +++ b/dyesub-tool/templates/document.xml @@ -6,17 +6,20 @@ {% for (key, (x, y)) in positions %} - - {% let dy = "0.125em" %} - {% let font_size = "0.45cm" %} - {% let latin_font_size = "0.4cm" %} - {% let alt_shift_font_size = "0.325cm" %} - {{ key.latin }} - {{ key.shift }} - {{ key.normal }} - {% if let Some(alt_shift) = key.alt_shift %} - {{ alt_shift }} - {% endif %} + {% match key %} + {% when crate::key::Key::Oyayubi with { latin, normal, shift, alt_shift } %} + + {% let dy = "0.125em" %} + {% let font_size = "0.45cm" %} + {% let latin_font_size = "0.4cm" %} + {% let alt_shift_font_size = "0.325cm" %} + {{ latin }} + {{ shift }} + {{ normal }} + {% if let Some(alt_shift) = alt_shift %} + {{ alt_shift }} + {% endif %} + {% endmatch %} {% endfor %}