From 9061327a1d58cdcea4c3427210c1c42887497112 Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Sun, 3 Jul 2022 00:22:24 +0200 Subject: [PATCH] Fix failing test and update formatting Tests were failing due to udpates to (downloaded) factorio linter file. Formatting changed due to update of Lua Language Server --- control.lua | 10 +- prototypes/shortcuts.lua | 28 ++-- prototypes/sprites.lua | 16 +- prototypes/styles.lua | 66 ++++----- scripts/camera.lua | 4 +- scripts/config.lua | 4 +- scripts/gui.lua | 252 +++++++++++++++++--------------- scripts/main.lua | 17 ++- scripts/tracker.lua | 25 ++-- tests/camera.lua | 50 ++++--- tests/camera_follow-tracker.lua | 21 +-- tests/main.lua | 25 ++-- tests/surface.lua | 15 +- tests/tracker-base.lua | 29 ++-- tests/tracker-player.lua | 13 +- tests/tracker-rocket.lua | 21 ++- tests/tracker.lua | 6 +- tests/utils.lua | 18 +-- 18 files changed, 329 insertions(+), 291 deletions(-) mode change 100755 => 100644 tests/camera_follow-tracker.lua mode change 100755 => 100644 tests/tracker-player.lua mode change 100755 => 100644 tests/tracker-rocket.lua diff --git a/control.lua b/control.lua index f42bee9..316694c 100644 --- a/control.lua +++ b/control.lua @@ -10,10 +10,10 @@ local function on_init() for index, player in pairs(game.players) do -- initialize player(s) when mod is loaded into existing game - TLBE.Config.reload({player_index = index}) + TLBE.Config.reload({ player_index = index }) - player.print({"mod-loaded"}, {r = 1, g = 0.5, b = 0}) - player.print({"mod-loaded2"}) + player.print({ "mod-loaded" }, { r = 1, g = 0.5, b = 0 }) + player.print({ "mod-loaded2" }) end local baseBBox = TLBE.Main.get_base_bbox() @@ -33,7 +33,7 @@ local function on_player_created(event) -- Initialize playerSettings TLBE.Config.reload(event) - game.players[event.player_index].print({"mod-loaded2"}, {r = 1, g = 0.5, b = 0}) + game.players[event.player_index].print({ "mod-loaded2" }, { r = 1, g = 0.5, b = 0 }) end local function on_tick() @@ -56,7 +56,7 @@ script.on_event(defines.events.on_surface_created, TLBE.GUI.onSurfacesUpdated) script.on_event(defines.events.on_surface_imported, TLBE.GUI.onSurfacesUpdated) script.on_event(defines.events.on_surface_renamed, TLBE.GUI.onSurfaceChanged) script.on_event(defines.events.on_built_entity, TLBE.Main.entity_built, - {{filter = "vehicle", invert = true}}) + { { filter = "vehicle", invert = true } }) script.on_event(defines.events.on_rocket_launch_ordered, TLBE.Main.rocket_launch) script.on_event(defines.events.on_rocket_launched, TLBE.Main.rocket_launched) diff --git a/prototypes/shortcuts.lua b/prototypes/shortcuts.lua index 1389117..6aeed30 100644 --- a/prototypes/shortcuts.lua +++ b/prototypes/shortcuts.lua @@ -19,7 +19,7 @@ data:extend( toggleable = true, order = "a[mod]-tlbe", action = "lua", - localised_name = {"shortcut.tlbe"}, + localised_name = { "shortcut.tlbe" }, associated_control_input = "tlbe-main-window-toggle", icon = { -- tlbe-logo @@ -27,9 +27,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 50, - position = {0, 0}, + position = { 0, 0 }, scale = 1, - flags = {"icon"} + flags = { "icon" } }, small_icon = { -- tlbe-logo @@ -37,9 +37,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 50, - position = {0, 0}, + position = { 0, 0 }, scale = 1, - flags = {"icon"} + flags = { "icon" } }, disabled_small_icon = { -- tlbe-logo-white @@ -47,9 +47,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 50, - position = {65, 0}, + position = { 65, 0 }, scale = 1, - flags = {"icon"} + flags = { "icon" } } }, { @@ -58,7 +58,7 @@ data:extend( toggleable = true, order = "a[mod]-tlbe", action = "lua", - localised_name = {"shortcut.tlbe-pause"}, + localised_name = { "shortcut.tlbe-pause" }, associated_control_input = "tlbe-pause-cameras", icon = { -- tlbe-logo @@ -66,9 +66,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 64, - position = {0, 0}, + position = { 0, 0 }, scale = 1, - flags = {"icon"} + flags = { "icon" } }, small_icon = { -- tlbe-logo @@ -76,9 +76,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 64, - position = {0, 0}, + position = { 0, 0 }, scale = 1, - flags = {"icon"} + flags = { "icon" } }, disabled_small_icon = { -- tlbe-logo-white @@ -86,9 +86,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 50, - position = {65, 0}, + position = { 65, 0 }, scale = 1, - flags = {"icon"} + flags = { "icon" } } } } diff --git a/prototypes/sprites.lua b/prototypes/sprites.lua index a767e09..846b38e 100644 --- a/prototypes/sprites.lua +++ b/prototypes/sprites.lua @@ -8,9 +8,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 50, - position = {0, 0}, + position = { 0, 0 }, scale = 0.5, - flags = {"gui-icon"} + flags = { "gui-icon" } }, { type = "sprite", @@ -19,9 +19,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 50, - position = {65, 0}, + position = { 65, 0 }, scale = 0.5, - flags = {"gui-icon"} + flags = { "gui-icon" } }, { type = "sprite", @@ -30,9 +30,9 @@ data:extend( priority = "extra-high-no-scale", width = 64, height = 64, - position = {0, 0}, + position = { 0, 0 }, scale = 0.5, - flags = {"gui-icon"} + flags = { "gui-icon" } }, { type = "sprite", @@ -43,7 +43,7 @@ data:extend( height = 32, mipmap_count = 2, scale = 0.5, - flags = {"gui-icon"} + flags = { "gui-icon" } }, { type = "sprite", @@ -53,7 +53,7 @@ data:extend( width = 32, height = 32, mipmap_count = 2, - flags = {"gui-icon"} + flags = { "gui-icon" } } } ) diff --git a/prototypes/styles.lua b/prototypes/styles.lua index 08125f8..3dbbd5d 100644 --- a/prototypes/styles.lua +++ b/prototypes/styles.lua @@ -10,7 +10,7 @@ local tab_width = 560 -- 'borrowed' from core local function default_glow(tint_value, scale_value) return { - position = {200, 128}, + position = { 200, 128 }, corner_size = 8, tint = tint_value, scale = scale_value, @@ -20,7 +20,7 @@ end local function rounded_corners_glow(tint_value) return { - position = {240, 783}, + position = { 240, 783 }, corner_size = 16, tint = tint_value, top_outer_border_shift = 4, @@ -31,8 +31,8 @@ local function rounded_corners_glow(tint_value) } end -local red_button_glow_color = {254, 90, 90, 128} -local default_dirt_color = {15, 7, 3, 100} +local red_button_glow_color = { 254, 90, 90, 128 } +local default_dirt_color = { 15, 7, 3, 100 } local default_dirt = default_glow(default_dirt_color, 0.5) local textbox_dirt = rounded_corners_glow(default_dirt_color) @@ -57,7 +57,7 @@ default_gui["tlbe_fancy_list_box_item_selected"] = { type = "frame_style", parent = "tlbe_fancy_list_box_item", graphical_set = { - base = {position = {34, 17}, corner_size = 8} + base = { position = { 34, 17 }, corner_size = 8 } } } @@ -110,13 +110,13 @@ default_gui["tlbe_frame_action_button_selected"] = { parent = "frame_action_button", -- From frame_action_button.selected_graphical_set default_graphical_set = { - base = {position = {272, 169}, corner_size = 8}, - shadow = {position = {440, 24}, corner_size = 8, draw_type = "outer"} + base = { position = { 272, 169 }, corner_size = 8 }, + shadow = { position = { 440, 24 }, corner_size = 8, draw_type = "outer" } }, -- From frame_action_button.selected_hovered_graphical_set hovered_graphical_set = { - base = {position = {369, 17}, corner_size = 8}, - shadow = {position = {440, 24}, corner_size = 8, draw_type = "outer"} + base = { position = { 369, 17 }, corner_size = 8 }, + shadow = { position = { 440, 24 }, corner_size = 8, draw_type = "outer" } } } @@ -125,12 +125,12 @@ default_gui["tlbe_tool_button_selected"] = { parent = "tool_button", -- From button.selected_graphical_set default_graphical_set = { - base = {position = {225, 17}, corner_size = 8}, + base = { position = { 225, 17 }, corner_size = 8 }, shadow = default_dirt }, -- From button.selected_hovered_graphical_set hovered_graphical_set = { - base = {position = {369, 17}, corner_size = 8}, + base = { position = { 369, 17 }, corner_size = 8 }, shadow = default_dirt } } @@ -162,16 +162,16 @@ default_gui["tble_tracker_add_dropdown"] = { -- Default button that glows red on hover/select default_gui["tlbe_tracker_remove_button"] = { type = "button_style", - size = {15, 28}, -- extra height to align (more) nicely with order buttons + size = { 15, 28 }, -- extra height to align (more) nicely with order buttons parent = "tlbe_fancy_list_box_button", -- from red_button hovered_graphical_set = { - base = {position = {170, 17}, corner_size = 8}, + base = { position = { 170, 17 }, corner_size = 8 }, shadow = default_dirt, glow = default_glow(red_button_glow_color, 0.5) }, clicked_graphical_set = { - base = {position = {187, 17}, corner_size = 8}, + base = { position = { 187, 17 }, corner_size = 8 }, shadow = default_dirt } } @@ -186,12 +186,12 @@ default_gui["tlbe_tracker_button_selected"] = { parent = "tlbe_fancy_list_box_button", -- From button.selected_graphical_set default_graphical_set = { - base = {position = {225, 17}, corner_size = 8}, + base = { position = { 225, 17 }, corner_size = 8 }, shadow = default_dirt }, -- From button.selected_hovered_graphical_set hovered_graphical_set = { - base = {position = {369, 17}, corner_size = 8}, + base = { position = { 369, 17 }, corner_size = 8 }, shadow = default_dirt } } @@ -201,72 +201,72 @@ default_gui["tlbe_tracker_button_red"] = { parent = "tlbe_fancy_list_box_button", -- From red_button default_graphical_set = { - base = {position = {136, 17}, corner_size = 8}, + base = { position = { 136, 17 }, corner_size = 8 }, shadow = default_dirt }, hovered_graphical_set = { - base = {position = {170, 17}, corner_size = 8}, + base = { position = { 170, 17 }, corner_size = 8 }, shadow = default_dirt, glow = default_glow(red_button_glow_color, 0.5) }, clicked_graphical_set = { - base = {position = {187, 17}, corner_size = 8}, + base = { position = { 187, 17 }, corner_size = 8 }, shadow = default_dirt }, disabled_graphical_set = { - base = {position = {153, 17}, corner_size = 8}, + base = { position = { 153, 17 }, corner_size = 8 }, shadow = default_dirt } } default_gui["tlbe_order_up_button"] = { type = "button_style", - size = {12, 12}, + size = { 12, 12 }, -- from column_ordering_ascending_button_style default_graphical_set = { filename = "__core__/graphics/arrows/table-header-sort-arrow-up-active.png", - size = {16, 16}, + size = { 16, 16 }, scale = 0.5 }, hovered_graphical_set = { filename = "__core__/graphics/arrows/table-header-sort-arrow-up-hover.png", - size = {16, 16}, + size = { 16, 16 }, scale = 0.5 }, clicked_graphical_set = { filename = "__core__/graphics/arrows/table-header-sort-arrow-up-active.png", - size = {16, 16}, + size = { 16, 16 }, scale = 0.5 }, disabled_graphical_set = { filename = "__core__/graphics/arrows/table-header-sort-arrow-up-white.png", - size = {16, 16}, + size = { 16, 16 }, scale = 0.5 } } default_gui["tlbe_order_down_button"] = { type = "button_style", - size = {12, 12}, + size = { 12, 12 }, -- from column_ordering_descending_button_style default_graphical_set = { filename = "__core__/graphics/arrows/table-header-sort-arrow-down-active.png", - size = {16, 16}, + size = { 16, 16 }, scale = 0.5 }, hovered_graphical_set = { filename = "__core__/graphics/arrows/table-header-sort-arrow-down-hover.png", - size = {16, 16}, + size = { 16, 16 }, scale = 0.5 }, clicked_graphical_set = { filename = "__core__/graphics/arrows/table-header-sort-arrow-down-active.png", - size = {16, 16}, + size = { 16, 16 }, scale = 0.5 }, disabled_graphical_set = { filename = "__core__/graphics/arrows/table-header-sort-arrow-down-white.png", - size = {16, 16}, + size = { 16, 16 }, scale = 0.5 } } @@ -303,11 +303,11 @@ default_gui["tlbe_config_half_width_textfield_invalid"] = { parent = "tlbe_config_half_width_textfield", -- from invalid_value_textfield default_background = { - base = {position = {0, 913}, corner_size = 8}, + base = { position = { 0, 913 }, corner_size = 8 }, shadow = textbox_dirt }, active_background = { - base = {position = {0, 913}, corner_size = 8}, + base = { position = { 0, 913 }, corner_size = 8 }, shadow = textbox_dirt } } @@ -315,7 +315,7 @@ default_gui["tlbe_config_half_width_textfield_invalid"] = { -- aligns 2 tlbe_config_half_width_textfield styles textfields with a single tlbe_config_textfield default_gui["tlbe_config_half_width_label"] = { type = "label_style", - size = {12, 28}, -- textbox height + size = { 12, 28 }, -- textbox height horizontal_align = "center", vertical_align = "center" } diff --git a/scripts/camera.lua b/scripts/camera.lua index 3b8fc18..10c6d5d 100644 --- a/scripts/camera.lua +++ b/scripts/camera.lua @@ -147,8 +147,8 @@ function Camera.followTrackerSmooth(playerSettings, player, camera, tracker) if camera.zoom < minZoom then if playerSettings.noticeMaxZoom == nil then - player.print({"max-zoom"}, {r = 1}) - player.print({"msg-once"}) + player.print({ "max-zoom" }, { r = 1 }) + player.print({ "msg-once" }) playerSettings.noticeMaxZoom = true end diff --git a/scripts/config.lua b/scripts/config.lua index 2ed4c49..27d7d63 100644 --- a/scripts/config.lua +++ b/scripts/config.lua @@ -33,11 +33,11 @@ function Config.newPlayerSettings(player) local camera = Camera.newCamera(player, {}) camera.name = "main" - camera.trackers = {trackers[1], trackers[2], trackers[3]} + camera.trackers = { trackers[1], trackers[2], trackers[3] } return { -- Setup a default camera and attach trackers to it - cameras = {camera}, + cameras = { camera }, trackers = trackers } end diff --git a/scripts/gui.lua b/scripts/gui.lua index 167563f..72263c4 100644 --- a/scripts/gui.lua +++ b/scripts/gui.lua @@ -1,11 +1,11 @@ local GUI = { - allTrackers = {"area", "base", "player", "rocket"}, - allTrackersLabels = {{"tracker-area"}, {"tracker-base"}, {"tracker-player"}, {"tracker-rocket"}}, + allTrackers = { "area", "base", "player", "rocket" }, + allTrackersLabels = { { "tracker-area" }, { "tracker-base" }, { "tracker-player" }, { "tracker-rocket" } }, allTrackersLabelsMap = { - area = {"tracker-area"}, - base = {"tracker-base"}, - player = {"tracker-player"}, - rocket = {"tracker-rocket"} + area = { "tracker-area" }, + base = { "tracker-base" }, + player = { "tracker-player" }, + rocket = { "tracker-rocket" } } } @@ -177,7 +177,7 @@ function GUI.onClick(event) local selectedTracker = playerSettings.trackers[playerSettings.guiPersist.selectedTracker] local tag = Utils.findChartTag(player.force.find_chart_tags(game.surfaces[1]), selectedTracker.name .. "-tr") if tag == nil then - player.print({"tag-not-found", selectedTracker.name .. "-tr"}) + player.print({ "tag-not-found", selectedTracker.name .. "-tr" }) else -- Note that game origin is top-left, so top is min and bottom is max selectedTracker.maxPos.x = math.floor(tag.position.x) @@ -191,7 +191,7 @@ function GUI.onClick(event) local selectedTracker = playerSettings.trackers[playerSettings.guiPersist.selectedTracker] local tag = Utils.findChartTag(player.force.find_chart_tags(game.surfaces[1]), selectedTracker.name .. "-bl") if tag == nil then - player.print({"tag-not-found", selectedTracker.name .. "-bl"}) + player.print({ "tag-not-found", selectedTracker.name .. "-bl" }) else -- Note that game origin is top-left, so top is min and bottom is max selectedTracker.minPos.x = math.floor(tag.position.x) @@ -211,7 +211,7 @@ function GUI.onClick(event) GUI.updateTrackerInfo( playerSettings.gui.cameraTrackerInfo, playerSettings.cameras[playerSettings.guiPersist.selectedCamera].trackers[ - playerSettings.guiPersist.selectedCameraTracker + playerSettings.guiPersist.selectedCameraTracker ] ) return @@ -259,6 +259,10 @@ function GUI.onClick(event) _, _, index = event.element.name:find("^camera_tracker_(%d+)_up$") if index ~= nil then index = tonumber(index) + if index == nil then + return + end + local cameraTrackers = playerSettings.cameras[playerSettings.guiPersist.selectedCamera].trackers local tmp = cameraTrackers[index] cameraTrackers[index] = cameraTrackers[index - 1] @@ -277,6 +281,10 @@ function GUI.onClick(event) _, _, index = event.element.name:find("^camera_tracker_(%d+)_down") if index ~= nil then index = tonumber(index) + if index == nil then + return + end + local cameraTrackers = playerSettings.cameras[playerSettings.guiPersist.selectedCamera].trackers local tmp = cameraTrackers[index] cameraTrackers[index] = cameraTrackers[index + 1] @@ -295,7 +303,11 @@ function GUI.onClick(event) _, _, index = event.element.name:find("^camera_tracker_(%d+)_remove$") if index ~= nil then index = tonumber(index) - table.remove(playerSettings.cameras[playerSettings.guiPersist.selectedCamera].trackers, index) + if index == nil then + return + end + + table.remove(playerSettings.cameras[playerSettings.guiPersist.selectedCamera].trackers, math.floor(index)) local currentIndex = playerSettings.guiPersist.selectedCameraTracker if currentIndex > 1 and currentIndex >= index then -- Select previous entry if entry above was deleted (so same entry stays selected) @@ -324,7 +336,11 @@ function GUI.onClick(event) end index = tonumber(index) - table.remove(playerSettings.trackers, index) + if index == nil then + return + end + + table.remove(playerSettings.trackers, math.floor(index)) if playerSettings.guiPersist.selectedTracker > #playerSettings.trackers then playerSettings.guiPersist.selectedTracker = #playerSettings.trackers @@ -437,8 +453,8 @@ function GUI.onSelected(event) local trackerToAdd = Utils.findName(playerSettings.trackers, event.element.items[event.element.selected_index]) table.insert(playerSettings.cameras[playerSettings.guiPersist.selectedCamera].trackers, trackerToAdd) - playerSettings.guiPersist.selectedCameraTracker = - #playerSettings.cameras[playerSettings.guiPersist.selectedCamera].trackers + playerSettings.guiPersist.selectedCameraTracker = # + playerSettings.cameras[playerSettings.guiPersist.selectedCamera].trackers GUI.createTrackerList( playerSettings.cameras[playerSettings.guiPersist.selectedCamera], @@ -456,13 +472,13 @@ function GUI.onSelected(event) playerSettings.cameras[playerSettings.guiPersist.selectedCamera] ) elseif event.element.name == "camera-surface" then - playerSettings.cameras[playerSettings.guiPersist.selectedCamera].surfaceName = - event.element.get_item(event.element.selected_index) + playerSettings.cameras[playerSettings.guiPersist.selectedCamera].surfaceName = event.element.get_item(event.element + .selected_index) GUI.createCameraTrackerList(playerSettings) elseif event.element.name == "tracker-surface" then - playerSettings.trackers[playerSettings.guiPersist.selectedTracker].surfaceName = - event.element.get_item(event.element.selected_index) + playerSettings.trackers[playerSettings.guiPersist.selectedTracker].surfaceName = event.element.get_item(event.element + .selected_index) GUI.createCameraTrackerList(playerSettings) end @@ -471,7 +487,7 @@ end function GUI.onTextChanged(event) local playerSettings = global.playerSettings[event.player_index] if event.element.name == "camera-name" then - Camera.setName(playerSettings.cameras[playerSettings.guiPersist.selectedCamera], event.element.text) + Camera.setName(playerSettings.cameras[playerSettings.guiPersist.selectedCamera], event.element.text) GUI.updateCameraList(playerSettings.gui, playerSettings.guiPersist, playerSettings.cameras) elseif event.element.name == "tracker-name" then playerSettings.trackers[playerSettings.guiPersist.selectedTracker].name = event.element.text @@ -503,10 +519,12 @@ function GUI.onTextChanged(event) ) elseif event.element.name == "camera-resolution-x" then Camera.setWidth(playerSettings.cameras[playerSettings.guiPersist.selectedCamera], event.element.text) - GUI.updateCameraInfo(playerSettings.gui.cameraInfo, playerSettings.cameras[playerSettings.guiPersist.selectedCamera]) + GUI.updateCameraInfo(playerSettings.gui.cameraInfo, + playerSettings.cameras[playerSettings.guiPersist.selectedCamera]) elseif event.element.name == "camera-resolution-y" then Camera.setHeight(playerSettings.cameras[playerSettings.guiPersist.selectedCamera], event.element.text) - GUI.updateCameraInfo(playerSettings.gui.cameraInfo, playerSettings.cameras[playerSettings.guiPersist.selectedCamera]) + GUI.updateCameraInfo(playerSettings.gui.cameraInfo, + playerSettings.cameras[playerSettings.guiPersist.selectedCamera]) elseif event.element.name == "camera-frame-rate" then Camera.setFrameRate(playerSettings.cameras[playerSettings.guiPersist.selectedCamera], event.element.text) elseif event.element.name == "camera-speed-gain" then @@ -621,7 +639,7 @@ function GUI.onSurfaceChanged(event) if playerSettings.gui ~= nil then GUI.updateCameraActions(playerSettings.gui, playerSettings.guiPersist, playerSettings.cameras) end - game.players[player.index].print({"camera-surface-deleted", camera.name}, {r = 1, g = 0.5, b = 0}) + game.players[player.index].print({ "camera-surface-deleted", camera.name }, { r = 1, g = 0.5, b = 0 }) end end end @@ -659,7 +677,7 @@ function GUI.toggleMainWindow(event) playerSettings.gui = nil else -- Create frame without caption (we have our own title_bar) - local mainWindow = player.gui.screen.add {type = "frame", name = "tlbe-main-window", direction = "vertical"} + local mainWindow = player.gui.screen.add { type = "frame", name = "tlbe-main-window", direction = "vertical" } playerSettings.gui = {} if playerSettings.guiPersist == nil then playerSettings.guiPersist = { @@ -671,12 +689,12 @@ function GUI.toggleMainWindow(event) end -- Add title bar - local title_bar = mainWindow.add {type = "flow"} - local title = title_bar.add {type = "label", caption = {"gui.frame-title"}, style = "frame_title"} + local title_bar = mainWindow.add { type = "flow" } + local title = title_bar.add { type = "label", caption = { "gui.frame-title" }, style = "frame_title" } title.drag_target = mainWindow -- Add 'dragger' (filler) between title and (close) buttons - local dragger = title_bar.add {type = "empty-widget", style = "draggable_space_header"} + local dragger = title_bar.add { type = "empty-widget", style = "draggable_space_header" } dragger.style.vertically_stretchable = true dragger.style.horizontally_stretchable = true dragger.drag_target = mainWindow @@ -686,7 +704,7 @@ function GUI.toggleMainWindow(event) title_bar.add { type = "sprite-button", name = "tlbe-main-window-pause", - tooltip = {"tooltip.pause-on-open"}, + tooltip = { "tooltip.pause-on-open" }, sprite = "pause-white", style = style } @@ -699,9 +717,9 @@ function GUI.toggleMainWindow(event) name = "tlbe-main-window-close" } - local tabPane = mainWindow.add {type = "tabbed-pane", style = "tlbe-tabbed_pane"} + local tabPane = mainWindow.add { type = "tabbed-pane", style = "tlbe-tabbed_pane" } - local cameraTab = tabPane.add {type = "tab", caption = {"gui.tab-cameras"}} + local cameraTab = tabPane.add { type = "tab", caption = { "gui.tab-cameras" } } tabPane.add_tab( cameraTab, GUI.createCameraSettings( @@ -713,7 +731,7 @@ function GUI.toggleMainWindow(event) ) ) - local trackerTab = tabPane.add {type = "tab", caption = {"gui.tab-trackers"}} + local trackerTab = tabPane.add { type = "tab", caption = { "gui.tab-trackers" } } tabPane.add_tab( trackerTab, GUI.createTrackerSettings( @@ -730,31 +748,30 @@ function GUI.toggleMainWindow(event) end function GUI.createCameraSettings(parent, playerGUI, guiPersist, cameras, trackers) - local flow = parent.add {type = "flow", direction = "vertical"} + local flow = parent.add { type = "flow", direction = "vertical" } -- Cameras - local cameraBox = flow.add {type = "flow"} - local cameraLeftFlow = cameraBox.add {type = "flow", direction = "vertical", style = "tlbe_fancy_list_parent"} + local cameraBox = flow.add { type = "flow" } + local cameraLeftFlow = cameraBox.add { type = "flow", direction = "vertical", style = "tlbe_fancy_list_parent" } - playerGUI.cameraSelector = - cameraLeftFlow.add { + playerGUI.cameraSelector = cameraLeftFlow.add { type = "drop-down", name = "tlbe-cameras-list", style = "tlbe_camera_dropdown" } GUI.updateCameraList(playerGUI, guiPersist, cameras) - playerGUI.cameraActions = cameraLeftFlow.add {type = "flow"} + playerGUI.cameraActions = cameraLeftFlow.add { type = "flow" } GUI.updateCameraActions(playerGUI, guiPersist, cameras) -- Camera info - playerGUI.cameraInfo = cameraBox.add {type = "table", column_count = 2} - playerGUI.cameraInfo.add {type = "label", caption = {"gui.label-name"}, style = "description_property_name_label"} - playerGUI.cameraInfo.add {type = "textfield", name = "camera-name", style = "tlbe_config_textfield"} + playerGUI.cameraInfo = cameraBox.add { type = "table", column_count = 2 } + playerGUI.cameraInfo.add { type = "label", caption = { "gui.label-name" }, style = "description_property_name_label" } + playerGUI.cameraInfo.add { type = "textfield", name = "camera-name", style = "tlbe_config_textfield" } playerGUI.cameraInfo.add { type = "label", name = "camera-surface-label", - caption = {"gui.label-surface"}, + caption = { "gui.label-surface" }, style = "description_property_name_label" } playerGUI.cameraInfo.add { @@ -765,17 +782,17 @@ function GUI.createCameraSettings(parent, playerGUI, guiPersist, cameras, tracke } playerGUI.cameraInfo.add { type = "label", - caption = {"gui.label-resolution"}, + caption = { "gui.label-resolution" }, style = "description_property_name_label" } - local resolutionFlow = playerGUI.cameraInfo.add {type = "flow", name = "camera-resolution"} + local resolutionFlow = playerGUI.cameraInfo.add { type = "flow", name = "camera-resolution" } resolutionFlow.add { type = "textfield", name = "camera-resolution-x", style = "tlbe_config_half_width_textfield", numeric = true } - resolutionFlow.add {type = "label", caption = "x", style = "tlbe_config_half_width_label"} + resolutionFlow.add { type = "label", caption = "x", style = "tlbe_config_half_width_label" } resolutionFlow.add { type = "textfield", name = "camera-resolution-y", @@ -784,73 +801,72 @@ function GUI.createCameraSettings(parent, playerGUI, guiPersist, cameras, tracke } playerGUI.cameraInfo.add { type = "label", - caption = {"gui.label-framerate"}, - tooltip = {"tooltip.camera-framerate"}, + caption = { "gui.label-framerate" }, + tooltip = { "tooltip.camera-framerate" }, style = "description_property_name_label" } playerGUI.cameraInfo.add { type = "textfield", name = "camera-frame-rate", - tooltip = {"tooltip.camera-framerate"}, + tooltip = { "tooltip.camera-framerate" }, style = "tlbe_config_half_width_textfield", numeric = true } playerGUI.cameraInfo.add { type = "label", - caption = {"gui.label-speedgain"}, - tooltip = {"tooltip.camera-speedgain"}, + caption = { "gui.label-speedgain" }, + tooltip = { "tooltip.camera-speedgain" }, style = "description_property_name_label" } playerGUI.cameraInfo.add { type = "textfield", name = "camera-speed-gain", - tooltip = {"tooltip.camera-speedgain"}, + tooltip = { "tooltip.camera-speedgain" }, style = "tlbe_config_half_width_textfield", numeric = true, allow_decimal = true } playerGUI.cameraInfo.add { type = "label", - caption = {"gui.label-zoomperiod"}, - tooltip = {"tooltip.camera-zoomperiod"}, + caption = { "gui.label-zoomperiod" }, + tooltip = { "tooltip.camera-zoomperiod" }, style = "description_property_name_label" } playerGUI.cameraInfo.add { type = "textfield", name = "camera-zoom-period", - tooltip = {"tooltip.camera-zoomperiod"}, + tooltip = { "tooltip.camera-zoomperiod" }, style = "tlbe_config_half_width_textfield", numeric = true, allow_decimal = true } - playerGUI.cameraInfo.add {type = "empty-widget"} + playerGUI.cameraInfo.add { type = "empty-widget" } playerGUI.cameraInfo.add { type = "checkbox", name = "camera-entity-info", - caption = {"gui.label-entity-info"}, - tooltip = {"tooltip.camera-entity-info"}, + caption = { "gui.label-entity-info" }, + tooltip = { "tooltip.camera-entity-info" }, state = false } playerGUI.cameraInfo.add { type = "label", - caption = {"gui.label-position"}, + caption = { "gui.label-position" }, style = "description_property_name_label" } - playerGUI.cameraInfo.add {type = "label", name = "camera-position"} - playerGUI.cameraInfo.add {type = "label", caption = {"gui.label-zoom"}, style = "description_property_name_label"} - playerGUI.cameraInfo.add {type = "label", name = "camera-zoom"} + playerGUI.cameraInfo.add { type = "label", name = "camera-position" } + playerGUI.cameraInfo.add { type = "label", caption = { "gui.label-zoom" }, style = "description_property_name_label" } + playerGUI.cameraInfo.add { type = "label", name = "camera-zoom" } GUI.updateCameraConfig(playerGUI.cameraInfo, cameras[guiPersist.selectedCamera]) GUI.updateCameraInfo(playerGUI.cameraInfo, cameras[guiPersist.selectedCamera]) -- Trackers - flow.add {type = "line"} - flow.add {type = "label", caption = {"gui.label-camera-trackers"}, style = "description_property_name_label"} - local trackerBox = flow.add {type = "flow"} - playerGUI.cameraTrackerListFlow = - trackerBox.add {type = "flow", direction = "vertical", style = "tlbe_fancy_list_parent"} - playerGUI.cameraTrackerList = - playerGUI.cameraTrackerListFlow.add { + flow.add { type = "line" } + flow.add { type = "label", caption = { "gui.label-camera-trackers" }, style = "description_property_name_label" } + local trackerBox = flow.add { type = "flow" } + playerGUI.cameraTrackerListFlow = trackerBox.add { type = "flow", direction = "vertical", + style = "tlbe_fancy_list_parent" } + playerGUI.cameraTrackerList = playerGUI.cameraTrackerListFlow.add { type = "scroll-pane", name = "tlbe-tracker-list", horizontal_scroll_policy = "never", @@ -869,25 +885,25 @@ function GUI.createCameraSettings(parent, playerGUI, guiPersist, cameras, tracke GUI.createCameraAddTracker(playerGUI.cameraTrackerListFlow, trackers, cameras[guiPersist.selectedCamera]) -- Tracker info - playerGUI.cameraTrackerInfo = trackerBox.add {type = "table", column_count = 2} + playerGUI.cameraTrackerInfo = trackerBox.add { type = "table", column_count = 2 } playerGUI.cameraTrackerInfo.add { type = "label", - caption = {"gui.label-type"}, + caption = { "gui.label-type" }, style = "description_property_name_label" } - playerGUI.cameraTrackerInfo.add {type = "label", name = "tracker-type"} + playerGUI.cameraTrackerInfo.add { type = "label", name = "tracker-type" } playerGUI.cameraTrackerInfo.add { type = "label", - caption = {"gui.label-center"}, + caption = { "gui.label-center" }, style = "description_property_name_label" } - playerGUI.cameraTrackerInfo.add {type = "label", name = "tracker-position"} + playerGUI.cameraTrackerInfo.add { type = "label", name = "tracker-position" } playerGUI.cameraTrackerInfo.add { type = "label", - caption = {"gui.label-size"}, + caption = { "gui.label-size" }, style = "description_property_name_label" } - playerGUI.cameraTrackerInfo.add {type = "label", name = "tracker-size"} + playerGUI.cameraTrackerInfo.add { type = "label", name = "tracker-size" } GUI.updateTrackerInfo( playerGUI.cameraTrackerInfo, cameras[guiPersist.selectedCamera].trackers[guiPersist.selectedCameraTracker] @@ -897,21 +913,20 @@ function GUI.createCameraSettings(parent, playerGUI, guiPersist, cameras, tracke end function GUI.createTrackerSettings(parent, playerGUI, guiPersist, cameras, trackers) - local flow = parent.add {type = "flow"} - local trackersFlow = flow.add {type = "flow", direction = "vertical", style = "tlbe_fancy_list_parent"} + local flow = parent.add { type = "flow" } + local trackersFlow = flow.add { type = "flow", direction = "vertical", style = "tlbe_fancy_list_parent" } -- New tracker GUI trackersFlow.add { type = "drop-down", selected_index = 1, name = "tlbe-tracker-add", - items = {{"gui.item-new-tracker"}, table.unpack(GUI.allTrackersLabels)}, + items = { { "gui.item-new-tracker" }, table.unpack(GUI.allTrackersLabels) }, style = "tble_tracker_add_dropdown" } -- Trackers - playerGUI.trackerList = - trackersFlow.add { + playerGUI.trackerList = trackersFlow.add { type = "scroll-pane", name = "tlbe-tracker-list", horizontal_scroll_policy = "never", @@ -928,8 +943,8 @@ function GUI.createTrackerSettings(parent, playerGUI, guiPersist, cameras, track ) -- Tracker info - local infoFlow = flow.add {type = "flow", direction = "vertical"} - playerGUI.trackerInfo = infoFlow.add {type = "table", column_count = 2} + local infoFlow = flow.add { type = "flow", direction = "vertical" } + playerGUI.trackerInfo = infoFlow.add { type = "table", column_count = 2 } GUI.createTrackerConfigAndInfo(playerGUI.trackerInfo, trackers[guiPersist.selectedTracker]) return flow @@ -952,7 +967,7 @@ function GUI.createTrackerList( end local trackerRow = - trackerList.add { + trackerList.add { type = "frame", name = namePrefix .. index, style = style @@ -991,7 +1006,7 @@ function GUI.addCameraTrackerButtons(index, selectedCamera, _, trackers, tracker local tracker = trackers[index] local isActiveTracker = findActiveTracker(trackers, selectedCamera.surfaceName) == tracker - local orderFlow = trackerRow.add {type = "flow", direction = "vertical"} + local orderFlow = trackerRow.add { type = "flow", direction = "vertical" } if index > 1 then orderFlow.add { @@ -1037,7 +1052,7 @@ function GUI.addCameraTrackerButtons(index, selectedCamera, _, trackers, tracker type = "sprite", sprite = "utility/warning_icon", style = "tlbe_fancy_list_box_image_reduce_size", - tooltip = {"tooltip.tracker-wrong-surface"} + tooltip = { "tooltip.tracker-wrong-surface" } } else trackerRow.add { @@ -1058,7 +1073,7 @@ function GUI.addTrackerButtons(index, _, cameras, trackers, trackerRow) trackerRow.add { type = "sprite-button", name = "tracker_" .. index .. "_enable", - tooltip = {"tooltip.tracker-enable"}, + tooltip = { "tooltip.tracker-enable" }, sprite = "utility/play", style = style } @@ -1066,7 +1081,7 @@ function GUI.addTrackerButtons(index, _, cameras, trackers, trackerRow) trackerRow.add { enabled = false, type = "sprite-button", - tooltip = {"tooltip.tracker-cannot-enable"}, + tooltip = { "tooltip.tracker-cannot-enable" }, sprite = "utility/play", style = "tlbe_fancy_list_box_button" } @@ -1074,7 +1089,7 @@ function GUI.addTrackerButtons(index, _, cameras, trackers, trackerRow) if #trackers > 1 then local button = - trackerRow.add { + trackerRow.add { type = "sprite-button", name = "tracker_" .. index .. "_delete", sprite = "utility/trash", @@ -1083,7 +1098,7 @@ function GUI.addTrackerButtons(index, _, cameras, trackers, trackerRow) if Tracker.inUse(tracker, cameras) then button.enabled = false - button.tooltip = {"tooltip.tracker-cannot-delete-inuse"} + button.tooltip = { "tooltip.tracker-cannot-delete-inuse" } end end @@ -1091,7 +1106,7 @@ function GUI.addTrackerButtons(index, _, cameras, trackers, trackerRow) trackerRow.add { type = "sprite-button", name = "tracker_" .. index .. "_recalculate", - tooltip = {"tooltip.base-recalculate"}, + tooltip = { "tooltip.base-recalculate" }, sprite = "utility/refresh", style = "tlbe_fancy_list_box_button" } @@ -1121,7 +1136,7 @@ function GUI.createCameraAddTracker(parent, allTrackers, camera) type = "drop-down", selected_index = 1, name = "tlbe-camera-add-tracker", - items = {{"gui.item-add-tracker"}, table.unpack(availableTrackerNames)}, + items = { { "gui.item-add-tracker" }, table.unpack(availableTrackerNames) }, style = "tble_tracker_add_dropdown" } end @@ -1139,7 +1154,7 @@ function GUI.updateCameraActions(playerGUI, guiPersist, cameras) playerGUI.cameraActions.add { type = "sprite-button", name = "tlbe_camera_enable", - tooltip = {"tooltip.camera-enable"}, + tooltip = { "tooltip.camera-enable" }, sprite = "utility/play", style = style } @@ -1148,7 +1163,7 @@ function GUI.updateCameraActions(playerGUI, guiPersist, cameras) type = "button", caption = "+", name = "tlbe_camera_add", - tooltip = {"tooltip.camera-add"}, + tooltip = { "tooltip.camera-add" }, style = "tool_button" } @@ -1156,7 +1171,7 @@ function GUI.updateCameraActions(playerGUI, guiPersist, cameras) playerGUI.cameraActions.add { type = "sprite-button", name = "tlbe_camera_delete", - tooltip = {"tooltip.camera-delete"}, + tooltip = { "tooltip.camera-delete" }, sprite = "utility/trash", style = "tool_button_red" } @@ -1165,7 +1180,7 @@ function GUI.updateCameraActions(playerGUI, guiPersist, cameras) playerGUI.cameraActions.add { type = "sprite-button", name = "tlbe_camera_refresh", - tooltip = {"tooltip.camera-refresh"}, + tooltip = { "tooltip.camera-refresh" }, sprite = "utility/refresh", style = "tool_button" } @@ -1199,13 +1214,13 @@ end function GUI.updateCameraInfo(cameraInfo, camera) if camera == nil or camera.centerPos == nil then - cameraInfo["camera-position"].caption = {"gui.value-unset"} + cameraInfo["camera-position"].caption = { "gui.value-unset" } else cameraInfo["camera-position"].caption = string.format("%d, %d", camera.centerPos.x, camera.centerPos.y) end if camera == nil then - cameraInfo["camera-zoom"].caption = {"gui.value-unset"} + cameraInfo["camera-zoom"].caption = { "gui.value-unset" } else cameraInfo["camera-zoom"].caption = string.format("%2.2f", camera.zoom) end @@ -1237,12 +1252,12 @@ end function GUI.createTrackerConfigAndInfo(trackerInfo, tracker) trackerInfo.clear() - trackerInfo.add {type = "label", caption = {"gui.label-name"}, style = "description_property_name_label"} - trackerInfo.add {type = "textfield", name = "tracker-name", style = "tlbe_config_textfield"} + trackerInfo.add { type = "label", caption = { "gui.label-name" }, style = "description_property_name_label" } + trackerInfo.add { type = "textfield", name = "tracker-name", style = "tlbe_config_textfield" } trackerInfo.add { type = "label", name = "tracker-surface-label", - caption = {"gui.label-surface"}, + caption = { "gui.label-surface" }, style = "description_property_name_label" } trackerInfo.add { @@ -1251,22 +1266,22 @@ function GUI.createTrackerConfigAndInfo(trackerInfo, tracker) items = {}, style = "tlbe_config_dropdown" } - trackerInfo.add {type = "empty-widget"} + trackerInfo.add { type = "empty-widget" } trackerInfo.add { type = "checkbox", name = "tracker-smooth", - caption = {"gui.label-smooth"}, - tooltip = {"tooltip.tracker-smooth"}, + caption = { "gui.label-smooth" }, + tooltip = { "tooltip.tracker-smooth" }, state = false } if tracker ~= nil and tracker.type == "area" then trackerInfo.add { type = "label", - caption = {"gui.label-top-right"}, + caption = { "gui.label-top-right" }, style = "description_property_name_label" } - local trFlow = trackerInfo.add {type = "flow", name = "tracker-tr"} + local trFlow = trackerInfo.add { type = "flow", name = "tracker-tr" } trFlow.add { type = "textfield", name = "tlbe-tracker-top", @@ -1274,7 +1289,7 @@ function GUI.createTrackerConfigAndInfo(trackerInfo, tracker) numeric = true, allow_negative = true } - trFlow.add {type = "label", caption = "/", style = "tlbe_config_half_width_label"} + trFlow.add { type = "label", caption = "/", style = "tlbe_config_half_width_label" } trFlow.add { type = "textfield", name = "tlbe-tracker-right", @@ -1285,20 +1300,21 @@ function GUI.createTrackerConfigAndInfo(trackerInfo, tracker) trFlow.add { type = "sprite-button", name = "tlbe-tracker-tr-player", - tooltip = {"tooltip.tracker-area-player"}, + tooltip = { "tooltip.tracker-area-player" }, sprite = "utility/show_player_names_in_map_view_black", style = "tlbe_config_button" } trFlow.add { type = "sprite-button", name = "tlbe-tracker-tr-map", - tooltip = {"tooltip.tracker-area-map", tracker.name .. "-tr"}, + tooltip = { "tooltip.tracker-area-map", tracker.name .. "-tr" }, sprite = "utility/station_name", style = "tlbe_config_button" } - trackerInfo.add {type = "label", caption = {"gui.label-bottom-left"}, style = "description_property_name_label"} - local blFlow = trackerInfo.add {type = "flow", name = "tracker-bl"} + trackerInfo.add { type = "label", caption = { "gui.label-bottom-left" }, + style = "description_property_name_label" } + local blFlow = trackerInfo.add { type = "flow", name = "tracker-bl" } blFlow.add { type = "textfield", name = "tlbe-tracker-bottom", @@ -1306,7 +1322,7 @@ function GUI.createTrackerConfigAndInfo(trackerInfo, tracker) numeric = true, allow_negative = true } - blFlow.add {type = "label", caption = "/", style = "tlbe_config_half_width_label"} + blFlow.add { type = "label", caption = "/", style = "tlbe_config_half_width_label" } blFlow.add { type = "textfield", name = "tlbe-tracker-left", @@ -1317,14 +1333,14 @@ function GUI.createTrackerConfigAndInfo(trackerInfo, tracker) blFlow.add { type = "sprite-button", name = "tlbe-tracker-bl-player", - tooltip = {"tooltip.tracker-area-player"}, + tooltip = { "tooltip.tracker-area-player" }, sprite = "utility/show_player_names_in_map_view_black", style = "tlbe_config_button" } blFlow.add { type = "sprite-button", name = "tlbe-tracker-bl-map", - tooltip = {"tooltip.tracker-area-map", tracker.name .. "-bl"}, + tooltip = { "tooltip.tracker-area-map", tracker.name .. "-bl" }, sprite = "utility/station_name", style = "tlbe_config_button" } @@ -1332,18 +1348,18 @@ function GUI.createTrackerConfigAndInfo(trackerInfo, tracker) trackerInfo.add { type = "label", - caption = {"gui.label-type"}, + caption = { "gui.label-type" }, style = "description_property_name_label" } - trackerInfo.add {type = "label", name = "tracker-type"} + trackerInfo.add { type = "label", name = "tracker-type" } trackerInfo.add { type = "label", - caption = {"gui.label-center"}, + caption = { "gui.label-center" }, style = "description_property_name_label" } - trackerInfo.add {type = "label", name = "tracker-position"} - trackerInfo.add {type = "label", caption = {"gui.label-size"}, style = "description_property_name_label"} - trackerInfo.add {type = "label", name = "tracker-size"} + trackerInfo.add { type = "label", name = "tracker-position" } + trackerInfo.add { type = "label", caption = { "gui.label-size" }, style = "description_property_name_label" } + trackerInfo.add { type = "label", name = "tracker-size" } GUI.updateTrackerConfig(trackerInfo, tracker) GUI.updateTrackerInfo(trackerInfo, tracker) end @@ -1399,13 +1415,13 @@ function GUI.updateTrackerInfo(trackerInfo, tracker) end if tracker == nil or tracker.centerPos == nil then - trackerInfo["tracker-position"].caption = {"gui.value-unset"} + trackerInfo["tracker-position"].caption = { "gui.value-unset" } else trackerInfo["tracker-position"].caption = string.format("%d, %d", tracker.centerPos.x, tracker.centerPos.y) end if tracker == nil or tracker.size == nil then - trackerInfo["tracker-size"].caption = {"gui.value-unset"} + trackerInfo["tracker-size"].caption = { "gui.value-unset" } else trackerInfo["tracker-size"].caption = string.format("%d, %d", tracker.size.x, tracker.size.y) end diff --git a/scripts/main.lua b/scripts/main.lua index b126793..2f33622 100644 --- a/scripts/main.lua +++ b/scripts/main.lua @@ -58,9 +58,10 @@ function Main.tick() by_player = player, surface = camera.surfaceName or game.surfaces[1], position = camera.centerPos, - resolution = {camera.width, camera.height}, + resolution = { camera.width, camera.height }, zoom = camera.zoom, - path = string.format("%s/%s/%08d-%s.png", playerSettings.saveFolder, camera.saveFolder, screenshotNumber, camera.saveName), + path = string.format("%s/%s/%08d-%s.png", playerSettings.saveFolder, camera.saveFolder, screenshotNumber + , camera.saveName), show_entity_info = camera.entityInfo, allow_in_replay = true, daytime = 0 -- take screenshot at full light @@ -95,8 +96,8 @@ function Main.entity_built(event) if tracker.size == nil then -- Set start point of base - tracker.minPos = {x = newEntityBBox.left, y = newEntityBBox.bottom} - tracker.maxPos = {x = newEntityBBox.right, y = newEntityBBox.top} + tracker.minPos = { x = newEntityBBox.left, y = newEntityBBox.bottom } + tracker.maxPos = { x = newEntityBBox.right, y = newEntityBBox.top } else -- Recalculate base boundary if (newEntityBBox.left < tracker.minPos.x) then @@ -131,7 +132,7 @@ function Main.rocket_launch(event) if tracker.enabled == false then tracker.enabled = true tracker.centerPos = event.rocket_silo.position - tracker.size = {x = 1, y = 1} -- don't care about size, it will fit with maxZoom + tracker.size = { x = 1, y = 1 } -- don't care about size, it will fit with maxZoom tracker.lastChange = game.tick end @@ -159,7 +160,7 @@ function Main.rocket_launched(event) end function Main.get_base_bbox() - local entities = game.surfaces[1].find_entities_filtered {force = "player"} + local entities = game.surfaces[1].find_entities_filtered { force = "player" } if #entities == 0 then return nil @@ -167,8 +168,8 @@ function Main.get_base_bbox() -- Find an initial bbox within the base local entityBBox = Utils.entityBBox(entities[1]) - local minPos = {x = entityBBox.left, y = entityBBox.bottom} - local maxPos = {x = entityBBox.right, y = entityBBox.top} + local minPos = { x = entityBBox.left, y = entityBBox.bottom } + local maxPos = { x = entityBBox.right, y = entityBBox.top } for _, entity in ipairs(entities) do if entity.type == "character" then diff --git a/scripts/tracker.lua b/scripts/tracker.lua index 32507ee..beb66e4 100644 --- a/scripts/tracker.lua +++ b/scripts/tracker.lua @@ -20,6 +20,7 @@ function Tracker.newTracker(trackerType, trackerList) end --- @class Tracker + --- @field centerPos {x: integer, y: integer } local newTracker = { name = trackerName, type = trackerType, @@ -32,11 +33,11 @@ function Tracker.newTracker(trackerType, trackerList) -- Add tracker specific details if trackerType == "area" then - newTracker.minPos = {x = -5, y = -5} - newTracker.maxPos = {x = 5, y = 5} + newTracker.minPos = { x = -5, y = -5 } + newTracker.maxPos = { x = 5, y = 5 } Tracker.updateCenterAndSize(newTracker) elseif trackerType == "player" then - newTracker.size = {x = 1, y = 1} + newTracker.size = { x = 1, y = 1 } newTracker.untilBuild = true newTracker.smooth = false elseif trackerType == "rocket" then @@ -51,10 +52,9 @@ end -- Update tracker state (if needed) function Tracker.tick(tracker, player) if tracker.type == "player" and tracker.surfaceName == player.surface.name then - if - tracker.centerPos == nil or tracker.centerPos.x ~= player.position.x or - tracker.centerPos.y ~= player.position.y - then + if tracker.centerPos == nil or tracker.centerPos.x ~= player.position.x or + tracker.centerPos.y ~= player.position.y + then tracker.lastChange = game.tick end @@ -120,12 +120,11 @@ function Tracker.updateCenterAndSize(tracker) y = tracker.minPos.y + size.y / 2 } - if - tracker.centerPos == nil or tracker.size == nil or centerPos.x ~= tracker.centerPos.x or - centerPos.y ~= tracker.centerPos.y or - size.x ~= tracker.size.x or - size.y ~= tracker.size.y - then + if tracker.centerPos == nil or tracker.size == nil or centerPos.x ~= tracker.centerPos.x or + centerPos.y ~= tracker.centerPos.y or + size.x ~= tracker.size.x or + size.y ~= tracker.size.y + then -- Tracker dimensions changed, so need to recenter camera tracker.lastChange = game.tick end diff --git a/tests/camera.lua b/tests/camera.lua index 35f42cf..47bfe6f 100644 --- a/tests/camera.lua +++ b/tests/camera.lua @@ -12,13 +12,13 @@ local tileSize = 32 TestNewCamera = {} function TestNewCamera.TestUniqueName() - local camera1 = TLBE.Camera.newCamera({postion = {0, 0}}, {}) + local camera1 = TLBE.Camera.newCamera({ postion = { 0, 0 } }, {}) lu.assertEquals(camera1.name, "new camera", "with empty list no index is needed") - local camera2 = TLBE.Camera.newCamera({postion = {0, 0}}, {camera1}) + local camera2 = TLBE.Camera.newCamera({ postion = { 0, 0 } }, { camera1 }) lu.assertEquals(camera2.name, "new camera-2", "with camera 'new camera' already in the list, add '-2' to the name") - local camera3 = TLBE.Camera.newCamera({postion = {0, 0}}, {camera1, camera2}) + local camera3 = TLBE.Camera.newCamera({ postion = { 0, 0 } }, { camera1, camera2 }) lu.assertEquals( camera3.name, "new camera-3", @@ -28,6 +28,7 @@ end TestCamera = {} +-- luacheck: globals game local function nextTick() TLBE.Main.tick() game.tick = game.tick + 1 @@ -38,20 +39,20 @@ function TestCamera:SetUp() global = {} game = { tick = 0, - surfaces = {{name = "nauvis"}}, + surfaces = { { name = "nauvis" } }, take_screenshot = function() end } -- mock TLBE tables global.playerSettings = { - TLBE.Config.newPlayerSettings({position = {x = 0, y = 0}}), - TLBE.Config.newPlayerSettings({position = {x = 0, y = 0}}) + TLBE.Config.newPlayerSettings({ position = { x = 0, y = 0 } }), + TLBE.Config.newPlayerSettings({ position = { x = 0, y = 0 } }) } game.players = { - {index = 1, surface = game.surfaces[1]}, - {index = 2, surface = game.surfaces[1]} + { index = 1, surface = game.surfaces[1] }, + { index = 2, surface = game.surfaces[1] } } -- Enable player1 camera @@ -79,7 +80,7 @@ function TestCamera:SetUp() end function TestCamera:TestTransitionFromPlayerToBaseTracker() - game.players[1].position = {x = 5, y = 4} + game.players[1].position = { x = 5, y = 4 } nextTick() @@ -88,14 +89,14 @@ function TestCamera:TestTransitionFromPlayerToBaseTracker() lu.assertEquals(self.testCameraPlayer1.zoom, 1, "expected that zoom at max_zoom") -- Move player and build entity - game.players[1].position = {x = 2, y = 2} + game.players[1].position = { x = 2, y = 2 } TLBE.Main.entity_built( { created_entity = { surface = game.surfaces[1], bounding_box = { - left_top = {x = 1, y = 3}, - right_bottom = {x = 3, y = 4} + left_top = { x = 1, y = 3 }, + right_bottom = { x = 3, y = 4 } } } } @@ -113,7 +114,7 @@ end function TestCamera:TestRocketLaunch() -- center camera at 0,0 - self.testCameraPlayer1.centerPos = {x = 0, y = 0} + self.testCameraPlayer1.centerPos = { x = 0, y = 0 } self.testCameraPlayer1.zoom = 1 -- Initialize base tracker @@ -122,8 +123,8 @@ function TestCamera:TestRocketLaunch() created_entity = { surface = game.surfaces[1], bounding_box = { - left_top = {x = -1, y = -1}, - right_bottom = {x = 1, y = 1} + left_top = { x = -1, y = -1 }, + right_bottom = { x = 1, y = 1 } } } } @@ -134,7 +135,7 @@ function TestCamera:TestRocketLaunch() lu.assertEquals(self.testCameraPlayer1.zoom, 1, "expected that zoom at max_zoom") -- Launch rocket - TLBE.Main.rocket_launch({rocket_silo = {surface = game.surfaces[1], position = {x = 10, y = 10}}}) + TLBE.Main.rocket_launch({ rocket_silo = { surface = game.surfaces[1], position = { x = 10, y = 10 } } }) nextTick() lu.assertEquals(self.testCameraPlayer1.centerPos.x, 10, "expected to be at rocket_silo position") @@ -142,7 +143,7 @@ function TestCamera:TestRocketLaunch() lu.assertEquals(self.testCameraPlayer1.zoom, 1, "expected that zoom at max_zoom") -- Rocket launched (return back to base) - TLBE.Main.rocket_launched({rocket_silo = {surface = game.surfaces[1]}}) + TLBE.Main.rocket_launched({ rocket_silo = { surface = game.surfaces[1] } }) nextTick() lu.assertEquals(self.testCameraPlayer1.centerPos.x, 0, "expected to be back at entity center") @@ -152,7 +153,7 @@ end function TestCamera:TestResolutionChange() -- Only keep base tracker (so it is the active tacker) - self.testCameraPlayer1.trackers = {self.testCameraPlayer1.trackers[3]} + self.testCameraPlayer1.trackers = { self.testCameraPlayer1.trackers[3] } local baseTracker = self.testCameraPlayer1.trackers[1]; TLBE.Main.entity_built( @@ -160,8 +161,8 @@ function TestCamera:TestResolutionChange() created_entity = { surface = game.surfaces[1], bounding_box = { - left_top = {x = -20, y = -20}, - right_bottom = {x = 20, y = 20} + left_top = { x = -20, y = -20 }, + right_bottom = { x = 20, y = 20 } } } } @@ -172,11 +173,12 @@ function TestCamera:TestResolutionChange() local oldZoom = self.testCameraPlayer1.zoom; local oldCenterPos = self.testCameraPlayer1.centerPos; - TLBE.Camera.setWidth(self.testCameraPlayer1, self.testCameraPlayer1.width*2) - TLBE.Camera.setHeight(self.testCameraPlayer1, self.testCameraPlayer1.height*2) + TLBE.Camera.setWidth(self.testCameraPlayer1, self.testCameraPlayer1.width * 2) + TLBE.Camera.setHeight(self.testCameraPlayer1, self.testCameraPlayer1.height * 2) lu.assertEquals(self.testCameraPlayer1.centerPos.x, oldCenterPos.x, "expected centerpos to be the same") lu.assertEquals(self.testCameraPlayer1.centerPos.y, oldCenterPos.y, "expected centerpos to be the same") lu.assertNotEquals(self.testCameraPlayer1.zoom, oldZoom, "expected that zoom has been changed") - lu.assertEquals(self.testCameraPlayer1.zoom, oldZoom * 2, "expected that zoom has doubled as resolution has been doubled") -end \ No newline at end of file + lu.assertEquals(self.testCameraPlayer1.zoom, oldZoom * 2, + "expected that zoom has doubled as resolution has been doubled") +end diff --git a/tests/camera_follow-tracker.lua b/tests/camera_follow-tracker.lua old mode 100755 new mode 100644 index 2f5f258..52e3d2d --- a/tests/camera_follow-tracker.lua +++ b/tests/camera_follow-tracker.lua @@ -1,11 +1,12 @@ package.path = package.path .. ";../?.lua" -local TLBE = {Camera = require("scripts.camera")} +local TLBE = { Camera = require("scripts.camera") } local lu = require("luaunit") local tileSize = 32 local MAX_TICKS = 100 +-- luacheck: globals game local function ConvergenceTester(playerSettings, player, camera, tracker) local startTick = game.tick local currentX = camera.centerPos.x @@ -35,27 +36,27 @@ TestCameraFollowTracker = {} function TestCameraFollowTracker:SetUp() -- mock Factorio provided globals - game = {tick = 0} + game = { tick = 0 } self.testCamera = { width = 20 * tileSize, height = 15 * tileSize, - centerPos = {x = 0, y = 0}, + centerPos = { x = 0, y = 0 }, screenshotInterval = 1, zoom = 1, zoomTicks = 15 } self.testTracker = { - centerPos = {x = 0, y = 0}, - size = {x = 1, y = 1}, + centerPos = { x = 0, y = 0 }, + size = { x = 1, y = 1 }, smooth = true, lastChange = 0 } end function TestCameraFollowTracker:TestInitialUpRight() - self.testTracker.centerPos = {x = 1, y = 1} + self.testTracker.centerPos = { x = 1, y = 1 } TLBE.Camera.followTracker({}, {}, self.testCamera, self.testTracker) @@ -65,7 +66,7 @@ function TestCameraFollowTracker:TestInitialUpRight() end function TestCameraFollowTracker:TestInitialBottomLeft() - self.testTracker.centerPos = {x = -1, y = -1} + self.testTracker.centerPos = { x = -1, y = -1 } TLBE.Camera.followTracker({}, {}, self.testCamera, self.testTracker) @@ -76,7 +77,7 @@ end function TestCameraFollowTracker:TestNotSmooth() self.testTracker.smooth = false - self.testTracker.centerPos = {x = 10, y = 6} + self.testTracker.centerPos = { x = 10, y = 6 } local ticks = ConvergenceTester({}, {}, self.testCamera, self.testTracker) @@ -87,7 +88,7 @@ function TestCameraFollowTracker:TestNotSmooth() end function TestCameraFollowTracker:TestZoom() - self.testTracker.size = {x = self.testCamera.width / tileSize * 2, y = self.testCamera.height / tileSize * 2} + self.testTracker.size = { x = self.testCamera.width / tileSize * 2, y = self.testCamera.height / tileSize * 2 } local ticks = ConvergenceTester({}, {}, self.testCamera, self.testTracker) @@ -99,7 +100,7 @@ function TestCameraFollowTracker:TestZoom() end function TestCameraFollowTracker:TestConvergenceDiagonal() - self.testTracker.centerPos = {x = 10, y = 6} + self.testTracker.centerPos = { x = 10, y = 6 } local ticks = ConvergenceTester({}, {}, self.testCamera, self.testTracker) diff --git a/tests/main.lua b/tests/main.lua index fa5ab35..4242c89 100644 --- a/tests/main.lua +++ b/tests/main.lua @@ -6,6 +6,7 @@ local lu = require("luaunit") TestGetBaseBBox = {} function TestGetBaseBBox.TestNoEntities() + -- luacheck: globals game game = { surfaces = { { @@ -21,7 +22,9 @@ function TestGetBaseBBox.TestNoEntities() lu.assertIsNil(bbox, "expected nil with empty base") end +---@diagnostic disable: need-check-nil function TestGetBaseBBox.TestSingleEntity() + -- luacheck: globals game game = { surfaces = { { @@ -29,8 +32,8 @@ function TestGetBaseBBox.TestSingleEntity() return { { bounding_box = { - left_top = {x = 1, y = 3}, - right_bottom = {x = 3, y = 4} + left_top = { x = 1, y = 3 }, + right_bottom = { x = 3, y = 4 } } } } @@ -48,7 +51,9 @@ function TestGetBaseBBox.TestSingleEntity() lu.assertEquals(bbox.maxPos.y, 4 + Utils.boundarySize) end +---@diagnostic disable: need-check-nil function TestGetBaseBBox.TestMultipleEntities() + -- luacheck: globals game game = { surfaces = { { @@ -56,27 +61,27 @@ function TestGetBaseBBox.TestMultipleEntities() return { { bounding_box = { - left_top = {x = 1, y = 3}, - right_bottom = {x = 3, y = 4} -- top most value + left_top = { x = 1, y = 3 }, + right_bottom = { x = 3, y = 4 } -- top most value } }, { bounding_box = { - left_top = {x = -1, y = 0}, -- left and bottom most values - right_bottom = {x = 2, y = 2} + left_top = { x = -1, y = 0 }, -- left and bottom most values + right_bottom = { x = 2, y = 2 } } }, { bounding_box = { - left_top = {x = 4, y = 2}, - right_bottom = {x = 6, y = 3} -- right most value + left_top = { x = 4, y = 2 }, + right_bottom = { x = 6, y = 3 } -- right most value } }, { type = "character", bounding_box = { - left_top = {x = 4, y = 2}, - right_bottom = {x = 20, y = 3} -- actual right most value (but skipped) + left_top = { x = 4, y = 2 }, + right_bottom = { x = 20, y = 3 } -- actual right most value (but skipped) } } } diff --git a/tests/surface.lua b/tests/surface.lua index 3435aae..59977b1 100644 --- a/tests/surface.lua +++ b/tests/surface.lua @@ -11,18 +11,19 @@ TestSurfaceEvents = {} function TestSurfaceEvents:SetUp() -- mock Factorio provided globals global = {} + -- luacheck: globals game game = { tick = 0, - surfaces = {{name = "nauvis"},{name = "active-surface"},{name = "inactive-surface"}}, + surfaces = { { name = "nauvis" }, { name = "active-surface" }, { name = "inactive-surface" } }, } -- mock TLBE tables global.playerSettings = { - TLBE.Config.newPlayerSettings({position = {x = 0, y = 0}}), + TLBE.Config.newPlayerSettings({ position = { x = 0, y = 0 } }), } game.players = { - {index = 1}, + { index = 1 }, } -- Make camera easier to test @@ -32,7 +33,7 @@ end function TestSurfaceEvents:TestDeleteUnusedSurface() -- send event that inactive-surface will be deleted - TLBE.GUI.onSurfaceChanged({surface_index = 3}) + TLBE.GUI.onSurfaceChanged({ surface_index = 3 }) lu.assertEquals(self.testCamera.surfaceName, "active-surface", "expected surface to be unchanged") end @@ -46,7 +47,7 @@ function TestSurfaceEvents:TestDeleteUsedSurface() end -- send event that active-surface will be deleted - TLBE.GUI.onSurfaceChanged({surface_index = 2}) + TLBE.GUI.onSurfaceChanged({ surface_index = 2 }) lu.assertEquals(self.testCamera.surfaceName, "nauvis", "expected surface to be changed") lu.assertFalse(self.testCamera.enabled, "expected for the camera to be disabled") @@ -54,13 +55,13 @@ function TestSurfaceEvents:TestDeleteUsedSurface() end function TestSurfaceEvents:TestRenameUnusedSurface() - TLBE.GUI.onSurfaceChanged({old_name = "inactive-surface", new_name="changed-surface"}) + TLBE.GUI.onSurfaceChanged({ old_name = "inactive-surface", new_name = "changed-surface" }) lu.assertEquals(self.testCamera.surfaceName, "active-surface", "expected surface to be unchanged") end function TestSurfaceEvents:TestRenameUsedSurface() - TLBE.GUI.onSurfaceChanged({old_name = "active-surface", new_name="changed-surface"}) + TLBE.GUI.onSurfaceChanged({ old_name = "active-surface", new_name = "changed-surface" }) lu.assertEquals(self.testCamera.surfaceName, "changed-surface", "expected surface to be changed") end diff --git a/tests/tracker-base.lua b/tests/tracker-base.lua index 822961f..64ab0b5 100644 --- a/tests/tracker-base.lua +++ b/tests/tracker-base.lua @@ -13,14 +13,15 @@ TestTrackerBase = {} function TestTrackerBase:SetUp() -- mock Factorio provided globals global = {} + -- luacheck: globals game game = { tick = 0, - surfaces = {{name = "nauvis"}, {name = "other-surface"}} + surfaces = { { name = "nauvis" }, { name = "other-surface" } } } -- mock TLBE tables global.playerSettings = { - TLBE.Config.newPlayerSettings({position = {x = 0, y = 0}}) + TLBE.Config.newPlayerSettings({ position = { x = 0, y = 0 } }) } -- Update base tracker with our test settings @@ -34,6 +35,7 @@ function TestTrackerBase:SetUp() end end +-- luacheck: globals game function TestTrackerBase:TestDisabledTracker() game.tick = 10 self.baseTracker.enabled = false @@ -42,8 +44,8 @@ function TestTrackerBase:TestDisabledTracker() created_entity = { surface = game.surfaces[1], bounding_box = { - left_top = {x = 1, y = 3}, - right_bottom = {x = 3, y = 4} + left_top = { x = 1, y = 3 }, + right_bottom = { x = 3, y = 4 } } } } @@ -54,6 +56,7 @@ function TestTrackerBase:TestDisabledTracker() lu.assertIsNil(self.baseTracker.size, "expected to be at old value") end +-- luacheck: globals game function TestTrackerBase:TestBuildOnOtherSurface() game.tick = 10 TLBE.Main.entity_built( @@ -61,8 +64,8 @@ function TestTrackerBase:TestBuildOnOtherSurface() created_entity = { surface = game.surfaces[2], bounding_box = { - left_top = {x = 1, y = 3}, - right_bottom = {x = 3, y = 4} + left_top = { x = 1, y = 3 }, + right_bottom = { x = 3, y = 4 } } } } @@ -73,6 +76,7 @@ function TestTrackerBase:TestBuildOnOtherSurface() lu.assertIsNil(self.baseTracker.size, "expected to be at old value") end +-- luacheck: globals game function TestTrackerBase:TestSingleEntityBuilt() game.tick = 10 TLBE.Main.entity_built( @@ -80,8 +84,8 @@ function TestTrackerBase:TestSingleEntityBuilt() created_entity = { surface = game.surfaces[1], bounding_box = { - left_top = {x = 1, y = 3}, - right_bottom = {x = 3, y = 4} + left_top = { x = 1, y = 3 }, + right_bottom = { x = 3, y = 4 } } } } @@ -102,6 +106,7 @@ function TestTrackerBase:TestSingleEntityBuilt() ) end +-- luacheck: globals game function TestTrackerBase:TestMultipleEntitiesBuilt() game.tick = 10 TLBE.Main.entity_built( @@ -109,8 +114,8 @@ function TestTrackerBase:TestMultipleEntitiesBuilt() created_entity = { surface = game.surfaces[1], bounding_box = { - left_top = {x = 1, y = 3}, - right_bottom = {x = 3, y = 4} + left_top = { x = 1, y = 3 }, + right_bottom = { x = 3, y = 4 } } } } @@ -124,8 +129,8 @@ function TestTrackerBase:TestMultipleEntitiesBuilt() created_entity = { surface = game.surfaces[1], bounding_box = { - left_top = {x = -2, y = 5}, - right_bottom = {x = 0, y = 8} + left_top = { x = -2, y = 5 }, + right_bottom = { x = 0, y = 8 } } } } diff --git a/tests/tracker-player.lua b/tests/tracker-player.lua old mode 100755 new mode 100644 index f1f31fc..8bdecee --- a/tests/tracker-player.lua +++ b/tests/tracker-player.lua @@ -11,36 +11,39 @@ TestTrackerPlayer = {} function TestTrackerPlayer:SetUp() -- mock Factorio provided globals global = {} + -- luacheck: globals game game = { tick = 0, - surfaces = {{name = "nauvis"}, {name = "other-surface"}} + surfaces = { { name = "nauvis" }, { name = "other-surface" } } } -- mock TLBE tables global.playerSettings = { - TLBE.Config.newPlayerSettings({position = {x = 0, y = 0}}) + TLBE.Config.newPlayerSettings({ position = { x = 0, y = 0 } }) } self.playerTracker = global.playerSettings[1].trackers[1] end +-- luacheck: globals game function TestTrackerPlayer:TestTrackerPlayer() game.tick = 10 - TLBE.Tracker.tick(self.playerTracker, {surface = game.surfaces[1], position = {x = 10, y = 20}}) + TLBE.Tracker.tick(self.playerTracker, { surface = game.surfaces[1], position = { x = 10, y = 20 } }) lu.assertEquals(self.playerTracker.lastChange, 10, "expected to be updated to game.tick") lu.assertEquals(self.playerTracker.centerPos.x, 10, "expected to center to player") lu.assertEquals(self.playerTracker.centerPos.y, 20, "expected to center to player") game.tick = 20 - TLBE.Tracker.tick(self.playerTracker, {surface = game.surfaces[1], position = {x = 10, y = 20}}) + TLBE.Tracker.tick(self.playerTracker, { surface = game.surfaces[1], position = { x = 10, y = 20 } }) lu.assertEquals(self.playerTracker.lastChange, 10, "expected to be the same as the player did not move") end +-- luacheck: globals game function TestTrackerPlayer:TestTrackerPlayerOnOtherSurface() game.tick = 10 - TLBE.Tracker.tick(self.playerTracker, {surface = game.surfaces[2], position = {x = 10, y = 20}}) + TLBE.Tracker.tick(self.playerTracker, { surface = game.surfaces[2], position = { x = 10, y = 20 } }) lu.assertEquals(self.playerTracker.lastChange, 0, "expected to be at old value") lu.assertEquals(self.playerTracker.centerPos, nil, "expected to be at old value") diff --git a/tests/tracker-rocket.lua b/tests/tracker-rocket.lua old mode 100755 new mode 100644 index f2dad8b..a8b7406 --- a/tests/tracker-rocket.lua +++ b/tests/tracker-rocket.lua @@ -11,21 +11,22 @@ TestTrackerRocket = {} function TestTrackerRocket:SetUp() -- mock Factorio provided globals global = {} + -- luacheck: globals game game = { tick = 0, - surfaces = {{name = "nauvis"}, {name = "other-surface"}} + surfaces = { { name = "nauvis" }, { name = "other-surface" } } } -- mock TLBE tables global.playerSettings = { - TLBE.Config.newPlayerSettings({position = {x = 0, y = 0}}) + TLBE.Config.newPlayerSettings({ position = { x = 0, y = 0 } }) } -- Update rocket tracker with our test settings self.rocketTracker = global.playerSettings[1].trackers[2] for k, v in pairs( { - centerPos = {x = 0, y = 0}, + centerPos = { x = 0, y = 0 }, lastChange = 1 } ) do @@ -33,9 +34,10 @@ function TestTrackerRocket:SetUp() end end +-- luacheck: globals game function TestTrackerRocket:TestRocketLaunch() game.tick = 10 - TLBE.Main.rocket_launch({rocket_silo = {surface = game.surfaces[1], position = {x = 10, y = 10}}}) + TLBE.Main.rocket_launch({ rocket_silo = { surface = game.surfaces[1], position = { x = 10, y = 10 } } }) lu.assertIsTrue(self.rocketTracker.enabled, "expected be enabled after rocket launch") lu.assertEquals(self.rocketTracker.lastChange, 10, "expected to be updated to game.tick") @@ -43,9 +45,10 @@ function TestTrackerRocket:TestRocketLaunch() lu.assertEquals(self.rocketTracker.centerPos.y, 10, "expected to center in middle of rocket_silo") end +-- luacheck: globals game function TestTrackerRocket:TestRocketLaunchAlreadyActive() self.rocketTracker.enabled = true - TLBE.Main.rocket_launch({rocket_silo = {surface = game.surfaces[1], position = {x = 10, y = 10}}}) + TLBE.Main.rocket_launch({ rocket_silo = { surface = game.surfaces[1], position = { x = 10, y = 10 } } }) lu.assertIsTrue(self.rocketTracker.enabled, "expected be still enabled after rocket launch") lu.assertEquals(self.rocketTracker.lastChange, 1, "expected to be at old value") @@ -54,24 +57,26 @@ function TestTrackerRocket:TestRocketLaunchAlreadyActive() end function TestTrackerRocket:TestRocketLaunchOtherSurface() - TLBE.Main.rocket_launch({rocket_silo = {surface = game.surfaces[2], position = {x = 10, y = 10}}}) + TLBE.Main.rocket_launch({ rocket_silo = { surface = game.surfaces[2], position = { x = 10, y = 10 } } }) lu.assertIsFalse(self.rocketTracker.enabled, "expected be disabled after rocket launch on other surface") end +-- luacheck: globals game function TestTrackerRocket:TestRocketLaunched() game.tick = 15 self.rocketTracker.enabled = true - TLBE.Main.rocket_launched({rocket_silo = {surface = game.surfaces[1]}}) + TLBE.Main.rocket_launched({ rocket_silo = { surface = game.surfaces[1] } }) lu.assertIsFalse(self.rocketTracker.enabled, "expected be disabled after rocket launched") lu.assertEquals(self.rocketTracker.lastChange, 15, "expected to be updated to game.tick") end +-- luacheck: globals game function TestTrackerRocket:TestRocketLaunched() game.tick = 15 self.rocketTracker.enabled = false - TLBE.Main.rocket_launched({rocket_silo = {surface = game.surfaces[1]}}) + TLBE.Main.rocket_launched({ rocket_silo = { surface = game.surfaces[1] } }) lu.assertIsFalse(self.rocketTracker.enabled, "expected be still disabled after rocket launched") lu.assertEquals(self.rocketTracker.lastChange, 1, "expected to be at old value") diff --git a/tests/tracker.lua b/tests/tracker.lua index 2667b77..f5cf2b3 100644 --- a/tests/tracker.lua +++ b/tests/tracker.lua @@ -8,16 +8,16 @@ function TestNewTracker.TestUniqueName() local baseTracker = Tracker.newTracker("base") lu.assertEquals(baseTracker.name, "base", "with empty list use tracker type as name") - local secondBaseTracker = Tracker.newTracker("base", {baseTracker}) + local secondBaseTracker = Tracker.newTracker("base", { baseTracker }) lu.assertEquals(secondBaseTracker.name, "base-2", "with tracker 'base' already in the list, add '-2' to the name") - local thirdBaseTracker = Tracker.newTracker("base", {baseTracker, secondBaseTracker}) + local thirdBaseTracker = Tracker.newTracker("base", { baseTracker, secondBaseTracker }) lu.assertEquals( thirdBaseTracker.name, "base-3", "with tracker 'base' and 'base-2' already in the list, add '-3' to the name" ) - local playerTracker = Tracker.newTracker("player", {baseTracker}) + local playerTracker = Tracker.newTracker("player", { baseTracker }) lu.assertEquals(playerTracker.name, "player", "with tracker 'base' in the list, tracker should be called 'player'") end diff --git a/tests/utils.lua b/tests/utils.lua index 07d2e0b..1e4fc41 100644 --- a/tests/utils.lua +++ b/tests/utils.lua @@ -3,29 +3,29 @@ local Utils = require("scripts.utils") local lu = require("luaunit") function TestFindName() - lu.assertIsNil(Utils.findName({{name = "name"}}, "other"), "'other' is not in the list") + lu.assertIsNil(Utils.findName({ { name = "name" } }, "other"), "'other' is not in the list") lu.assertEquals( - Utils.findName({{name = "name"}}, "name"), - {name = "name"}, + Utils.findName({ { name = "name" } }, "name"), + { name = "name" }, "'name' is in the list and should be returned" ) end function TestUniqueName() lu.assertTrue(Utils.uniqueName({}, "name"), "any name is unique in empty list") - lu.assertTrue(Utils.uniqueName({{name = "other"}}, "name"), "any name is unique if list only contains 'other'") - lu.assertFalse(Utils.uniqueName({{name = "name"}}, "name"), "any name is not unique if list also contains 'name'") + lu.assertTrue(Utils.uniqueName({ { name = "other" } }, "name"), "any name is unique if list only contains 'other'") + lu.assertFalse(Utils.uniqueName({ { name = "name" } }, "name"), "any name is not unique if list also contains 'name'") end function TestFilterOut() - lu.assertEquals(Utils.filterOut({}, {"name"}), {}, "empty completeList should result in empty result") + lu.assertEquals(Utils.filterOut({}, { "name" }), {}, "empty completeList should result in empty result") lu.assertEquals( - Utils.filterOut({"name"}, {"not name"}), - {"name"}, + Utils.filterOut({ "name" }, { "not name" }), + { "name" }, "name should be in resultList as it is not in filteredList" ) lu.assertEquals( - Utils.filterOut({"name"}, {"name"}), + Utils.filterOut({ "name" }, { "name" }), {}, "name not should be in resultList as it is in filteredList" )