feat: implement AttackType enum and conversions. Implement AttackType…#110
Closed
sasasamaes wants to merge 3 commits intoAkatsukiLabs:mainfrom
Closed
feat: implement AttackType enum and conversions. Implement AttackType…#110sasasamaes wants to merge 3 commits intoAkatsukiLabs:mainfrom
sasasamaes wants to merge 3 commits intoAkatsukiLabs:mainfrom
Conversation
… enum in attack.cairo with variants. Add Into implementations for felt252/u8. Include unit tests. Resolves AkatsukiLabs#80
jimenezz22
requested changes
May 6, 2025
…o as it was implemented in another PR. Updated lib.cairo to remove the attack_type module reference.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
This PR introduces the
AttackTypeenum 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
xall the checkboxes that apply (like[x]).lib.cairofixAttackType🔄 Changes Made
What's Changed
backend/dojo_examples/combat_game/src/types/attack.cairo.AttackTypeenum with 13 variants (Slash, Beam, Wave, Punch, Kick, Blast, Crush, Pierce, Smash, Burn, Freeze, Shock, None).Intotraits for convertingAttackTypetofelt252(string representation) andu8(numeric representation).Intotrait for convertingu8back toAttackType, handling fallback cases toAttackType::None.attack.cairo.backend/dojo_examples/combat_game/src/lib.cairoby removing duplicate module declarations forbagandbattle_status.Implementation Details
AttackTypeenum 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 uniqueu8value (0-12).impl Into<u8, AttackType>uses a match statement to convertu8values back, with a wildcard_pattern mapping any other value toAttackType::None.#[cfg(test)] mod tests {}block inattack.cairoand use standardassertcalls.lib.cairoinvolved removing redundantpub modlines.Technical Notes
lib.cairowas necessary to allow the project tests (including the newAttackTypetests) to compile and run successfully.🔧 Tests Results
Describe the tests you performed to verify your changes.
sozo testwithin thebackend/dojo_examples/combat_game/directory.AttackTypeconversions.Test Coverage
Evidence
Testing Notes
AttackTypevariant for both-> felt252and-> u8conversions.u8 -> AttackTypetests cover all valid mappings (0-12) and also check fallback cases for out-of-range values (e.g., 13, 255) correctly mapping toAttackType::None.🔜 Next Steps
AttackTypeinto the actual combat system logic (e.g., inbattlesystem or related models) where attack types are used.