-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposing detailed knife details #431
base: master
Are you sure you want to change the base?
Exposing detailed knife details #431
Conversation
pkg/demoinfocs/common/equipment.go
Outdated
wep = eqNameToWeapon[eqName] | ||
} | ||
// If the eqName isn't known it will be EqUnknown as that is the default value for EquipmentType | ||
wep := eqNameToWeapon[eqName] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, this doesn't really scale well for when they add new knifes - we would need to update the parser every time. and worse, our consumers would need to upgrade, otherwise they will get EqUnknown
for the new knife, which would be really hard to debug.
I suggest that we instead expose the raw eqName
somewhere upstream in the call chain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good point, I will take a look at it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Edit - I found the attribute "m_sWeaponName". Is that what you (@markus-wa) meant regarding exposing the raw eqName?
If so disregard the rest of the comment.
***Edit2 - I digged a bit deeper regarding the "m_sWeaponName" property, and it seems like it is not possible to get any relevant data from it. I have not found any other properties that holds weapon name data. Let me know if you know of any.
I don't think there is a good way to handle valve adding new knives. However, I think there are some options:
-
Exposing the weapon "code"/itemindex - eg. we give the consumers the possibility to see what code the EqUnkown has.
- Pros:
- This technically means that consumers can still handle new knives even before the parser is updated.
- Cons:
- It will still to a degree be hard for consumers to debug, as they only get a weapon code and nothing "human readable".
- Parser will still need to be updated to handle new knives with EqTypes and so forth.
- Pros:
-
Exposing a more raw weapon string.
- Pros:
- Makes it more human readable for consumers to debug.
- Cons:
- The parser needs to be updated before consumers can add new knives.
- Pros:
After writing this out I find myself gravitating more towards option 1. As the raw weapon string is not something coming from the engine but something we attach from the item index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also why not keeping strings.Contains(eqName, "knife")
as a fallback when wep
is unknown?
i think it's better to have weapon_knife
instead of "Unknown" when we know it's a knife
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also why not keeping
strings.Contains(eqName, "knife")
as a fallback whenwep
is unknown? i think it's better to haveweapon_knife
instead of "Unknown" when we know it's a knife
My thought was that the parser defines what a knife "is". Therefore it would be an error in the parser if the EqName did not map to an EqType.
I can add it back, I guess it is nice to have if new knives are added and the eqname/eqtype map is not updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually - I don't think we can add new EqKnifeXYZ
types anyway as it's not backwards compatible and would lead to confusion (e.g. if the user wants to check if a kill was a knife kill, using EqKnife
is more straight forward than checking all cases.
So we should expose this as additional data, not as replacement.
So we'll need another way of solving this - not yet sure how exactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the idea of adding a field to the equipment struct with additional detailes about the weapon/equipment?
Let me know if there is something I can do. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good! Maybe something similar to what we already have with Equipment.OriginalString
but for this new string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed in comments
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #431 +/- ##
==========================================
+ Coverage 80.38% 80.53% +0.14%
==========================================
Files 47 47
Lines 6257 6304 +47
==========================================
+ Hits 5030 5077 +47
Misses 1018 1018
Partials 209 209
☔ View full report in Codecov by Sentry. |
…rebet/demoinfocs-golang into exposing-detailed-wep-data
…rebet/demoinfocs-golang into exposing-detailed-wep-data
EqKnifeOutdoor EquipmentType = 437 | ||
EqKnifeStiletto EquipmentType = 438 | ||
EqKnifeWidowmaker EquipmentType = 439 | ||
EqKnifeSkeleton EquipmentType = 440 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the RawEquipment
part looks good now - but this part will need to be removed as it's not backwards compatible as mentioned in the other thread.
So all we should do for now is expose RawEquipment
.
Maybe we can have a separate type KnifeType
and constants KnifeTypeXYZ
with a map KnifeTypes map[string]KnifeType
which includes all known knife types to still provide some kind of mapping.
The good thing about this is that if a new knife comes out the users can just add it to the map themselves,. as the map will be mutable.
I think this would be the best middleground
eqNameToWeapon["knife_outdoor"] = EqKnifeOutdoor | ||
eqNameToWeapon["knife_stiletto"] = EqKnifeStiletto | ||
eqNameToWeapon["knife_widowmaker"] = EqKnifeWidowmaker | ||
eqNameToWeapon["knife_skeleton"] = EqKnifeSkeleton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, would need to be moved to the new map I wrote about
eqElementToName[EqKnifeOutdoor] = "Outdoor Knife" | ||
eqElementToName[EqKnifeStiletto] = "Stiletto Knife" | ||
eqElementToName[EqKnifeWidowmaker] = "Widowmaker Knife" | ||
eqElementToName[EqKnifeSkeleton] = "Skeleton Knife" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would have to be in a new map knifeTypeToName
- don't forget to implement the String()
method on KnifeType
521: EqKnifeOutdoor, // weapon_knife_outdoor | ||
522: EqKnifeStiletto, // weapon_knife_stiletto | ||
523: EqKnifeWidowmaker, // weapon_knife_widowmaker | ||
525: EqKnifeSkeleton, // weapon_knife_skeleton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these would need to be put in a new map as well KnifeTypeIndexMapping
thanks for the changes @Falderebet - sorry this is taking a while, but I think it's important to get this right to prevent issues in the future - thanks for your patience here! |
Why this PR is needed
As of now it is not possible to see what "type" of knife players have equipped as they are all maped to EqKnife. This PR is an attempt to make that possible.
What this PR adds