Attempt to take the current collider and write it to collider_filepath. If there isn't a collider, or writing fails, then `false` is returned. Otherwise `true` is returned.
(&self)
| 102 | /// Attempt to take the current collider and write it to collider_filepath. If there isn't a |
| 103 | /// collider, or writing fails, then `false` is returned. Otherwise `true` is returned. |
| 104 | pub fn write_collider(&self) -> bool { |
| 105 | if self.collider == Collider::NoCollider { |
| 106 | return false; |
| 107 | } |
| 108 | // Bevy's asset system is relative from the assets/ subdirectory, so we must be too |
| 109 | let filepath = PathBuf::from("assets").join(self.collider_filepath.clone()); |
| 110 | let mut fh = match File::create(filepath) { |
| 111 | Ok(fh) => fh, |
| 112 | Err(e) => { |
| 113 | eprintln!("failed creating collider file: {}", e); |
| 114 | return false; |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | let collider_ron = match ron::ser::to_string_pretty(&self.collider, Default::default()) { |
| 119 | Ok(r) => r, |
| 120 | Err(e) => { |
| 121 | eprintln!("failed converting collider to ron: {}", e); |
| 122 | return false; |
| 123 | } |
| 124 | }; |
| 125 | match fh.write_all(collider_ron.as_bytes()) { |
| 126 | Ok(_) => true, |
| 127 | Err(e) => { |
| 128 | eprintln!("failed writing collider file: {}", e); |
| 129 | false |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | /// Add a collider point. `p` is a `Vec2` in worldspace (usually the mouse coordinate). See the |
| 134 | /// `collider` example. |
| 135 | pub fn add_collider_point(&mut self, mut p: Vec2) { |