Skip to content

Commit

Permalink
Fix some documentation annotations to remove LuaLS warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
veger committed Nov 13, 2023
1 parent faa3c5e commit 03e5343
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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 } --[[@as LuaPlayerBuiltEntityEventFilter]] })
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)

Expand Down
3 changes: 3 additions & 0 deletions migrations/tlbe.1.4.5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@ for player_index, player in pairs(game.players) do
camera.transitionSpeedGain = camera.speedGain
Camera.updateConfig(camera)

---@diagnostic disable: inject-field Clear old fields
camera.zoomPeriod = nil
camera.zoomTicks = nil
camera.zoomTicksRealtime = nil
---@diagnostic enable: inject-field
camera.chartTags = {}
camera.showGUI = false
end
end

for _, tracker in pairs(playerSettings.trackers) do
tracker.changeId = 0
---@diagnostic disable-next-line: inject-field
tracker.lastChange = nil
end

Expand Down
5 changes: 3 additions & 2 deletions scripts/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ local Camera = {}
--- @field alwaysDay boolean Render screenshot in daylight
--- @field frameRate number
--- @field height number
--- @field lastKnownActiveTracker Tracker.tracker
--- @field changeId integer Last known change ID of the tracker
--- @field lastKnownActiveTracker Tracker.tracker|nil
--- @field changeId integer|nil Last known change ID of the tracker
--- @field name string
--- @field saveFolder string
--- @field saveName string
Expand Down Expand Up @@ -69,6 +69,7 @@ function Camera.newCamera(player, cameraList)
end

--- @type Camera.camera
--- @diagnostic disable-next-line: missing-fields The missing fields are set in updateConfig() and setName()
local camera = {
enabled = false,
surfaceName = game.surfaces[1].name,
Expand Down
29 changes: 15 additions & 14 deletions scripts/tracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ local Tracker = {}
--- @field type string
--- @field untilBuild boolean
--- @field userCanEnable boolean When true, the user can enabled/disable the tracker, otherwise the tracker is controlled by TBLE
--- @field moveToNextTracker boolean Disables the tracker after the cameras are processed (end of game tick)
--- @field moveToNextTracker boolean|nil Disables the tracker after the cameras are processed (end of game tick)
--- @field changeId integer Incremented on each position/size change of the tracker
--- @field centerPos MapPosition.0 Center position of the tracker area (Calculated from minPos and maxPos)
--- @field size MapPosition.0 Size of the tracker area (Calculated from minPos and maxPos)
--- @field centerPos MapPosition.0|nil Center position of the tracker area (Calculated from minPos and maxPos)
--- @field size MapPosition.0|nil Size of the tracker area (Calculated from minPos and maxPos)
--- @field minPos MapPosition.0 Bottom/Left of tracker area
--- @field maxPos MapPosition.0 TopRight of tracker area
--- @field cityBlock Tracker.cityBlock? City block vital statistics, used when type="cityblock"
Expand All @@ -28,11 +28,11 @@ Tracker.cityBlock = {}

---@return Tracker.cityBlock
function Tracker.cityBlock:new()
local cityBlock = {}
local cityBlock = {}

cityBlock.blockSize = { x=32, y=32 }
cityBlock.blockOffset = { x=0, y=0 }
cityBlock.currentBlock = { x=0, y=0 }
cityBlock.blockSize = { x = 32, y = 32 }
cityBlock.blockOffset = { x = 0, y = 0 }
cityBlock.currentBlock = { x = 0, y = 0 }
cityBlock.blockScale = 1.5
return cityBlock
end
Expand All @@ -56,15 +56,17 @@ function Tracker.newTracker(trackerType, trackerList)
surfaceName = game.surfaces[1].name,
userCanEnable = true,
enabled = true,
realtimeCamera = false,
smooth = true,
untilBuild = false,
changeId = 0
changeId = 0,
-- Set some sensible dafaults but will be most likely overwritten by the tracker specific implementations
minPos = { x = -5, y = -5 },
maxPos = { x = 5, y = 5 }
}

-- Add tracker specific details
if trackerType == "area" then
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 }
Expand Down Expand Up @@ -106,7 +108,7 @@ function Tracker.recalculateCityBlock(tracker)
if tracker.type ~= "cityblock" then
return
end

local cityBlock = tracker.cityBlock
if cityBlock == nil then
return
Expand Down Expand Up @@ -137,17 +139,16 @@ function Tracker.recalculateCityBlock(tracker)
x = minPosX,
y = minPosY
}

tracker.maxPos = {
x = tracker.centerPos.x + widthRad,
y = tracker.centerPos.y + heightRad
}

Tracker.changed(tracker)
end
end


-- Update tracker state (if needed)
--- @param tracker Tracker.tracker
--- @param player LuaPlayer
Expand Down
1 change: 1 addition & 0 deletions tests/camera_follow-tracker.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: missing-fields When mocking a game state we don't care about unused/missing fields
package.path = package.path .. ";../?.lua"
local TLBE = { Camera = require("scripts.camera") }

Expand Down
3 changes: 3 additions & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/sh

lua5.2 test-suite.lua
1 change: 1 addition & 0 deletions tests/tracker-player.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: missing-fields When mocking a game state we don't care about unused/missing fields
package.path = package.path .. ";../?.lua"
local TLBE = {
Config = require("scripts.config"),
Expand Down

0 comments on commit 03e5343

Please sign in to comment.