mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'pfau/fix-char-creation' into 'master'
Fixed char select bugs, improved code quality See merge request veloren/veloren!739
This commit is contained in:
commit
2ddb6d362e
@ -65,12 +65,14 @@ impl PlayState for CharSelectionState {
|
||||
return PlayStateResult::Pop;
|
||||
}
|
||||
ui::Event::Play => {
|
||||
let char_data = self
|
||||
.char_selection_ui
|
||||
.get_character_data()
|
||||
.expect("Character data is required to play");
|
||||
self.client.borrow_mut().request_character(
|
||||
self.char_selection_ui.character_name.clone(),
|
||||
comp::Body::Humanoid(self.char_selection_ui.character_body),
|
||||
self.char_selection_ui
|
||||
.character_tool
|
||||
.map(|specifier| specifier.to_owned()),
|
||||
char_data.name,
|
||||
char_data.body,
|
||||
char_data.tool,
|
||||
);
|
||||
return PlayStateResult::Push(Box::new(SessionState::new(
|
||||
global_state,
|
||||
@ -83,23 +85,32 @@ impl PlayState for CharSelectionState {
|
||||
// Maintain global state.
|
||||
global_state.maintain(clock.get_last_delta().as_secs_f32());
|
||||
|
||||
let humanoid_body = self
|
||||
.char_selection_ui
|
||||
.get_character_data()
|
||||
.and_then(|data| match data.body {
|
||||
comp::Body::Humanoid(body) => Some(body),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
// Maintain the scene.
|
||||
self.scene.maintain(
|
||||
global_state.window.renderer_mut(),
|
||||
&self.client.borrow(),
|
||||
self.char_selection_ui.character_body,
|
||||
humanoid_body.clone(),
|
||||
);
|
||||
|
||||
// Render the scene.
|
||||
self.scene.render(
|
||||
global_state.window.renderer_mut(),
|
||||
&self.client.borrow(),
|
||||
self.char_selection_ui.character_body,
|
||||
humanoid_body.clone(),
|
||||
&comp::Equipment {
|
||||
main: self
|
||||
.char_selection_ui
|
||||
.character_tool
|
||||
.and_then(|specifier| assets::load_cloned(&specifier).ok()),
|
||||
.get_character_data()
|
||||
.and_then(|data| data.tool)
|
||||
.and_then(|tool| assets::load_cloned(&tool).ok()),
|
||||
alt: None,
|
||||
},
|
||||
);
|
||||
|
@ -115,7 +115,12 @@ impl Scene {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maintain(&mut self, renderer: &mut Renderer, client: &Client, body: humanoid::Body) {
|
||||
pub fn maintain(
|
||||
&mut self,
|
||||
renderer: &mut Renderer,
|
||||
client: &Client,
|
||||
body: Option<humanoid::Body>,
|
||||
) {
|
||||
self.camera.set_focus_pos(Vec3::unit_z() * 1.5);
|
||||
self.camera.update(client.state().get_time());
|
||||
self.camera.set_distance(3.0); // 4.2
|
||||
@ -147,17 +152,19 @@ impl Scene {
|
||||
|
||||
self.figure_model_cache.clean(client.get_tick());
|
||||
|
||||
let tgt_skeleton = IdleAnimation::update_skeleton(
|
||||
self.figure_state.skeleton_mut(),
|
||||
client.state().get_time(),
|
||||
client.state().get_time(),
|
||||
&mut 0.0,
|
||||
&SkeletonAttr::from(&body),
|
||||
);
|
||||
self.figure_state.skeleton_mut().interpolate(
|
||||
&tgt_skeleton,
|
||||
client.state().ecs().read_resource::<DeltaTime>().0,
|
||||
);
|
||||
if let Some(body) = body {
|
||||
let tgt_skeleton = IdleAnimation::update_skeleton(
|
||||
self.figure_state.skeleton_mut(),
|
||||
client.state().get_time(),
|
||||
client.state().get_time(),
|
||||
&mut 0.0,
|
||||
&SkeletonAttr::from(&body),
|
||||
);
|
||||
self.figure_state.skeleton_mut().interpolate(
|
||||
&tgt_skeleton,
|
||||
client.state().ecs().read_resource::<DeltaTime>().0,
|
||||
);
|
||||
}
|
||||
|
||||
self.figure_state.update(
|
||||
renderer,
|
||||
@ -178,31 +185,33 @@ impl Scene {
|
||||
&mut self,
|
||||
renderer: &mut Renderer,
|
||||
client: &Client,
|
||||
body: humanoid::Body,
|
||||
body: Option<humanoid::Body>,
|
||||
equipment: &Equipment,
|
||||
) {
|
||||
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
|
||||
|
||||
let model = &self
|
||||
.figure_model_cache
|
||||
.get_or_create_model(
|
||||
renderer,
|
||||
Body::Humanoid(body),
|
||||
Some(equipment),
|
||||
client.get_tick(),
|
||||
CameraMode::default(),
|
||||
None,
|
||||
)
|
||||
.0;
|
||||
if let Some(body) = body {
|
||||
let model = &self
|
||||
.figure_model_cache
|
||||
.get_or_create_model(
|
||||
renderer,
|
||||
Body::Humanoid(body),
|
||||
Some(equipment),
|
||||
client.get_tick(),
|
||||
CameraMode::default(),
|
||||
None,
|
||||
)
|
||||
.0;
|
||||
|
||||
renderer.render_figure(
|
||||
model,
|
||||
&self.globals,
|
||||
self.figure_state.locals(),
|
||||
self.figure_state.bone_consts(),
|
||||
&self.lights,
|
||||
&self.shadows,
|
||||
);
|
||||
renderer.render_figure(
|
||||
model,
|
||||
&self.globals,
|
||||
self.figure_state.locals(),
|
||||
self.figure_state.bone_consts(),
|
||||
&self.lights,
|
||||
&self.shadows,
|
||||
);
|
||||
}
|
||||
|
||||
renderer.render_figure(
|
||||
&self.backdrop_model,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,7 @@ use std::{fs, io, path::PathBuf};
|
||||
pub struct CharacterData {
|
||||
pub name: String,
|
||||
pub body: comp::Body,
|
||||
pub tool: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user