Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
francisdb committed Jun 19, 2024
1 parent 38fdc91 commit 048ac0a
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 108 deletions.
72 changes: 48 additions & 24 deletions examples/create_basic_vpx_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use vpin::vpx;
use vpin::vpx::color::Color;
use vpin::vpx::gameitem::bumper::Bumper;
use vpin::vpx::gameitem::flipper::Flipper;
use vpin::vpx::gameitem::plunger::Plunger;
use vpin::vpx::gameitem::vertex2d::Vertex2D;
use vpin::vpx::gameitem::GameItemEnum;
use vpin::vpx::material::Material;
use vpin::vpx::VPX;
Expand All @@ -11,45 +13,67 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut vpx = VPX::default();

// playfield material
let mut material = Material::default();
material.name = "Playfield".to_string();
// material defaults to purple
material.base_color = Color::from_rgb(0x966F33); // Wood
let material = Material {
name: "Playfield".to_string(),
// material defaults to purple
base_color: Color::from_rgb(0x966F33), // Wood
..Default::default()
};
vpx.gamedata.materials = Some(vec![material]);

// black background (default is bluish gray)
vpx.gamedata.backdrop_color = Color::from_rgb(0x060606); // Dark Gray
vpx.gamedata.playfield_material = "Playfield".to_string();

// add a plunger
let mut plunger = vpx::gameitem::plunger::Plunger::default();
plunger.name = "Plunger".to_string();
plunger.center.x = 898.027;
plunger.center.y = 2105.312;
let plunger = Plunger {
name: "Plunger".to_string(),
center: Vertex2D {
x: 898.027,
y: 2105.312,
},
..Default::default()
};

vpx.add_game_item(GameItemEnum::Plunger(plunger));

// add a bumper in the center of the playfield
let mut bumper = Bumper::default();
bumper.name = "Bumper1".to_string();
bumper.center.x = (vpx.gamedata.left + vpx.gamedata.right) / 2.;
bumper.center.y = (vpx.gamedata.top + vpx.gamedata.bottom) / 2.;
let bumper = Bumper {
name: "Bumper1".to_string(),
center: Vertex2D {
x: (vpx.gamedata.left + vpx.gamedata.right) / 2.,
y: (vpx.gamedata.top + vpx.gamedata.bottom) / 2.,
},
..Default::default()
};

vpx.add_game_item(GameItemEnum::Bumper(bumper));

// add 2 flippers
let mut flipper_left = Flipper::default();
flipper_left.name = "LeftFlipper".to_string();
flipper_left.center.x = 278.2138;
flipper_left.center.y = 1803.271;
flipper_left.start_angle = 120.5;
flipper_left.end_angle = 70.;
let flipper_left = Flipper {
name: "LeftFlipper".to_string(),
center: Vertex2D {
x: 278.2138,
y: 1803.271,
},
start_angle: 120.5,
end_angle: 70.,
..Default::default()
};

vpx.add_game_item(GameItemEnum::Flipper(flipper_left));

let mut flipper_right = Flipper::default();
flipper_right.name = "RightFlipper".to_string();
flipper_right.center.x = 595.869;
flipper_right.center.y = 1803.271;
flipper_right.start_angle = -120.5;
flipper_right.end_angle = -70.;
let flipper_right = Flipper {
name: "RightFlipper".to_string(),
center: Vertex2D {
x: 595.869,
y: 1803.271,
},
start_angle: -120.5,
end_angle: -70.,
..Default::default()
};

vpx.add_game_item(GameItemEnum::Flipper(flipper_right));

// add a script
Expand Down
9 changes: 4 additions & 5 deletions src/vpx/expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn write<P: AsRef<Path>>(vpx: &VPX, expanded_dir: &P) -> Result<(), WriteErr
Ok(())
}

fn materials_index(materials: &Vec<Material>) -> HashMap<String, Material> {
fn materials_index(materials: &[Material]) -> HashMap<String, Material> {
let mut index = HashMap::new();
materials.iter().for_each(|m| {
index.insert(m.name.clone(), (*m).clone());
Expand Down Expand Up @@ -924,7 +924,7 @@ fn write_gameitems<P: AsRef<Path>>(
)?;
}
let full_table_gltf_path = expanded_dir.as_ref().join("table.gltf");
write_whole_table_gltf(&vpx, &full_table_gltf_path)
write_whole_table_gltf(vpx, &full_table_gltf_path)
.map_err(|e| WriteError::Io(io::Error::new(io::ErrorKind::Other, format!("{}", e))))?;
// write the gameitems index as array with names being the type and the name
let gameitems_index_path = expanded_dir.as_ref().join("gameitems.json");
Expand Down Expand Up @@ -982,7 +982,7 @@ fn write_gameitem_binaries(
})?;
let gltf_path = gameitems_dir.join(format!("{}.gltf", json_file_name));
let image_rel_path = if !&primitive.image.is_empty() {
let primitive_image = UniCase::new(primitive.image.clone().into());
let primitive_image = UniCase::new(primitive.image.clone());
if let Some(p) = image_index.get(&primitive_image) {
let file_name = p.file_name().unwrap().to_string_lossy().to_string();
Some(
Expand All @@ -1005,7 +1005,7 @@ fn write_gameitem_binaries(
};
let material = if !primitive.material.is_empty() {
if let Some(m) = material_index.get(&primitive.material) {
Some(m.name.clone())
Some(m)
} else {
eprintln!(
"Material not found for primitive {}: {}",
Expand All @@ -1016,7 +1016,6 @@ fn write_gameitem_binaries(
} else {
None
};
let material = material_index.get(&primitive.material);
write_gltf(
gameitem.name().to_string(),
&mesh,
Expand Down
8 changes: 4 additions & 4 deletions src/vpx/gameitem/bumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ pub struct Bumper {
pub timer_interval: i32,
pub threshold: f32,
pub force: f32,
/// BSCT (added in ?)
pub scatter: Option<f32>,
// BSCT (added in ?)
pub height_scale: f32,
pub ring_speed: f32,
pub orientation: f32,
/// RDLI (added in ?)
pub ring_drop_offset: Option<f32>,
// RDLI (added in ?)
pub cap_material: String,
pub base_material: String,
pub socket_material: String,
/// RIMA (added in ?)
pub ring_material: Option<String>,
// RIMA (added in ?)
surface: String,
pub surface: String,
pub name: String,
pub is_cap_visible: bool,
pub is_base_visible: bool,
Expand Down
62 changes: 31 additions & 31 deletions src/vpx/gameitem/flipper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,43 @@ use super::{vertex2d::Vertex2D, GameItem};
#[derive(Debug, PartialEq, Clone, Dummy)]
pub struct Flipper {
pub center: Vertex2D,
base_radius: f32,
end_radius: f32,
flipper_radius_max: f32,
return_: f32,
pub base_radius: f32,
pub end_radius: f32,
pub flipper_radius_max: f32,
pub return_: f32,
pub start_angle: f32,
pub end_angle: f32,
override_physics: u32,
mass: f32,
is_timer_enabled: bool,
timer_interval: i32,
surface: String,
material: String,
pub override_physics: u32,
pub mass: f32,
pub is_timer_enabled: bool,
pub timer_interval: i32,
pub surface: String,
pub material: String,
pub name: String,
rubber_material: String,
rubber_thickness_int: u32, // RTHK deprecated
rubber_thickness: Option<f32>, // RTHF (added in 10.?)
rubber_height_int: u32, // RHGT deprecated
rubber_height: Option<f32>, // RHGF (added in 10.?)
rubber_width_int: u32, // RWDT deprecated
rubber_width: Option<f32>, // RHGF (added in 10.?)
strength: f32,
elasticity: f32,
elasticity_falloff: f32,
friction: f32,
ramp_up: f32,
scatter: Option<f32>,
pub rubber_material: String,
pub rubber_thickness_int: u32, // RTHK deprecated
pub rubber_thickness: Option<f32>, // RTHF (added in 10.?)
pub rubber_height_int: u32, // RHGT deprecated
pub rubber_height: Option<f32>, // RHGF (added in 10.?)
pub rubber_width_int: u32, // RWDT deprecated
pub rubber_width: Option<f32>, // RHGF (added in 10.?)
pub strength: f32,
pub elasticity: f32,
pub elasticity_falloff: f32,
pub friction: f32,
pub ramp_up: f32,
pub scatter: Option<f32>,
// SCTR (added in 10.?)
torque_damping: Option<f32>,
pub torque_damping: Option<f32>,
// TODA (added in 10.?)
torque_damping_angle: Option<f32>,
pub torque_damping_angle: Option<f32>,
// TDAA (added in 10.?)
flipper_radius_min: f32,
is_visible: bool,
is_enabled: bool,
height: f32,
image: Option<String>, // IMAG (was missing in 10.01)
is_reflection_enabled: Option<bool>, // REEN (was missing in 10.01)
pub flipper_radius_min: f32,
pub is_visible: bool,
pub is_enabled: bool,
pub height: f32,
pub image: Option<String>, // IMAG (was missing in 10.01)
pub is_reflection_enabled: Option<bool>, // REEN (was missing in 10.01)

// these are shared between all items
pub is_locked: bool,
Expand Down
60 changes: 30 additions & 30 deletions src/vpx/gameitem/plunger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,37 +109,37 @@ impl<'de> Deserialize<'de> for PlungerType {
#[derive(Debug, PartialEq, Dummy)]
pub struct Plunger {
pub center: Vertex2D,
width: f32,
height: f32,
z_adjust: f32,
stroke: f32,
speed_pull: f32,
speed_fire: f32,
plunger_type: PlungerType,
anim_frames: u32,
material: String,
image: String,
mech_strength: f32,
is_mech_plunger: bool,
auto_plunger: bool,
park_position: f32,
scatter_velocity: f32,
momentum_xfer: f32,
is_timer_enabled: bool,
timer_interval: i32,
is_visible: bool,
is_reflection_enabled: Option<bool>, // REEN (was missing in 10.01)
surface: String,
pub width: f32,
pub height: f32,
pub z_adjust: f32,
pub stroke: f32,
pub speed_pull: f32,
pub speed_fire: f32,
pub plunger_type: PlungerType,
pub anim_frames: u32,
pub material: String,
pub image: String,
pub mech_strength: f32,
pub is_mech_plunger: bool,
pub auto_plunger: bool,
pub park_position: f32,
pub scatter_velocity: f32,
pub momentum_xfer: f32,
pub is_timer_enabled: bool,
pub timer_interval: i32,
pub is_visible: bool,
pub is_reflection_enabled: Option<bool>, // REEN (was missing in 10.01)
pub surface: String,
pub name: String,
tip_shape: String,
rod_diam: f32,
ring_gap: f32,
ring_diam: f32,
ring_width: f32,
spring_diam: f32,
spring_gauge: f32,
spring_loops: f32,
spring_end_loops: f32,
pub tip_shape: String,
pub rod_diam: f32,
pub ring_gap: f32,
pub ring_diam: f32,
pub ring_width: f32,
pub spring_diam: f32,
pub spring_gauge: f32,
pub spring_loops: f32,
pub spring_end_loops: f32,

// these are shared between all items
pub is_locked: bool,
Expand Down
Loading

0 comments on commit 048ac0a

Please sign in to comment.