fix prop search

This commit is contained in:
Robin Appelman 2022-09-03 17:45:41 +02:00
commit d360ffec68
8 changed files with 19 additions and 19 deletions

View file

@ -124,7 +124,7 @@ impl Parser {
.iter()
.map(|(identifier, table, prop)| {
JsValue::from_serde(&PropName {
identifier: *identifier,
identifier: identifier.to_string(),
table: table.to_string(),
prop: prop.to_string(),
})
@ -147,7 +147,7 @@ impl Parser {
}
pub fn search(&self, filter: JsValue) -> Vec<usize> {
let filter: SearchFilter = filter.into_serde().unwrap();
let filter: SearchFilter = filter.into_serde().expect("failed to parse search filter");
self.packets
.iter()
.enumerate()
@ -158,7 +158,7 @@ impl Parser {
#[derive(Serialize)]
pub struct PropName {
pub identifier: u64,
pub identifier: String,
pub table: String,
pub prop: String,
}

View file

@ -11,18 +11,18 @@ use tf_demo_parser::demo::message::{
StringCmdMessage,
};
use tf_demo_parser::demo::packet::consolecmd::ConsoleCmdPacket;
use tf_demo_parser::demo::packet::datatable::ClassId;
use tf_demo_parser::demo::packet::message::MessagePacket;
use tf_demo_parser::demo::packet::stringtable::{StringTableEntry, StringTablePacket};
use tf_demo_parser::demo::packet::Packet;
use tf_demo_parser::demo::sendprop::SendPropIdentifier;
#[derive(Serialize, Deserialize)]
pub struct SearchFilter {
pub entity: u32,
pub search: String,
#[serde(default)]
pub prop_ids: Vec<u64>,
#[serde(default)]
pub class_ids: Vec<u32>,
pub prop_ids: Vec<SendPropIdentifier>,
pub class_ids: Vec<ClassId>,
}
impl SearchFilter {
@ -97,7 +97,7 @@ fn message_matches(message: &Message, filter: &SearchFilter) -> bool {
Message::SetView(SetViewMessage { index }) => (*index as u32) == filter.entity,
Message::UserMessage(_) => false,
Message::EntityMessage(EntityMessage { class_id, .. }) => {
filter.class_ids.contains(&(*class_id as u32))
filter.class_ids.contains(&((*class_id).into()))
}
Message::GameEvent(GameEventMessage { event, .. }) => {
has_search && event.event_type().as_str().contains(&filter.search)

View file

@ -32,7 +32,7 @@ interface AppState {
header: Header | null,
progress: number,
packets: PacketMeta[],
prop_names: Map<number, { table: string, prop: string }>,
prop_names: Map<string, { table: string, prop: string }>,
class_names: Map<number, string>,
active: Packet | null,
activeIndex: number | null,

View file

@ -4,7 +4,7 @@ import {filterEntity, filterMessage, isSearchEmpty, SearchFilter} from "../searc
export interface MessageInfoProps {
msg: Message,
prop_names: Map<number, { table: String, prop: String }>,
prop_names: Map<string, { table: String, prop: String }>,
class_names: Map<number, String>,
search: SearchFilter
}
@ -78,7 +78,7 @@ function formatPropValue(value: SendPropValue): string {
}
}
function formatEntity(entity: PacketEntity, prop_names: Map<number, { table: String, prop: String }>, class_names: Map<number, String>,): string {
function formatEntity(entity: PacketEntity, prop_names: Map<string, { table: String, prop: String }>, class_names: Map<number, String>,): string {
let class_name = class_names.get(entity.server_class);
// let baseline = entity.baseline_props.map(prop => {
// let names = prop_names.get(prop.identifier);

2
www/src/parser.d.ts vendored
View file

@ -3212,7 +3212,7 @@ export type GameEventValue =
Boolean: boolean;
};
export type GameEventTypeId = number;
export type SendPropIdentifier = number;
export type SendPropIdentifier = string;
export type SendPropValue = Vector | VectorXY | number | number | string | SendPropValue[];
export type EntityId = number;
export type ClassId = number;

View file

@ -9,6 +9,6 @@ export type RequestMessageData = {type: "data", data: ArrayBuffer}
export type ResponseMessageData = { type: "progress", progress: number }
| { type: "packet", packet: Packet }
| { type: "done", packets: PacketMeta[], header: Header, prop_names: { identifier: number, table: string, prop: string }[], class_names: { identifier: number, name: string }[] }
| { type: "done", packets: PacketMeta[], header: Header, prop_names: { identifier: string, table: string, prop: string }[], class_names: { identifier: number, name: string }[] }
| { type: "packet_names", packet: {} }
| { type: "search_result", matches: number[] };

View file

@ -6,13 +6,13 @@ import {Message, Packet, SendProp, StringTable} from "./parser";
export interface SearchFilter {
entity: number,
search: string,
prop_ids: number[],
prop_ids: string[],
class_ids: number[],
}
export interface SearchBarProps {
onSearch: (search: SearchFilter) => void,
prop_names: Map<number, { table: string, prop: string }>,
prop_names: Map<string, { table: string, prop: string }>,
class_names: Map<number, string>,
}
@ -91,7 +91,7 @@ export function filterPacket(
}
}
function filterPropNames(prop_names: Map<number, { table: string, prop: string }>, filter: string): number[] {
function filterPropNames(prop_names: Map<string, { table: string, prop: string }>, filter: string): string[] {
if (filter.length === 0) {
return [];
}
@ -166,7 +166,7 @@ export function filterEntity(class_id: number, props: SendProp[], search: Search
return true;
}
return search.class_ids.includes(class_id) || props.some(prop => search.prop_ids.includes(prop.identifier))
return search.class_ids.includes(class_id) || props.some(prop => search.prop_ids.includes(`${prop.identifier}`))
|| props.some(prop => prop.value == search.search);
}

View file

@ -8,7 +8,7 @@ import {PacketMeta, PacketType} from "./index"
interface TableProps {
packets: PacketMeta[],
prop_names: Map<number, { table: string, prop: string }>,
prop_names: Map<string, { table: string, prop: string }>,
class_names: Map<number, string>,
onClick: (i: number) => void,
activeIndex: number | null,
@ -79,7 +79,7 @@ export function PacketRow({packet}: RowProps) {
interface DetailProps {
packet: Packet,
prop_names: Map<number, { table: string, prop: string }>,
prop_names: Map<string, { table: string, prop: string }>,
class_names: Map<number, string>,
search: SearchFilter,
}