show statistics about how often a variable is used in the show usage formspec
This commit is contained in:
parent
85a9a50d38
commit
ceaff334e3
@ -393,6 +393,8 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec
|
||||
local npc_list = yl_speak_up.get_npc_users_of_variable(var_name)
|
||||
-- list of all relevant preconditions, actions and effects
|
||||
local res = {}
|
||||
local count_read = 0
|
||||
local count_changed = 0
|
||||
for i, n_id in ipairs(npc_list) do
|
||||
-- the NPC may not even be loaded
|
||||
local dialog = yl_speak_up.load_dialog(n_id)
|
||||
@ -414,6 +416,7 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec
|
||||
minetest.formspec_escape(
|
||||
yl_speak_up.show_precondition(p, pname))
|
||||
sort_value = (p.p_var_cmp_value or 0)
|
||||
count_read = count_read + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -430,6 +433,7 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec
|
||||
-- values set in the results are more important than
|
||||
-- those set in preconditions
|
||||
sort_value = (r.r_var_cmp_value or 0)
|
||||
count_changed = count_changed + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -505,11 +509,27 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec
|
||||
minetest.formspec_escape(back_button_text).."]",
|
||||
"button[0.2,31.6;56.6,1.2;"..back_button_name..";"..
|
||||
minetest.formspec_escape(back_button_text).."]",
|
||||
"label[20.0,1.8;"..
|
||||
minetest.formspec_escape("Variable \""..tostring(var_name or "- ? -")..
|
||||
"\" is used here:").."]"..
|
||||
-- type x_id color type text
|
||||
"tablecolumns[color,span=1;text;color,span=1;text;color,span=1;text;color,span=1;text]",
|
||||
"table[1.2,1.4;55.0,30.0;table_of_variable_uses;"
|
||||
"table[1.2,2.4;55.0,28.0;table_of_variable_uses;"
|
||||
}
|
||||
-- insert blank lines between lines belonging together
|
||||
table.insert(formspec, table.concat(sorted_res, ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#FFFFFF,,"))
|
||||
table.insert(formspec, table.concat(sorted_res, ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#FFFFFF,,").."]")
|
||||
|
||||
if(#sorted_res > 0 and (count_read > 0 or count_changed > 0)) then
|
||||
table.insert(formspec,
|
||||
"label[16.0,31.0;The variable is accessed in "..tostring(count_read)..
|
||||
" pre(C)onditions and changed in "..tostring(count_changed)..
|
||||
" (Ef)ffects.]")
|
||||
else
|
||||
-- TODO: make delete_unused_variable work
|
||||
table.insert(formspec,
|
||||
"button[0.2,30.6;56.6,1.2;delete_unused_variable;"..
|
||||
minetest.formspec_escape("Delete this unused variable \""..
|
||||
tostring(var_name or "- ? -")).."\".]")
|
||||
end
|
||||
return table.concat(formspec, "\n")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user