Skip to content

Commit 4efb049

Browse files
committed
0.2.0 - filters support
1 parent f95c9de commit 4efb049

10 files changed

Lines changed: 718 additions & 78 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "coldmaps"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
authors = ["Tails8521 <tails8521@gmail.com>"]
55
edition = "2018"
66

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Tip: You can use setpos \<x> \<y> \<z> to position yourself accurately
1515
3: Drag and drop the screenshot over the program's window
1616
4: Drag and drop the demo(s) you want to use for the heatmap
1717
5: Fill the camera coordinates and zoom level, don't forget to tick the checkbox corresponding to what type of coordinates you used (cl_showpos or the console)
18-
6: Click on the "Process demos" button to begin the demo analysis, once it has completed, you can click on the "Generate heatmap" and the heatmap should appear in the preview pane
19-
7: The "Export image" button lets you export the heatmap as an image file
18+
6: The "Export image" button lets you export the heatmap as an image file
2019

2120
# How to build
2221

22+
(This step is only needed if you want to build from source, if you're on Windows you can simply download a pre-built exe from the [releases page](https://github.com/Tails8521/coldmaps/releases))
2323
Download and install [Rust](https://www.rust-lang.org/learn/get-started) then `cargo build` or `cargo build --release`

fonts/tf2-classicons.ttf

12.9 KB
Binary file not shown.

src/filters.rs

Lines changed: 148 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::heatmap_analyser::{Class, Death, PlayerEntity, Team};
1+
use crate::heatmap_analyser::{Death, PlayerEntity, Team, PlayerState};
22
use enum_dispatch::enum_dispatch;
3+
use std::fmt::Display;
34
use tf_demo_parser::demo::vector::Vector;
45

56
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -12,13 +13,91 @@ pub enum OrderedOperator {
1213
SmallerOrEqual,
1314
}
1415

16+
impl OrderedOperator {
17+
pub const ALL: [OrderedOperator; 6] = [
18+
OrderedOperator::Equal,
19+
OrderedOperator::NotEqual,
20+
OrderedOperator::Greater,
21+
OrderedOperator::Smaller,
22+
OrderedOperator::GreaterOrEqual,
23+
OrderedOperator::SmallerOrEqual,
24+
];
25+
}
26+
27+
impl Default for OrderedOperator {
28+
fn default() -> Self {
29+
OrderedOperator::Equal
30+
}
31+
}
32+
33+
impl Display for OrderedOperator {
34+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35+
match self {
36+
OrderedOperator::Equal => write!(f, "="),
37+
OrderedOperator::NotEqual => write!(f, "≠"),
38+
OrderedOperator::Greater => write!(f, ">"),
39+
OrderedOperator::Smaller => write!(f, "<"),
40+
OrderedOperator::GreaterOrEqual => write!(f, "≥"),
41+
OrderedOperator::SmallerOrEqual => write!(f, "≤"),
42+
}
43+
}
44+
}
45+
1546
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16-
pub enum UnorderedOperator {
17-
Is,
18-
IsNot,
47+
pub enum PropertyOperator {
48+
IsPresent,
49+
IsNotPresent,
50+
}
51+
52+
impl PropertyOperator {
53+
pub const ALL: [PropertyOperator; 2] = [PropertyOperator::IsPresent, PropertyOperator::IsNotPresent];
54+
}
55+
56+
impl Default for PropertyOperator {
57+
fn default() -> Self {
58+
PropertyOperator::IsPresent
59+
}
60+
}
61+
62+
impl Display for PropertyOperator {
63+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64+
match self {
65+
PropertyOperator::IsPresent => write!(f, "present"),
66+
PropertyOperator::IsNotPresent => write!(f, "not present"),
67+
}
68+
}
69+
}
70+
71+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
72+
pub enum Property {
73+
Suicide,
74+
Posthumous,
75+
}
76+
77+
impl Property {
78+
pub const ALL: [Property; 2] = [
79+
Property::Suicide,
80+
Property::Posthumous,
81+
];
82+
}
83+
84+
impl Default for Property {
85+
fn default() -> Self {
86+
Property::Suicide
87+
}
88+
}
89+
90+
impl Display for Property {
91+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
92+
match self {
93+
Property::Suicide => write!(f, "Suicide"),
94+
Property::Posthumous => write!(f, "Posthumous"),
95+
}
96+
}
1997
}
2098

2199
#[enum_dispatch]
100+
#[derive(Debug)]
22101
pub enum Filter {
23102
KillerTeamFilter,
24103
VictimTeamFilter,
@@ -28,73 +107,72 @@ pub enum Filter {
28107
VictimElevationFilter,
29108
Distance2DFilter,
30109
Distance3DFilter,
110+
RoundFilter,
111+
PropertyFilter,
31112
}
32113

33114
#[enum_dispatch(Filter)]
34115
pub trait FilterTrait {
35116
fn apply(&self, death: &Death) -> bool;
36117
}
37118

119+
#[derive(Debug)]
38120
pub struct KillerTeamFilter {
39-
pub op: UnorderedOperator,
40121
pub team: Team,
41122
}
42123

43124
impl FilterTrait for KillerTeamFilter {
44125
fn apply(&self, death: &Death) -> bool {
45-
match (&death.killer_entity_state, self.op) {
46-
(Some(PlayerEntity { team, .. }), UnorderedOperator::Is) => *team == self.team,
47-
(Some(PlayerEntity { team, .. }), UnorderedOperator::IsNot) => *team != self.team,
48-
(None, _) => false,
126+
match &death.killer_entity_state {
127+
Some(PlayerEntity { team, .. }) => *team == self.team,
128+
None => false,
49129
}
50130
}
51131
}
52132

133+
#[derive(Debug)]
53134
pub struct VictimTeamFilter {
54-
pub op: UnorderedOperator,
55135
pub team: Team,
56136
}
57137

58138
impl FilterTrait for VictimTeamFilter {
59139
fn apply(&self, death: &Death) -> bool {
60-
match (&death.victim_entity_state, self.op) {
61-
(Some(PlayerEntity { team, .. }), UnorderedOperator::Is) => *team == self.team,
62-
(Some(PlayerEntity { team, .. }), UnorderedOperator::IsNot) => *team != self.team,
63-
(None, _) => false,
140+
match &death.victim_entity_state {
141+
Some(PlayerEntity { team, .. }) => *team == self.team,
142+
None => false,
64143
}
65144
}
66145
}
67146

147+
#[derive(Debug)]
68148
pub struct KillerClassFilter {
69-
pub op: UnorderedOperator,
70-
pub class: Class,
149+
pub classes: [bool; 10],
71150
}
72151

73152
impl FilterTrait for KillerClassFilter {
74153
fn apply(&self, death: &Death) -> bool {
75-
match (&death.killer_entity_state, self.op) {
76-
(Some(PlayerEntity { class, .. }), UnorderedOperator::Is) => *class == self.class,
77-
(Some(PlayerEntity { class, .. }), UnorderedOperator::IsNot) => *class != self.class,
78-
(None, _) => false,
154+
match &death.killer_entity_state {
155+
Some(PlayerEntity { class, .. }) => self.classes[*class as usize],
156+
None => false,
79157
}
80158
}
81159
}
82160

161+
#[derive(Debug)]
83162
pub struct VictimClassFilter {
84-
pub op: UnorderedOperator,
85-
pub class: Class,
163+
pub classes: [bool; 10],
86164
}
87165

88166
impl FilterTrait for VictimClassFilter {
89167
fn apply(&self, death: &Death) -> bool {
90-
match (&death.victim_entity_state, self.op) {
91-
(Some(PlayerEntity { class, .. }), UnorderedOperator::Is) => *class == self.class,
92-
(Some(PlayerEntity { class, .. }), UnorderedOperator::IsNot) => *class != self.class,
93-
(None, _) => false,
168+
match &death.victim_entity_state {
169+
Some(PlayerEntity { class, .. }) => self.classes[*class as usize],
170+
None => false,
94171
}
95172
}
96173
}
97174

175+
#[derive(Debug)]
98176
pub struct KillerElevationFilter {
99177
pub op: OrderedOperator,
100178
pub z: f32,
@@ -114,6 +192,7 @@ impl FilterTrait for KillerElevationFilter {
114192
}
115193
}
116194

195+
#[derive(Debug)]
117196
pub struct VictimElevationFilter {
118197
pub op: OrderedOperator,
119198
pub z: f32,
@@ -133,6 +212,7 @@ impl FilterTrait for VictimElevationFilter {
133212
}
134213
}
135214

215+
#[derive(Debug)]
136216
pub struct Distance2DFilter {
137217
pub op: OrderedOperator,
138218
pub distance: f32,
@@ -158,6 +238,7 @@ impl FilterTrait for Distance2DFilter {
158238
}
159239
}
160240

241+
#[derive(Debug)]
161242
pub struct Distance3DFilter {
162243
pub op: OrderedOperator,
163244
pub distance: f32,
@@ -183,3 +264,44 @@ impl FilterTrait for Distance3DFilter {
183264
}
184265
}
185266
}
267+
268+
#[derive(Debug)]
269+
pub struct RoundFilter {
270+
pub op: OrderedOperator,
271+
pub round: u32,
272+
}
273+
274+
impl FilterTrait for RoundFilter {
275+
fn apply(&self, death: &Death) -> bool {
276+
match self.op {
277+
OrderedOperator::Equal => death.round == self.round,
278+
OrderedOperator::NotEqual => death.round != self.round,
279+
OrderedOperator::Greater => death.round > self.round,
280+
OrderedOperator::Smaller => death.round < self.round,
281+
OrderedOperator::GreaterOrEqual => death.round >= self.round,
282+
OrderedOperator::SmallerOrEqual => death.round <= self.round,
283+
}
284+
}
285+
}
286+
287+
#[derive(Debug)]
288+
pub struct PropertyFilter {
289+
pub op: PropertyOperator,
290+
pub property: Property,
291+
}
292+
293+
impl FilterTrait for PropertyFilter {
294+
fn apply(&self, death: &Death) -> bool {
295+
let ret = match self.property {
296+
Property::Suicide => death.killer == death.victim,
297+
Property::Posthumous => match death.killer_entity_state {
298+
Some(PlayerEntity { state: PlayerState::Alive, .. } ) => false,
299+
_ => true
300+
}
301+
};
302+
match self.op {
303+
PropertyOperator::IsPresent => ret,
304+
PropertyOperator::IsNotPresent => !ret,
305+
}
306+
}
307+
}

0 commit comments

Comments
 (0)