1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
use super::tunnel::*; use babalcore::*; use gdnative::prelude::*; pub struct TunnelWrapper<'a> { obj: RefInstance<'a, Tunnel, Shared>, } impl TunnelWrapper<'_> { pub fn new<'a>(instance: RefInstance<'a, Tunnel, Shared>) -> TunnelWrapper<'a> { TunnelWrapper::<'a> { obj: instance } } pub fn from_variant<'a>(variant: &'a Variant) -> Result<TunnelWrapper<'a>, FromVariantError> { match variant.try_to_object_with_error::<Spatial>() { Ok(obj) => { let obj = unsafe { obj.assume_safe() }; if let Some(tun) = obj.cast_instance::<Tunnel>() { Ok(Self::new(tun)) } else { Err(FromVariantError::CannotCast { class: format_type_of(&obj), to: "Tunnel", }) } } Err(e) => Err(e), } } } impl LevelQuery for TunnelWrapper<'_> { fn width(&self) -> usize { match self.obj.map(|x, o| x.width(&o)) { Ok(v) => v, Err(e) => { godot_print!("unable to get tunnel width: {}", e); 0 } } } fn len(&self) -> usize { match self.obj.map(|x, o| x.len(&o)) { Ok(v) => v, Err(e) => { godot_print!("unable to get tunnel len: {}", e); 0 } } } fn first(&self) -> isize { match self.obj.map(|x, o| x.first(&o)) { Ok(v) => v, Err(e) => { godot_print!("unable to get tunnel first row: {}", e); 0 } } } fn last(&self) -> isize { match self.obj.map(|x, o| x.last(&o)) { Ok(v) => v, Err(e) => { godot_print!("unable to get tunnel last row: {}", e); 0 } } } fn item(&self, col: isize, row: isize) -> i64 { match self.obj.map(|x, o| x.item(&o, col, row)) { Ok(v) => v, Err(e) => { godot_print!("unable to get tunnel item: {}", e); 0 } } } fn find_start_spot(&self, col: isize, row: isize) -> Option<(isize, isize)> { match self.obj.map(|x, o| x.find_start_spot(&o, col, row)) { Ok(v) => v, Err(e) => { godot_print!("unable find tunnel start spot: {}", e); None } } } }