MCPcopy Create free account
hub / github.com/CleanCut/rusty_engine / write_collider

Method write_collider

src/sprite.rs:104–132  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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) {

Callers 1

game_logicFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected