correct location names after editing and creation

This commit is contained in:
Christof Petig 2023-09-12 22:32:11 +02:00
parent 28dc1dc7b0
commit b6e421facc
2 changed files with 25 additions and 20 deletions

View File

@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dungeons now have an outer wall, preventing them from intersecting with caves or leaving holes in sides of mountains.
- Location names are displayed in character selection dialog
- You can no longer write messages to old groups after being kicked and not having updated your chat mode.
- Location names are now also correct after editing and creating characters
## [0.15.0] - 2023-07-01

View File

@ -72,7 +72,7 @@ use common::grid::Grid;
use common::{
assets::AssetExt,
calendar::Calendar,
character::CharacterId,
character::{CharacterId, CharacterItem},
cmd::ServerChatCommand,
comp,
event::{EventBus, ServerEvent},
@ -652,6 +652,24 @@ impl Server {
/// Get a reference to the server's world.
pub fn world(&self) -> &World { &self.world }
fn parse_locations(&self, character_list_data: &mut [CharacterItem]) {
character_list_data.iter_mut().for_each(|c| {
let name = c
.location
.as_ref()
.and_then(|s| {
persistence::parse_waypoint(s)
.ok()
.and_then(|(waypoint, _)| waypoint.map(|w| w.get_pos()))
})
.and_then(|wpos| {
self.world
.get_location_name(self.index.as_index_ref(), wpos.xy().as_::<i32>())
});
c.location = name;
});
}
/// Execute a single server tick, handle input and update the game state by
/// the given duration.
pub fn tick(&mut self, _input: Input, dt: Duration) -> Result<Vec<Event>, Error> {
@ -903,23 +921,7 @@ impl Server {
match response.response_kind {
CharacterScreenResponseKind::CharacterList(result) => match result {
Ok(mut character_list_data) => {
character_list_data.iter_mut().for_each(|c| {
let name = c
.location
.as_ref()
.and_then(|s| {
persistence::parse_waypoint(s).ok().and_then(
|(waypoint, _)| waypoint.map(|w| w.get_pos()),
)
})
.and_then(|wpos| {
self.world.get_location_name(
self.index.as_index_ref(),
wpos.xy().as_::<i32>(),
)
});
c.location = name;
});
self.parse_locations(&mut character_list_data);
self.notify_client(
response.target_entity,
ServerGeneral::CharacterListUpdate(character_list_data),
@ -931,7 +933,8 @@ impl Server {
),
},
CharacterScreenResponseKind::CharacterCreation(result) => match result {
Ok((character_id, list)) => {
Ok((character_id, mut list)) => {
self.parse_locations(&mut list);
self.notify_client(
response.target_entity,
ServerGeneral::CharacterListUpdate(list),
@ -947,7 +950,8 @@ impl Server {
),
},
CharacterScreenResponseKind::CharacterEdit(result) => match result {
Ok((character_id, list)) => {
Ok((character_id, mut list)) => {
self.parse_locations(&mut list);
self.notify_client(
response.target_entity,
ServerGeneral::CharacterListUpdate(list),