mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
use iter once.chain(once).flatten trick to deduplicate SiteInfo generation
This commit is contained in:
parent
49d7c40bec
commit
4563cb40ce
@ -118,20 +118,16 @@ impl World {
|
|||||||
self.civs()
|
self.civs()
|
||||||
.caves
|
.caves
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_, info)| world_msg::SiteInfo {
|
.map(|(_, info)| {
|
||||||
name: Some(info.name.clone()),
|
// separate the two locations, combine with name
|
||||||
|
std::iter::once((info.name.clone(), info.location.0))
|
||||||
|
.chain(std::iter::once((info.name.clone(), info.location.1)))
|
||||||
|
})
|
||||||
|
.flatten() // unwrap inner iteration
|
||||||
|
.map(|(name, pos)| world_msg::SiteInfo {
|
||||||
|
name: Some(name),
|
||||||
kind: world_msg::SiteKind::Cave,
|
kind: world_msg::SiteKind::Cave,
|
||||||
wpos: info.location.0,
|
wpos: pos,
|
||||||
}),
|
|
||||||
)
|
|
||||||
.chain(
|
|
||||||
self.civs()
|
|
||||||
.caves
|
|
||||||
.iter()
|
|
||||||
.map(|(_, info)| world_msg::SiteInfo {
|
|
||||||
name: Some(info.name.clone()),
|
|
||||||
kind: world_msg::SiteKind::Cave,
|
|
||||||
wpos: info.location.1,
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.collect(),
|
.collect(),
|
||||||
|
Loading…
Reference in New Issue
Block a user