mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
check project code style. add .luacheckrc (#7)
This commit is contained in:
parent
235476fee4
commit
12f5f22b69
51
.luacheckrc
Normal file
51
.luacheckrc
Normal file
@ -0,0 +1,51 @@
|
||||
std = "max"
|
||||
files['.luacheckrc'].global = false
|
||||
unused_args = false
|
||||
|
||||
max_code_line_length = 90
|
||||
max_comment_line_length = false
|
||||
|
||||
globals = {
|
||||
"sys",
|
||||
"go",
|
||||
"gui",
|
||||
"label",
|
||||
"render",
|
||||
"crash",
|
||||
"sprite",
|
||||
"sound",
|
||||
"tilemap",
|
||||
"spine",
|
||||
"particlefx",
|
||||
"physics",
|
||||
"factory",
|
||||
"collectionfactory",
|
||||
"iac",
|
||||
"msg",
|
||||
"vmath",
|
||||
"url",
|
||||
"http",
|
||||
"image",
|
||||
"json",
|
||||
"zlib",
|
||||
"iap",
|
||||
"push",
|
||||
"facebook",
|
||||
"hash",
|
||||
"hash_to_hex",
|
||||
"pprint",
|
||||
"init",
|
||||
"final",
|
||||
"update",
|
||||
"on_input",
|
||||
"on_message",
|
||||
"on_reload",
|
||||
"socket",
|
||||
"table",
|
||||
"debug",
|
||||
"timer",
|
||||
"window",
|
||||
"buffer",
|
||||
"resource",
|
||||
"defos",
|
||||
}
|
15
README.md
15
README.md
@ -1,14 +1,15 @@
|
||||
# druid
|
||||
# Defold Druid
|
||||
Defold UI library
|
||||
--
|
||||
|
||||
This project was created from the "empty" project template.
|
||||
# Install
|
||||
|
||||
The settings in ["game.project"](defold://open?path=/game.project) are all the default. A bootstrap empty ["main.collection"](defold://open?path=/main/main.collection) is included.
|
||||
# Setup
|
||||
|
||||
Check out [the documentation pages](https://defold.com/learn) for examples, tutorials, manuals and API docs.
|
||||
# Usage
|
||||
|
||||
If you run into trouble, help is available in [our forum](https://forum.defold.com).
|
||||
# API
|
||||
|
||||
Happy Defolding!
|
||||
# Authors
|
||||
|
||||
---
|
||||
# License
|
||||
|
@ -1,7 +1,6 @@
|
||||
local data = require("druid.data")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.interest = {
|
||||
data.ON_INPUT
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -69,4 +69,5 @@ function M.on_layout_updated(instance)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
@ -3,7 +3,6 @@ local formats = require("druid.helper.formats")
|
||||
local helper = require("druid.helper.ui_helper")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.interest = {
|
||||
data.LAYOUT_CHANGED,
|
||||
data.ON_UPDATE
|
||||
@ -81,4 +80,5 @@ function M.update(instance, dt)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
@ -9,9 +9,7 @@ local _factory = {}
|
||||
|
||||
local STRING = "string"
|
||||
|
||||
--- New druid era, registering components
|
||||
M.comps = {
|
||||
-- basic
|
||||
button = require("druid.base.button"),
|
||||
android_back = require("druid.base.android_back"),
|
||||
text = require("druid.base.text"),
|
||||
@ -34,6 +32,7 @@ function M.register(name, module)
|
||||
log("Register component", name)
|
||||
end
|
||||
|
||||
|
||||
--- Create UI instance for ui elements
|
||||
-- @return instance with all ui components
|
||||
function M.new(self)
|
||||
@ -46,7 +45,6 @@ function M.new(self)
|
||||
return factory
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function input_init(factory)
|
||||
if not factory.input_inited then
|
||||
@ -56,7 +54,7 @@ local function input_init(factory)
|
||||
end
|
||||
|
||||
|
||||
local function create(module, factory, name, ...)
|
||||
local function create(module, factory, name)
|
||||
local instance = setmetatable({}, {__index = module})
|
||||
instance.parent = factory
|
||||
if name then
|
||||
@ -155,4 +153,5 @@ function _factory.update(factory, dt)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
@ -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,6 +20,7 @@ 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
|
||||
@ -33,6 +35,7 @@ function M.alpha(self, node, alpha, callback, time, delay, easing, playback)
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.color(self, node, color, callback, time, delay, easing, playback)
|
||||
time = time or M.ALPHA_ANIMATION_TIME
|
||||
delay = delay or 0
|
||||
@ -47,6 +50,7 @@ function M.color(self, node, color, callback, time, delay, easing, playback)
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.shake(self, node, callback, str, time)
|
||||
str = str or - 30
|
||||
time = time or 0.25
|
||||
@ -63,6 +67,7 @@ function M.shake(self, node, callback, str, time)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function M.bounce(self, node, change_to, callback, time, easing, playback, delaly)
|
||||
time = time or M.BOUNCE_ANIMATION_TIME
|
||||
delaly = delaly or 0
|
||||
@ -77,6 +82,7 @@ function M.bounce(self, node, change_to, callback, time, easing, playback, delal
|
||||
playback)
|
||||
end
|
||||
|
||||
|
||||
function M.fly_to(self, node, to_pos, speed, callback, delay, easing)
|
||||
easing = easing or gui.EASING_OUTSINE
|
||||
delay = delay or 0
|
||||
@ -89,6 +95,7 @@ function M.fly_to(self, node, to_pos, speed, callback, delay, easing)
|
||||
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
|
||||
@ -102,6 +109,7 @@ function M.fly_by_x(self, node, to_x, time, callback, delay, easing, playback)
|
||||
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
|
||||
@ -116,6 +124,7 @@ function M.fly_by_y(self, node, to_y, time, callback, delay, easing, playback)
|
||||
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
|
||||
@ -130,10 +139,12 @@ function M.scale_to(self, node, to, callback, time, delay, easing)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function M.scale(self, node, to, 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
|
||||
@ -152,6 +163,7 @@ function M.scale_x_from_to(self, node, from, to, callback, time, easing, delay,
|
||||
)
|
||||
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
|
||||
@ -170,4 +182,5 @@ function M.scale_y_from_to(self, node, from, to, callback, time, easing, delay,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
|
||||
function M.remove()
|
||||
msg.post(PATH_OBJ, REMOVE_FOCUS)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@ -14,6 +14,7 @@ function M.add_prefix_zeros(num, count)
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
-- Convert seconds to string minutes:seconds
|
||||
-- @param num - number of seconds
|
||||
-- @return string minutes:seconds
|
||||
@ -23,6 +24,7 @@ function M.second_string_min(sec)
|
||||
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
|
||||
@ -31,4 +33,5 @@ function M.interpolate_strinng(s, tab)
|
||||
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
|
||||
end
|
||||
|
||||
|
||||
return M
|
@ -1,18 +1,23 @@
|
||||
local M = {}
|
||||
|
||||
function M.centrate_text_with_icon(text_node, icon_node)
|
||||
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 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)
|
||||
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)
|
||||
@ -21,4 +26,5 @@ function M.step(current, target, step)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
@ -6,7 +6,7 @@ M.button = {
|
||||
IS_HOVER = true,
|
||||
IS_HOLD = true,
|
||||
BTN_SOUND = "click",
|
||||
BTN_SOUND_DISABLED = "button_click_disabled",
|
||||
BTN_SOUND_DISABLED = "click_disabled",
|
||||
HOVER_SCALE = vmath.vector3(-0.025, -0.025, 1),
|
||||
HOVER_TIME = 0.05,
|
||||
SCALE_CHANGE = vmath.vector3(-0.05, - 0.05, 1),
|
||||
@ -24,6 +24,7 @@ function M.play_sound(name)
|
||||
-- override to play sound with name
|
||||
end
|
||||
|
||||
|
||||
function M.log(...)
|
||||
if M.is_debug then
|
||||
print("[Druid]: ", ...)
|
||||
@ -31,5 +32,4 @@ function M.log(...)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return M
|
Loading…
x
Reference in New Issue
Block a user