From b07d22bdf2a34992ec60b8302708797e508a2794 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 24 Sep 2017 18:36:54 -0400 Subject: [PATCH] nil reference fix whitespace cleanup --- tasklist.lua | 309 +++++++++++++++++++++++++-------------------------- 1 file changed, 154 insertions(+), 155 deletions(-) diff --git a/tasklist.lua b/tasklist.lua index 250bc86b..ce2b06af 100644 --- a/tasklist.lua +++ b/tasklist.lua @@ -4,208 +4,207 @@ ---------------------------------------------------------------------------------------------------------------------------------------- local function create_tasklist_gui(event) - local player = game.players[event.player_index] + local player = game.players[event.player_index] - if player.gui.top.tasklist == nil then - local button = player.gui.top.add { name = "tasklist", type = "sprite-button", sprite = "item/blueprint" } - button.style.font = "default-bold" - button.style.minimal_height = 38 - button.style.minimal_width = 38 - button.style.top_padding = 2 - button.style.left_padding = 4 - button.style.right_padding = 4 - button.style.bottom_padding = 2 - end + if player.gui.top.tasklist == nil then + local button = player.gui.top.add { name = "tasklist", type = "sprite-button", sprite = "item/blueprint" } + button.style.font = "default-bold" + button.style.minimal_height = 38 + button.style.minimal_width = 38 + button.style.top_padding = 2 + button.style.left_padding = 4 + button.style.right_padding = 4 + button.style.bottom_padding = 2 + end end local function tasklist_show(player) - player.gui.left.direction = "horizontal" - local frame = player.gui.left.add { type = "frame", name = "tasklist-panel", direction = "vertical" } + player.gui.left.direction = "horizontal" + local frame = player.gui.left.add { type = "frame", name = "tasklist-panel", direction = "vertical" } - frame.add { type = "table", name = "tasklist_panel_table", colspan = 1 } + frame.add { type = "table", name = "tasklist_panel_table", colspan = 1 } - local tasklist_panel_table = frame.tasklist_panel_table + local tasklist_panel_table = frame.tasklist_panel_table - tasklist_panel_table.add { type = "label", caption = "Task List:", single_line = false, name = "tasklist_title"} - local tasklist_label = tasklist_panel_table["tasklist_title"] - tasklist_label.style.maximal_width = 208 - tasklist_label.style.minimal_width = 208 - tasklist_label.style.maximal_height = 165 - tasklist_label.style.font = "default" + tasklist_panel_table.add { type = "label", caption = "Task List:", single_line = false, name = "tasklist_title"} + local tasklist_label = tasklist_panel_table["tasklist_title"] + tasklist_label.style.maximal_width = 208 + tasklist_label.style.minimal_width = 208 + tasklist_label.style.maximal_height = 165 + tasklist_label.style.font = "default" - local counter = 0 - for y = 1, 5 do - if not (global.tasklist_items[y] == "") then - counter = counter + 1 + local counter = 0 + for y = 1, 5 do + if not (global.tasklist_items[y] == "") then + counter = counter + 1 - local z = tostring(y) + local z = tostring(y) - tasklist_panel_table.add { type = "label", caption = counter .. ". " .. global.tasklist_items[y], single_line = false, name = "tasklist_item_label_" .. z} - local tasklist_label = tasklist_panel_table["tasklist_item_label_" .. z] - tasklist_label.style.maximal_width = 208 - tasklist_label.style.minimal_width = 208 - tasklist_label.style.maximal_height = 165 - tasklist_label.style.font = "default" - end - end + tasklist_panel_table.add { type = "label", caption = counter .. ". " .. global.tasklist_items[y], single_line = false, name = "tasklist_item_label_" .. z} + local tasklist_label = tasklist_panel_table["tasklist_item_label_" .. z] + tasklist_label.style.maximal_width = 208 + tasklist_label.style.minimal_width = 208 + tasklist_label.style.maximal_height = 165 + tasklist_label.style.font = "default" + end + end - if global.tasklist_author ~= nil then - tasklist_panel_table.add { type = "label", caption = "-- updated by: " .. global.tasklist_author, single_line = false, name = "tasklist_author"} - local tasklist_label = tasklist_panel_table["tasklist_author"] - tasklist_label.style.maximal_width = 208 - tasklist_label.style.minimal_width = 208 - tasklist_label.style.maximal_height = 165 - tasklist_label.style.font = "default" - end + if global.tasklist_author ~= nil then + tasklist_panel_table.add { type = "label", caption = "-- updated by: " .. global.tasklist_author, single_line = false, name = "tasklist_author"} + local tasklist_label = tasklist_panel_table["tasklist_author"] + tasklist_label.style.maximal_width = 208 + tasklist_label.style.minimal_width = 208 + tasklist_label.style.maximal_height = 165 + tasklist_label.style.font = "default" + end - frame.add { type = "table", name = "tasklist_panel_button_table", colspan = 3 } - local tasklist_panel_button_table = frame.tasklist_panel_button_table + frame.add { type = "table", name = "tasklist_panel_button_table", colspan = 3 } + local tasklist_panel_button_table = frame.tasklist_panel_button_table - global.tasklist_panel_creation_time[player.index] = game.tick + global.tasklist_panel_creation_time[player.index] = game.tick - if is_regular( player.name ) or is_mod( player.name ) or player.admin then - tasklist_panel_button_table.add { type = "button", caption = "New Tasks", name = "new_tasklist_assembler_button" } - end + if is_regular( player.name ) or is_mod( player.name ) or player.admin then + tasklist_panel_button_table.add { type = "button", caption = "New Tasks", name = "new_tasklist_assembler_button" } + tasklist_panel_button_table.new_tasklist_assembler_button.style.font = "default-bold" + tasklist_panel_button_table.new_tasklist_assembler_button.style.minimal_height = 38 + end - tasklist_panel_button_table.add { type = "button", caption = "Hide", name = "tasklist_hide_button" } - - tasklist_panel_button_table.tasklist_hide_button.style.minimal_width = 70 - tasklist_panel_button_table.new_tasklist_assembler_button.style.font = "default-bold" - tasklist_panel_button_table.new_tasklist_assembler_button.style.minimal_height = 38 - tasklist_panel_button_table.tasklist_hide_button.style.font = "default-bold" - tasklist_panel_button_table.tasklist_hide_button.style.minimal_height = 38 - -- Possible for later preferences tasklist_panel_button_table.add { type = "checkbox", caption = "Show Tasklist", state = global.autoshow_tasklist_for_player[player.name], name = "auto_show_tasklist_checkbox" } + tasklist_panel_button_table.add { type = "button", caption = "Hide", name = "tasklist_hide_button" } + tasklist_panel_button_table.tasklist_hide_button.style.minimal_width = 70 + tasklist_panel_button_table.tasklist_hide_button.style.font = "default-bold" + tasklist_panel_button_table.tasklist_hide_button.style.minimal_height = 38 + -- Possible for later preferences tasklist_panel_button_table.add { type = "checkbox", caption = "Show Tasklist", state = global.autoshow_tasklist_for_player[player.name], name = "auto_show_tasklist_checkbox" } end local function tasklist(player) - local frame = player.gui.left["tasklist-assembler"] - frame = frame.table_tasklist_assembler + local frame = player.gui.left["tasklist-assembler"] + frame = frame.table_tasklist_assembler - global.tasklist_items = {"","","","",""} - global.tasklist_items[1] = frame.textfield_task_1.text - global.tasklist_items[2] = frame.textfield_task_2.text - global.tasklist_items[3] = frame.textfield_task_3.text - global.tasklist_items[4] = frame.textfield_task_4.text - global.tasklist_items[5] = frame.textfield_task_5.text - if (global.tasklist_items[5] .. global.tasklist_items[4] .. global.tasklist_items[3] .. global.tasklist_items[2] .. global.tasklist_items[1] == "") then - return - end + global.tasklist_items = {"","","","",""} + global.tasklist_items[1] = frame.textfield_task_1.text + global.tasklist_items[2] = frame.textfield_task_2.text + global.tasklist_items[3] = frame.textfield_task_3.text + global.tasklist_items[4] = frame.textfield_task_4.text + global.tasklist_items[5] = frame.textfield_task_5.text + if (global.tasklist_items[5] .. global.tasklist_items[4] .. global.tasklist_items[3] .. global.tasklist_items[2] .. global.tasklist_items[1] == "") then + return + end - global.tasklist_author = player.name + global.tasklist_author = player.name - local msg = player.name - msg = msg .. " has created an updated tasklist!" + local msg = player.name + msg = msg .. " has created an updated tasklist!" - local frame = player.gui.left["tasklist-assembler"] - frame.destroy() + local frame = player.gui.left["tasklist-assembler"] + frame.destroy() - for _,player in pairs(game.players) do + for _,player in pairs(game.players) do - local frame = player.gui.left["tasklist-panel"] + local frame = player.gui.left["tasklist-panel"] - if (frame) then - frame.destroy() - end + if (frame) then + frame.destroy() + end - if (global.autoshow_tasklist_for_player[player.name] == true) then - tasklist_show(player) - end + if (global.autoshow_tasklist_for_player[player.name] == true) then + tasklist_show(player) + end - end + end - game.print(msg) + game.print(msg) end local function tasklist_assembler(player) - local frame = player.gui.left.add { type = "frame", name = "tasklist-assembler", caption = "" } - local frame_table = frame.add { type = "table", name = "table_tasklist_assembler", colspan = 2 } - frame_table.add { type = "label", caption = "Task #1:" } - frame_table.add { type = "textfield", name = "textfield_task_1", text = global.tasklist_items[1], } - frame_table["textfield_task_1"].style.minimal_width = 450 - frame_table["textfield_task_1"].style.maximal_width = 450 - frame_table.add { type = "label", caption = "Task #2:" } - frame_table.add { type = "textfield", name = "textfield_task_2", text = global.tasklist_items[2] } - frame_table["textfield_task_2"].style.minimal_width = 450 - frame_table["textfield_task_2"].style.maximal_width = 450 - frame_table.add { type = "label", caption = "Task #3:" } - frame_table.add { type = "textfield", name = "textfield_task_3", text = global.tasklist_items[3] } - frame_table["textfield_task_3"].style.minimal_width = 450 - frame_table["textfield_task_3"].style.maximal_width = 450 - frame_table.add { type = "label", caption = "Task #4:" } - frame_table.add { type = "textfield", name = "textfield_task_4", text = global.tasklist_items[4] } - frame_table["textfield_task_4"].style.minimal_width = 450 - frame_table["textfield_task_4"].style.maximal_width = 450 - frame_table.add { type = "label", caption = "Task #5:" } - frame_table.add { type = "textfield", name = "textfield_task_5", text = global.tasklist_items[5] } - frame_table["textfield_task_5"].style.minimal_width = 450 - frame_table["textfield_task_5"].style.maximal_width = 450 - frame_table.add { type = "label", caption = "" } - frame_table.add { type = "button", name = "create_new_tasklist_button", caption = "Publish" } + local frame = player.gui.left.add { type = "frame", name = "tasklist-assembler", caption = "" } + local frame_table = frame.add { type = "table", name = "table_tasklist_assembler", colspan = 2 } + frame_table.add { type = "label", caption = "Task #1:" } + frame_table.add { type = "textfield", name = "textfield_task_1", text = global.tasklist_items[1], } + frame_table["textfield_task_1"].style.minimal_width = 450 + frame_table["textfield_task_1"].style.maximal_width = 450 + frame_table.add { type = "label", caption = "Task #2:" } + frame_table.add { type = "textfield", name = "textfield_task_2", text = global.tasklist_items[2] } + frame_table["textfield_task_2"].style.minimal_width = 450 + frame_table["textfield_task_2"].style.maximal_width = 450 + frame_table.add { type = "label", caption = "Task #3:" } + frame_table.add { type = "textfield", name = "textfield_task_3", text = global.tasklist_items[3] } + frame_table["textfield_task_3"].style.minimal_width = 450 + frame_table["textfield_task_3"].style.maximal_width = 450 + frame_table.add { type = "label", caption = "Task #4:" } + frame_table.add { type = "textfield", name = "textfield_task_4", text = global.tasklist_items[4] } + frame_table["textfield_task_4"].style.minimal_width = 450 + frame_table["textfield_task_4"].style.maximal_width = 450 + frame_table.add { type = "label", caption = "Task #5:" } + frame_table.add { type = "textfield", name = "textfield_task_5", text = global.tasklist_items[5] } + frame_table["textfield_task_5"].style.minimal_width = 450 + frame_table["textfield_task_5"].style.maximal_width = 450 + frame_table.add { type = "label", caption = "" } + frame_table.add { type = "button", name = "create_new_tasklist_button", caption = "Publish" } end function tasklist_sync_for_new_joining_player(event) - if not global.tasklist_items then global.tasklist_items = {"","","","",""} end - if not global.autoshow_tasklist_for_player then global.autoshow_tasklist_for_player = {} end - if not global.tasklist_duration_in_seconds then global.tasklist_duration_in_seconds = 99 end - if not global.tasklist_panel_creation_time then global.tasklist_panel_creation_time = {} end + if not global.tasklist_items then global.tasklist_items = {"","","","",""} end + if not global.autoshow_tasklist_for_player then global.autoshow_tasklist_for_player = {} end + if not global.tasklist_duration_in_seconds then global.tasklist_duration_in_seconds = 99 end + if not global.tasklist_panel_creation_time then global.tasklist_panel_creation_time = {} end - local player = game.players[event.player_index] + local player = game.players[event.player_index] - global.autoshow_tasklist_for_player[player.name] = true + global.autoshow_tasklist_for_player[player.name] = true - local frame = player.gui.left["tasklist-panel"] - if (frame == nil) then - tasklist_show(player) - end + local frame = player.gui.left["tasklist-panel"] + if (frame == nil) then + tasklist_show(player) + end end local function on_gui_click(event) - if not (event and event.element and event.element.valid) then return end - local player = game.players[event.element.player_index] - local name = event.element.name + if not (event and event.element and event.element.valid) then return end + local player = game.players[event.element.player_index] + local name = event.element.name - if (name == "tasklist") then - local frame = player.gui.left["tasklist-panel"] - if (frame) then - frame.destroy() - else - tasklist_show(player) - end + if (name == "tasklist") then + local frame = player.gui.left["tasklist-panel"] + if (frame) then + frame.destroy() + else + tasklist_show(player) + end - local frame = player.gui.left["tasklist-assembler"] - if (frame) then - frame.destroy() - end - end + local frame = player.gui.left["tasklist-assembler"] + if (frame) then + frame.destroy() + end + end - if (name == "new_tasklist_assembler_button") then - local frame = player.gui.left["tasklist-assembler"] - if (frame) then - frame.destroy() - else - tasklist_assembler(player) - end - end + if (name == "new_tasklist_assembler_button") then + local frame = player.gui.left["tasklist-assembler"] + if (frame) then + frame.destroy() + else + tasklist_assembler(player) + end + end - if (name == "create_new_tasklist_button") then - tasklist(player) - end + if (name == "create_new_tasklist_button") then + tasklist(player) + end - if (name == "tasklist_hide_button") then - local frame = player.gui.left["tasklist-panel"] - if (frame) then - frame.destroy() - end - local frame = player.gui.left["tasklist-assembler"] - if (frame) then - frame.destroy() - end - end + if (name == "tasklist_hide_button") then + local frame = player.gui.left["tasklist-panel"] + if (frame) then + frame.destroy() + end + local frame = player.gui.left["tasklist-assembler"] + if (frame) then + frame.destroy() + end + end - if (name == "auto_show_tasklist_checkbox") then - global.autoshow_tasklist_for_player[player.name] = event.element.state - end + if (name == "auto_show_tasklist_checkbox") then + global.autoshow_tasklist_for_player[player.name] = event.element.state + end end Event.register(defines.events.on_gui_click, on_gui_click)