Skip to content

Commit

Permalink
Added byte datatype.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Dec 24, 2023
1 parent 4bc799d commit 977747e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions i18n/de/game_cheetah.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ invalid-number-error = Zahl ungültig
conversion-error = Fehler beim Konvertieren { $valuetype }: { $message }
guess-value-item = Zahl (2-8 Bytes)
byte-value-item = Byte (1 byte)
short-value-item = Short (2 Bytes)
int-value-item = Int (4 Bytes)
int64-value-item = Int64 (8 Bytes)
float-value-item = Float (4 Bytes)
double-value-item = Double (8 Bytes)
guess-descr = Zahl
byte-descr = Byte
short-descr = Short
int-descr = Int
int64-descr = Int64
Expand Down
2 changes: 2 additions & 0 deletions i18n/en/game_cheetah.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ invalid-number-error = Invalid number
conversion-error = Error converting { $valuetype }: { $message }
guess-value-item = number (2-8 bytes)
byte-value-item = byte (1 byte)
short-value-item = short (2 bytes)
int-value-item = int (4 bytes)
int64-value-item = int64 (8 bytes)
float-value-item = float (4 bytes)
double-value-item = double (8 bytes)
guess-descr = Number
byte-descr = byte
short-descr = short
int-descr = int
int64-descr = int64
Expand Down
5 changes: 5 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ impl GameCheetahEngine {
SearchType::Guess,
SearchType::Guess.get_short_description_text(),
);
ui.selectable_value(
&mut search_context.search_type,
SearchType::Byte,
SearchType::Byte.get_short_description_text(),
);
ui.selectable_value(
&mut search_context.search_type,
SearchType::Short,
Expand Down
11 changes: 11 additions & 0 deletions src/search_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::SearchValue;
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum SearchType {
Guess,
Byte,
Short,
Int,
Int64,
Expand All @@ -16,6 +17,7 @@ impl SearchType {
pub fn get_description_text(&self) -> String {
match self {
SearchType::Guess => fl!(crate::LANGUAGE_LOADER, "guess-value-item"),
SearchType::Byte => fl!(crate::LANGUAGE_LOADER, "byte-value-item"),
SearchType::Short => fl!(crate::LANGUAGE_LOADER, "short-value-item"),
SearchType::Int => fl!(crate::LANGUAGE_LOADER, "int-value-item"),
SearchType::Int64 => fl!(crate::LANGUAGE_LOADER, "int64-value-item"),
Expand All @@ -27,6 +29,7 @@ impl SearchType {
pub fn get_byte_length(&self) -> usize {
match self {
SearchType::Guess => panic!("guess has no length"),
SearchType::Byte => 1,
SearchType::Short => 2,
SearchType::Int => 4,
SearchType::Int64 => 4,
Expand All @@ -38,6 +41,7 @@ impl SearchType {
pub fn get_short_description_text(&self) -> String {
match self {
SearchType::Guess => fl!(crate::LANGUAGE_LOADER, "guess-descr"),
SearchType::Byte => fl!(crate::LANGUAGE_LOADER, "byte-descr"),
SearchType::Short => fl!(crate::LANGUAGE_LOADER, "short-descr"),
SearchType::Int => fl!(crate::LANGUAGE_LOADER, "int-descr"),
SearchType::Int64 => fl!(crate::LANGUAGE_LOADER, "int64-descr"),
Expand All @@ -48,6 +52,13 @@ impl SearchType {

pub fn from_string(&self, txt: &str) -> Result<SearchValue, String> {
match self {
SearchType::Byte => {
let parsed = txt.parse::<u8>();
match parsed {
Ok(f) => Ok(SearchValue(SearchType::Byte, vec![f])),
Err(_) => Err(fl!(crate::LANGUAGE_LOADER, "invalid-input-error")),
}
}
SearchType::Short => {
let parsed = txt.parse::<i16>();
match parsed {
Expand Down
1 change: 1 addition & 0 deletions src/search_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct SearchValue(pub SearchType, pub Vec<u8>);
impl Display for SearchValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self.0 {
SearchType::Byte => self.1[0].to_string(),
SearchType::Short => i16::from_le_bytes(self.1.clone().try_into().unwrap()).to_string(),
SearchType::Int => i32::from_le_bytes(self.1.clone().try_into().unwrap()).to_string(),
SearchType::Int64 => i64::from_le_bytes(self.1.clone().try_into().unwrap()).to_string(),
Expand Down

0 comments on commit 977747e

Please sign in to comment.