mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
check project code style. add .luacheckrc (#7)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
local data = require("druid.data")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.interest = {
|
||||
data.ON_INPUT
|
||||
}
|
||||
@@ -27,4 +26,4 @@ function M.on_input(instance, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return M
|
@@ -4,7 +4,6 @@ local settings = require("druid.settings")
|
||||
local b_settings = settings.button
|
||||
|
||||
local M = {}
|
||||
|
||||
M.interest = {
|
||||
data.ON_INPUT
|
||||
}
|
||||
@@ -15,9 +14,9 @@ M.DEFAULT_ACTIVATE_SCALE = vmath.vector3(1, 1, 1)
|
||||
M.DEFAUL_ACTIVATION_TIME = 0.2
|
||||
|
||||
|
||||
function M.init(instance, callback, params, animate_node_name, event)
|
||||
function M.init(instance, callback, params, anim_node)
|
||||
instance.event = data.A_TOUCH
|
||||
instance.anim_node = animate_node_name and gui.get_node(animate_node_name) or instance.node
|
||||
instance.anim_node = anim_node and gui.get_node(anim_node) or instance.node
|
||||
instance.scale_from = gui.get_scale(instance.anim_node)
|
||||
instance.scale_to = instance.scale_from + b_settings.SCALE_CHANGE
|
||||
instance.scale_hover_to = instance.scale_from + b_settings.HOVER_SCALE
|
||||
@@ -40,6 +39,7 @@ local function set_hover(instance, state)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function on_button_release(instance)
|
||||
if not instance.disabled then
|
||||
if not instance.stub and instance.can_action then
|
||||
@@ -83,6 +83,7 @@ function M.on_input(instance, action_id, action)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M.tap_scale_animation(instance)
|
||||
ui_animate.scale_to(instance, instance.anim_node, instance.scale_to,
|
||||
function()
|
||||
@@ -109,12 +110,14 @@ function M.deactivate(instance, is_animate, callback)
|
||||
callback(instance.parent.parent)
|
||||
end
|
||||
end
|
||||
ui_animate.color(instance, instance.node, M.DEFAULT_DEACTIVATE_COLOR, clbk, M.DEFAUL_ACTIVATION_TIME, 0,
|
||||
gui.EASING_OUTBOUNCE)
|
||||
ui_animate.scale_y_from_to(instance, instance.node, M.DEFAULT_ACTIVATE_SCALE.x, M.DEFAULT_DEACTIVATE_SCALE.x, clbk,
|
||||
M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
ui_animate.scale_x_from_to(instance, instance.node, M.DEFAULT_ACTIVATE_SCALE.y, M.DEFAULT_DEACTIVATE_SCALE.y, clbk,
|
||||
M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
ui_animate.color(instance, instance.node, M.DEFAULT_DEACTIVATE_COLOR,
|
||||
clbk, M.DEFAUL_ACTIVATION_TIME, 0, gui.EASING_OUTBOUNCE)
|
||||
|
||||
ui_animate.scale_y_from_to(instance, instance.node, M.DEFAULT_ACTIVATE_SCALE.x,
|
||||
M.DEFAULT_DEACTIVATE_SCALE.x, clbk, M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
|
||||
ui_animate.scale_x_from_to(instance, instance.node, M.DEFAULT_ACTIVATE_SCALE.y,
|
||||
M.DEFAULT_DEACTIVATE_SCALE.y, clbk, M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
else
|
||||
gui.set_color(instance.node, M.DEFAULT_DEACTIVATE_COLOR)
|
||||
gui.set_scale(instance.node, M.DEFAULT_DEACTIVATE_SCALE)
|
||||
@@ -137,12 +140,14 @@ function M.activate(instance, is_animate, callback)
|
||||
end
|
||||
end
|
||||
end
|
||||
ui_animate.color(instance, instance.node, ui_animate.TINT_SHOW, clbk, M.DEFAUL_ACTIVATION_TIME, 0,
|
||||
gui.EASING_OUTBOUNCE)
|
||||
ui_animate.scale_y_from_to(instance, instance.node, M.DEFAULT_DEACTIVATE_SCALE.x, M.DEFAULT_ACTIVATE_SCALE.x, clbk,
|
||||
M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
ui_animate.scale_x_from_to(instance, instance.node, M.DEFAULT_DEACTIVATE_SCALE.y, M.DEFAULT_ACTIVATE_SCALE.y, clbk,
|
||||
M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
ui_animate.color(instance, instance.node, ui_animate.TINT_SHOW,
|
||||
clbk, M.DEFAUL_ACTIVATION_TIME, 0, gui.EASING_OUTBOUNCE)
|
||||
|
||||
ui_animate.scale_y_from_to(instance, instance.node, M.DEFAULT_DEACTIVATE_SCALE.x,
|
||||
M.DEFAULT_ACTIVATE_SCALE.x, clbk, M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
|
||||
ui_animate.scale_x_from_to(instance, instance.node, M.DEFAULT_DEACTIVATE_SCALE.y,
|
||||
M.DEFAULT_ACTIVATE_SCALE.y, clbk, M.DEFAUL_ACTIVATION_TIME, gui.EASING_OUTBOUNCE)
|
||||
else
|
||||
gui.set_color(instance.node, ui_animate.TINT_SHOW)
|
||||
gui.set_scale(instance.node, M.DEFAULT_ACTIVATE_SCALE)
|
||||
|
@@ -3,70 +3,71 @@ local settings = require("druid.settings")
|
||||
|
||||
local M = {}
|
||||
M.interest = {
|
||||
data.TRANSLATABLE,
|
||||
data.LAYOUT_CHANGED
|
||||
data.TRANSLATABLE,
|
||||
data.LAYOUT_CHANGED
|
||||
}
|
||||
|
||||
|
||||
function M.init(instance, value, is_locale)
|
||||
instance.last_color = gui.get_color(instance.node)
|
||||
if is_locale then
|
||||
instance.text_id = value
|
||||
instance:translate()
|
||||
else
|
||||
instance:set_to(value or 0)
|
||||
end
|
||||
return instance
|
||||
instance.last_color = gui.get_color(instance.node)
|
||||
if is_locale then
|
||||
instance.text_id = value
|
||||
instance:translate()
|
||||
else
|
||||
instance:set_to(value or 0)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
function M.translate(instance)
|
||||
if instance.text_id then
|
||||
instance:set_to(settings.get_text(instance.text_id))
|
||||
end
|
||||
if instance.text_id then
|
||||
instance:set_to(settings.get_text(instance.text_id))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Set text to text field
|
||||
-- @param set_to - set value to text field
|
||||
function M.set_to(instance, set_to)
|
||||
instance.last_value = set_to
|
||||
gui.set_text(instance.node, set_to)
|
||||
instance.last_value = set_to
|
||||
gui.set_text(instance.node, set_to)
|
||||
end
|
||||
|
||||
|
||||
--- Set color
|
||||
-- @param color
|
||||
function M.set_color(instance, color)
|
||||
instance.last_color = color
|
||||
gui.set_color(instance.node, color)
|
||||
instance.last_color = color
|
||||
gui.set_color(instance.node, color)
|
||||
end
|
||||
|
||||
|
||||
--- Set alpha
|
||||
-- @param alpha, number [0-1]
|
||||
function M.set_alpha(instance, alpha)
|
||||
instance.last_color.w = alpha
|
||||
gui.set_color(instance.node, instance.last_color)
|
||||
instance.last_color.w = alpha
|
||||
gui.set_color(instance.node, instance.last_color)
|
||||
end
|
||||
|
||||
|
||||
--- Set scale
|
||||
-- @param scale
|
||||
function M.set_scale(instance, scale)
|
||||
instance.last_scale = scale
|
||||
gui.set_scale(instance.node, scale)
|
||||
instance.last_scale = scale
|
||||
gui.set_scale(instance.node, scale)
|
||||
end
|
||||
|
||||
|
||||
--- Called when layout updated (rotate for example)
|
||||
function M.on_layout_updated(instance)
|
||||
if instance.last_color then
|
||||
M.set_color(instance, instance.last_color)
|
||||
end
|
||||
if instance.last_scale then
|
||||
M.set_scale(instance, instance.last_scale)
|
||||
end
|
||||
if instance.last_color then
|
||||
M.set_color(instance, instance.last_color)
|
||||
end
|
||||
if instance.last_scale then
|
||||
M.set_scale(instance, instance.last_scale)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
@@ -3,49 +3,48 @@ local formats = require("druid.helper.formats")
|
||||
local helper = require("druid.helper.ui_helper")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.interest = {
|
||||
data.LAYOUT_CHANGED,
|
||||
data.ON_UPDATE
|
||||
data.LAYOUT_CHANGED,
|
||||
data.ON_UPDATE
|
||||
}
|
||||
|
||||
local empty = function() end
|
||||
|
||||
function M.init(instance, seconds_from, seconds_to, callback)
|
||||
seconds_from = math.max(seconds_from, 0)
|
||||
seconds_to = math.max(seconds_to or 0, 0)
|
||||
callback = callback or empty
|
||||
seconds_from = math.max(seconds_from, 0)
|
||||
seconds_to = math.max(seconds_to or 0, 0)
|
||||
callback = callback or empty
|
||||
|
||||
instance:set_to(seconds_from)
|
||||
instance:set_interval(seconds_from, seconds_to)
|
||||
instance.callback = callback
|
||||
instance:set_to(seconds_from)
|
||||
instance:set_interval(seconds_from, seconds_to)
|
||||
instance.callback = callback
|
||||
|
||||
if seconds_to - seconds_from == 0 then
|
||||
instance:set_state(false)
|
||||
instance.callback(instance.parent.parent, instance)
|
||||
end
|
||||
return instance
|
||||
if seconds_to - seconds_from == 0 then
|
||||
instance:set_state(false)
|
||||
instance.callback(instance.parent.parent, instance)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
--- Set text to text field
|
||||
-- @param set_to - set value in seconds
|
||||
function M.set_to(instance, set_to)
|
||||
instance.last_value = set_to
|
||||
gui.set_text(instance.node, formats.second_string_min(set_to))
|
||||
instance.last_value = set_to
|
||||
gui.set_text(instance.node, formats.second_string_min(set_to))
|
||||
end
|
||||
|
||||
|
||||
--- Called when layout updated (rotate for example)
|
||||
function M.on_layout_updated(instance)
|
||||
M.set_to(instance, instance.last_value)
|
||||
M.set_to(instance, instance.last_value)
|
||||
end
|
||||
|
||||
|
||||
--- Called when update
|
||||
-- @param is_on - boolean is timer on
|
||||
function M.set_state(instance, is_on)
|
||||
instance.is_on = is_on
|
||||
instance.is_on = is_on
|
||||
end
|
||||
|
||||
|
||||
@@ -53,32 +52,33 @@ end
|
||||
-- @param from - "from" time in seconds
|
||||
-- @param to - "to" time in seconds
|
||||
function M.set_interval(instance, from, to)
|
||||
instance.from = from
|
||||
instance.value = from
|
||||
instance.temp = 0
|
||||
instance.target = to
|
||||
M.set_state(instance, true)
|
||||
M.set_to(instance, from)
|
||||
instance.from = from
|
||||
instance.value = from
|
||||
instance.temp = 0
|
||||
instance.target = to
|
||||
M.set_state(instance, true)
|
||||
M.set_to(instance, from)
|
||||
end
|
||||
|
||||
|
||||
--- Called when update
|
||||
-- @param dt - delta time
|
||||
function M.update(instance, dt)
|
||||
if instance.is_on then
|
||||
instance.temp = instance.temp + dt
|
||||
local dist = math.min(1, math.abs(instance.value - instance.target))
|
||||
if instance.is_on then
|
||||
instance.temp = instance.temp + dt
|
||||
local dist = math.min(1, math.abs(instance.value - instance.target))
|
||||
|
||||
if instance.temp > dist then
|
||||
instance.temp = instance.temp - dist
|
||||
instance.value = helper.step(instance.value, instance.target, 1)
|
||||
M.set_to(instance, instance.value)
|
||||
if instance.value == instance.target then
|
||||
instance:set_state(false)
|
||||
instance.callback(instance.parent.parent, instance)
|
||||
end
|
||||
end
|
||||
end
|
||||
if instance.temp > dist then
|
||||
instance.temp = instance.temp - dist
|
||||
instance.value = helper.step(instance.value, instance.target, 1)
|
||||
M.set_to(instance, instance.value)
|
||||
if instance.value == instance.target then
|
||||
instance:set_state(false)
|
||||
instance.callback(instance.parent.parent, instance)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
return M
|
Reference in New Issue
Block a user