Skip to content

Commit

Permalink
LDoc - Possibly fix for Dynamic Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteOne committed Aug 16, 2023
1 parent 468bfea commit f1890ad
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 42 deletions.
48 changes: 48 additions & 0 deletions .github/generate_dynamic_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import re

# Get the directory where the script is located
script_dir = os.path.dirname(os.path.abspath(__file__))

# Directory containing the API files
API_DIR = os.path.join(script_dir, "..", "System", "API")

# Placeholder for documentation content
docs = []

# Process each file in the directory
for filename in os.listdir(API_DIR):
filepath = os.path.join(API_DIR, filename)

with open(filepath, "r") as f:
lines = f.readlines()

# Iterate over the lines and look for the @dynamicFunction tag
i = 0
while i < len(lines):
line = lines[i]
if "@dynamicFunction" in line:
func_name = re.search(r"@dynamicFunction (.+)", line).group(1)
doc_block = [f"### {func_name}\n"]
i += 1
while i < len(lines) and not lines[i].strip().startswith("cast."):
if "@description" in lines[i]:
description = re.search(r"@description (.+)", lines[i]).group(1)
doc_block.append(f"\n{description}\n")
elif "@tparam" in lines[i]:
tparam = re.search(r"@tparam (.+)", lines[i]).group(1)
doc_block.append(f"- Parameter: {tparam}")
elif "@return" in lines[i]:
return_val = re.search(r"@return (.+)", lines[i]).group(1)
doc_block.append(f"- Returns: {return_val}")
i += 1
docs.append("\n".join(doc_block) + "\n")
else:
i += 1

# Sort the documentation blocks alphabetically by function name (if desired)
docs = sorted(docs)

# Write the documentation to a Markdown file
with open(os.path.join(script_dir, "..", "DOCS.md"), "w") as f:
f.write("\n".join(docs))
1 change: 1 addition & 0 deletions .github/workflows/discord_notificaiton.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'LICENSE'
- 'Rotations/Old/**'
- 'Rotations/sample rotation.lua'
- 'System/API/**' # Temp Ignore API Folder

jobs:
Discord_notification:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/ldoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Generate Dynamic Documentation
run: python .github/generate_dynamic_docs.py

- name: Setup Lua
uses: leafo/gh-actions-lua@v8
with:
Expand All @@ -27,6 +35,9 @@ jobs:
- name: Build docs
run: ldoc .

- name: Append Dynamic Documentation to LDoc Output
run: cat DOCS.md >> ./docs/index.html # Adjust the path if LDoc outputs to a different file

- name: Deploy
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: peaceiris/actions-gh-pages@v3
Expand Down
63 changes: 21 additions & 42 deletions System/API/Cast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ br.api.cast = function(self,spell,id)
---
-- @section CastAPIFunctions

---
-- @function br.player.cast.functionForSpell
-- @dynamicFunction br.player.cast.functionForSpell
-- @description Creates a function that can be used to cast a spell based on various parameters. The function name is dynamically generated based on the spell name.
-- For example, for a spell named "thisSpell", the function would be `cast.thisSpell()`.
-- @tparam string thisUnit The target unit for the spell. Can be standard WoW units, dynamic units, or special parameters like "best", "playerGround", etc.
Expand Down Expand Up @@ -69,8 +68,7 @@ br.api.cast = function(self,spell,id)
return br.createCastFunction(thisUnit,castType,minUnits,effectRng,spellID,spell,predict,predictPad,enemies)
end

---
-- @function br.player.cast.able.functionForSpell
-- @dynamicFunction br.player.cast.able.functionForSpell
-- @description Checks if a spell can be cast based on various parameters and returns True/False.
-- @tparam string thisUnit The target unit for the spell. Can be standard WoW units, dynamic units, or special parameters.
-- @tparam string castType Defines the type of AoE or special cast conditions.
Expand Down Expand Up @@ -100,8 +98,7 @@ br.api.cast = function(self,spell,id)
return br.createCastFunction(thisUnit,castType,minUnits,effectRng,spellID,spell,predict,predictPad,enemies,true)
end

---
-- @function br.player.cast.active.functionForSpell
-- @dynamicFunction br.player.cast.active.functionForSpell
-- @description Returns if the spell is the one currently being cast.
-- @tparam string thisUnit The unit to check if it's casting the spell. Can be standard WoW units or dynamic units.
-- @return True/False
Expand All @@ -110,16 +107,14 @@ br.api.cast = function(self,spell,id)
return br.isCastingSpell(id,thisUnit)
end

---
-- @function br.player.cast.auto.functionForSpell
-- @dynamicFunction br.player.cast.auto.functionForSpell
-- @description Checks if the spell is set to auto-repeat or if it's the current spell being cast.
-- @return True/False
cast.auto[spell] = function()
return br._G.IsAutoRepeatSpell(br._G.GetSpellInfo(id)) or br._G.IsCurrentSpell(id)
end

---
-- @function br.player.cast.cancel.functionForSpell
-- @dynamicFunction br.player.cast.cancel.functionForSpell
-- @description Cancels the current spell being cast if it matches the specified spell.
-- @return True/False
cast.cancel[spell] = function()
Expand All @@ -131,8 +126,7 @@ br.api.cast = function(self,spell,id)
return false
end

---
-- @function br.player.cast.cost.functionForSpell
-- @dynamicFunction br.player.cast.cost.functionForSpell
-- @description Returns the cost of the spell.
-- @tparam boolean altPower Set to "true" to return alternate power cost.
-- @return The cost of the spell.
Expand All @@ -145,8 +139,7 @@ br.api.cast = function(self,spell,id)
end
end

---
-- @function br.player.cast.current.functionForSpell
-- @dynamicFunction br.player.cast.current.functionForSpell
-- @description Returns if the spell is the currently cast spell for the target (Alternate to br.player.cast.active.spell()).
-- @tparam string thisUnit Acceptable parameters: nil (defaults to "player"), standard WoW units, or dynamic units.
-- @return True/False
Expand All @@ -163,8 +156,7 @@ br.api.cast = function(self,spell,id)
return br.botSpell
end

---
-- @function br.player.cast.dispel.functionForSpell
-- @dynamicFunction br.player.cast.dispel.functionForSpell
-- @description Returns if the spell if capable of dispelling the target.
-- @tparam string thisUnit Acceptable parameters: nil (defaults to "target"), standard WoW units, or dynamic units.
-- @return True/False
Expand All @@ -173,8 +165,7 @@ br.api.cast = function(self,spell,id)
return br.canDispel(thisUnit,id) or false
end

---
-- @function br.player.cast.empowered.functionForSpell
-- @dynamicFunction br.player.cast.empowered.functionForSpell
-- @description Returns current empowered rank of the spell or 0 if not empowered.
-- @return The current empowered rank of the spell.
cast.empowered[spell] = function()
Expand All @@ -192,8 +183,7 @@ br.api.cast = function(self,spell,id)
return CastShapeshiftForm(formIndex)
end

---
-- @function br.player.cast.inFlight.functionForSpell
-- @dynamicFunction br.player.cast.inFlight.functionForSpell
-- @description Returns if the spell is currently in flight to the target.
-- @tparam string thisUnit Acceptable parameters: nil (defaults to "target"), standard WoW units, or dynamic units.
-- @return True/False
Expand All @@ -202,17 +192,15 @@ br.api.cast = function(self,spell,id)
return br.InFlight.Check(id, thisUnit)
end

---
-- @function br.player.cast.inFlightRemain.functionForSpell
-- @dynamicFunction br.player.cast.inFlightRemain.functionForSpell
-- @description Returns time remaining on a spell in flight to the target.
-- @tparam string thisUnit The target unit to check for the spell in flight.
-- @return Time remaining on the spell in flight.
cast.inFlightRemain[spell] = function(thisUnit)
return br.InFlight.Remain(id, thisUnit)
end

---
-- @function br.player.cast.last.functionForSpell
-- @dynamicFunction br.player.cast.last.functionForSpell
-- @description Returns if the spell was the last one cast or not.
-- @tparam number index Number of last cast spell up to 10 previous spells, default value is 1 if not provided.
-- @return True/False
Expand All @@ -222,17 +210,15 @@ br.api.cast = function(self,spell,id)
return tracker[index] and tracker[index] == id
end

---
-- @function br.player.cast.last.time.functionForSpell
-- @dynamicFunction br.player.cast.last.time.functionForSpell
-- @description Returns the GetTime() value the last cast of this spell occurred.
-- @return The last time the spell was cast.
cast.last.time[spell] = function()
if br.lastCastTable.castTime[id] == nil then br.lastCastTable.castTime[id] = br._G.GetTime() end
return br.lastCastTable.castTime[id]
end

---
-- @function br.player.cast.noControl.functionForSpell
-- @dynamicFunction br.player.cast.noControl.functionForSpell
-- @description Returns true if the spell can free you of a "no control" effect.
-- @tparam string thisUnit The target unit to check for the "no control" effect. Defaults to "player" if not provided.
-- @return True/False
Expand Down Expand Up @@ -266,8 +252,7 @@ br.api.cast = function(self,spell,id)
return castOpenerFail(thisSpell,thisTracker,thisCount)
end

---
-- @function br.player.cast.pool.functionForSpell
-- @dynamicFunction br.player.cast.pool.functionForSpell
-- @description Returns true if specified power requirements are not met.
-- @tparam boolean altPower Set to "true" to return alternate power cost. Defaults to false if not provided.
-- @tparam number specificAmt Set to specified power amount. Defaults to 0 if not provided.
Expand All @@ -283,24 +268,21 @@ br.api.cast = function(self,spell,id)
power[powerType].amount() < specificAmt
end

---
-- @function br.player.cast.range.functionForSpell
-- @dynamicFunction br.player.cast.range.functionForSpell
-- @description Returns the spell's range, if it has one.
-- @return The spell's range.
cast.range[spell] = function()
return br.getSpellRange(id)
end

---
-- @function br.player.cast.regen.functionForSpell
-- @dynamicFunction br.player.cast.regen.functionForSpell
-- @description Returns the amount of power spell will generate when cast.
-- @return The amount of power spell will generate.
cast.regen[spell] = function()
return br.getCastingRegen(id)
end

---
-- @function br.player.cast.safe.functionForSpell
-- @dynamicFunction br.player.cast.safe.functionForSpell
-- @description Return if safe to cast specified aoe spell on unit given the aoe dimensions.
-- @tparam string thisUnit The target unit to check for safety. Defaults to "target" if not provided.
-- @tparam string aoeType The type of AoE to check for safety. Can be "rect", "cone", "ground", or "aoe".
Expand All @@ -311,17 +293,15 @@ br.api.cast = function(self,spell,id)
return br.isSafeToAoE(id,thisUnit,effectRng,minUnits,aoeType)
end

---
-- @function br.player.cast.time.functionForSpell
-- @dynamicFunction br.player.cast.time.functionForSpell
-- @description Return cast time of player's spell. If the spell has no cast time, it returns the global cooldown.
-- @return The cast time of the spell.
cast.time[spell] = function()
local castTime = br.getCastTime(id)
return castTime > 0 and castTime or br.getGlobalCD(true)
end

---
-- @function br.player.cast.timeRemain
-- @dynamicFunction br.player.cast.timeRemain
-- @description Return cast time remaining on player's cast or supplied target.
-- @tparam string thisUnit The unit to check cast time remaining. Defaults to "player" if not provided.
-- @return The cast time remaining.
Expand All @@ -330,8 +310,7 @@ br.api.cast = function(self,spell,id)
return br.getCastTimeRemain(thisUnit)
end

---
-- @function br.player.cast.timeSinceLast.functionForSpell
-- @dynamicFunction br.player.cast.timeSinceLast.functionForSpell
-- @description Returns the time since the last cast of this spell occurred.
-- @return The time since the last cast of this spell occurred.
cast.timeSinceLast[spell] = function()
Expand Down

0 comments on commit f1890ad

Please sign in to comment.