18
18
---- ----------------------------------------------------------------------------
19
19
local function filter_texture_pack_list (list )
20
20
local retval = {}
21
+
21
22
for _ , item in ipairs (list ) do
22
23
if item ~= " base" then
23
24
retval [# retval + 1 ] = item
@@ -35,9 +36,9 @@ local function render_texture_pack_list(list)
35
36
local retval = " "
36
37
37
38
for i , v in ipairs (list ) do
38
- if v :sub (1 ,1 ) ~= " ." then
39
+ if v :sub (1 , 1 ) ~= " ." then
39
40
if retval ~= " " then
40
- retval = retval .. " ,"
41
+ retval = retval .. " ,"
41
42
end
42
43
43
44
retval = retval .. core .formspec_escape (v )
50
51
---- ----------------------------------------------------------------------------
51
52
local function get_formspec (tabview , name , tabdata )
52
53
53
- local retval = " label[4,-0.25;" .. fgettext (" Select texture pack:" ) .. " ]" ..
54
+ local retval = " label[4,-0.25;" .. fgettext (" Select texture pack:" ) .. " ]" ..
54
55
" textlist[4,0.25;7.5,5.0;TPs;"
55
56
56
57
local current_texture_path = core .setting_get (" texture_path" )
57
58
local list = filter_texture_pack_list (core .get_dir_list (core .get_texturepath (), true ))
58
59
local index = tonumber (core .setting_get (" mainmenu_last_selected_TP" ))
59
60
60
- if index == nil then index = 1 end
61
+ if not index then index = 1 end
61
62
62
63
if current_texture_path == " " then
63
64
retval = retval ..
@@ -66,15 +67,16 @@ local function get_formspec(tabview, name, tabdata)
66
67
return retval
67
68
end
68
69
69
- local infofile = current_texture_path .. DIR_DELIM .. " description.txt"
70
+ local infofile = current_texture_path .. DIR_DELIM .. " description.txt"
70
71
-- This adds backwards compatibility for old texture pack description files named
71
72
-- "info.txt", and should be removed once all such texture packs have been updated
72
73
if not file_exists (infofile ) then
73
- infofile = current_texture_path .. DIR_DELIM .. " info.txt"
74
+ infofile = current_texture_path .. DIR_DELIM .. " info.txt"
74
75
if file_exists (infofile ) then
75
- core .log (" info.txt is depreciated. description.txt should be used instead." );
76
+ core .log (" info.txt is depreciated. description.txt should be used instead." )
76
77
end
77
78
end
79
+
78
80
local infotext = " "
79
81
local f = io.open (infofile , " r" )
80
82
if not f then
@@ -84,8 +86,8 @@ local function get_formspec(tabview, name, tabdata)
84
86
f :close ()
85
87
end
86
88
87
- local screenfile = current_texture_path .. DIR_DELIM .. " screenshot.png"
88
- local no_screenshot = nil
89
+ local screenfile = current_texture_path .. DIR_DELIM .. " screenshot.png"
90
+ local no_screenshot
89
91
if not file_exists (screenfile ) then
90
92
screenfile = nil
91
93
no_screenshot = defaulttexturedir .. " no_screenshot.png"
@@ -94,24 +96,24 @@ local function get_formspec(tabview, name, tabdata)
94
96
return retval ..
95
97
render_texture_pack_list (list ) ..
96
98
" ;" .. index .. " ]" ..
97
- " image[0.25,0.25;4.0,3.7;" .. core .formspec_escape (screenfile or no_screenshot ).. " ]" ..
98
- " textarea[0.6,3.25 ;3.7,1.5;;" .. core .formspec_escape (infotext or " " ).. " ;]"
99
+ " image[0.25,0.25;4.0,3.7;" .. core .formspec_escape (screenfile or no_screenshot ) .. " ]" ..
100
+ " textarea[0.6,3.5 ;3.7,1.5;;" .. core .formspec_escape (infotext or " " ) .. " ;]"
99
101
end
100
102
101
103
---- ----------------------------------------------------------------------------
102
104
local function main_button_handler (tabview , fields , name , tabdata )
103
- if fields [" TPs" ] ~= nil then
105
+ if fields [" TPs" ] then
104
106
local event = core .explode_textlist_event (fields [" TPs" ])
105
107
if event .type == " CHG" or event .type == " DCL" then
106
108
local index = core .get_textlist_index (" TPs" )
107
- core .setting_set (" mainmenu_last_selected_TP" ,
108
- index )
109
+ core .setting_set (" mainmenu_last_selected_TP" , index )
109
110
local list = filter_texture_pack_list (core .get_dir_list (core .get_texturepath (), true ))
110
111
local current_index = core .get_textlist_index (" TPs" )
111
- if current_index ~= nil and # list >= current_index then
112
- local new_path = core .get_texturepath ().. DIR_DELIM .. list [current_index ]
113
- if list [current_index ] == fgettext (" None" ) then new_path = " " end
114
-
112
+ if current_index and # list >= current_index then
113
+ local new_path = core .get_texturepath () .. DIR_DELIM .. list [current_index ]
114
+ if list [current_index ] == fgettext (" None" ) then
115
+ new_path = " "
116
+ end
115
117
core .setting_set (" texture_path" , new_path )
116
118
end
117
119
end
0 commit comments