updated docs, Util functions and fixed last issues
This commit is contained in:
@@ -34,7 +34,7 @@ function AirGroup:New(groupName, groupType, config, logger, spawnManager)
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._spawnManager = spawnManager
|
||||
self._routeDrawing = nil
|
||||
self._routeDrawings = {}
|
||||
|
||||
local group = Group.getByName(self._groupName)
|
||||
if group then
|
||||
|
||||
@@ -538,14 +538,14 @@ function Stage:OnStageNumberChanged(number, stageLaneIdentifier)
|
||||
---@return boolean
|
||||
local needsPreActivation = function()
|
||||
if self._stageLaneIdentifier == stageLaneIdentifier then
|
||||
if self.stageNumber - number < self._stageConfig.AmountPreactivateStage then
|
||||
if self.stageNumber <= number + self._stageConfig.AmountPreactivateStage then
|
||||
return true
|
||||
end
|
||||
elseif self._stageLaneIdentifier == nil then
|
||||
--main lane
|
||||
--Check if this stage is a chapter stage
|
||||
if self._stageRepository:getStageLane(self._stageLaneIdentifier):IsChapterStart(self.stageNumber)
|
||||
and self.stageNumber - number < self._stageConfig.AmountPreactivateStage
|
||||
and self.stageNumber < number + self._stageConfig.AmountPreactivateStage
|
||||
then
|
||||
return true
|
||||
end
|
||||
@@ -568,7 +568,7 @@ function Stage:OnStageNumberChanged(number, stageLaneIdentifier)
|
||||
|
||||
---@return boolean
|
||||
local needsBlueActivation = function()
|
||||
if self._stageLaneIdentifier == stageLaneIdentifier and self.stageNumber > number then
|
||||
if self._stageLaneIdentifier == stageLaneIdentifier and self.stageNumber < number then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
||||
@@ -6,7 +6,7 @@ local drawingLogger = Logger.new("CustomDrawing")
|
||||
|
||||
|
||||
---@class CustomDrawing
|
||||
---@field protected _id integer?
|
||||
---@field protected _IDs Array<integer>?
|
||||
---@field protected _name string?
|
||||
---@field protected _drawingObject DrawingObject
|
||||
local CustomDrawing = {}
|
||||
@@ -18,7 +18,7 @@ CustomDrawing.__index = CustomDrawing
|
||||
function CustomDrawing.New(drawingObject)
|
||||
local self = setmetatable({}, CustomDrawing)
|
||||
self._drawingObject = drawingObject
|
||||
self._id = nil -- initiate ID as nil, when drawn it will be set to the ID returned by DrawingHelper.Draw
|
||||
self._IDs = {} -- initiate IDs as an empty array, when drawn it will be set to the IDs returned by DrawingHelper.Draw
|
||||
self._name = drawingObject.name
|
||||
return self
|
||||
end
|
||||
@@ -110,20 +110,24 @@ function CustomDrawing:GetName()
|
||||
end
|
||||
|
||||
function CustomDrawing:Draw()
|
||||
drawingLogger:debug("Drawing custom drawing with ID " .. tostring(self._id))
|
||||
drawingLogger:debug("Drawing custom drawing with IDs " .. table.concat(self._IDs, ", "))
|
||||
|
||||
if self._id ~= nil then
|
||||
DrawingHelper.Remove(self._id)
|
||||
if self._IDs ~= nil then
|
||||
for _, id in ipairs(self._IDs) do
|
||||
DrawingHelper.Remove(id)
|
||||
end
|
||||
end
|
||||
|
||||
self._id = DrawingHelper.Draw(self._drawingObject)
|
||||
self._IDs = DrawingHelper.Draw(self._drawingObject)
|
||||
end
|
||||
|
||||
function CustomDrawing:Remove()
|
||||
if self._id ~= nil then
|
||||
drawingLogger:debug("Removing custom drawing with ID " .. tostring(self._id))
|
||||
DrawingHelper.Remove(self._id)
|
||||
self._id = nil
|
||||
if self._IDs ~= nil then
|
||||
for _, id in ipairs(self._IDs) do
|
||||
drawingLogger:debug("Removing custom drawing with ID " .. tostring(id))
|
||||
DrawingHelper.Remove(id)
|
||||
end
|
||||
self._IDs = {}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,57 +1,46 @@
|
||||
local Util = require("classes.util.Util")
|
||||
local DcsUtil = require("classes.util.DcsUtil")
|
||||
local Logger = require("classes.util.Logger")
|
||||
local GlobalConfig = require("classes.configuration.GlobalConfig")
|
||||
|
||||
---@type LogLevel
|
||||
local level = "INFO"
|
||||
if GlobalConfig:isDebugEnabled() then
|
||||
if GlobalConfig.New():isDebugEnabled() then
|
||||
level = "DEBUG"
|
||||
end
|
||||
|
||||
local drawingLogger = Logger.new("DrawingHelper", level)
|
||||
local logger = Logger.new("DrawingHelper", level)
|
||||
|
||||
---@class DrawingHelper
|
||||
local DrawingHelper = {}
|
||||
DrawingHelper.__index = DrawingHelper
|
||||
|
||||
|
||||
local customDrawingIdIncrementer = 4210
|
||||
|
||||
---@param object DrawingObject
|
||||
---@param logger Logger?
|
||||
---@return integer? id
|
||||
function DrawingHelper.Draw(object, logger)
|
||||
---@return Array<integer> id
|
||||
function DrawingHelper.Draw(object)
|
||||
if object == nil then
|
||||
if logger then
|
||||
logger:warn("DrawingHelper.Draw called with nil object")
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local id = DrawingHelper.GetAndAddId()
|
||||
|
||||
if logger then
|
||||
logger:debug("Drawing object with ID " .. tostring(id) .. " and primitive type: " .. tostring(object.primitiveType))
|
||||
return {}
|
||||
end
|
||||
|
||||
if(object.primitiveType == "Polygon") then
|
||||
DrawingHelper.DrawPolygon(object--[[@as Polygon]], id, logger)
|
||||
return DrawingHelper.DrawPolygon(object--[[@as Polygon]])
|
||||
elseif(object.primitiveType == "Line") then
|
||||
DrawingHelper.DrawLine(object--[[@as Line]], id, logger)
|
||||
return DrawingHelper.DrawLine(object--[[@as Line]])
|
||||
elseif(object.primitiveType == "TextBox") then
|
||||
DrawingHelper.DrawTextBox(object--[[@as TextBox]], id)
|
||||
return DrawingHelper.DrawTextBox(object--[[@as TextBox]])
|
||||
else
|
||||
if logger then
|
||||
logger:warn("Unknown primitive type: " .. tostring(object.primitiveType))
|
||||
end
|
||||
logger:warn("Unknown primitive type: " .. tostring(object.primitiveType))
|
||||
end
|
||||
|
||||
return id
|
||||
return {}
|
||||
end
|
||||
|
||||
function DrawingHelper.GetAndAddId()
|
||||
customDrawingIdIncrementer = customDrawingIdIncrementer + 1
|
||||
return customDrawingIdIncrementer
|
||||
return DcsUtil.GetNextDrawID()
|
||||
end
|
||||
|
||||
---@private
|
||||
@@ -62,8 +51,7 @@ end
|
||||
---@param lineColor table
|
||||
---@param lineStyle LineType
|
||||
---@param lineThickness number
|
||||
---@param logger Logger?
|
||||
local function MarkupToAll(shapeID, drawID, points, fillColor, lineColor, lineStyle, lineThickness, logger)
|
||||
local function MarkupToAll(shapeID, drawID, points, fillColor, lineColor, lineStyle, lineThickness)
|
||||
|
||||
if lineThickness == nil or lineThickness <= 0 then
|
||||
lineStyle = 0
|
||||
@@ -76,23 +64,19 @@ local function MarkupToAll(shapeID, drawID, points, fillColor, lineColor, lineS
|
||||
end
|
||||
functionString = functionString .. "{0,1,0,1}, {0,1,0,1}, " .. lineStyle .. ")"
|
||||
|
||||
if logger then
|
||||
logger:debug("Drawing complex drawing with ID " .. tostring(drawID) .. " and function string: " .. functionString)
|
||||
end
|
||||
logger:debug("Drawing complex drawing with ID " .. tostring(drawID) .. " and function string: " .. functionString)
|
||||
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
local f, err = loadstring(functionString)
|
||||
if f then
|
||||
f()
|
||||
else
|
||||
env.error("Something failed when drawing complex drawing" .. err)
|
||||
logger:error("Something failed when drawing complex drawing" .. err)
|
||||
end
|
||||
|
||||
if logger then
|
||||
logger:debug("Drawing with fill color: " .. table.concat(fillColor, ",") .. " and line color: " .. table.concat(lineColor, ",") .. " and line style: " .. tostring(lineStyle) .. " and line thickness: " .. tostring(lineThickness))
|
||||
if fillColor then
|
||||
trigger.action.setMarkupColorFill(drawID, fillColor)
|
||||
end
|
||||
|
||||
trigger.action.setMarkupColorFill(drawID, fillColor)
|
||||
trigger.action.setMarkupColor(drawID, lineColor)
|
||||
trigger.action.setMarkupTypeLine(drawID, lineStyle)
|
||||
|
||||
@@ -100,13 +84,14 @@ end
|
||||
|
||||
---@private
|
||||
---@param object Polygon
|
||||
---@param id integer
|
||||
---@param logger Logger?
|
||||
function DrawingHelper.DrawPolygon(object, id, logger)
|
||||
---@return Array<integer>
|
||||
function DrawingHelper.DrawPolygon(object)
|
||||
if object == nil then
|
||||
return
|
||||
return {}
|
||||
end
|
||||
|
||||
local id = DrawingHelper.GetAndAddId()
|
||||
|
||||
---@param circle Circle
|
||||
local function DrawCircle(circle)
|
||||
local vec3 = { x = circle.mapX, y = 0, z = circle.mapY }
|
||||
@@ -117,8 +102,8 @@ function DrawingHelper.DrawPolygon(object, id, logger)
|
||||
end
|
||||
|
||||
---@param oval Oval
|
||||
---@param logger Logger?
|
||||
local function DrawOval(oval, logger)
|
||||
---@return integer?, Array<CustomDrawing>?
|
||||
local function DrawOval(oval)
|
||||
---@type Array<Vec3>
|
||||
local points = {}
|
||||
local pointsNo = 30
|
||||
@@ -134,12 +119,11 @@ function DrawingHelper.DrawPolygon(object, id, logger)
|
||||
local y = oval.mapY + (oval.r2 * math.sin(angle))
|
||||
table.insert(points, { x = x, y = 0, z = y } )
|
||||
end
|
||||
MarkupToAll(7, id, points, fillColor, color, lineStyle, oval.thickness, logger)
|
||||
MarkupToAll(7, id, points, fillColor, color, lineStyle, oval.thickness)
|
||||
end
|
||||
|
||||
---@param free Free
|
||||
---@param logger Logger?
|
||||
local function DrawFree(free, logger)
|
||||
local function DrawFree(free)
|
||||
local fillColor = DrawingHelper.ColorToColorTable(free.fillColorString)
|
||||
local color = DrawingHelper.ColorToColorTable(free.colorString)
|
||||
local lineStyle = DrawingHelper.ToLineStyleInteger(free.style)
|
||||
@@ -163,7 +147,7 @@ function DrawingHelper.DrawPolygon(object, id, logger)
|
||||
end
|
||||
end
|
||||
|
||||
MarkupToAll(7, id, points, fillColor, color, lineStyle, free.thickness, logger)
|
||||
MarkupToAll(7, id, points, fillColor, color, lineStyle, free.thickness)
|
||||
end
|
||||
|
||||
---@param rect Rect
|
||||
@@ -175,19 +159,16 @@ function DrawingHelper.DrawPolygon(object, id, logger)
|
||||
local pointA = { x = rect.mapX, y = 0, z = rect.mapY }
|
||||
local pointB = { x = rect.mapX + rect.width, y = 0, z = rect.mapY + rect.height }
|
||||
trigger.action.rectToAll(-1, id, pointA, pointB, color, fillColor, lineStyle, true)
|
||||
|
||||
end
|
||||
|
||||
---@param arrow Arrow
|
||||
---@param logger Logger?
|
||||
local function DrawArrow(arrow, logger)
|
||||
local function DrawArrow(arrow)
|
||||
local fillColor = DrawingHelper.ColorToColorTable(arrow.fillColorString)
|
||||
local color = DrawingHelper.ColorToColorTable(arrow.colorString)
|
||||
local lineStyle = DrawingHelper.ToLineStyleInteger(arrow.style)
|
||||
|
||||
if logger then
|
||||
logger:debug("Drawing arrow with start point: " .. tostring(arrow.mapX) .. ", " .. tostring(arrow.mapY) .. " and angle: " .. tostring(arrow.angle) .. " and length: " .. tostring(arrow.length))
|
||||
end
|
||||
logger:debug("Drawing arrow with start point: " .. tostring(arrow.mapX) .. ", " .. tostring(arrow.mapY) .. " and angle: " .. tostring(arrow.angle) .. " and length: " .. tostring(arrow.length))
|
||||
|
||||
|
||||
local endPoint = { x = arrow.mapX, y = 0, z = arrow.mapY }
|
||||
local rad = math.rad(arrow.angle or 0)
|
||||
@@ -203,44 +184,56 @@ function DrawingHelper.DrawPolygon(object, id, logger)
|
||||
if object.polygonMode == "circle" then
|
||||
DrawCircle(object--[[@as Circle]])
|
||||
elseif object.polygonMode == "oval" then
|
||||
DrawOval(object--[[@as Oval]], logger)
|
||||
DrawOval(object--[[@as Oval]])
|
||||
elseif object.polygonMode == "free" then
|
||||
DrawFree(object--[[@as Free]], logger)
|
||||
DrawFree(object--[[@as Free]])
|
||||
elseif object.polygonMode == "rect" then
|
||||
DrawRect(object--[[@as Rect]])
|
||||
elseif object.polygonMode == "arrow" then
|
||||
DrawArrow(object--[[@as Arrow]], logger)
|
||||
DrawArrow(object--[[@as Arrow]])
|
||||
end
|
||||
return {id}
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param object Line
|
||||
---@param id integer
|
||||
---@param logger Logger?
|
||||
function DrawingHelper.DrawLine(object, id, logger)
|
||||
---@return Array<integer>
|
||||
function DrawingHelper.DrawLine(object)
|
||||
|
||||
---@type Array<Vec3>
|
||||
local points = {}
|
||||
local ids = {}
|
||||
|
||||
for _, point in ipairs(object.points) do
|
||||
table.insert(points, { x = point.x, y = 0, z = point.y } )
|
||||
table.insert(points, { x = object.mapX + point.x, y = 0, z = object.mapY + point.y } )
|
||||
end
|
||||
|
||||
local color = DrawingHelper.ColorToColorTable(object.colorString)
|
||||
local lineStyle = DrawingHelper.ToLineStyleInteger(object.style)
|
||||
MarkupToAll(1, id, points, color, color, lineStyle, object.thickness, logger)
|
||||
|
||||
for i = 1, #points - 1 do
|
||||
local id = DrawingHelper.GetAndAddId()
|
||||
trigger.action.lineToAll(-1, id, points[i], points[i + 1], color, lineStyle, true)
|
||||
table.insert(ids, id)
|
||||
end
|
||||
return ids
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param object TextBox
|
||||
---@param id integer
|
||||
function DrawingHelper.DrawTextBox(object, id)
|
||||
---@return Array<integer>
|
||||
function DrawingHelper.DrawTextBox(object)
|
||||
|
||||
local id = DrawingHelper.GetAndAddId()
|
||||
|
||||
trigger.action.textToAll(-1, id, { x= object.mapX, y = 0, z = object.mapY },
|
||||
DrawingHelper.ColorToColorTable(object.colorString),
|
||||
DrawingHelper.ColorToColorTable(object.fillColorString),
|
||||
object.fontSize or 12,
|
||||
true,
|
||||
object.text or "")
|
||||
|
||||
return {id}
|
||||
end
|
||||
|
||||
function DrawingHelper.Remove(id)
|
||||
@@ -252,7 +245,7 @@ end
|
||||
function DrawingHelper.ColorToColorTable(hexStr)
|
||||
|
||||
if hexStr == nil then
|
||||
drawingLogger:warn("ColorToColorTable called with nil hexStr, returning default color {0, 0, 0, 0}")
|
||||
logger:warn("ColorToColorTable called with nil hexStr, returning default color {0, 0, 0, 0}")
|
||||
return { 0, 0, 0, 0 }
|
||||
end
|
||||
|
||||
@@ -270,7 +263,7 @@ end
|
||||
---@return string
|
||||
function DrawingHelper.ColorTableToColorString(rgba)
|
||||
if rgba == nil or #rgba < 4 or rgba[1] == nil or rgba[2] == nil or rgba[3] == nil or rgba[4] == nil then
|
||||
drawingLogger:warn("ColorTableToColorString called with invalid rgba table, returning default color string '0x00000000'")
|
||||
logger:warn("ColorTableToColorString called with invalid rgba table, returning default color string '0x00000000'")
|
||||
return "0x00000000"
|
||||
end
|
||||
|
||||
@@ -293,11 +286,11 @@ function DrawingHelper.ToLineStyleInteger(lineStyle)
|
||||
return 2
|
||||
elseif lineStyle == "dotted" then
|
||||
return 3
|
||||
elseif lineStyle == "dot dash" then
|
||||
elseif lineStyle == "dotdash" then
|
||||
return 4
|
||||
elseif lineStyle == "long dash" then
|
||||
elseif lineStyle == "longdash" then
|
||||
return 5
|
||||
elseif lineStyle == "two dash" then
|
||||
elseif lineStyle == "twodash" then
|
||||
return 6
|
||||
else
|
||||
return 0
|
||||
@@ -314,11 +307,11 @@ function DrawingHelper.ToLineStyleString(lineStyle)
|
||||
elseif lineStyle == 3 then
|
||||
return "dotted"
|
||||
elseif lineStyle == 4 then
|
||||
return "dot dash"
|
||||
return "dotdash"
|
||||
elseif lineStyle == 5 then
|
||||
return "long dash"
|
||||
return "longdash"
|
||||
elseif lineStyle == 6 then
|
||||
return "two dash"
|
||||
return "twodash"
|
||||
else
|
||||
return "no line"
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ local RunwayStrikeMission = {}
|
||||
---@field corners Array<Vec2>
|
||||
---@field kilosHit number
|
||||
---@field repairGroups Array<string>
|
||||
---@field drawID number?
|
||||
---@field drawID Array<number>
|
||||
|
||||
|
||||
---@param runway Runway
|
||||
@@ -172,8 +172,10 @@ function RunwayStrikeMission:Draw()
|
||||
|
||||
runwaySection.drawID = DrawingHelper.Draw(drawObject)
|
||||
else
|
||||
DcsUtil.SetFillColor(runwaySection.drawID, fillColor)
|
||||
DcsUtil.SetLineColor(runwaySection.drawID, lineColor)
|
||||
for _, drawID in pairs(runwaySection.drawID) do
|
||||
DcsUtil.SetFillColor(drawID, fillColor)
|
||||
DcsUtil.SetLineColor(drawID, lineColor)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -497,6 +499,7 @@ function RunwayStrikeMission:ToSections(runway, numSections)
|
||||
corners = corners,
|
||||
kilosHit = 0,
|
||||
repairGroups = {},
|
||||
drawID = {},
|
||||
}
|
||||
|
||||
table.insert(sections, section)
|
||||
|
||||
@@ -632,6 +632,12 @@ do -- INIT DCS_UTIL
|
||||
---@field b number
|
||||
---@field a number
|
||||
|
||||
local drawID = 4210
|
||||
|
||||
function DCS_UTIL.GetNextDrawID()
|
||||
drawID = drawID + 1
|
||||
return drawID
|
||||
end
|
||||
|
||||
---@param groupID number
|
||||
---@param text string
|
||||
@@ -677,6 +683,10 @@ do -- INIT DCS_UTIL
|
||||
---@param drawID number
|
||||
---@param fillColor DrawColor
|
||||
function DCS_UTIL.SetFillColor(drawID, fillColor)
|
||||
if fillColor == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local lineColorMapped = {
|
||||
fillColor.r or 0,
|
||||
fillColor.g or 0,
|
||||
|
||||
Reference in New Issue
Block a user