Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/cjunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,17 @@ pub fn bake(roots: &crate::install::Roots, layout: &Layout, assets: &mut Assets,
std::fs::create_dir_all(dir.join("texture"))?;
// the plate between the arms: the roadway, kerbs and footways, with its lanes
let mut plate_paths = String::new();
let mut plate_bus_paths = Vec::new();
let mut plate_path_count = 0;
let asphalt = crate::junction::asphalt_texture(&roots.omsi);
for arms in &resolved.plates {
for a in arms {
anyhow::ensure!(assets.spline_wait(&a.file, 5000).is_some(), "{}: {}", tr("the spline cannot be read", "сплайн не читается"), a.file);
}
let plate = crate::junction::layout_plate(assets, arms, asphalt.as_deref()).ok_or_else(|| anyhow::anyhow!("{}", tr("the plate could not be made from these arms", "плиту не удалось построить из этих въездов")))?;
joined.append(&plate.model_mesh(&mut src.model.materials, &mut textures), 0);
plate_bus_paths.extend(plate.bus_paths.iter().map(|i| i + plate_path_count));
plate_path_count += plate.lanes.len();
plate_paths.push_str(&plate.paths);
}
for piece in resolved.pieces.iter().filter(|p| !p.hidden) {
Expand All @@ -377,6 +381,9 @@ pub fn bake(roots: &crate::install::Roots, layout: &Layout, assets: &mut Assets,
let mut cut = layout.clone();
cut.pieces = resolved.pieces.clone();
src.extra = extra_lines(&cut, &|f| models.get(&f.to_lowercase()).cloned());
let preceding_paths = src.extra.lines().filter(|line| line.trim() == "[path]").count();
let indices: Vec<_> = plate_bus_paths.into_iter().map(|i| i + preceding_paths).collect();
src.extra.push_str(&crate::junction::bus_path_metadata(&indices));
src.extra.push_str(&plate_paths);
for (name, path) in &textures {
let _ = name;
Expand Down
10 changes: 6 additions & 4 deletions src/ed_cjunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ impl Editor {
let folder = crate::junction::folder_name(doc);
let asphalt = crate::junction::junction_asphalt(Some(&doc.dir), asphalt.as_deref());
for arms in &resolved.plates {
let plate = crate::junction::layout_plate(assets, arms, asphalt.as_deref());
let Some(rel) = plate.and_then(|p| p.write_object(&content, &folder).ok()) else { continue };
let Some(plate) = crate::junction::layout_plate(assets, arms, asphalt.as_deref()) else { continue };
let rules = crate::junction::bus_path_rules(&plate.bus_paths);
let Ok(rel) = plate.write_object(&content, &folder) else { continue };
let k = tile_of(origin);
if doc.tiles.contains_key(&k) {
let id = doc.new_id();
let org = tile_origin(k);
let Some(t) = doc.tiles.get_mut(&k) else { return };
t.tile.objects.push(MapObject { file: rel, id, pos: [origin.x - org.x, origin.y - org.y, z], rot: [rot, 0.0, 0.0], ..Default::default() });
t.tile.objects.push(MapObject { file: rel, id, pos: [origin.x - org.x, origin.y - org.y, z], rot: [rot, 0.0, 0.0], rules, ..Default::default() });
t.touch_content();
things.push((k, id));
}
Expand Down Expand Up @@ -119,6 +120,7 @@ pub(crate) fn apply_custom(doc: &mut Document, assets: &mut Assets, layouts: &[L
let listed: Vec<(f64, String)> = roads_at.iter().map(|r| (r.1, r.2.clone())).collect();
let (layout, rot, by_arm) = candidates.iter().filter_map(|l| cjunction::fit(l, &listed, &same).map(|(rot, by, err)| (err, *l, rot, by))).min_by(|a, b| a.0.total_cmp(&b.0)).map(|(_, l, rot, by)| (l, rot, by))?;
let baked = layout.baked.clone()?;
let rules = crate::junction::read_bus_path_rules(&assets.resolve(&baked));
let z = centre.z;
// everything is checked before anything is cut: the roads must be long enough and their
// tiles there
Expand Down Expand Up @@ -157,7 +159,7 @@ pub(crate) fn apply_custom(doc: &mut Document, assets: &mut Assets, layouts: &[L
let org = tile_origin(k);
let id = doc.new_id();
let t = doc.tiles.get_mut(&k)?;
t.tile.objects.push(MapObject { file: baked, id, pos: [centre.x - org.x, centre.y - org.y, z], rot: [rot, 0.0, 0.0], ..Default::default() });
t.tile.objects.push(MapObject { file: baked, id, pos: [centre.x - org.x, centre.y - org.y, z], rot: [rot, 0.0, 0.0], rules, ..Default::default() });
t.touch_content();
cjunction::place_objects(doc, layout, centre.truncate(), z, rot);
if follow {
Expand Down
3 changes: 3 additions & 0 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16088,6 +16088,9 @@ mod tests {
let _ = std::fs::remove_dir_all(&content);
}

include!("junction_snapshot_tests.rs");
include!("junction_placement_tests.rs");

/// Two road types made here, the second with a pocket lane, in a scratch content folder.
fn pocket_fixture(tag: &str) -> (Assets, std::path::PathBuf, String, String) {
let dir = std::env::temp_dir().join(format!("om-pocket-{tag}-{}", std::process::id()));
Expand Down
Loading
Loading