From 819912cfd3e5a7ed58e904811f4b6ffbf929ca8c Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 28 Jan 2023 15:39:42 +0100 Subject: [PATCH] Database - Polygon drawings are adde as polygon zones to DB --- Moose Development/Moose/Core/Database.lua | 63 ++++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index afa1d6a64..2bd712f72 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -370,11 +370,70 @@ do -- Zones -- Add zone to DB. self:AddZone( ZoneName, Zone_Polygon ) end + end + + -- Drawings as zones + if env.mission.drawings and env.mission.drawings.layers then + + -- Loop over layers. + for layerID, layerData in pairs(env.mission.drawings.layers or {}) do + + -- Loop over objects in layers. + for objectID, objectData in pairs(layerData.objects or {}) do + + -- Check for polygon which has at least 4 points (we would need 3 but the origin seems to be there twice) + if objectData.polygonMode=="free" and objectData.points and #objectData.points>=4 then + + -- Name of the zone. + local ZoneName=objectData.name or "Unknown Drawing" + + -- Reference point. All other points need to be translated by this. + local vec2={x=objectData.mapX, y=objectData.mapY} + + -- Debug stuff. + --local vec3={x=objectData.mapX, y=0, z=objectData.mapY} + --local coord=COORDINATE:NewFromVec2(vec2):MarkToAll("MapX, MapY") + --trigger.action.markToAll(id, "mapXY", vec3) + -- Copy points array. + local points=UTILS.DeepCopy(objectData.points) + + -- Translate points. + for i,_point in pairs(points) do + local point=_point --DCS#Vec2 + points[i]=UTILS.Vec2Add(point, vec2) + end + + -- Remove last point. + table.remove(points, #points) + + -- Debug output + self:I(string.format("Register ZONE: %s (Polygon drawing with %d verticies)", ZoneName, #points)) + + -- Create new polygon zone. + local Zone=ZONE_POLYGON:NewFromPointsArray(ZoneName, points) + + -- Set color. + Zone:SetColor({1, 0, 0}, 0.15) + + -- Store in DB. + self.ZONENAMES[ZoneName] = ZoneName + + -- Add zone. + self:AddZone(ZoneName, Zone) + + end + + end + + end + + end + + end - - + end -- zone do -- Zone_Goal