Skip to content

Commit 694018f

Browse files
0x1NotMeclaude
andcommitted
refactor: add EquipmentInfo struct for cleaner equipment getter returns
- Add EquipmentInfo struct to Types.sol for grouped equipment data - Update _getEquippableWeapons to return EquipmentInfo struct - Update _getEquippableArmor to return EquipmentInfo struct - Update pollForFrontendData to use the new struct return values - Improves code readability by grouping related return values 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8a4b36f commit 694018f

2 files changed

Lines changed: 34 additions & 31 deletions

File tree

src/battle-nads/Getters.sol

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
Inventory,
1111
Weapon,
1212
Armor,
13-
DataFeed
13+
DataFeed,
14+
EquipmentInfo
1415
} from "./Types.sol";
1516

1617
import { SessionKeyData } from "lib/fastlane-contracts/src/common/relay/types/GasRelayTypes.sol";
@@ -68,8 +69,14 @@ contract Getters is TaskHandler {
6869
}
6970
combatants = _getCombatantBattleNads(characterID);
7071
noncombatants = _getNonCombatantBattleNads(characterID);
71-
(equipableWeaponIDs, equipableWeaponNames,) = _getEquippableWeapons(characterID);
72-
(equipableArmorIDs, equipableArmorNames,) = _getEquippableArmor(characterID);
72+
73+
EquipmentInfo memory weaponInfo = _getEquippableWeapons(characterID);
74+
equipableWeaponIDs = weaponInfo.itemIDs;
75+
equipableWeaponNames = weaponInfo.itemNames;
76+
77+
EquipmentInfo memory armorInfo = _getEquippableArmor(characterID);
78+
equipableArmorIDs = armorInfo.itemIDs;
79+
equipableArmorNames = armorInfo.itemNames;
7380
if (startBlock >= block.number) {
7481
startBlock = block.number - 1;
7582
} else if (startBlock < block.number - 20) {
@@ -384,18 +391,12 @@ contract Getters is TaskHandler {
384391
/**
385392
* @notice Get weapons that a character can equip
386393
* @param characterID ID of the character
387-
* @return weaponIDs Array of equippable weapon IDs
388-
* @return weaponNames Array of weapon names
389-
* @return currentWeaponID Currently equipped weapon ID
394+
* @return equipmentInfo Struct containing weapon IDs, names, and current weapon
390395
*/
391-
function _getEquippableWeapons(bytes32 characterID)
392-
internal
393-
view
394-
returns (uint8[] memory weaponIDs, string[] memory weaponNames, uint8 currentWeaponID)
395-
{
396+
function _getEquippableWeapons(bytes32 characterID) internal view returns (EquipmentInfo memory equipmentInfo) {
396397
BattleNad memory character = getBattleNad(characterID);
397398
Inventory memory inv = character.inventory;
398-
currentWeaponID = character.stats.weaponID;
399+
equipmentInfo.currentItemID = character.stats.weaponID;
399400

400401
// Count available weapons
401402
uint256 weaponCount = 0;
@@ -406,37 +407,31 @@ contract Getters is TaskHandler {
406407
}
407408

408409
// Initialize arrays
409-
weaponIDs = new uint8[](weaponCount);
410-
weaponNames = new string[](weaponCount);
410+
equipmentInfo.itemIDs = new uint8[](weaponCount);
411+
equipmentInfo.itemNames = new string[](weaponCount);
411412

412413
// Fill arrays
413414
uint256 index = 0;
414415
for (uint8 i = 0; i < 64; i++) {
415416
if (inv.weaponBitmap & (1 << i) != 0) {
416-
weaponIDs[index] = i;
417-
weaponNames[index] = getWeaponName(i);
417+
equipmentInfo.itemIDs[index] = i;
418+
equipmentInfo.itemNames[index] = getWeaponName(i);
418419
index++;
419420
}
420421
}
421422

422-
return (weaponIDs, weaponNames, currentWeaponID);
423+
return equipmentInfo;
423424
}
424425

425426
/**
426427
* @notice Get armor that a character can equip
427428
* @param characterID ID of the character
428-
* @return armorIDs Array of equippable armor IDs
429-
* @return armorNames Array of armor names
430-
* @return currentArmorID Currently equipped armor ID
429+
* @return equipmentInfo Struct containing armor IDs, names, and current armor
431430
*/
432-
function _getEquippableArmor(bytes32 characterID)
433-
internal
434-
view
435-
returns (uint8[] memory armorIDs, string[] memory armorNames, uint8 currentArmorID)
436-
{
431+
function _getEquippableArmor(bytes32 characterID) internal view returns (EquipmentInfo memory equipmentInfo) {
437432
BattleNad memory character = getBattleNad(characterID);
438433
Inventory memory inv = character.inventory;
439-
currentArmorID = character.stats.armorID;
434+
equipmentInfo.currentItemID = character.stats.armorID;
440435

441436
// Count available armor
442437
uint256 armorCount = 0;
@@ -447,20 +442,20 @@ contract Getters is TaskHandler {
447442
}
448443

449444
// Initialize arrays
450-
armorIDs = new uint8[](armorCount);
451-
armorNames = new string[](armorCount);
445+
equipmentInfo.itemIDs = new uint8[](armorCount);
446+
equipmentInfo.itemNames = new string[](armorCount);
452447

453448
// Fill arrays
454449
uint256 index = 0;
455450
for (uint8 i = 0; i < 64; i++) {
456451
if (inv.armorBitmap & (1 << i) != 0) {
457-
armorIDs[index] = i;
458-
armorNames[index] = getArmorName(i);
452+
equipmentInfo.itemIDs[index] = i;
453+
equipmentInfo.itemNames[index] = getArmorName(i);
459454
index++;
460455
}
461456
}
462457

463-
return (armorIDs, armorNames, currentArmorID);
458+
return equipmentInfo;
464459
}
465460

466461
function _shortfallToRecommendedBalanceInMON(BattleNad memory player)

src/battle-nads/Types.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,11 @@ struct DataFeed {
214214
Log[] logs;
215215
string[] chatLogs;
216216
}
217+
218+
// Typed return structs for cleaner function signatures
219+
220+
struct EquipmentInfo {
221+
uint8[] itemIDs;
222+
string[] itemNames;
223+
uint8 currentItemID;
224+
}

0 commit comments

Comments
 (0)