Skip to content

Comments

feat: implement AttackType enum and conversions. Implement AttackType…#110

Closed
sasasamaes wants to merge 3 commits intoAkatsukiLabs:mainfrom
sasasamaes:feat/implement-attack
Closed

feat: implement AttackType enum and conversions. Implement AttackType…#110
sasasamaes wants to merge 3 commits intoAkatsukiLabs:mainfrom
sasasamaes:feat/implement-attack

Conversation

@sasasamaes
Copy link

📝 Summary

This PR introduces the AttackType enum and its associated conversions as specified in issue #80. This provides a standardized way to handle different attack types within the combat game, improving type safety and consistency for combat mechanics. It also includes fixes for unrelated compilation errors discovered during testing.

Related Issues

Type of Change

Mark with an x all the checkboxes that apply (like [x]).

  • 📝 Documentation (updates to README, docs, or comments)
  • 🐛 Bug fix (non-breaking change which fixes an issue) - Only for the lib.cairo fix
  • 👌 Enhancement (non-breaking change which adds functionality) - Primary purpose: AttackType
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)

🔄 Changes Made

What's Changed

  • Created backend/dojo_examples/combat_game/src/types/attack.cairo.
  • Defined the AttackType enum with 13 variants (Slash, Beam, Wave, Punch, Kick, Blast, Crush, Pierce, Smash, Burn, Freeze, Shock, None).
  • Implemented Into traits for converting AttackType to felt252 (string representation) and u8 (numeric representation).
  • Implemented Into trait for converting u8 back to AttackType, handling fallback cases to AttackType::None.
  • Added comprehensive unit tests for all conversion functions within attack.cairo.
  • Fixed compilation errors in backend/dojo_examples/combat_game/src/lib.cairo by removing duplicate module declarations for bag and battle_status.

Implementation Details

  • The AttackType enum uses #[derive(Copy, Drop, Serde)] for basic functionality.
  • impl Into<AttackType, felt252> provides string names for each attack type.
  • impl Into<AttackType, u8> maps each variant to a unique u8 value (0-12).
  • impl Into<u8, AttackType> uses a match statement to convert u8 values back, with a wildcard _ pattern mapping any other value to AttackType::None.
  • Tests are located within a #[cfg(test)] mod tests {} block in attack.cairo and use standard assert calls.
  • The fix in lib.cairo involved removing redundant pub mod lines.

Technical Notes

  • The fix in lib.cairo was necessary to allow the project tests (including the new AttackType tests) to compile and run successfully.

🔧 Tests Results

Describe the tests you performed to verify your changes.

  • Executed sozo test within the backend/dojo_examples/combat_game/ directory.
  • All 44 tests in the suite passed, including the newly added tests for AttackType conversions.

Test Coverage

  • Unit Tests
  • Integration Tests
  • Manual Testing

Evidence

Screenshot 2025-05-03 at 11 09 06 AM

Testing Notes

  • The unit tests cover every AttackType variant for both -> felt252 and -> u8 conversions.
  • The u8 -> AttackType tests cover all valid mappings (0-12) and also check fallback cases for out-of-range values (e.g., 13, 255) correctly mapping to AttackType::None.

🔜 Next Steps

  • Integrate AttackType into the actual combat system logic (e.g., in battle system or related models) where attack types are used.

… enum in attack.cairo with variants. Add Into implementations for felt252/u8. Include unit tests. Resolves AkatsukiLabs#80
Copy link
Contributor

@jimenezz22 jimenezz22 left a comment

Choose a reason for hiding this comment

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

This enum had to be implemented in another PR because it was necessary. So instead, delete this file you created and run a couple of tests on the enum in the path: /src/types/skill.cairo

@jimenezz22 jimenezz22 added the Changes Requested PR with changes requested label May 6, 2025
…o as it was implemented in another PR. Updated lib.cairo to remove the attack_type module reference.
@coxmars coxmars closed this May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changes Requested PR with changes requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📝 [FEAT]: Implement attack.cairo type for game combat mechanics

3 participants