Add weapon and some other info to perround

In the events per round, it now dispalys the weapon used and headshot and noscope if applicable.
Otherwise also cleaned up other code
This commit is contained in:
Lol3rrr
2024-11-03 14:47:34 +01:00
parent 7e50a627f6
commit 898a889a53
8 changed files with 80 additions and 28 deletions

View File

@@ -60,7 +60,16 @@ pub struct Round {
pub enum RoundEvent {
BombPlanted,
BombDefused,
Kill { attacker: u64, died: u64 },
Kill {
attacker: u64,
died: u64,
#[serde(default)]
weapon: Option<String>,
#[serde(default)]
headshot: bool,
#[serde(default)]
noscope: bool,
},
}
#[derive(Debug)]
@@ -138,7 +147,7 @@ pub fn parse(buf: &[u8]) -> Result<PerRound, ()> {
};
}
let event = match ge.as_ref() {
let event = match *ge {
csdemo::game_event::GameEvent::BombPlanted(planted) => RoundEvent::BombPlanted,
csdemo::game_event::GameEvent::BombDefused(defused) => RoundEvent::BombDefused,
csdemo::game_event::GameEvent::PlayerDeath(death) => {
@@ -157,6 +166,9 @@ pub fn parse(buf: &[u8]) -> Result<PerRound, ()> {
RoundEvent::Kill {
attacker: attacker_player.xuid,
died: died_player.xuid,
weapon: death.weapon,
noscope: death.noscope.unwrap_or(false),
headshot: death.headshot.unwrap_or(false),
}
}
_ => continue,

View File

@@ -47,7 +47,16 @@ impl Analysis for PerRoundAnalysis {
Box::pin(async move {
let query = diesel::dsl::insert_into(crate::schema::demo_round::dsl::demo_round)
.values(&values)
.on_conflict_do_nothing();
.on_conflict((
crate::schema::demo_round::dsl::demo_id,
crate::schema::demo_round::dsl::round_number,
))
.do_update()
.set(
crate::schema::demo_round::dsl::events.eq(diesel::upsert::excluded(
crate::schema::demo_round::dsl::events,
)),
);
query.execute(connection).await?;

View File

@@ -505,7 +505,13 @@ async fn perround(
analysis::perround::RoundEvent::BombDefused => {
common::demo_analysis::RoundEvent::BombDefused
}
analysis::perround::RoundEvent::Kill { attacker, died } => {
analysis::perround::RoundEvent::Kill {
attacker,
died,
weapon,
noscope,
headshot,
} => {
let attacker_name = players
.iter()
.find(|p| p.steam_id == attacker.to_string())
@@ -520,6 +526,9 @@ async fn perround(
common::demo_analysis::RoundEvent::Killed {
attacker: attacker_name,
died: died_name,
weapon,
headshot,
noscope,
}
}
})

View File

@@ -74,5 +74,11 @@ pub enum RoundWinReason {
pub enum RoundEvent {
BombPlanted,
BombDefused,
Killed { attacker: String, died: String },
Killed {
attacker: String,
died: String,
weapon: Option<String>,
noscope: bool,
headshot: bool,
},
}

View File

@@ -42,13 +42,6 @@ pub fn demo() -> impl leptos::IntoView {
None => String::new(),
};
let selected_tab = move || {
let loc = leptos_router::use_location();
let loc_path = loc.pathname.get();
let trailing = loc_path.split('/').last();
trailing.unwrap_or("/").to_owned()
};
let style = stylers::style! {
"Demo",
.analysis_bar {
@@ -87,13 +80,27 @@ pub fn demo() -> impl leptos::IntoView {
}
#[leptos::component]
pub fn tab_bar<P>(prefix: P, parts: &'static [(&'static str, &'static str)]) -> impl leptos::IntoView where P: Fn() -> String + Copy + 'static {
pub fn tab_bar<P>(
prefix: P,
parts: &'static [(&'static str, &'static str)],
) -> impl leptos::IntoView
where
P: Fn() -> String + Copy + 'static,
{
let selected_tab = move || {
let prefix = prefix();
let loc = leptos_router::use_location();
let loc_path = loc.pathname.get();
let trailing = loc_path.strip_prefix(&prefix).unwrap_or(&loc_path).split('/').filter(|l| !l.is_empty()).next();
trailing.or(parts.first().map(|p| p.0)).unwrap_or("").to_owned()
let trailing = loc_path
.strip_prefix(&prefix)
.unwrap_or(&loc_path)
.split('/')
.filter(|l| !l.is_empty())
.next();
trailing
.or(parts.first().map(|p| p.0))
.unwrap_or("")
.to_owned()
};
let style = stylers::style! {
@@ -122,7 +129,8 @@ pub fn tab_bar<P>(prefix: P, parts: &'static [(&'static str, &'static str)]) ->
}
};
let tabs = move || parts.into_iter().map(|(routename, name)| {
let tabs = move || {
parts.into_iter().map(|(routename, name)| {
view! {class=style,
<div class="analysis_selector" class:current=move || selected_tab() == routename.to_string()>
<A href=routename.to_string()>
@@ -130,7 +138,8 @@ pub fn tab_bar<P>(prefix: P, parts: &'static [(&'static str, &'static str)]) ->
</A>
</div>
}
}).collect::<Vec<_>>();
}).collect::<Vec<_>>()
};
view! {class = style,
<div class="analysis_bar" style=format!("--rows: {}", parts.len())>

View File

@@ -79,24 +79,33 @@ pub fn per_round() -> impl leptos::IntoView {
match (current_round, teams) {
(Some(round), Some(teams)) => {
round.events.iter().map(|event| {
round.events.into_iter().map(|event| {
match event {
common::demo_analysis::RoundEvent::BombPlanted => view! { <li>Bomb has been planted</li> }.into_view(),
common::demo_analysis::RoundEvent::BombDefused => view! { <li>Bomb has been defused</li> }.into_view(),
common::demo_analysis::RoundEvent::Killed { attacker, died } => {
let mut attacker_t = teams.iter().find(|t| t.players.contains(attacker)).map(|t| t.name == "TERRORIST").unwrap_or(false);
let mut died_t = teams.iter().find(|t| t.players.contains(died)).map(|t| t.name == "TERRORIST").unwrap_or(false);
common::demo_analysis::RoundEvent::Killed { attacker, died, weapon, headshot, noscope } => {
let mut attacker_t = teams.iter().find(|t| t.players.contains(&attacker)).map(|t| t.name == "TERRORIST").unwrap_or(false);
let mut died_t = teams.iter().find(|t| t.players.contains(&died)).map(|t| t.name == "TERRORIST").unwrap_or(false);
if (12..27).contains(&round_index) {
attacker_t = !attacker_t;
died_t = !died_t;
}
let weapon_display = move || {
let parts = weapon.as_ref().into_iter().map(|w| w.as_str())
.chain(headshot.then_some("Headshot").into_iter())
.chain(noscope.then_some("Noscope").into_iter());
format!("(using {})", parts.collect::<Vec<_>>().join(","))
};
view! {
class=style,
<li>{"'"}
<span class:t_player=move || attacker_t class:ct_player=move || !attacker_t>{ attacker }</span>{"'"} killed {"'"}
<span class:t_player=move || died_t class:ct_player=move || !died_t>{ died }</span>{"'"}
<li>
{"'"}<span class:t_player=move || attacker_t class:ct_player=move || !attacker_t>{ attacker }</span>{"'"}
killed { weapon_display }
{"'"}<span class:t_player=move || died_t class:ct_player=move || !died_t>{ died }</span>{"'"}
</li>
}.into_view()
},

View File

@@ -22,7 +22,7 @@ fn main() {
<Route path="/demo/:id" view=Demo>
<Route path="scoreboard" view=frontend::demo::scoreboard::Scoreboard>
<Route path="general" view=frontend::demo::scoreboard::general::General />
<Route path="utility" view=frontend::demo::scoreboard::utility::Utility />
<Route path="utility" view=frontend::demo::scoreboard::utility::Utility />
<Route path="" view=frontend::demo::scoreboard::general::General />
</Route>
<Route path="perround" view=frontend::demo::perround::PerRound />

View File

@@ -31,9 +31,7 @@ fn steam_login(height: &'static str, width: &'static str) -> impl leptos::IntoVi
}
};
view! {
{ tmp }
}
tmp
}
#[leptos::component]