-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat: add weapon bag input schema. #855
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
Conversation
WalkthroughAdded a comprehensive TypeScript weapon schema, refactored mapping to use those types and adjusted weapon range/scatter field paths and typings, and re-exported the new types from the unitStats entry. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)src/unitStats/mappingWeapon.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/unitStats/mappingWeapon.ts (1)
155-178:node: anytype bypasses runtime validation—property access failures are possible with malformed JSON.While typing
const weapon_bag: WeaponBagSchema["weapon_bag"] = node.weapon_bag;provides editor support, thenodeparameter remainsany. TheisWeaponBagContainerpredicate only checks that the first key is"weapon_bag"but does not validate the structure. If weapon.json contains malformed entries, accessing unguarded properties likeweapon_bag.ui_name(line 167),weapon_bag.weapon_class(line 173), orweapon_bag.icon_name(line 168) will fail at runtime. Note the inconsistent use of optional chaining (e.g.,weapon_bag.accuracy?.nearvs. direct access toweapon_bag.ui_name).Consider:
- Narrowing the
nodetype signature in the traversal callback, or- Adding lightweight schema validation before extraction (e.g., checking required fields exist and have expected types).
🧹 Nitpick comments (3)
src/unitStats/types.ts (1)
45-116: Schema wiring betweenWeaponBag,Range, andScatterlooks consistent; consider tightening a few loose ends later.The new schema lines up cleanly with how
mappingWeapon.tsconsumes it (e.g.,weapon_bag.range.distance.*andweapon_bag.scatter.distance_scatter_obj_hit_min). UsingWeaponClass/WeaponCategoryasas constarrays for string unions is a solid choice.If you want to incrementally harden the model later, two low-risk options would be:
- Narrow frequently boolean‑ish strings (e.g.
"True"/"False") to string unions instead of barestring.- Replace some
any[]fields that you actively consume (target_type_table,conditional_table,weapon_tags) with minimal shaped types once those structures stabilize.These are non‑blocking and can be deferred.
Also applies to: 425-432, 443-464
src/unitStats/mappingWeapon.ts (2)
4-4: Good move centralizing weapon taxonomy intypes.ts.Importing
WeaponBagSchema,WeaponCategory, andWeaponClassfrom a shared types module keeps the weapon model consistent across the codebase and avoids duplicate enum definitions.
316-329: Potential singular/plural typo intarget_type_tablepath.In this block you read from:
target_types.target_unit_type_multipliers?.unit_typetarget_types.target_unit_type_multipliers?.base_damage_modifiertarget_types.target_unit_type_multipliers?.weapon_multiplier?.*but for
damage_multiplieryou switch to:
target_types.target_unit_type_multiplier?.weapon_multipliers?.damage_multiplierNote the singular vs plural difference in both
target_unit_type_multiplierandweapon_multipliers. If the underlying JSON only has the plural form (target_unit_type_multipliers.weapon_multipliers),damage_multiplierhere will always fall back to1.Please double‑check the JSON structure and align this path; e.g., it might need to be:
damage_multiplier: target_types.target_unit_type_multipliers?.weapon_multipliers?.damage_multiplier || 1,If you want to verify this across your current data, you could grep the raw JSON for both key shapes to confirm which one is actually present.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/unitStats/mappingWeapon.ts(4 hunks)src/unitStats/types.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/unitStats/mappingWeapon.ts (1)
src/unitStats/types.ts (1)
WeaponBagSchema(46-50)
🔇 Additional comments (1)
src/unitStats/mappingWeapon.ts (1)
300-305: Scatter distance mapping now matches the schema.Using
weapon_bag.scatter?.distance_scatter_obj_hit_minforscatter_distance_object_minaligns with the newScattertype and should fix the missing accessor for that field.
src/unitStats/mappingWeapon.ts
Outdated
| if (weapon_bag.range.distance.near === -1) | ||
| weapon_bag.range.distance.near = weapon_bag.range.min; | ||
| if (weapon_bag.range.distance.mid === -1) | ||
| weapon_bag.range.distance.mid = (weapon_bag.range.max - weapon_bag.range.min) / 2; | ||
| if (weapon_bag.range.distance.far === -1) weapon_bag.range.distance.far = weapon_bag.range.max; |
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.
Move the range normalization block before constructing weaponData to ensure normalized values are reflected in exported stats.
The normalization code at lines 310-314 currently executes after weaponData is built (lines 265-277). Since numeric values are primitives copied by value in JavaScript, the already-constructed weaponData object retains the original values (which may be -1) and never sees the normalized values set later. This makes the normalization block ineffective for the DPS chart and other consumers of mapWeaponData.
Move the normalization block before the weaponData object literal, or compute effective distances into locals and use those in the assignment. Additionally, update the optional chaining (?.) calls to direct access after normalization, or maintain fallback logic explicitly if you expect entries to sometimes lack range data.
For the mid-range formula (weapon_bag.range.max - weapon_bag.range.min) / 2, confirm whether this represents the half-distance of the range span or should be min + (max - min) / 2 (the midpoint between min and max). This distinction affects DPS bucket placement.
🤖 Prompt for AI Agents
In src/unitStats/mappingWeapon.ts around lines 310-314 and the earlier
weaponData construction (around lines 265-277), the range normalization
currently runs after weaponData is built so normalized values never make it into
the exported object; move the normalization block to before constructing
weaponData (or compute effective distance locals like
effectiveNear/effectiveMid/effectiveFar and use those in the weaponData
assignment), replace optional chaining with direct property access after
normalization (or keep explicit fallbacks if range may be missing), and if you
intend the midpoint use min + (max - min) / 2 rather than just (max - min) / 2.
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.
@KingDarBoja this seems like it makes sense right? We are changing weapon bag after we assign it to the weaponData, this code block should be before that ?
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.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
|
🌐 Branch deployed as preview to: |
This fixes the wrongly DPS chart because we were missing the correct accessor for weapon bag props.
Summary by CodeRabbit
Refactor
Chores
Impact
✏️ Tip: You can customize this high-level summary in your review settings.