mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
check project code style. add .luacheckrc (#7)
This commit is contained in:
@@ -2,13 +2,14 @@ local M = {}
|
||||
|
||||
local PROP_SCALE = gui.PROP_SCALE
|
||||
local PROP_POSITION = gui.PROP_POSITION
|
||||
M.PROP_POS_X = hash("position.x")
|
||||
M.PROP_POS_Y = hash("position.y")
|
||||
M.PROP_ALPHA = hash("color.w")
|
||||
local PROP_COLOR = hash("color")
|
||||
local PROP_SCALE_X = "scale.x"
|
||||
local PROP_SCALE_Y = "scale.y"
|
||||
|
||||
M.PROP_POS_X = hash("position.x")
|
||||
M.PROP_POS_Y = hash("position.y")
|
||||
M.PROP_ALPHA = hash("color.w")
|
||||
|
||||
M.TINT_HIDE = vmath.vector4(1, 1, 1, 0)
|
||||
M.TINT_SHOW = vmath.vector4(1, 1, 1, 1)
|
||||
|
||||
@@ -19,155 +20,167 @@ M.SCALE_ANIMATION_TIME = 0.1
|
||||
M.BOUNCE_ANIMATION_TIME = 0.25
|
||||
M.ALPHA_ANIMATION_TIME = 0.25
|
||||
|
||||
|
||||
function M.alpha(self, node, alpha, callback, time, delay, easing, playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
easing = easing or gui.EASING_LINEAR
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
gui.animate(node, M.PROP_ALPHA, alpha, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
easing = easing or gui.EASING_LINEAR
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
gui.animate(node, M.PROP_ALPHA, alpha, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.color(self, node, color, callback, time, delay, easing, playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
easing = easing or gui.EASING_LINEAR
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
gui.animate(node, PROP_COLOR, color, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
easing = easing or gui.EASING_LINEAR
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
gui.animate(node, PROP_COLOR, color, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.shake(self, node, callback, str, time)
|
||||
str = str or - 30
|
||||
time = time or 0.25
|
||||
local pos = gui.get_position(node)
|
||||
pos.x = pos.x + str
|
||||
gui.animate(node, PROP_POSITION, pos, gui.EASING_INELASTIC, time,
|
||||
0,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
gui.PLAYBACK_ONCE_BACKWARD
|
||||
)
|
||||
str = str or - 30
|
||||
time = time or 0.25
|
||||
local pos = gui.get_position(node)
|
||||
pos.x = pos.x + str
|
||||
gui.animate(node, PROP_POSITION, pos, gui.EASING_INELASTIC, time,
|
||||
0,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
gui.PLAYBACK_ONCE_BACKWARD
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function M.bounce(self, node, change_to, callback, time, easing, playback, delaly)
|
||||
time = time or M.BOUNCE_ANIMATION_TIME
|
||||
delaly = delaly or 0
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
playback = playback or gui.PLAYBACK_ONCE_PINGPONG
|
||||
gui.animate(node, PROP_SCALE, change_to, easing, time, delaly,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
time = time or M.BOUNCE_ANIMATION_TIME
|
||||
delaly = delaly or 0
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
playback = playback or gui.PLAYBACK_ONCE_PINGPONG
|
||||
gui.animate(node, PROP_SCALE, change_to, easing, time, delaly,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.fly_to(self, node, to_pos, speed, callback, delay, easing)
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
local time = vmath.length(to_pos - gui.get_position(node)) / 100 / speed
|
||||
gui.animate(node, gui.PROP_POSITION, to_pos, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end)
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
local time = vmath.length(to_pos - gui.get_position(node)) / 100 / speed
|
||||
gui.animate(node, gui.PROP_POSITION, to_pos, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function M.fly_by_x(self, node, to_x, time, callback, delay, easing, playback)
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
gui.animate(node, M.PROP_POS_X, to_x, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
gui.animate(node, M.PROP_POS_X, to_x, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.fly_by_y(self, node, to_y, time, callback, delay, easing, playback)
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
time = time or 0.25
|
||||
gui.animate(node, M.PROP_POS_Y, to_y, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
time = time or 0.25
|
||||
gui.animate(node, M.PROP_POS_Y, to_y, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end,
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.scale_to(self, node, to, callback, time, delay, easing)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
time = time or 0.25
|
||||
gui.animate(node, PROP_SCALE, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end
|
||||
)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
time = time or 0.25
|
||||
gui.animate(node, PROP_SCALE, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self, node)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function M.scale(self, node, to, time)
|
||||
gui.animate(node, "scale", to, gui.EASING_OUTSINE, time)
|
||||
gui.animate(node, "scale", to, gui.EASING_OUTSINE, time)
|
||||
end
|
||||
|
||||
|
||||
function M.scale_x_from_to(self, node, from, to, callback, time, easing, delay, playback)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
local scale = gui.get_scale(node)
|
||||
scale.x = from
|
||||
gui.set_scale(node, scale)
|
||||
gui.animate(node, PROP_SCALE_X, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback
|
||||
)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
local scale = gui.get_scale(node)
|
||||
scale.x = from
|
||||
gui.set_scale(node, scale)
|
||||
gui.animate(node, PROP_SCALE_X, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function M.scale_y_from_to(self, node, from, to, callback, time, easing, delay, playback)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
local scale = gui.get_scale(node)
|
||||
scale.y = from
|
||||
gui.set_scale(node, scale)
|
||||
gui.animate(node, PROP_SCALE_Y, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback
|
||||
)
|
||||
easing = easing or gui.EASING_INSINE
|
||||
time = time or M.SCALE_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
playback = playback or gui.PLAYBACK_ONCE_FORWARD
|
||||
local scale = gui.get_scale(node)
|
||||
scale.y = from
|
||||
gui.set_scale(node, scale)
|
||||
gui.animate(node, PROP_SCALE_Y, to, easing, time, delay,
|
||||
function()
|
||||
if callback then
|
||||
callback(self)
|
||||
end
|
||||
end,
|
||||
playback
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
@@ -4,12 +4,15 @@ local ADD_FOCUS = hash("acquire_input_focus")
|
||||
local REMOVE_FOCUS = hash("release_input_focus")
|
||||
local PATH_OBJ = "."
|
||||
|
||||
|
||||
function M.focus()
|
||||
msg.post(PATH_OBJ, ADD_FOCUS)
|
||||
msg.post(PATH_OBJ, ADD_FOCUS)
|
||||
end
|
||||
|
||||
|
||||
function M.remove()
|
||||
msg.post(PATH_OBJ, REMOVE_FOCUS)
|
||||
msg.post(PATH_OBJ, REMOVE_FOCUS)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@@ -7,28 +7,31 @@ local ZERO = "0"
|
||||
-- @param count - count of numerals
|
||||
-- @return string with need count of zero (1,3) -> 001
|
||||
function M.add_prefix_zeros(num, count)
|
||||
local result = tostring(num)
|
||||
for i = string.len(result), count - 1 do
|
||||
result = ZERO..result
|
||||
end
|
||||
return result
|
||||
local result = tostring(num)
|
||||
for i = string.len(result), count - 1 do
|
||||
result = ZERO..result
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
-- Convert seconds to string minutes:seconds
|
||||
-- @param num - number of seconds
|
||||
-- @return string minutes:seconds
|
||||
function M.second_string_min(sec)
|
||||
local mins = math.floor(sec / 60)
|
||||
local seconds = math.floor(sec - mins * 60)
|
||||
return string.format("%.2d:%.2d", mins, seconds)
|
||||
local mins = math.floor(sec / 60)
|
||||
local seconds = math.floor(sec - mins * 60)
|
||||
return string.format("%.2d:%.2d", mins, seconds)
|
||||
end
|
||||
|
||||
|
||||
-- Interpolate string with named Parameters in Table
|
||||
-- @param s - string for interpolate
|
||||
-- @param tab - table with parameters
|
||||
-- @return string with replaced parameters
|
||||
function M.interpolate_strinng(s, tab)
|
||||
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
|
||||
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
@@ -1,24 +1,30 @@
|
||||
local M = {}
|
||||
|
||||
function M.centrate_text_with_icon(text_node, icon_node)
|
||||
local metr = gui.get_text_metrics_from_node(text_node)
|
||||
local scl = gui.get_scale(text_node).x
|
||||
local scl_i = gui.get_scale(icon_node).x
|
||||
local pos_i = gui.get_position(icon_node)
|
||||
local pos = gui.get_position(text_node)
|
||||
local w = metr.width * scl * scl_i
|
||||
local icon_w = gui.get_size(icon_node).x * scl_i
|
||||
local width = w + icon_w + (math.abs(pos.x) - icon_w / 2) * scl_i
|
||||
pos_i.x = width / 2 - (icon_w / 2)
|
||||
gui.set_position(icon_node, pos_i)
|
||||
function M.centrate_text_with_icon(text_node, icon_node, offset_x)
|
||||
offset_x = offset_x or 0
|
||||
local metr = gui.get_text_metrics_from_node(text_node)
|
||||
local scl = gui.get_scale(text_node).x
|
||||
local pos = gui.get_position(text_node)
|
||||
local scl_i = gui.get_scale(icon_node).x
|
||||
local pos_i = gui.get_position(icon_node)
|
||||
local w = metr.width * scl -- text width
|
||||
local icon_w = gui.get_size(icon_node).x * scl_i -- icon width
|
||||
local width = w + icon_w
|
||||
|
||||
pos.x = -width/2 + w + offset_x
|
||||
gui.set_position(text_node, pos)
|
||||
pos_i.x = width/2 - icon_w + offset_x
|
||||
gui.set_position(icon_node, pos_i)
|
||||
end
|
||||
|
||||
|
||||
function M.step(current, target, step)
|
||||
if current < target then
|
||||
return math.min(current + step, target)
|
||||
else
|
||||
return math.max(target, current - step)
|
||||
end
|
||||
if current < target then
|
||||
return math.min(current + step, target)
|
||||
else
|
||||
return math.max(target, current - step)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
Reference in New Issue
Block a user