diff --git a/CHANGELOG.md b/CHANGELOG.md index f80d0b98cf..8a7fd22d5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/server/src/lib.rs b/server/src/lib.rs index fe7b14c373..491d70ed17 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -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_::()) + }); + 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, 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_::(), - ) - }); - 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),