Skip to content

Commit fc02304

Browse files
committed
Add the option to generate heatmaps with the killer position rather than the victim position
1 parent 038952b commit fc02304

7 files changed

Lines changed: 64 additions & 10 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.0"
3+
version = "0.1.1"
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
@@ -5,7 +5,7 @@ A tool for creating heatmaps from Team Fortress 2 demos
55

66
# Download
77

8-
Check the [releases page](https://github.com/Tails8521/coldmaps/releases) and download the latest version, the .exe is under Assets
8+
Check the [releases page](https://github.com/Tails8521/coldmaps/releases) and download the latest version
99

1010
# How to use
1111

@@ -16,7 +16,7 @@ Tip: You can use setpos \<x> \<y> \<z> to position yourself accurately
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)
1818
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, don't forget to specify the file extension in the file name you save as (don't type "my heatmap" but rather "my heatmap.png")
19+
7: The "Export image" button lets you export the heatmap as an image file
2020

2121
# How to build
2222

screenshot.png

324 KB
Loading

src/heatmap.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ impl Display for CoordsType {
2626
}
2727
}
2828

29+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
30+
pub enum HeatmapType {
31+
VictimPosition,
32+
KillerPosition,
33+
}
34+
35+
impl Default for HeatmapType {
36+
fn default() -> Self {
37+
Self::VictimPosition
38+
}
39+
}
40+
41+
impl Display for HeatmapType {
42+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43+
match self {
44+
HeatmapType::VictimPosition => write!(f, "Victim position"),
45+
HeatmapType::KillerPosition => write!(f, "Killer position"),
46+
}
47+
}
48+
}
49+
2950
#[derive(Debug)]
3051
struct HeatMapParameters {
3152
screen_width: f32,
@@ -79,6 +100,7 @@ impl HeatMapGenerator {
79100

80101
pub fn generate_heatmap<'a>(
81102
&self,
103+
heatmap_type: HeatmapType,
82104
deaths: impl IntoIterator<Item = &'a Death>,
83105
image: &mut ImageBuffer<Rgb<u8>, Vec<u8>>,
84106
) {
@@ -96,7 +118,11 @@ impl HeatMapGenerator {
96118
// LinSrgba::new(1.0, 1.0, 1.0, 1.0),
97119
]);
98120
for death in deaths {
99-
if let Some(entity_state) = &death.victim_entity_state {
121+
let entity_state = match heatmap_type {
122+
HeatmapType::VictimPosition => &death.victim_entity_state,
123+
HeatmapType::KillerPosition => &death.killer_entity_state,
124+
};
125+
if let Some(entity_state) = entity_state {
100126
let game_coords = entity_state.position;
101127
let (x_f, y_f) = self.game_coords_to_screen_coords(game_coords.x, game_coords.y);
102128
let x_i = x_f.round() as i32;

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use image::{ImageBuffer, Rgb};
66
use rayon::prelude::*;
77
use std::{fs, mem, path::PathBuf, rc::Rc};
88

9-
use heatmap::CoordsType;
9+
use heatmap::{CoordsType, HeatmapType};
1010
use tf_demo_parser::{Demo, DemoParser};
1111

1212
pub fn process_demos(input_paths: Vec<PathBuf>) -> (Vec<Death>, Vec<String>) {
@@ -49,6 +49,7 @@ pub fn process_demos(input_paths: Vec<PathBuf>) -> (Vec<Death>, Vec<String>) {
4949
}
5050

5151
pub fn generate_heatmap(
52+
heatmap_type: HeatmapType,
5253
deaths: Vec<Death>,
5354
mut image: ImageBuffer<Rgb<u8>, Vec<u8>>,
5455
screen_width: u32,
@@ -66,6 +67,6 @@ pub fn generate_heatmap(
6667
scale,
6768
coords_type,
6869
);
69-
heatmap_generator.generate_heatmap(deaths.iter(), &mut image);
70+
heatmap_generator.generate_heatmap(heatmap_type, deaths.iter(), &mut image);
7071
image
7172
}

src/main.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use coldmaps::*;
22
mod style;
33

4-
use heatmap::CoordsType;
4+
use heatmap::{CoordsType, HeatmapType};
55
use heatmap_analyser::Death;
66
use iced::{
77
button, executor, image::Handle, pane_grid, scrollable, text_input, window, Align, Application,
@@ -74,6 +74,7 @@ enum Message {
7474
DemoRemoved(usize),
7575
ThemeChanged(style::Theme),
7676
CoordsTypeChanged(CoordsType),
77+
HeatmapTypeChanged(HeatmapType),
7778
XPosInputChanged(String),
7879
YPosInputChanged(String),
7980
ScaleInputChanged(String),
@@ -246,6 +247,7 @@ struct SettingsPane {
246247
demos_need_processing: bool, // has the current list not been processed?
247248
image_ready: bool,
248249
coords_type: CoordsType,
250+
heatmap_type: HeatmapType,
249251
}
250252

251253
impl SettingsPane {
@@ -285,6 +287,22 @@ impl SettingsPane {
285287
)
286288
},
287289
);
290+
let choose_heatmap_type = [HeatmapType::VictimPosition, HeatmapType::KillerPosition]
291+
.iter()
292+
.fold(
293+
Column::new().spacing(10).push(Text::new("Heatmap type:")),
294+
|column, heatmap_type| {
295+
column.push(
296+
Radio::new(
297+
*heatmap_type,
298+
&format!("{}", heatmap_type),
299+
Some(self.heatmap_type),
300+
Message::HeatmapTypeChanged,
301+
)
302+
.style(self.theme),
303+
)
304+
},
305+
);
288306

289307
let x_pos_input = TextInput::new(
290308
&mut self.x_pos_input_state,
@@ -376,6 +394,7 @@ impl SettingsPane {
376394
CoordsType::Console => "Camera coordinates (use the console)",
377395
};
378396
let settings_content: Element<_> = Column::new()
397+
.push(choose_heatmap_type)
379398
.push(Text::new(coords_label))
380399
.push(x_pos_border)
381400
.push(y_pos_border)
@@ -605,6 +624,9 @@ impl Application for App {
605624
Message::CoordsTypeChanged(coords_type) => {
606625
self.get_settings_pane().coords_type = coords_type;
607626
}
627+
Message::HeatmapTypeChanged(heatmap_type) => {
628+
self.get_settings_pane().heatmap_type = heatmap_type;
629+
}
608630
Message::XPosInputChanged(input) => {
609631
let settings_pane = self.get_settings_pane();
610632
settings_pane.x_pos = input.parse().ok();
@@ -667,6 +689,7 @@ impl Application for App {
667689
let pos_y = settings_pane.y_pos.unwrap();
668690
let scale = settings_pane.scale.unwrap();
669691
let coords_type = settings_pane.coords_type;
692+
let heatmap_type = settings_pane.heatmap_type;
670693
let preview_pane = self.get_preview_pane();
671694
let image = match &preview_pane.heatmap_image {
672695
Some(image) => image.image.clone(),
@@ -676,6 +699,7 @@ impl Application for App {
676699
let screen_height = image.height();
677700
return Command::perform(
678701
generate_heatmap_async(
702+
heatmap_type,
679703
deaths,
680704
image,
681705
screen_width,
@@ -689,11 +713,12 @@ impl Application for App {
689713
);
690714
}
691715
Message::HeatmapGenerationDone(heatmap_generation_output) => {
716+
let heatmap_type = self.get_settings_pane().heatmap_type;
692717
match heatmap_generation_output.result {
693718
Ok(image) => {
694719
self.log(&format!(
695-
"Heatmap generated in {:.2}s",
696-
heatmap_generation_output.time_elapsed
720+
"{} heatmap generated in {:.2}s",
721+
heatmap_type, heatmap_generation_output.time_elapsed
697722
));
698723
match &mut self.get_preview_pane().heatmap_image {
699724
Some(heatmap_image) => {
@@ -857,6 +882,7 @@ async fn process_demos_async<'a>(input_paths: Vec<PathBuf>) -> DemoProcessingOut
857882
}
858883

859884
async fn generate_heatmap_async(
885+
heatmap_type: HeatmapType,
860886
deaths: Vec<Death>,
861887
image: ImageBuffer<Rgb<u8>, Vec<u8>>,
862888
screen_width: u32,
@@ -869,6 +895,7 @@ async fn generate_heatmap_async(
869895
let chrono = Instant::now();
870896
let result = tokio::task::spawn_blocking(move || {
871897
coldmaps::generate_heatmap(
898+
heatmap_type,
872899
deaths,
873900
image,
874901
screen_width,

0 commit comments

Comments
 (0)