Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMMY(animHelper): Create emmylua annotations for animHelper #32

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions scripts/animHelper.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
tableHelper = require("tableHelper")

--- Master table for all animHelper functions
--- @class AnimHelper
--- @field GetAnimation fun(pid: PlayerID, animAlias: string): string
--- @field GetValidList fun(pid: PlayerID): string[]
local animHelper = {}

--- Literal animation names common to all races and genders
--- @class AnimTable
--- @field animNames string[]
local defaultAnimNames = { "hit1", "hit2", "hit3", "hit4", "hit5", "idle2", "idle3", "idle4",
"idle5", "idle6", "idle7", "idle8", "idle9", "pickprobe" }

--- Animation names common to all races and genders
--- @class AnimAliases
local generalAnimAliases = { act_impatient = "idle6", check_missing_item = "idle9", examine_hand = "idle7",
look_behind = "idle3", shift_feet = "idle2", scratch_neck = "idle4", touch_chin = "idle8",
touch_shoulder = "idle5" }

--- Dictionary of female animation aliases mapped to their literal names
--- @class FemaleAnimAliases
local femaleAnimAliases = { adjust_hair = "idle4", touch_hip = "idle5" }

--- Dictionary of beast animation aliases mapped to their literal names
--- @class BeastAnimAliases
local beastAnimAliases = { act_confused = "idle9", look_around = "idle2", touch_hands = "idle6" }

--- Retrieve a real animation name using its alias relative to player race/gender
--- @param pid integer The playerID
--- @param animAlias string Practical name for the animation, used as a table key in the animAlias tables
--- @return string animation Literal animation name or invalid if the anim does not exist for this race/gender
function animHelper.GetAnimation(pid, animAlias)

-- Is this animation included in the default animation names?
Expand Down Expand Up @@ -49,6 +68,9 @@ function animHelper.GetAnimation(pid, animAlias)
return "invalid"
end

--- Get all animations a particular player could play
--- @param pid PlayerID Player whose animation list is requested
--- @return string[] animList All literal animation names valid for this PlayerID
function animHelper.GetValidList(pid)

local validList = {}
Expand All @@ -75,20 +97,24 @@ function animHelper.GetValidList(pid)
end

if isBeast then
for beastAlias, defaultAnim in pairs(beastAnimAliases) do
for beastAlias, _ in pairs(beastAnimAliases) do
table.insert(validList, beastAlias)
end
end

if isFemale then
for femaleAlias, defaultAnim in pairs(femaleAnimAliases) do
for femaleAlias, _ in pairs(femaleAnimAliases) do
table.insert(validList, femaleAlias)
end
end

return tableHelper.concatenateFromIndex(validList, 1, ", ")
end

--- Given a specific animation alias, play it on the target PlayerID
--- @param pid PlayerID Player to animate
--- @param animAlias string Animation to run, see AnimAliases, FemaleAnimAliases, and BeastAnimAliases classes for aliases
--- @return boolean success Whether the animation played
function animHelper.PlayAnimation(pid, animAlias)

local defaultAnim = animHelper.GetAnimation(pid, animAlias)
Expand Down
1 change: 1 addition & 0 deletions scripts/serverCore.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("wrapper")
require("types")
require("utils")
require("enumerations")
tableHelper = require("tableHelper")
Expand Down
2 changes: 2 additions & 0 deletions scripts/types.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--- Unsigned int representing player id
--- @class PlayerID