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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use crate::parser::raws::{info_txt::DFInfoFile, DFRawCommon, RawObjectKind};
use super::{DFGraphic, Kind, SpriteGraphic};
impl DFGraphic {
pub fn new(raw: &str, token: &str, info_text: &DFInfoFile) -> Self {
// [CREATURE_CASTE_GRAPHICS:<creature id>:<caste id>]
// [CREATURE_GRAPHICS:<creature id>]
// [TILE_GRAPHICS:ITEMS4:0:1:ITEM_BRANCH]
//idx 0 1 2 3 4
// [TILE_GRAPHICS:ITEM_COFFIN:1:0:ITEM_COFFIN_WOOD_UNUSED]
//idx 0 1 2 3 4
let split = token.split(':').collect::<Vec<&str>>();
match *split.first().unwrap_or(&"") {
"TILE_GRAPHICS" => {
let Some(identifier) = split.get(4) else {
return Self {
raw_header: DFRawCommon::from(
split[1],
raw,
info_text,
RawObjectKind::Graphics,
),
caste_identifier: String::new(),
graphics: Vec::new(),
kind: Kind::Empty,
}
};
let graphic = match SpriteGraphic::parse(token) {
Some(g) => g,
None => {
return Self {
raw_header: DFRawCommon::from(
split[1],
raw,
info_text,
RawObjectKind::Graphics,
),
caste_identifier: String::new(),
graphics: Vec::new(),
kind: Kind::Empty,
}
}
};
Self {
raw_header: DFRawCommon::from(
identifier,
raw,
info_text,
RawObjectKind::Graphics,
),
caste_identifier: String::new(),
graphics: vec![graphic],
kind: Kind::Tile,
}
}
"CREATURE_CASTE_GRAPHICS" => Self {
raw_header: DFRawCommon::from(split[1], raw, info_text, RawObjectKind::Graphics),
caste_identifier: String::from(split[2]),
graphics: Vec::new(),
kind: Kind::Empty,
},
"CREATURE_GRAPHICS" => Self {
raw_header: DFRawCommon::from(split[1], raw, info_text, RawObjectKind::Graphics),
caste_identifier: String::new(),
graphics: Vec::new(),
kind: Kind::Creature,
},
"PLANT_GRAPHICS" => Self {
raw_header: DFRawCommon::from(split[1], raw, info_text, RawObjectKind::Graphics),
caste_identifier: String::new(),
graphics: Vec::new(),
kind: Kind::Plant,
},
_ => Self {
raw_header: DFRawCommon::from(token, raw, info_text, RawObjectKind::Graphics),
caste_identifier: String::new(),
graphics: Vec::new(),
kind: Kind::Empty,
},
}
}
pub fn add_tile_from_token(&mut self, token: &str) {
match self.kind {
Kind::Creature | Kind::CreatureCaste => {
let graphic = match SpriteGraphic::parse_creature(token) {
Some(g) => g,
None => {
return;
}
};
self.graphics.push(graphic);
}
Kind::Tile => {
let graphic = match SpriteGraphic::parse(token) {
Some(g) => g,
None => {
return;
}
};
self.graphics.push(graphic);
}
Kind::Plant => {
let graphic = match SpriteGraphic::parse_plant(token) {
Some(g) => g,
None => {
return;
}
};
self.graphics.push(graphic);
}
Kind::Empty => {}
}
}
pub fn get_raw_header(&self) -> &DFRawCommon {
&self.raw_header
}
pub fn get_caste_identifier(&self) -> String {
self.caste_identifier.to_string()
}
pub fn get_kind(&self) -> Kind {
self.kind
}
pub fn get_graphics(&self) -> Vec<SpriteGraphic> {
// cloning vec
self.graphics.clone()
}
}