Extract spell constants to dedicated module with type-safe API#26
Open
MaxBittker wants to merge 1 commit intomainfrom
Open
Extract spell constants to dedicated module with type-safe API#26MaxBittker wants to merge 1 commit intomainfrom
MaxBittker wants to merge 1 commit intomainfrom
Conversation
Addresses #24 - the castSpellOnNpc API was confusing because it required opaque numeric spell component IDs with no guidance on valid values. Changes: - Add sdk/spells.ts as the canonical source for spell constants, exported as `Spells` with a `SpellName` type derived from its keys - Update castSpellOnNpc, sendSpellOnNpc, and sendSpellOnItem to accept `SpellName | number` (e.g. 'WIND_STRIKE' or 1152), following the same pattern as sendTogglePrayer which accepts PrayerName | number - Re-export Spells and SpellName from actions.ts for convenient imports - Replace inline Spells definition in save-generator.ts with re-export - Remove duplicate Spells constant from scripts/magic/script.ts - Document all spell IDs in API.md with a new Constants section Closes #24 https://claude.ai/code/session_01CjzdFWTHRru5kYDGeXgyZe
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
Refactored spell handling by extracting spell constants into a dedicated
sdk/spells.tsmodule and updated the API to accept spell names as strings in addition to numeric component IDs. This improves type safety, code organization, and developer experience.Key Changes
sdk/spells.ts: Centralized spell constant definitions with 33 spells organized by tier (strikes, bolts, blasts, waves, and other)resolveSpell()function to accept bothSpellName(string literals like'WIND_STRIKE') and numeric component IDsgetSpellName()function to map component IDs back to spell namescastSpellOnNpc(target, spell, timeout)- now acceptsSpellName | numbersendSpellOnNpc(npcIndex, spell)- now acceptsSpellName | numbersendSpellOnItem(slot, spell)- now acceptsSpellName | numbersdk/test/utils/save-generator.tsin favor of re-exporting from the canonical sourceAPI.mdwith usage examples and full spell reference tablescripts/magic/script.tsto import spells from the new moduleImplementation Details
SpellNametype for compile-time type checking of spell namessdk/actions.tsfor convenient access alongside other SDK exportshttps://claude.ai/code/session_01CjzdFWTHRru5kYDGeXgyZe