Merge remote-tracking branch 'origin/master' into develop

This commit is contained in:
Applevangelist 2024-07-14 17:49:53 +02:00
commit 504e56e827
2 changed files with 63 additions and 16 deletions

View File

@ -170,10 +170,11 @@ end
--- Adds a Unit based on the Unit Name in the DATABASE. --- Adds a Unit based on the Unit Name in the DATABASE.
-- @param #DATABASE self -- @param #DATABASE self
-- @param #string DCSUnitName Unit name. -- @param #string DCSUnitName Unit name.
-- @param #boolean force
-- @return Wrapper.Unit#UNIT The added unit. -- @return Wrapper.Unit#UNIT The added unit.
function DATABASE:AddUnit( DCSUnitName ) function DATABASE:AddUnit( DCSUnitName, force )
if not self.UNITS[DCSUnitName] then if not self.UNITS[DCSUnitName] or force == true then
-- Debug info. -- Debug info.
self:T( { "Add UNIT:", DCSUnitName } ) self:T( { "Add UNIT:", DCSUnitName } )
@ -832,15 +833,25 @@ end
function DATABASE:FindGroup( GroupName ) function DATABASE:FindGroup( GroupName )
local GroupFound = self.GROUPS[GroupName] local GroupFound = self.GROUPS[GroupName]
if GroupFound == nil and GroupName ~= nil then
-- see if the group exists in the API, maybe a dynamic slot
self:_RegisterDynamicGroup(GroupName)
return self.GROUPS[GroupName]
end
return GroupFound return GroupFound
end end
--- Adds a GROUP based on the GroupName in the DATABASE. --- Adds a GROUP based on the GroupName in the DATABASE.
-- @param #DATABASE self -- @param #DATABASE self
function DATABASE:AddGroup( GroupName ) -- @param #string GroupName
-- @param #boolean force
-- @return Wrapper.Group#GROUP The Group
function DATABASE:AddGroup( GroupName, force )
if not self.GROUPS[GroupName] then if not self.GROUPS[GroupName] or force == true then
self:T( { "Add GROUP:", GroupName } ) self:T( { "Add GROUP:", GroupName } )
self.GROUPS[GroupName] = GROUP:Register( GroupName ) self.GROUPS[GroupName] = GROUP:Register( GroupName )
end end
@ -1346,6 +1357,36 @@ function DATABASE:_RegisterPlayers()
return self return self
end end
--- Private method that registers a single dynamic slot Group and Units within in the mission.
-- @param #DATABASE self
-- @return #DATABASE self
function DATABASE:_RegisterDynamicGroup(Groupname)
local DCSGroup = Group.getByName(Groupname)
if DCSGroup:isExist() then
-- Group name.
local DCSGroupName = DCSGroup:getName()
-- Add group.
self:I(string.format("Register Group: %s", tostring(DCSGroupName)))
self:AddGroup( DCSGroupName, true )
-- Loop over units in group.
for DCSUnitId, DCSUnit in pairs( DCSGroup:getUnits() ) do
-- Get unit name.
local DCSUnitName = DCSUnit:getName()
-- Add unit.
self:I(string.format("Register Unit: %s", tostring(DCSUnitName)))
self:AddUnit( DCSUnitName, true )
end
else
self:E({"Group does not exist: ", DCSGroup})
end
return self
end
--- Private method that registers all Groups and Units within in the mission. --- Private method that registers all Groups and Units within in the mission.
-- @param #DATABASE self -- @param #DATABASE self
@ -1519,8 +1560,8 @@ function DATABASE:_EventOnBirth( Event )
if Event.IniObjectCategory == Object.Category.UNIT then if Event.IniObjectCategory == Object.Category.UNIT then
Event.IniUnit = self:FindUnit( Event.IniDCSUnitName )
Event.IniGroup = self:FindGroup( Event.IniDCSGroupName ) Event.IniGroup = self:FindGroup( Event.IniDCSGroupName )
Event.IniUnit = self:FindUnit( Event.IniDCSUnitName )
-- Client -- Client
local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT
@ -1550,12 +1591,17 @@ function DATABASE:_EventOnBirth( Event )
self:AddPlayer( Event.IniUnitName, PlayerName ) self:AddPlayer( Event.IniUnitName, PlayerName )
end end
local function SetPlayerSettings(self,PlayerName,IniUnit)
-- Player settings. -- Player settings.
local Settings = SETTINGS:Set( PlayerName ) local Settings = SETTINGS:Set( PlayerName )
Settings:SetPlayerMenu(Event.IniUnit) --Settings:SetPlayerMenu(Event.IniUnit)
Settings:SetPlayerMenu(IniUnit)
-- Create an event. -- Create an event.
self:CreateEventPlayerEnterAircraft(Event.IniUnit) self:CreateEventPlayerEnterAircraft(IniUnit)
--self:CreateEventPlayerEnterAircraft(Event.IniUnit)
end
self:ScheduleOnce(1,SetPlayerSettings,self,PlayerName,Event.IniUnit)
end end
@ -1719,6 +1765,7 @@ function DATABASE:_EventOnPlayerLeaveUnit( Event )
local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT
if client then if client then
client:RemovePlayer(PlayerName) client:RemovePlayer(PlayerName)
--self.PLAYERSETTINGS[PlayerName] = nil
end end
end end

View File

@ -738,7 +738,7 @@ do -- SETTINGS
local PlayerGroup = PlayerUnit:GetGroup() local PlayerGroup = PlayerUnit:GetGroup()
local PlayerName = PlayerUnit:GetPlayerName() local PlayerName = PlayerUnit:GetPlayerName()
local PlayerNames = PlayerGroup:GetPlayerNames() --local PlayerNames = PlayerGroup:GetPlayerNames()
local PlayerMenu = MENU_GROUP:New( PlayerGroup, 'Settings "' .. PlayerName .. '"' ) local PlayerMenu = MENU_GROUP:New( PlayerGroup, 'Settings "' .. PlayerName .. '"' )