1#[derive(Debug)]
2pub enum Error {
3 DeJsonErr {
4 msg: String,
5 line: usize,
6 col: usize,
7 },
8 NonUniqueLayerName {
9 layer: String,
10 },
11 TextureNotFound {
12 texture: String,
13 },
14 LayerTypeNotFound {
15 layer_type: String,
16 },
17}
18
19impl From<nanoserde::DeJsonErr> for Error {
20 fn from(error: nanoserde::DeJsonErr) -> Error {
21 Error::DeJsonErr {
22 msg: error.msg.clone(),
23 line: error.line,
24 col: error.col,
25 }
26 }
27}
28
29impl std::fmt::Display for Error {
30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 match self {
32 Error::DeJsonErr { .. } | Error::TextureNotFound {..} => std::fmt::Debug::fmt(self, f),
33 Error::NonUniqueLayerName { layer } => write!(
34 f,
35 "Layer name should be unique to load tiled level in macroquad, non-unique layer name: {}", layer
36 ),
37 Error::LayerTypeNotFound{layer_type} => write!(
38 f,
39 "{} type layer not found.", layer_type
40 ),
41
42 }
43 }
44}
45
46impl std::error::Error for Error {}