Skip to content

Commit

Permalink
[Eluna] updated Eluna to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1arm committed Sep 29, 2024
1 parent 6fe020a commit c33672c
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 456 deletions.
2 changes: 1 addition & 1 deletion src/modules/Eluna/.github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
fail-fast: false
matrix:
eluna: [ON, OFF]
patch: [zero, one, two]
patch: [zero, one, two, three]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
60 changes: 51 additions & 9 deletions src/modules/Eluna/docs/ElunaDoc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import typing
import markdown
from typedecorator import params, returns, Nullable
from typing import Any, List, TypedDict

class TableDict(TypedDict):
columns: List[str]
values: List[List[Any]]

class ParameterDoc(object):
"""The documentation data of a parameter or return value for an Eluna method."""
Expand Down Expand Up @@ -64,13 +68,24 @@ def __init__(self, name, data_type, description, default_value=None):

class MethodDoc(object):
"""The documentation data of an Eluna method."""
@params(self=object, name=str, description=str, prototypes=[str], parameters=[ParameterDoc], returned=[ParameterDoc])
def __init__(self, name, description, prototypes, parameters, returned):
@params(self=object, name=str, description=str, table=TableDict, prototypes=[str], parameters=[ParameterDoc], returned=[ParameterDoc])
def __init__(self, name, description, table, prototypes, parameters, returned):
self.name = name
self.prototypes = prototypes
self.table = table
self.parameters = parameters
self.returned = returned


if table:
# Generate Markdown Table
md_table = '| ' + ' | '.join(table['columns']) + ' |\n' # Header
md_table += '| ' + ' | '.join(['---'] * len(table['columns'])) + ' |\n' # Separator

for row in table['values']:
md_table += '| ' + ' | '.join(row) + ' |\n' # Rows

self.table = markdown.markdown(md_table, extensions=['tables'])

# Parse the description as Markdown.
self.description = markdown.markdown(description)
# Pull the first paragraph out of the description as the short description.
Expand Down Expand Up @@ -121,7 +136,12 @@ class ClassParser(object):
start_regex = re.compile(r"\s*/\*\*") # The start of documentation, i.e. /**
body_regex = re.compile(r"\s*\s?\*\s?(.*)") # The "body", i.e. a * and optionally some descriptive text.
# An extra optional space (\s?) was thrown in to make it different from `class_body_regex`.


# Regular expressions for parsing a table.
table_regex = re.compile(r"\s*\*\s@table")
table_columns_regex = re.compile(r"\s*\*\s@columns\s*\[(.+)\]")
table_values_regex = re.compile(r"\s*\*\s@values\s*\[(.+)\]")

param_regex = re.compile(r"""\s*\*\s@param\s # The @param tag starts with opt. whitespace followed by "* @param ".
([^\s]+)\s(\w+)? # The data type, a space, and the name of the param.
(?:\s=\s(\w+))? # The default value: a = surrounded by spaces, followed by text.
Expand Down Expand Up @@ -162,6 +182,7 @@ def reset(self):
self.returned = []
self.method_name = None
self.prototypes = []
self.table = {}

def handle_class_body(self, match):
text = match.group(1)
Expand All @@ -171,6 +192,21 @@ def handle_body(self, match):
text = match.group(1)
self.description += text + '\n'

def handle_table(self, line):
self.table = {
"columns": [],
"values": []
}

def handle_table_columns(self, match):
if self.table:
self.table["columns"] = match.group(1).split(", ")

def handle_table_values(self, match):
if self.table:
values = re.findall(r'(?:[^,"]|"(?:\\.|[^"])*")+', match.group(1))
self.table["values"].append([v.strip(' "') for v in values])

def handle_param(self, match):
data_type, name, default, description = match.group(1), match.group(2), match.group(3), match.group(4)
self.params.append(ParameterDoc(name, data_type, description, default))
Expand Down Expand Up @@ -246,7 +282,7 @@ def make_prototype(parameters):
# Format the method name into each prototype.
self.prototypes = [proto.format(self.method_name) for proto in self.prototypes]

self.methods.append(MethodDoc(self.method_name, self.description, self.prototypes, self.params, self.returned))
self.methods.append(MethodDoc(self.method_name, self.description, self.table, self.prototypes, self.params, self.returned))

# Table of which handler is used to handle each regular expressions.
regex_handlers = {
Expand All @@ -255,6 +291,9 @@ def make_prototype(parameters):
class_end_regex: None,
start_regex: None,
body_regex: handle_body,
table_regex: handle_table,
table_columns_regex: handle_table_columns,
table_values_regex: handle_table_values,
param_regex: handle_param,
return_regex: handle_return,
proto_regex: handle_proto,
Expand All @@ -269,10 +308,13 @@ def make_prototype(parameters):
class_start_regex: [class_end_regex, class_body_regex],
class_body_regex: [class_end_regex, class_body_regex],
class_end_regex: [],
start_regex: [param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
body_regex: [param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
proto_regex: [param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
param_regex: [param_regex, return_regex, comment_end_regex, body_regex],
start_regex: [table_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
body_regex: [table_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
proto_regex: [table_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
table_regex: [table_regex, table_columns_regex, param_regex, return_regex, comment_end_regex, body_regex],
table_columns_regex: [table_values_regex, param_regex, return_regex, comment_end_regex, body_regex],
table_values_regex: [table_values_regex, param_regex, return_regex, comment_end_regex, body_regex],
param_regex: [table_regex, param_regex, return_regex, comment_end_regex, body_regex],
return_regex: [return_regex, comment_end_regex],
comment_end_regex: [end_regex],
end_regex: [],
Expand Down
36 changes: 35 additions & 1 deletion src/modules/Eluna/docs/ElunaDoc/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,41 @@ nav.sub {
min-height: 100%;
}

.content, nav { max-width: 960px; }
.content, nav { max-width: 80vw; }

.docblock .table-container {
width: 100%;
overflow-x: auto;
margin-bottom: 20px;
}

.docblock table {
max-width: 50vw;
border-collapse: collapse !important;
table-layout: auto;
margin-bottom: 20px;
font-family: "Source Code Pro", Menlo, Monaco, Consolas, "DejaVu Sans Mono", Inconsolata, monospace;
}

.docblock th, .docblock td {
padding: 10px;
text-align: left;
border: 1px solid #ddd;
white-space: nowrap;
}

.docblock th {
background-color: #f5f5f5;
font-weight: bold;
}

.docblock tr:nth-child(even) {
background-color: #f9f9f9;
}

.docblock table {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Everything else */

Expand Down
11 changes: 10 additions & 1 deletion src/modules/Eluna/docs/ElunaDoc/templates/method.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ <h2>{{ current_class.name }} Methods</h2>
<p>This method is <em>undocumented</em>. <strong>Use at your own risk.</strong></p>
<p>For temporary documentation, please check the <a href="https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp">LuaFunctions</a> source file.</p>
{%- endif %}


{%- if current_method.table %}
<div class="table-container">
<p>
{{ current_method.table }}
</p>
</div>
{%- endif %}


<h2 id="synopsis" class='section-header'>
<a href="#synopsis">Synopsis</a>
</h2>
Expand Down
7 changes: 5 additions & 2 deletions src/modules/Eluna/methods/CMangos/ItemMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,12 +845,15 @@ namespace LuaItem
#else
{ "IsCurrencyToken", METHOD_REG_NONE },
#endif
#if ELUNA_EXPANSION == EXP_WOTLK
#if ELUNA_EXPANSION >= EXP_WOTLK
{ "IsBoundAccountWide", &LuaItem::IsBoundAccountWide },
#else
{ "IsBoundAccountWide", METHOD_REG_NONE },
#endif
#if ELUNA_EXPANSION == EXP_WOTLK
{ "IsWeaponVellum", &LuaItem::IsWeaponVellum },
{ "IsArmorVellum", &LuaItem::IsArmorVellum },
#else
{ "IsBoundAccountWide", METHOD_REG_NONE },
{ "IsWeaponVellum", METHOD_REG_NONE },
{ "IsArmorVellum", METHOD_REG_NONE },
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/modules/Eluna/methods/CMangos/PlayerMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ namespace LuaPlayer
}
#endif

#if ELUNA_EXPANSION == EXP_WOTLK
#if ELUNA_EXPANSION >= EXP_WOTLK
/**
* Returns the normal phase of the player instead of the actual phase possibly containing GM phase
*
Expand Down Expand Up @@ -3802,7 +3802,7 @@ namespace LuaPlayer
{ "GetArenaPoints", METHOD_REG_NONE },
{ "GetHonorPoints", METHOD_REG_NONE },
#endif
#if ELUNA_EXPANSION == EXP_WOTLK
#if ELUNA_EXPANSION >= EXP_WOTLK
{ "GetPhaseMaskForSpawn", &LuaPlayer::GetPhaseMaskForSpawn },
{ "GetActiveSpec", &LuaPlayer::GetActiveSpec },
{ "GetSpecsCount", &LuaPlayer::GetSpecsCount },
Expand Down Expand Up @@ -3916,7 +3916,7 @@ namespace LuaPlayer
{ "CanFly", METHOD_REG_NONE },
{ "IsFlying", METHOD_REG_NONE },
#endif
#if ELUNA_EXPANSION == EXP_WOTLK
#if ELUNA_EXPANSION >= EXP_WOTLK
{ "HasAchieved", &LuaPlayer::HasAchieved },
{ "HasTalent", &LuaPlayer::HasTalent },
{ "CanTitanGrip", &LuaPlayer::CanTitanGrip },
Expand Down Expand Up @@ -4019,7 +4019,7 @@ namespace LuaPlayer
{ "ModifyHonorPoints", METHOD_REG_NONE },
{ "ModifyArenaPoints", METHOD_REG_NONE },
#endif
#if ELUNA_EXPANSION == EXP_WOTLK
#if ELUNA_EXPANSION >= EXP_WOTLK
{ "ResetPetTalents", &LuaPlayer::ResetPetTalents },
{ "ResetAchievements", &LuaPlayer::ResetAchievements },
{ "SendMovieStart", &LuaPlayer::SendMovieStart },
Expand Down
78 changes: 74 additions & 4 deletions src/modules/Eluna/methods/CMangos/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,71 @@ namespace LuaUnit
return 0;
}

/**
* Returns whether or not the [Unit] can have stat modifiers applied.
*
* @return bool canModifyStats
*/
int CanModifyStats(Eluna* E, Unit* unit)
{
E->Push(unit->CanModifyStats());
return 1;
}

/**
* Modifies a flat amount of a specific stat of the [Unit]
*
* <pre>
* enum UnitModifierFlatType
* {
* BASE_VALUE = 0,
* TOTAL_VALUE = 1
* };
* </pre>
*
* @param uint32 statType : The stat to modify
* @param [UnitModifierFlatType] modType : The type of modifier to apply
* @param float value : The value to apply to the stat
* @param bool apply = true : True applies a positive modifier, false applies a negative
*/
int AddFlatStatModifier(Eluna* E, Unit* unit)
{
uint32 statType = E->CHECKVAL<uint32>(2);
uint8 modType = E->CHECKVAL<uint8>(3);
float value = E->CHECKVAL<float>(4);
bool apply = E->CHECKVAL<bool>(5, true);
UnitModifierType type = (modType == 0) ? BASE_VALUE : TOTAL_VALUE;

unit->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + statType), (UnitModifierType)type, value, apply);
return 0;
}

/**
* Modifies a percentage amount of a specific stat of the [Unit]
*
* <pre>
* enum UnitModifierPctType
* {
* BASE_PCT = 0,
* TOTAL_PCT = 1
* };
* </pre>
*
* @param uint32 statType : The stat to modify
* @param [UnitModifierPctType] modType : The type of modifier to apply
* @param float value : The value to apply to the stat
*/
int AddPctStatModifier(Eluna* E, Unit* unit)
{
uint32 statType = E->CHECKVAL<uint32>(2);
uint8 modType = E->CHECKVAL<uint8>(3);
float value = E->CHECKVAL<float>(4);
UnitModifierType type = (modType == 0) ? BASE_PCT : TOTAL_PCT;

unit->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + statType), (UnitModifierType)type, value, true);
return 0;
}

ElunaRegister<Unit> UnitMethods[] =
{
// Getters
Expand Down Expand Up @@ -2528,6 +2593,7 @@ namespace LuaUnit
{ "HasAura", &LuaUnit::HasAura },
{ "IsCasting", &LuaUnit::IsCasting },
{ "IsStandState", &LuaUnit::IsStandState },
{ "CanModifyStats", &LuaUnit::CanModifyStats },

// Other
{ "AddAura", &LuaUnit::AddAura },
Expand Down Expand Up @@ -2568,12 +2634,18 @@ namespace LuaUnit
{ "MoveClear", &LuaUnit::MoveClear },
{ "DealDamage", &LuaUnit::DealDamage },
{ "DealHeal", &LuaUnit::DealHeal },
{ "AddFlatStatModifier", &LuaUnit::AddFlatStatModifier },
{ "AddPctStatModifier", &LuaUnit::AddPctStatModifier },

// Expansion specific methods
#if ELUNA_EXPANSION >= EXP_TBC
{ "IsOnVehicle", &LuaUnit::IsOnVehicle },
{ "RemoveArenaAuras", &LuaUnit::RemoveArenaAuras },
#elif ELUNA_EXPANSION >= EXP_WOTLK
#else
{ "IsOnVehicle", METHOD_REG_NONE },
{ "RemoveArenaAuras", METHOD_REG_NONE },
#endif
#if ELUNA_EXPANSION >= EXP_WOTLK
{ "GetCritterGUID", &LuaUnit::GetCritterGUID },
{ "GetVehicleKit", &LuaUnit::GetVehicleKit },
{ "SetFFA", &LuaUnit::SetFFA },
Expand All @@ -2586,8 +2658,6 @@ namespace LuaUnit
{ "SetFFA", METHOD_REG_NONE },
{ "SetSanctuary", METHOD_REG_NONE },
{ "SetCritterGUID", METHOD_REG_NONE },
{ "IsOnVehicle", METHOD_REG_NONE },
{ "RemoveArenaAuras", METHOD_REG_NONE },
{ "MoveJump", METHOD_REG_NONE },
#endif

Expand All @@ -2604,7 +2674,7 @@ namespace LuaUnit
{ "RemoveBindSightAuras", METHOD_REG_NONE }, // not implemented
{ "RemoveCharmAuras", METHOD_REG_NONE }, // not implemented
{ "DisableMelee", METHOD_REG_NONE }, // not implemented
{ "SummonGuardian", METHOD_REG_NONE } // not implemented
{ "SummonGuardian", METHOD_REG_NONE }, // not implemented
};
};
#endif
2 changes: 1 addition & 1 deletion src/modules/Eluna/methods/CMangos/WorldObjectMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ namespace LuaWorldObject
{ "GetExactDistance2d", &LuaWorldObject::GetExactDistance2d },
{ "GetRelativePoint", &LuaWorldObject::GetRelativePoint },
{ "GetAngle", &LuaWorldObject::GetAngle },
#if ELUNA_EXPANSION == EXP_WOTLK
#if ELUNA_EXPANSION > EXP_TBC
{ "GetPhaseMask", &LuaWorldObject::GetPhaseMask },
{ "SetPhaseMask", &LuaWorldObject::SetPhaseMask },
#else
Expand Down
Loading

0 comments on commit c33672c

Please sign in to comment.