From 21c1b04cf02992e09bb8fad27d5a6f71aa215934 Mon Sep 17 00:00:00 2001 From: AugmenTab Date: Sat, 1 Jul 2023 16:18:59 -0500 Subject: [PATCH] Fixes ranged weapon faction parsing and ammo group ToJSON 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. --- CHANGELOG.md | 1 + domain/src/Data/Types/Foundry.hs | 2 +- domain/src/Data/Types/Prelude.hs | 15 +++++++++++++++ domain/src/Domain/Convert/Foundry.hs | 2 +- domain/src/Domain/Request.hs | 2 +- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa7990b..d0ad18c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/domain/src/Data/Types/Foundry.hs b/domain/src/Data/Types/Foundry.hs index 73df22b..01906c1 100644 --- a/domain/src/Data/Types/Foundry.hs +++ b/domain/src/Data/Types/Foundry.hs @@ -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 diff --git a/domain/src/Data/Types/Prelude.hs b/domain/src/Data/Types/Prelude.hs index 94603f9..b2c95a1 100644 --- a/domain/src/Data/Types/Prelude.hs +++ b/domain/src/Data/Types/Prelude.hs @@ -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 diff --git a/domain/src/Domain/Convert/Foundry.hs b/domain/src/Domain/Convert/Foundry.hs index 19e6326..2f5df0e 100644 --- a/domain/src/Domain/Convert/Foundry.hs +++ b/domain/src/Domain/Convert/Foundry.hs @@ -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 diff --git a/domain/src/Domain/Request.hs b/domain/src/Domain/Request.hs index bb2425f..449faee 100644 --- a/domain/src/Domain/Request.hs +++ b/domain/src/Domain/Request.hs @@ -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") )