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
93
94
95
96
97
98
99
100
101
102
103
use std::fmt::{self, Display, Debug};
use std::path::PathBuf;
use std::u128;
use rinecs::{Changes, Component};
use serde_derive::{Deserialize, Serialize};
#[derive(Clone,Debug,Component,Eq,PartialEq, Serialize, Deserialize)]
#[storage(VecStorage)]
pub struct Name(pub String);
impl Display for Name{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result{
Display::fmt(&self.0, fmt)
}
}
#[derive(Clone,Debug,Component,Serialize,Deserialize)]
#[autochanges]
pub struct Visible{
visible: bool,
tags: u128,
has_changed: bool
}
impl PartialEq for Visible {
fn eq(&self, other: &Visible) -> bool{
self.visible == other.visible && self.tags == other.tags
}
}
impl Eq for Visible {}
impl Visible{
pub fn new(visible: bool) -> Visible{
Visible{
visible,
tags: u128::MAX,
has_changed: true,
}
}
pub fn is_visible(&self) -> bool{
self.visible && self.tags == u128::MAX
}
pub fn show(&mut self){
self.has_changed = self.visible != true;
self.visible = true;
}
pub fn hide(&mut self){
self.has_changed = self.visible != false;
self.visible = false;
}
pub fn set(&mut self, visible: bool){
self.has_changed |= self.visible != visible;
self.visible = visible;
}
pub fn set_tag<K>(&mut self, tag: K, visible: bool)
where K: Into<u8>
{
let prev_tags = self.tags;
if visible {
self.tags |= 1 << tag.into() as u128;
}else{
self.tags &= !(1 << tag.into() as u128);
}
self.has_changed |= self.tags != prev_tags;
}
}
impl Changes for Visible{
fn has_changed(&self) -> bool{
self.has_changed
}
fn reset_changed(&mut self){
self.has_changed = false
}
}
pub struct VisibleChanges;
#[derive(Clone,Copy,Debug,Component,Eq,PartialEq, Serialize, Deserialize)]
pub enum Ty{
Model,
Light,
Armature,
Empty,
Mesh,
Bone,
}
#[derive(Component, Eq, PartialEq, Debug, Ord, PartialOrd, Hash, Clone, Serialize, Deserialize)]
pub struct SourcePath(pub PathBuf);