Skip to content

Commit

Permalink
derive Inspect on simple enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Jan 15, 2024
1 parent 772c2d3 commit 3e382f4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 38 deletions.
51 changes: 24 additions & 27 deletions prototypes/src/prototypes/company.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
use crate::prototypes::PrototypeBase;
use crate::{get_with_err, GoodsCompanyID, Prototype, Recipe, Zone};
use egui_inspect::debug_inspect_impl;
use egui_inspect::{debug_inspect_impl, Inspect};
use geom::Vec2;
use mlua::{FromLua, Lua, Table, Value};
use serde::{Deserialize, Serialize};
use std::ops::Deref;

#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub enum BuildingGen {
House,
Farm,
CenteredDoor {
vertical_factor: f32, // 1.0 means that the door is at the bottom, just on the street
},
NoWalkway {
door_pos: Vec2, // door_pos is relative to the center of the building
},
}
debug_inspect_impl!(BuildingGen);

#[derive(Copy, Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Inspect)]
pub enum CompanyKind {
/// Buyers come to get their goods
Store,
/// Buyers get their goods delivered to them
Factory,
/// Buyers get their goods instantly delivered, useful for things like electricity/water/..
Network,
}

#[derive(Debug)]
pub struct GoodsCompanyPrototype {
pub base: PrototypeBase,
Expand Down Expand Up @@ -56,16 +79,6 @@ impl Deref for GoodsCompanyPrototype {
}
}

#[derive(Copy, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum CompanyKind {
// Buyers come to get their goods
Store,
// Buyers get their goods delivered to them
Factory,
// Buyers get their goods instantly delivered, useful for things like electricity/water/..
Network,
}

impl<'a> FromLua<'a> for CompanyKind {
fn from_lua(value: Value<'a>, lua: &'a Lua) -> mlua::Result<Self> {
let s: String = FromLua::from_lua(value, lua)?;
Expand All @@ -81,22 +94,6 @@ impl<'a> FromLua<'a> for CompanyKind {
}
}

debug_inspect_impl!(CompanyKind);

#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub enum BuildingGen {
House,
Farm,
CenteredDoor {
vertical_factor: f32, // 1.0 means that the door is at the bottom, just on the street
},
NoWalkway {
door_pos: Vec2, // door_pos is relative to the center of the building
},
}

debug_inspect_impl!(BuildingGen);

impl<'a> FromLua<'a> for BuildingGen {
fn from_lua(value: Value<'a>, _: &'a Lua) -> mlua::Result<Self> {
let table = match value {
Expand Down
4 changes: 1 addition & 3 deletions simulation/src/souls/human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ pub enum HumanDecisionKind {
MultiStack(Vec<HumanDecisionKind>),
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Inspect)]
pub enum Gender {
M,
F,
}

debug_inspect_impl!(Gender);

#[derive(Inspect, Serialize, Deserialize)]
pub struct PersonalInfo {
pub name: String,
Expand Down
3 changes: 1 addition & 2 deletions simulation/src/transportation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ impl Debug for Speed {
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Inspect)]
pub enum TransportationGroup {
Unknown,
Vehicles,
Pedestrians,
}
debug_inspect_impl!(TransportationGroup);

#[derive(Copy, Clone, Serialize, Deserialize, Inspect)]
pub struct TransportState {
Expand Down
4 changes: 1 addition & 3 deletions simulation/src/transportation/train.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ pub struct LocomotiveReservation {
upcoming_inters: Vec<IntersectionID>,
}

#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Inspect)]
pub enum RailWagonKind {
Locomotive,
Passenger,
Freight,
}

debug_inspect_impl!(RailWagonKind);

#[derive(Inspect, Serialize, Deserialize)]
pub struct RailWagon {
pub kind: RailWagonKind,
Expand Down
4 changes: 1 addition & 3 deletions simulation/src/transportation/vehicle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum VehicleState {

debug_inspect_impl!(VehicleState);

#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Inspect)]
pub enum VehicleKind {
Car,
Truck,
Expand Down Expand Up @@ -222,5 +222,3 @@ impl Vehicle {
}
}
}

debug_inspect_impl!(VehicleKind);

0 comments on commit 3e382f4

Please sign in to comment.