Update elements and fix background9 unparsing
This commit is contained in:
parent
d1ba059652
commit
17503d543b
19
core.lua
19
core.lua
@ -402,27 +402,28 @@ local compare_blanks
|
|||||||
do
|
do
|
||||||
local function get_nonempty(a)
|
local function get_nonempty(a)
|
||||||
if a.nonempty then
|
if a.nonempty then
|
||||||
return a.nonempty, a.strings
|
return a.nonempty, a.strings, a.total_length
|
||||||
end
|
end
|
||||||
local nonempty, strings = 0, 0
|
local nonempty, strings, total_length = 0, 0, #a
|
||||||
for _, i in ipairs(a) do
|
for _, i in ipairs(a) do
|
||||||
if type(i) == 'string' and i ~= '' then
|
if type(i) == 'string' and i ~= '' then
|
||||||
nonempty = nonempty + 1
|
nonempty = nonempty + 1
|
||||||
strings = strings + 1
|
strings = strings + 1
|
||||||
elseif type(i) == 'table' then
|
elseif type(i) == 'table' then
|
||||||
nonempty = nonempty + get_nonempty(i)
|
local n, s, t = get_nonempty(i)
|
||||||
|
nonempty = nonempty + n
|
||||||
|
strings = strings + s
|
||||||
|
total_length = total_length + t
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
a.nonempty, a.strings = nonempty, strings
|
a.nonempty, a.strings, a.total_length = nonempty, strings, total_length
|
||||||
return nonempty, strings
|
return nonempty, strings, total_length
|
||||||
end
|
end
|
||||||
|
|
||||||
function compare_blanks(a, b)
|
function compare_blanks(a, b)
|
||||||
local a_n, a_strings = get_nonempty(a)
|
local a_n, a_strings, a_l = get_nonempty(a)
|
||||||
local b_n, b_strings = get_nonempty(b)
|
local b_n, b_strings, b_l = get_nonempty(b)
|
||||||
if a_n == b_n then
|
if a_n == b_n then
|
||||||
local a_l = #a
|
|
||||||
local b_l = #b
|
|
||||||
if a_l == b_l then
|
if a_l == b_l then
|
||||||
-- Prefer elements with less tables
|
-- Prefer elements with less tables
|
||||||
return a_strings > b_strings
|
return a_strings > b_strings
|
||||||
|
File diff suppressed because one or more lines are too long
@ -242,6 +242,21 @@ listring:
|
|||||||
- [list_name, string]
|
- [list_name, string]
|
||||||
- []
|
- []
|
||||||
model:
|
model:
|
||||||
|
- - - [x, number]
|
||||||
|
- [y, number]
|
||||||
|
- - [w, number]
|
||||||
|
- [h, number]
|
||||||
|
- [name, string]
|
||||||
|
- [mesh, string]
|
||||||
|
- - - [textures, string]
|
||||||
|
- '...'
|
||||||
|
- - [rotation_x, number]
|
||||||
|
- [rotation_y, number]
|
||||||
|
- [continuous, boolean]
|
||||||
|
- [mouse_control, boolean]
|
||||||
|
- - [frame_loop_begin, number]
|
||||||
|
- [frame_loop_end, number]
|
||||||
|
- [animation_speed, number]
|
||||||
- - - [x, number]
|
- - - [x, number]
|
||||||
- [y, number]
|
- [y, number]
|
||||||
- - [w, number]
|
- - [w, number]
|
||||||
|
@ -16,7 +16,7 @@ def _make_known(**kwargs):
|
|||||||
_known = _make_known(
|
_known = _make_known(
|
||||||
number=('x', 'y', 'w', 'h', 'selected_idx', 'version',
|
number=('x', 'y', 'w', 'h', 'selected_idx', 'version',
|
||||||
'starting_item_index', 'scroll_factor', 'frame_count',
|
'starting_item_index', 'scroll_factor', 'frame_count',
|
||||||
'frame_duration', 'frame_start'),
|
'frame_duration', 'frame_start', 'animation_speed'),
|
||||||
boolean=('auto_clip', 'fixed_size', 'transparent', 'draw_border', 'bool',
|
boolean=('auto_clip', 'fixed_size', 'transparent', 'draw_border', 'bool',
|
||||||
'noclip', 'drawborder', 'selected', 'force', 'close_on_enter',
|
'noclip', 'drawborder', 'selected', 'force', 'close_on_enter',
|
||||||
'continuous', 'mouse_control', 'index_event'),
|
'continuous', 'mouse_control', 'index_event'),
|
||||||
|
48
tests.lua
48
tests.lua
@ -87,6 +87,9 @@ local fs = [[
|
|||||||
bgcolor[blue;both;green]
|
bgcolor[blue;both;green]
|
||||||
tooltip[1,2;3,4;text]
|
tooltip[1,2;3,4;text]
|
||||||
tooltip[elem;text;bgcolor]
|
tooltip[elem;text;bgcolor]
|
||||||
|
background9[1,2;3,4;bg.png;false;5]
|
||||||
|
background9[1,2;3,4;bg.png;false;5,6]
|
||||||
|
background9[1,2;3,4;bg.png;false;5,6,7,8]
|
||||||
]]
|
]]
|
||||||
fs = ('\n' .. fs):gsub('\n[ \n]*', '')
|
fs = ('\n' .. fs):gsub('\n[ \n]*', '')
|
||||||
|
|
||||||
@ -213,9 +216,43 @@ test_parse_unparse(fs, {
|
|||||||
tooltip_text = "text",
|
tooltip_text = "text",
|
||||||
bgcolor = "bgcolor",
|
bgcolor = "bgcolor",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type = "background9",
|
||||||
|
x = 1,
|
||||||
|
y = 2,
|
||||||
|
w = 3,
|
||||||
|
h = 4,
|
||||||
|
texture_name = "bg.png",
|
||||||
|
auto_clip = false,
|
||||||
|
middle_x = 5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "background9",
|
||||||
|
x = 1,
|
||||||
|
y = 2,
|
||||||
|
w = 3,
|
||||||
|
h = 4,
|
||||||
|
texture_name = "bg.png",
|
||||||
|
auto_clip = false,
|
||||||
|
middle_x = 5,
|
||||||
|
middle_y = 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "background9",
|
||||||
|
x = 1,
|
||||||
|
y = 2,
|
||||||
|
w = 3,
|
||||||
|
h = 4,
|
||||||
|
texture_name = "bg.png",
|
||||||
|
auto_clip = false,
|
||||||
|
middle_x = 5,
|
||||||
|
middle_y = 6,
|
||||||
|
middle_x2 = 7,
|
||||||
|
middle_y2 = 8,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
local function permutations(elem_s, elem, ...)
|
local function remove_trailing_params(elem_s, elem, ...)
|
||||||
local res = {}
|
local res = {}
|
||||||
local strings = {}
|
local strings = {}
|
||||||
local optional_params = {...}
|
local optional_params = {...}
|
||||||
@ -244,8 +281,8 @@ local function permutations(elem_s, elem, ...)
|
|||||||
return table.concat(strings, ""), res
|
return table.concat(strings, ""), res
|
||||||
end
|
end
|
||||||
|
|
||||||
test_parse_unparse(permutations(
|
test_parse_unparse(remove_trailing_params(
|
||||||
"model[1,2;3,4;abc;def;ghi,jkl;5,6;true;false;7,8]",
|
"model[1,2;3,4;abc;def;ghi,jkl;5,6;true;false;7,8;9]",
|
||||||
{
|
{
|
||||||
type = "model",
|
type = "model",
|
||||||
x = 1,
|
x = 1,
|
||||||
@ -260,10 +297,11 @@ test_parse_unparse(permutations(
|
|||||||
continuous = true,
|
continuous = true,
|
||||||
mouse_control = false,
|
mouse_control = false,
|
||||||
frame_loop_begin = 7,
|
frame_loop_begin = 7,
|
||||||
frame_loop_end = 8
|
frame_loop_end = 8,
|
||||||
|
animation_speed = 9
|
||||||
},
|
},
|
||||||
{"rotation_x", "rotation_y"}, "continuous", "mouse_control",
|
{"rotation_x", "rotation_y"}, "continuous", "mouse_control",
|
||||||
{"frame_loop_begin", "frame_loop_end"}
|
{"frame_loop_begin", "frame_loop_end"}, "animation_speed"
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user