added ev display
parent
2917ba457e
commit
b071b55a58
|
|
@ -48,6 +48,7 @@ fn try_parse(data: &[u8], offset: usize) -> Option<PokemonInstance> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let decrypted = decrypt_pokemon(encrypted).ok()?;
|
let decrypted = decrypt_pokemon(encrypted).ok()?;
|
||||||
|
// println!("{}", debug_pokemon_data(&decrypted));
|
||||||
let pokemon = parse_pokemon(&decrypted).ok()?;
|
let pokemon = parse_pokemon(&decrypted).ok()?;
|
||||||
Some(pokemon)
|
Some(pokemon)
|
||||||
}
|
}
|
||||||
|
|
@ -125,32 +126,47 @@ fn parse_pokemon(data: &[u8]) -> Result<PokemonInstance, String> {
|
||||||
instance.pokemon.national = read_short(data, offset_a + 0x00);
|
instance.pokemon.national = read_short(data, offset_a + 0x00);
|
||||||
|
|
||||||
let ivs = read_long(data, offset_b + 0x10);
|
let ivs = read_long(data, offset_b + 0x10);
|
||||||
|
instance.ivs.insert(BaseStat::Hp, ((ivs >> 0) & 31) as u8);
|
||||||
instance
|
instance
|
||||||
.ivs
|
.ivs
|
||||||
.insert(crate::pokemon::BaseStat::Hp, ((ivs >> 0) & 31) as u8);
|
.insert(BaseStat::Attack, ((ivs >> 5) & 31) as u8);
|
||||||
instance
|
instance
|
||||||
.ivs
|
.ivs
|
||||||
.insert(crate::pokemon::BaseStat::Attack, ((ivs >> 5) & 31) as u8);
|
.insert(BaseStat::Defense, ((ivs >> 10) & 31) as u8);
|
||||||
instance
|
instance
|
||||||
.ivs
|
.ivs
|
||||||
.insert(crate::pokemon::BaseStat::Defense, ((ivs >> 10) & 31) as u8);
|
.insert(BaseStat::Speed, ((ivs >> 15) & 31) as u8);
|
||||||
instance
|
instance
|
||||||
.ivs
|
.ivs
|
||||||
.insert(crate::pokemon::BaseStat::Speed, ((ivs >> 15) & 31) as u8);
|
.insert(BaseStat::SpecialAttack, ((ivs >> 20) & 31) as u8);
|
||||||
instance.ivs.insert(
|
instance
|
||||||
crate::pokemon::BaseStat::SpecialAttack,
|
.ivs
|
||||||
((ivs >> 20) & 31) as u8,
|
.insert(BaseStat::SpecialDefense, ((ivs >> 25) & 31) as u8);
|
||||||
);
|
|
||||||
instance.ivs.insert(
|
|
||||||
crate::pokemon::BaseStat::SpecialDefense,
|
|
||||||
((ivs >> 25) & 31) as u8,
|
|
||||||
);
|
|
||||||
|
|
||||||
instance.nature = Some(Nature {
|
instance.nature = Some(Nature {
|
||||||
pid: read_byte(data, offset_b + 0x19),
|
pid: read_byte(data, offset_b + 0x19),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
instance
|
||||||
|
.evs
|
||||||
|
.insert(BaseStat::Hp, read_byte(data, offset_a + 0x10));
|
||||||
|
instance
|
||||||
|
.evs
|
||||||
|
.insert(BaseStat::Attack, read_byte(data, offset_a + 0x11));
|
||||||
|
instance
|
||||||
|
.evs
|
||||||
|
.insert(BaseStat::Defense, read_byte(data, offset_a + 0x12));
|
||||||
|
instance
|
||||||
|
.evs
|
||||||
|
.insert(BaseStat::Speed, read_byte(data, offset_a + 0x13));
|
||||||
|
instance
|
||||||
|
.evs
|
||||||
|
.insert(BaseStat::SpecialAttack, read_byte(data, offset_a + 0x14));
|
||||||
|
instance
|
||||||
|
.evs
|
||||||
|
.insert(BaseStat::SpecialDefense, read_byte(data, offset_a + 0x15));
|
||||||
|
|
||||||
Ok(instance)
|
Ok(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,7 +248,7 @@ fn debug_pokemon_data(data: &[u8]) -> String {
|
||||||
_ => offset,
|
_ => offset,
|
||||||
};
|
};
|
||||||
if address % 4 == 0 {
|
if address % 4 == 0 {
|
||||||
result += format!("[ {:#06X} ]", address - offset).as_str();
|
result += format!("[ {:#06X} :: {:#06X} ]", address, address - offset).as_str();
|
||||||
}
|
}
|
||||||
result += format!(" {value:#04X}").as_str();
|
result += format!(" {value:#04X}").as_str();
|
||||||
if address % 4 == 3 {
|
if address % 4 == 3 {
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ fn init_memory_reader(queue: Res<EventQueue>) {
|
||||||
|
|
||||||
let (tx, rx) = std::sync::mpsc::channel();
|
let (tx, rx) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
let mut debouncer = new_debouncer(Duration::from_millis(1_000), None, tx)
|
let mut debouncer = new_debouncer(Duration::from_millis(200), None, tx)
|
||||||
.expect("Could not create notify debouncer");
|
.expect("Could not create notify debouncer");
|
||||||
|
|
||||||
debouncer
|
debouncer
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ use super::inspector::{Inspector, PokemonInstance};
|
||||||
const BAR_HEIGHT: f32 = 12.0;
|
const BAR_HEIGHT: f32 = 12.0;
|
||||||
const SPRITE_SIZE: f32 = 128.0;
|
const SPRITE_SIZE: f32 = 128.0;
|
||||||
const SPRITE_PADDING: f32 = 32.0;
|
const SPRITE_PADDING: f32 = 32.0;
|
||||||
const BASE_STAT_WIDTH_MULT: f32 = 0.8;
|
const BASE_STAT_WIDTH_MULT: f32 = 0.5;
|
||||||
const IV_WIDTH_MULT: f32 = 4.0;
|
const IV_WIDTH_MULT: f32 = 4.0;
|
||||||
// const EV_WIDTH_MULT: f32 = 1.0;
|
const EV_WIDTH_MULT: f32 = 0.25;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref BASE_STAT_COLOR_RANGES: Vec<(u8, egui::Color32)> = vec![
|
static ref BASE_STAT_COLOR_RANGES: Vec<(u8, egui::Color32)> = vec![
|
||||||
|
|
@ -34,12 +34,13 @@ lazy_static! {
|
||||||
static ref COLUMNS: Vec<f32> = vec![
|
static ref COLUMNS: Vec<f32> = vec![
|
||||||
25.0, // Base stat
|
25.0, // Base stat
|
||||||
255.0 * BASE_STAT_WIDTH_MULT, // Base stat bar
|
255.0 * BASE_STAT_WIDTH_MULT, // Base stat bar
|
||||||
|
25.0, // EV value
|
||||||
|
255.0 * EV_WIDTH_MULT, // EV bar
|
||||||
60.0, // Stat name
|
60.0, // Stat name
|
||||||
25.0, // IV value
|
25.0, // IV value
|
||||||
32.0 * IV_WIDTH_MULT, // IV bar
|
32.0 * IV_WIDTH_MULT, // IV bar
|
||||||
// 40.0, // EV value
|
|
||||||
// 255.0 * EV_WIDTH_MULT, // EV bar
|
|
||||||
];
|
];
|
||||||
|
static ref TRACK_COLOR: egui::Color32 = egui::Color32::from_rgb(48, 48, 48);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UiPlugin;
|
pub struct UiPlugin;
|
||||||
|
|
@ -131,7 +132,16 @@ fn render_pokemon_instance(
|
||||||
1 => {
|
1 => {
|
||||||
ui.label(egui::RichText::new("Base stat"));
|
ui.label(egui::RichText::new("Base stat"));
|
||||||
}
|
}
|
||||||
|
2 => {
|
||||||
|
ui.label(egui::RichText::new("EV"));
|
||||||
|
}
|
||||||
3 => {
|
3 => {
|
||||||
|
ui.label(egui::RichText::new(format!(
|
||||||
|
"{} / 510",
|
||||||
|
instance.evs.values().map(|v| *v as i32).sum::<i32>()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
5 => {
|
||||||
ui.label(egui::RichText::new("IV"));
|
ui.label(egui::RichText::new("IV"));
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
@ -184,6 +194,51 @@ fn render_pokemon_instance(
|
||||||
ui.add(image);
|
ui.add(image);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// EV stat
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if let Some(width) = column_size.next() {
|
||||||
|
ui.set_width(*width);
|
||||||
|
}
|
||||||
|
if let Some(ev) = instance.evs.get(&stat) {
|
||||||
|
ui.label(egui::RichText::new(format!("{ev}")));
|
||||||
|
} else {
|
||||||
|
ui.label("-");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// EV stat bar
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if let Some(width) = column_size.next() {
|
||||||
|
ui.set_width(*width);
|
||||||
|
}
|
||||||
|
if let Some(ev) = instance.evs.get(&stat) {
|
||||||
|
let bar_length = *ev as f32 * EV_WIDTH_MULT;
|
||||||
|
let track_length = 255. * EV_WIDTH_MULT - bar_length;
|
||||||
|
let color = egui::Color32::LIGHT_GRAY;
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.spacing_mut().item_spacing = egui::Vec2::ZERO;
|
||||||
|
|
||||||
|
// Bar
|
||||||
|
ui.add(
|
||||||
|
egui::Image::new(
|
||||||
|
ui_assets.bar_handle.1,
|
||||||
|
[bar_length, BAR_HEIGHT],
|
||||||
|
)
|
||||||
|
.tint(color),
|
||||||
|
);
|
||||||
|
// Track
|
||||||
|
ui.add(
|
||||||
|
egui::Image::new(
|
||||||
|
ui_assets.bar_handle.1,
|
||||||
|
[track_length, BAR_HEIGHT],
|
||||||
|
)
|
||||||
|
.tint(TRACK_COLOR.clone()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Stat name
|
// Stat name
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if let Some(width) = column_size.next() {
|
if let Some(width) = column_size.next() {
|
||||||
|
|
@ -234,7 +289,7 @@ fn render_pokemon_instance(
|
||||||
ui_assets.bar_handle.1,
|
ui_assets.bar_handle.1,
|
||||||
[track_length, BAR_HEIGHT],
|
[track_length, BAR_HEIGHT],
|
||||||
)
|
)
|
||||||
.tint(egui::Color32::from_rgb(64, 64, 64)),
|
.tint(TRACK_COLOR.clone()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue