use crate::{assets::LevelIndices, ldtk::Level, LevelIid};
use bevy::prelude::*;
#[derive(Clone, Eq, PartialEq, Debug, Resource)]
pub enum LevelSelection {
Identifier(String),
Indices(LevelIndices),
Iid(LevelIid),
Uid(i32),
}
impl Default for LevelSelection {
fn default() -> Self {
LevelSelection::index(0)
}
}
impl LevelSelection {
pub fn iid(iid: impl Into<String>) -> Self {
LevelSelection::Iid(LevelIid::new(iid))
}
pub fn index(level_index: usize) -> Self {
LevelSelection::Indices(LevelIndices::in_root(level_index))
}
pub fn indices(world_index: usize, level_index: usize) -> Self {
LevelSelection::Indices(LevelIndices::in_world(world_index, level_index))
}
pub fn is_match(&self, indices: &LevelIndices, level: &Level) -> bool {
match self {
LevelSelection::Identifier(s) => *s == level.identifier,
LevelSelection::Indices(i) => *i == *indices,
LevelSelection::Iid(i) => *i.get() == level.iid,
LevelSelection::Uid(u) => *u == level.uid,
}
}
}