Skip to content

Commit

Permalink
Fixes ranged weapon faction parsing and ammo group ToJSON
Browse files Browse the repository at this point in the history
The reason the weapon postables were breaking for ranged weapons
was twofold:

1. Special ammo group values in the `ToJSON` instance were being
set to the `WeaponGroup` value, so were not producing a valid value
for that field.

2. We were attempting to parse the faction from the raw name, so
it was always producing a `Nothing` and thus not filling the
faction training correctly.

This has been tested and confirmed that items from the ranged
weapon compendium are posting correctly even when their sheet has
never been opened (which populates the fields with the default
select options at render). We're also rendering properly if posted
directly from the sheet while still in the compendium.
  • Loading branch information
AugmenTab committed Jul 1, 2023
1 parent 3df39cd commit 21c1b04
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Fixes bug where weapon nickname references in the HTML templates were broken.
* Fixes bug where null value role owner references were having illegal operations performed on them.
* Fixes bug where references on postable weapon templates in chat messages would be broken for items immediately copied from the compendium packs.

## 0.3.0

Expand Down
2 changes: 1 addition & 1 deletion domain/src/Data/Types/Foundry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ instance ToJSON Weapon where
, "type" .= weaponType w
, "magazineCapacity" .= weaponMagCap w
, "ammo" .= weaponAmmo w
, "ammoGroup" .= weaponGroup w
, "ammoGroup" .= weaponAmmoGroup w
, "scopeMagnification" .= weaponScopeMag w
, "scopeMinimum" .= valueRatio 1
, "owner" .= nullJSON
Expand Down
15 changes: 15 additions & 0 deletions domain/src/Data/Types/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ data AmmoGroup
| MRC
| BruteShot

instance ToJSON AmmoGroup where
toJSON = toJSON . ammoGroupToText

ammoGroupToText :: AmmoGroup -> T.Text
ammoGroupToText ag =
case ag of
None -> "none"
STD -> "std"
Shotgun -> "shotgun"
Flamethrower -> "flamethrower"
Sniper -> "sniper"
Grenade -> "grenade"
MRC -> "mrc"
BruteShot -> "bruteShot"

newtype AmmoList = AmmoList [Ammunition]

instance ToJSON AmmoList where
Expand Down
2 changes: 1 addition & 1 deletion domain/src/Domain/Convert/Foundry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ mkRanged :: Maybe Faction
-> RawRangedBase
-> Either T.Text FoundryData
mkRanged mbFaction raw rawBase = do
let faction = eitherToMaybe . factionFromText $ rawRangedName raw
let faction = eitherToMaybe . factionFromText $ rawRangedFaction raw
(name, nickname) = mkNameAndNickname $ rawRangedName raw
weaponType = rawRangedBaseType rawBase
weaponDetails = Map.lookup (T.toUpper weaponType) weaponDetailsMap
Expand Down
2 changes: 1 addition & 1 deletion domain/src/Domain/Request.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sheetDataMap =
[ ( AbilitySheet , (GID "1007822165", Range "A2:F96") )
, ( ArmorSheet , (GID "226189720" , Range "A2:P199") )
, ( EquipmentSheet , (GID "515202982" , Range "A2:F607") )
-- , ( FloodSheet , (GID "1809814064", Range "A2:AA381") )
, ( FloodSheet , (GID "1809814064", Range "A2:AA381") )
, ( MeleeWeaponSheet , (GID "346860164" , Range "A2:AH63") )
, ( PermutationSheet , (GID "80923077" , Range "A2:F74") )
, ( RangedWeaponSheet, (GID "1510373161", Range "B2:AF397") )
Expand Down

1 comment on commit 21c1b04

@AugmenTab
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.