Update elements and fix background9 unparsing

This commit is contained in:
luk3yx 2021-03-21 17:42:52 +13:00
parent d1ba059652
commit 17503d543b
5 changed files with 70 additions and 16 deletions

View File

@ -402,27 +402,28 @@ local compare_blanks
do
local function get_nonempty(a)
if a.nonempty then
return a.nonempty, a.strings
return a.nonempty, a.strings, a.total_length
end
local nonempty, strings = 0, 0
local nonempty, strings, total_length = 0, 0, #a
for _, i in ipairs(a) do
if type(i) == 'string' and i ~= '' then
nonempty = nonempty + 1
strings = strings + 1
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
a.nonempty, a.strings = nonempty, strings
return nonempty, strings
a.nonempty, a.strings, a.total_length = nonempty, strings, total_length
return nonempty, strings, total_length
end
function compare_blanks(a, b)
local a_n, a_strings = get_nonempty(a)
local b_n, b_strings = get_nonempty(b)
local a_n, a_strings, a_l = get_nonempty(a)
local b_n, b_strings, b_l = get_nonempty(b)
if a_n == b_n then
local a_l = #a
local b_l = #b
if a_l == b_l then
-- Prefer elements with less tables
return a_strings > b_strings

File diff suppressed because one or more lines are too long

View File

@ -242,6 +242,21 @@ listring:
- [list_name, string]
- []
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]
- [y, number]
- - [w, number]

View File

@ -16,7 +16,7 @@ def _make_known(**kwargs):
_known = _make_known(
number=('x', 'y', 'w', 'h', 'selected_idx', 'version',
'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',
'noclip', 'drawborder', 'selected', 'force', 'close_on_enter',
'continuous', 'mouse_control', 'index_event'),

View File

@ -87,6 +87,9 @@ local fs = [[
bgcolor[blue;both;green]
tooltip[1,2;3,4;text]
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]*', '')
@ -213,9 +216,43 @@ test_parse_unparse(fs, {
tooltip_text = "text",
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 strings = {}
local optional_params = {...}
@ -244,8 +281,8 @@ local function permutations(elem_s, elem, ...)
return table.concat(strings, ""), res
end
test_parse_unparse(permutations(
"model[1,2;3,4;abc;def;ghi,jkl;5,6;true;false;7,8]",
test_parse_unparse(remove_trailing_params(
"model[1,2;3,4;abc;def;ghi,jkl;5,6;true;false;7,8;9]",
{
type = "model",
x = 1,
@ -260,10 +297,11 @@ test_parse_unparse(permutations(
continuous = true,
mouse_control = false,
frame_loop_begin = 7,
frame_loop_end = 8
frame_loop_end = 8,
animation_speed = 9
},
{"rotation_x", "rotation_y"}, "continuous", "mouse_control",
{"frame_loop_begin", "frame_loop_end"}
{"frame_loop_begin", "frame_loop_end"}, "animation_speed"
))