Merge branch 'fix-invalid-player-position-for-debug-info' into 'master'

Fix debug coordinates window crashing when player has no Pos component yet

Closes #136

See merge request veloren/veloren!196

Former-commit-id: d57c2307307290a15f290bc1f8affe6415ea6d36
This commit is contained in:
Joshua Barretto 2019-05-28 19:49:02 +00:00
commit cb6b60fefe
2 changed files with 8 additions and 4 deletions

View File

@ -32,6 +32,7 @@ use crate::{
};
use client::Client;
use common::comp;
use common::comp::phys::Pos;
use conrod_core::{
color, graph,
widget::{self, Button, Image, Rectangle, Text},
@ -104,7 +105,7 @@ font_ids! {
pub struct DebugInfo {
pub tps: f64,
pub ping_ms: f64,
pub coordinates: Vec3<f32>,
pub coordinates: Option<Pos>,
}
pub enum Event {
@ -393,7 +394,11 @@ impl Hud {
.font_id(self.fonts.opensans)
.font_size(14)
.set(self.ids.ping, ui_widgets);
Text::new(&format!("Coordinates: {:.1}", debug_info.coordinates))
let coordinates_text = match debug_info.coordinates {
Some(coordinates) => format!("Coordinates: {:.1}", coordinates.0),
None => "Player has no Pos component".to_owned(),
};
Text::new(&coordinates_text)
.color(TEXT_COLOR)
.down_from(self.ids.ping, 5.0)
.font_id(self.fonts.opensans)

View File

@ -170,8 +170,7 @@ impl PlayState for SessionState {
.ecs()
.read_storage::<Pos>()
.get(self.client.borrow().entity())
.unwrap()
.0,
.cloned(),
},
&self.scene.camera(),
);