Skip to content

Commit d79e505

Browse files
committed
Consistent naming for methods. Return error instead of panic with expect.
1 parent de04763 commit d79e505

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

crates/xray-db/src/data/particles/particle_effect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::data::particles::particle_effect_editor_data::ParticleEffectEditorDat
77
use crate::data::particles::particle_effect_frame::ParticleEffectFrame;
88
use crate::data::particles::particle_effect_sprite::ParticleEffectSprite;
99
use crate::export::LtxImportExport;
10-
use crate::file_import::{read_ini_optional_field, read_ltx_field};
10+
use crate::file_import::{read_ltx_field, read_ltx_optional_field};
1111
use byteorder::{ByteOrder, WriteBytesExt};
1212
use serde::{Deserialize, Serialize};
1313
use xray_chunk::{
@@ -299,17 +299,17 @@ impl LtxImportExport for ParticleEffect {
299299
flags: read_ltx_field("flags", section)?,
300300
frame: ParticleEffectFrame::import_optional(&Self::get_frame_section(section_name), ltx)?,
301301
sprite: ParticleEffectSprite::import(&Self::get_sprite_section(section_name), ltx)?,
302-
time_limit: read_ini_optional_field("time_limit", section)?,
302+
time_limit: read_ltx_optional_field("time_limit", section)?,
303303
collision: ParticleEffectCollision::import_optional(
304304
&Self::get_collision_section(section_name),
305305
ltx,
306306
)?,
307-
velocity_scale: read_ini_optional_field("velocity_scale", section)?,
307+
velocity_scale: read_ltx_optional_field("velocity_scale", section)?,
308308
description: ParticleDescription::import_optional(
309309
&Self::get_description_section(section_name),
310310
ltx,
311311
)?,
312-
rotation: read_ini_optional_field("rotation", section)?,
312+
rotation: read_ltx_optional_field("rotation", section)?,
313313
editor_data: ParticleEffectEditorData::import_optional(
314314
&Self::get_editor_data_section(section_name),
315315
ltx,

crates/xray-db/src/file_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn read_ltx_field<T: FromStr>(field_name: &str, section: &Section) -> XRayRe
2222
}
2323

2424
/// Read optional value from ltx section and parse it as provided T type.
25-
pub fn read_ini_optional_field<T: FromStr>(
25+
pub fn read_ltx_optional_field<T: FromStr>(
2626
field_name: &str,
2727
section: &Section,
2828
) -> XRayResult<Option<T>> {

crates/xray-db/src/ogf/ogf_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ impl OgfFile {
8080
pub fn read_motion_refs_from_path<T: ByteOrder, P: AsRef<Path>>(
8181
path: &P,
8282
) -> XRayResult<Vec<String>> {
83-
Self::read_motions_refs_from_file::<T>(File::open(path)?)
83+
Self::read_motion_refs_from_file::<T>(File::open(path)?)
8484
}
8585

8686
/// Read only list of motion refs specifically and skip other data parts.
87-
pub fn read_motions_refs_from_file<T: ByteOrder>(file: File) -> XRayResult<Vec<String>> {
87+
pub fn read_motion_refs_from_file<T: ByteOrder>(file: File) -> XRayResult<Vec<String>> {
8888
let mut reader: ChunkReader = ChunkReader::from_file(file)?;
8989
let chunks: Vec<ChunkReader> = reader.read_children();
9090

crates/xray-db/src/spawn/spawn_file.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fs::File;
1111
use std::io::Write;
1212
use std::path::Path;
1313
use xray_chunk::{find_required_chunk_by_id, ChunkReader, ChunkWriter};
14-
use xray_error::XRayResult;
14+
use xray_error::{XRayError, XRayResult};
1515
use xray_utils::{assert_equal, assert_length, open_export_file};
1616

1717
/// Descriptor of generic spawn file used by xray game engine.
@@ -80,8 +80,17 @@ impl SpawnFile {
8080

8181
/// Write spawn file data to the file by provided path.
8282
pub fn write_to_path<T: ByteOrder, P: AsRef<Path>>(&self, path: &P) -> XRayResult {
83-
fs::create_dir_all(path.as_ref().parent().expect("Spawn file parent directory"))?;
84-
self.write_to::<T>(&mut open_export_file(path)?)
83+
let path_ref: &Path = path.as_ref();
84+
85+
if let Some(parent) = path_ref.parent() {
86+
fs::create_dir_all(parent)?;
87+
self.write_to::<T>(&mut open_export_file(path)?)
88+
} else {
89+
Err(XRayError::new_not_found_error(format!(
90+
"Spawn file parent directory was not found for {:?}",
91+
path_ref.to_str()
92+
)))
93+
}
8594
}
8695

8796
/// Write spawn file data to the writer.

0 commit comments

Comments
 (0)