-
Ok it's just easier to show, i have no idea what i should write in title: Here is Animation file ---@class Animation.Simple.package
---@field addGrid Animation.Simple
---@field build Animation.Simple.Builder
---@class Animation.Simple
---@overload fun(O:animationOpts?): Animation.Simple
---@field image love.Image
---@field width number width of frame
---@field height number height of frame
---@field duration table|number duration of frame
---@field state string animation state type
---@field private __grid? table
---@field private newGrid function
---@field type table type of animation
local Animation = class("Animation.Simple")
function Animation:initialize(O)
...
end
--- Create animation grid
---@class animationOpts
---@field image love.Image
---@field width number width of frames
---@field height number height of frames
---@field state? string animation state type
---@field top? number origin coordinate top
---@field left? number origin coordinate left
---@field border? number
---@field duration number
---Create new grid
---@param O animationOpts
---@return self
function Animation:newGrid(O)
...
end
--- Add animation based on frames and grid
---@param name string of animation
---@param frames table string of frames
---@param duration? table | number duration of frame
---@param onLoop? function fn called every loop
---@return self
function Animation:add(name, frames, duration, onLoop)
...
end
---@class AnimationTable
---@field [string] Animation.Simple
---@class Animation.Simple.Builder
---@overload fun(O: fun(): {[string]: Animation.Simple}): Animation.Simple.Builder
---@field private __current string
---@field types AnimationTable
local AnimationBuilder = class("Animation.Builder")
function AnimationBuilder:initialize(fun)
end
--- Set default animation
---@param str string animation name
---@return self
function AnimationBuilder:grid(str)
...
end
---get current Animation
---@return Animation.Simple
function AnimationBuilder:current()
...
end
return {
addGrid = Animation,
build = AnimationBuilder,
} and here how i use it self.animation = Animation.build(function()
local image = love.graphics.newImage("assets/RPGW/Zombie.png")
return {
default = Animation.addGrid({
image = image,
height = 32,
width = 32,
duration = 0.2,
})
:add("idle", { "1-8", 1 })
:add("running", { "1-8", 3 })
:add("attack", { "1-7", 2 })
:add("dying", { "1-9", 6 }, nil, function(s)
s:pauseAtEnd()
end)
:action("idle"),
second = Animation.addGrid({
image = image,
height = 32,
width = 32,
duration = 0.2,
})
:add("idle", { "1-8", 1 })
:add("running", { "1-8", 3 })
:add("attack", { "1-7", 2 })
:add("dying", { "1-9", 6 }, nil, function(s)
s:pauseAtEnd()
end)
:action("idle"),
}
end):grid("default") i would like to know if there exist a way for luals to infer names of default and second, they are fields that will exist in self.animation.types table |
Beta Was this translation helpful? Give feedback.
Answered by
tomlau10
Feb 19, 2025
Replies: 1 comment 1 reply
-
One of the things i thought about and do it like so: ---@class Animation.Simple.Zombie: Animation.Simple.Builder
---@field types.default Animation.Simple
---@field types.second Animation.Simple
self.animation = Animation.build(function()
... but is there an option for luals automatically infer such fields? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IIUC, you want
self.animation.types
to suggestdefault
/second
as its fields?In other words, you want the return table type of the callback from
Animation.build()
, to be the type ofself.animation.types
?firstly your syntax is incorrect
The syntax
@field types.default ...
in your original comment is incorrect.You cannot define nested sub fields in this way.
The closest thing is using table literal:
but of course this still doesn't fulfil your request that automatically suggest
default/second
fields with…