From ee97680c12bdf7ed90eff16fc49d7c41943562e6 Mon Sep 17 00:00:00 2001 From: Louis Capitanchik <contact@louiscap.co> Date: Thu, 8 Dec 2022 18:13:47 +0000 Subject: [PATCH] Support one-way routes --- game_core/src/world/towns.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/game_core/src/world/towns.rs b/game_core/src/world/towns.rs index a2a0cb8..a538869 100644 --- a/game_core/src/world/towns.rs +++ b/game_core/src/world/towns.rs @@ -194,6 +194,7 @@ impl From<Vec<&EntityInstance>> for TownPaths { let mut from_place = None; let mut to_place = None; let mut nodes: Vec<RouteNode> = Vec::new(); + let mut is_one_way = false; for field in &entity.field_instances { match &*field.identifier { @@ -213,6 +214,11 @@ impl From<Vec<&EntityInstance>> for TownPaths { }; } } + "one_way" => { + if let Some(Value::Bool(val)) = &field.value { + is_one_way = *val; + } + } _ => {} } } @@ -229,16 +235,19 @@ impl From<Vec<&EntityInstance>> for TownPaths { }, ); - let mut route_entry = routes.entry(to.clone()).or_insert_with(|| Destinations { - source: to.clone(), - routes: Default::default(), - }); - route_entry.routes.insert( - from.clone(), - Route { - nodes: nodes.iter().rev().cloned().collect(), - }, - ); + if !is_one_way { + let mut route_entry = + routes.entry(to.clone()).or_insert_with(|| Destinations { + source: to.clone(), + routes: Default::default(), + }); + route_entry.routes.insert( + from.clone(), + Route { + nodes: nodes.iter().rev().cloned().collect(), + }, + ); + } } } -- GitLab