Skip to main content

tool that finds the first SpellScript by searching for public SpellScriptLoader in a file and converts it to use registry macros

Project description

Spellscript Refactor Tool for AzerothCore

Python tool to convert spellscript(s) to use registry macros (see official wiki https://www.azerothcore.org/wiki/core-scripts)

The acore_spellscript_refactor tool provides modules to refactor spellscripts to use registry macros (see official wiki https://www.azerothcore.org/wiki/core-scripts).

Disclaimer: This tool is dumb. It finds the first SpellScript by searching for public SpellScriptLoader in a file and converts it. It does not add enums for magic numbers, and may remove variables; some manual work is required, but it is a good first pass

Features

  • convert AuraScript
  • convert SpellScript
  • convert Spell- and Aurascript Pairs
  • add bool Validate... if it does not exist already
  • read/write to file
  • create skeleton update statement spell_script_names to script_name.sql if type is _aura
  • fill in spell_ids skeleton update with spell_ids from table acore_world spell_script_names
  • --skip to specify line number to search for SpellScript
  • --verbose/-v to output debug info
  • --sql-file to write script_name updates to specific file
  • discover runs repeatedly on all *cpp in directory
  • spell scripts with args
  • magic numbers to Enum

See sample log./refactor.log

Install

The acore-spellscript-refactor package is published on Test PyPI for testing and development purposes. Follow the steps below to install it.

Installation Steps

  1. Clone the Repository (Optional)
    If you want to work with the source code, clone the repository to your local machine:

    git clone https://github.com/your-username/acore-spellscript-refactor.git
    cd acore-spellscript-refactor
    pip install -e .
    
  2. Install from Test PyPI
    To install the latest version of acore-spellscript-refactor from Test PyPI, use the following command:

    pip install acore-spellscript-refactor
    

    This installs the package and all required dependencies from the Test PyPI repository.

  3. Verify the Installation
    Confirm the installation by running:

    python3 -m acore_spellscript_refactor.main --help
    

For more information, visit the acore-spellscript-refactor page on Test PyPI.

Usage

This covers basic usage, command options, and examples for the main and discover modules.

To create a rev_*.sql file, use create_sql.sh

./data/sql/updates/pending_db_world/create_sql.sh

In the sections below $REV_SQL refers to absolute path of this created rev_*.sql.

REV_SQL="/azerothcore-wotlk/data/sql/updates/pending_db_world/rev_1730477106741869456.sql"

note: for file arguments, use absolute paths

Examples

Using main

The main module refactors a single script file at a time or all scripts within a directory.

Refactoring a Single Script with Line Offset

To refactor a single script file and specify an offset (e.g., skip the first 950 lines):

python3 -m acore_spellscript_refactor.main "/azerothcore-wotlk/src/server/scripts/Northrend/Ulduar/Ulduar/boss_xt002.cpp" --skip 950
python3 -m acore_spellscript_refactor.main `realpath boss_xt002.cpp` --skip 950
python3 -m acore_spellscript_refactor.main `realpath boss_xt002.cpp` --skip 950 --verbose
Refactoring All Scripts in a Directory

To refactor all .cpp files in a directory, use xargs to iterate through each file:

ls *cpp | xargs -n 1 -I {} python3 -m acore_spellscript_refactor.main `realpath {}`
Command Options
  1. Specify input and output files:

    • Provide an input_file and output_file to save results to a specific file.
    python3 -m acore_spellscript_refactor.main input_file output_file
    
  2. Overwrite input file:

    • Use the same file for both input_file and output_file to overwrite.
    python3 -m acore_spellscript_refactor.main input_file input_file
    
  3. Default single file refactor:

    • Refactor a single file without specifying an output, defaults to overwriting the input_file.
    python3 -m acore_spellscript_refactor.main input_file
    
  4. Skip a specified number of lines:

    • Use --skip to ignore a set number of lines.
    python3 -m acore_spellscript_refactor.main input_file output_file --skip 1200
    
  5. Use with SQL file generation:

    • Refactor with associated SQL queries stored in a specified file.
    python3 -m acore_spellscript_refactor.main input_file output_file --skip 1200 --sql_file $REV_SQL
    
  6. Commit changes:

    • Add the --commit flag to save changes with an optional SQL file for database updates.
    python3 -m acore_spellscript_refactor.main input_file --commit --sql_file $REV_SQL
    

Using discover

The discover module finds .cpp files and creates commits and SQL files as necessary.

Example Usage
  1. Commit all discovered files:

    • Specify a .sql file for database changes, or allow discover to auto-create one by omitting --sql_file
    python3 -m acore_spellscript_refactor.discover --commit --sql_file $REV_SQL
    
  2. Run on all scripts in a directory:

    • Set the working directory to azerothcore-wotlk/src/server/scripts/***/scripts_folder and recursively discover .cpp files.
    python3 -m acore_spellscript_refactor.discover --commit --recursive --sql_file $REV_SQL
    
  3. Run on all scripts:

    • Set the working directory to azerothcore-wotlk/src/server/scripts and recursively discover .cpp files.
    python3 -m acore_spellscript_refactor.discover --commit --recursive --sql_file $REV_SQL
    

Development

Run tests

pytest .

Development

pip install -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

acore_spellscript_refactor-1.8.4.tar.gz (224.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

acore_spellscript_refactor-1.8.4-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file acore_spellscript_refactor-1.8.4.tar.gz.

File metadata

File hashes

Hashes for acore_spellscript_refactor-1.8.4.tar.gz
Algorithm Hash digest
SHA256 fcba7194afcb1ba63543de999a368d919cedfffdf5dfa81c28d14186cc51e5a2
MD5 9d42c3999b07742d383d3c175a1c1794
BLAKE2b-256 749696bd307fa00841861ba7a677dfeb3daab43fac8c2c0b1037605031b1c678

See more details on using hashes here.

File details

Details for the file acore_spellscript_refactor-1.8.4-py3-none-any.whl.

File metadata

File hashes

Hashes for acore_spellscript_refactor-1.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 03c2c7585d6ec0248a7f4e3b7302053e4de99b290152b2d119d7aab6b4025c1a
MD5 6e2b9c54493186ebcadeb2ed8a506a29
BLAKE2b-256 53099742e7ad6f2d5e9dccf8304315e57100bfb4fd0b9f38605a415e1b8508f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page