Skip to content

Commit

Permalink
Re-order files to stop polluting generic files (FAForever#5366)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas authored Aug 27, 2023
1 parent b498cef commit 2ebe4d0
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 200 deletions.
4 changes: 0 additions & 4 deletions lua/keymap/debugKeyActions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ local keyActionsDebug = {
action = 'UI_Lua import("/lua/ui/game/maputilities.lua").OpenWindow()',
category = 'debug',
},
['test'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").SelectExternalFactory()',
category = 'debug',
},
['toggle_ai_screen'] = {
action = 'UI_Lua import("/lua/ui/dialogs/aiutilitiesview.lua").OpenWindow()',
category = 'debug'
Expand Down
32 changes: 14 additions & 18 deletions lua/keymap/keyactions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1585,86 +1585,82 @@ local keyActionsOrders = {
action = 'UI_Lua import("/lua/ui/game/orders.lua").Dock(false)',
category = 'orders',
},
['load_transports'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").LoadIntoTransports()',
category = 'orders',
},
}

local keyActionsOrdersAdvanced = {
['load_transports'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").LoadIntoTransports(false)',
action = 'UI_Lua import("/lua/ui/game/hotkeys/load-in-transport.lua").LoadIntoTransports(false)',
category = 'ordersAdvanced',
wikiURL = 'Play/Game/Hotkeys/OrdersAdvanced#load-into-transports'
},
['load_transports_clear'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").LoadIntoTransports(true)',
action = 'UI_Lua import("/lua/ui/game/hotkeys/load-in-transport.lua").LoadIntoTransports(true)',
category = 'ordersAdvanced',
wikiURL = 'Play/Game/Hotkeys/OrdersAdvanced#load-into-transports'
},
['shift_load_transports'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").LoadIntoTransports(false)',
action = 'UI_Lua import("/lua/ui/game/hotkeys/load-in-transport.lua").LoadIntoTransports(false)',
category = 'ordersAdvanced',
wikiURL = 'Play/Game/Hotkeys/OrdersAdvanced#load-into-transports'
},
['shift_load_transports_clear'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").LoadIntoTransports(true)',
action = 'UI_Lua import("/lua/ui/game/hotkeys/load-in-transport.lua").LoadIntoTransports(true)',
category = 'ordersAdvanced',
wikiURL = 'Play/Game/Hotkeys/OrdersAdvanced#load-into-transports'
},
['filter_highest_engineer_and_assist'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").SelectHighestEngineerAndAssist()',
action = 'UI_Lua import("/lua/ui/game/hotkeys/filter-engineers.lua").SelectHighestEngineerAndAssist()',
category = 'ordersAdvanced',
wikiURL = 'Play/Game/Hotkeys/OrdersAdvanced#filter-engineers'
},
['shift_filter_highest_engineer_and_assist'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").SelectHighestEngineerAndAssist()',
action = 'UI_Lua import("/lua/ui/game/hotkeys/filter-engineers.lua").SelectHighestEngineerAndAssist()',
category = 'ordersAdvanced',
wikiURL = 'Play/Game/Hotkeys/OrdersAdvanced#filter-engineers'
},
}

local keyActionsOrdersQueueBased = {
['distribute_orders'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").DistributeOrders(true)',
action = 'UI_Lua import("/lua/ui/game/hotkeys/distribute-queue.lua").DistributeOrders(true)',
category = 'ordersQueueBased',
wikiURL = 'Play/Game/Hotkeys/OrdersQueueManipulation#distribute-orders'
},
['shift_distribute_orders'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").DistributeOrders(true)',
action = 'UI_Lua import("/lua/ui/game/hotkeys/distribute-queue.lua").DistributeOrders(true)',
category = 'ordersQueueBased',
wikiURL = 'Play/Game/Hotkeys/OrdersQueueManipulation#distribute-orders'
},
['distribute_orders_context'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").DistributeOrdersOfMouseContext(true)',
action = 'UI_Lua import("/lua/ui/game/hotkeys/distribute-queue.lua").DistributeOrdersOfMouseContext(true)',
category = 'ordersQueueBased',
wikiURL = 'Play/Game/Hotkeys/OrdersQueueManipulation#distribute-orders'
},
['shift_distribute_orders_context'] = {
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").DistributeOrdersOfMouseContext(true)',
action = 'UI_Lua import("/lua/ui/game/hotkeys/distribute-queue.lua").DistributeOrdersOfMouseContext(true)',
category = 'ordersQueueBased',
wikiURL = 'Play/Game/Hotkeys/OrdersQueueManipulation#distribute-orders'
},
['copy_orders'] = {
action = 'UI_LUA import("/lua/keymap/misckeyactions.lua").CopyOrders()',
action = 'UI_LUA import("/lua/ui/game/hotkeys/copy-queue.lua").CopyOrders()',
category = 'ordersQueueBased',
wikiURL = 'Play/Game/Hotkeys/OrdersQueueManipulation#copy-orders'
},
['shift_copy_orders'] = {
action = 'UI_LUA import("/lua/keymap/misckeyactions.lua").CopyOrders()',
action = 'UI_LUA import("/lua/ui/game/hotkeys/copy-queue.lua").CopyOrders()',
category = 'ordersQueueBased',
wikiURL = 'Play/Game/Hotkeys/OrdersQueueManipulation#copy-orders'
},
}

local keyactionsOrdersContextBased = {
['cycle_context_based_templates'] = {
action = 'UI_Lua import("/lua/ui/game/commands/context-based-templates.lua").Cycle()',
action = 'UI_Lua import("/lua/ui/game/hotkeys/context-based-templates.lua").Cycle()',
category = 'ordersContextBased',
wikiURL = 'Play/Game/Hotkeys/OrdersMouseContext#cycle-templates'
},
['shift_cycle_context_based_templates'] = {
action = 'UI_Lua import("/lua/ui/game/commands/context-based-templates.lua").Cycle()',
action = 'UI_Lua import("/lua/ui/game/hotkeys/context-based-templates.lua").Cycle()',
category = 'ordersContextBased',
wikiURL = 'Play/Game/Hotkeys/OrdersMouseContext#cycle-templates'
},
Expand Down
8 changes: 8 additions & 0 deletions lua/keymap/keymapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,18 @@ function GetKeyActions()
local debugKeyActions = import("/lua/keymap/debugkeyactions.lua").debugKeyActions

for k,v in keyActions do
if ret[k] and ret[k] != v.action then
WARN(string.format("Overwriting user key action: %s -> %s", k, ret[k].action))
end

ret[k] = v
end

for k,v in debugKeyActions do
if ret[k] and ret[k] != v.action then
WARN(string.format("Overwriting user key action: %s -> %s", k, ret[k].action))
end

ret[k] = v
end

Expand Down
102 changes: 0 additions & 102 deletions lua/keymap/misckeyactions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -529,75 +529,6 @@ LoadIntoTransports = function(clearCommands)
SimCallback({ Func = 'LoadIntoTransports', Args = { ClearCommands = clearCommands or false } }, true)
end

--- Distributes the orders of the unit in the selection that is closest to the mouse location
DistributeOrders = function(clearCommands)
local mouse = GetMouseWorldPos()
local selection = GetSelectedUnits()
if mouse[1] and mouse[3] and selection and (not table.empty(selection)) then

-- we only support distributing the orders of non-factory units. Factories
-- use separate orders that would make the logic of this function much
-- more complicated
local validUnits = EntityCategoryFilterOut(categories.FACTORY, selection)

if table.empty(validUnits) then
print("No orders to distribute")
return
end

-- find nearest unit
local nearestUnit = validUnits[1]
local shortestDistance = 4096 * 4096
for k, unit in validUnits do
local position = unit:GetPosition()
local dx = position[1] - mouse[1]
local dz = position[3] - mouse[3]
local distance = dx * dx + dz * dz

if distance < shortestDistance then
nearestUnit = unit
shortestDistance = distance
end
end

-- determine if there are orders to distribute
local queue = nearestUnit:GetCommandQueue()
local queueCount = table.getn(queue)
if queueCount > 0 then
print(string.format("Distributing orders"))
SimCallback({ Func = 'DistributeOrders', Args = { Target = nearestUnit:GetEntityId(), ClearCommands = clearCommands or false } }, true)
else
print("No orders to distribute")
end
else
print("No orders to distribute")
end
end

--- Distributes the orders of the unit that the mouse is hovering over
DistributeOrdersOfMouseContext = function(clearCommands)
local target = GetRolloverInfo().userUnit
if target then
local orderCount = table.getn(target:GetCommandQueue())
if orderCount > 0 then
print(string.format("Distributing orders", orderCount))
SimCallback({ Func = 'DistributeOrders', Args = { Target = target:GetEntityId() }, ClearCommands = clearCommands or false }, true)
else
print("No orders to distribute")
end
end
end

CopyOrders = function(clearCommands)
local info = GetRolloverInfo()
if info.userUnit then
print("Copying orders")
SimCallback({ Func = 'CopyOrders', Args = { Target = info.userUnit:GetEntityId(), ClearCommands = clearCommands or false } }, true)
else
print("Can not copy orders")
end
end

AssignPlatoonBehaviorSilo = function()
SimCallback({ Func = 'AIPlatoonSiloTacticalBehavior', Args = { Behavior = 'AIBehaviorTacticalSimple' } }, true)
end
Expand All @@ -623,30 +554,6 @@ RestoreCameraPosition = function()
camera:MoveTo(settings.Focus, { settings.Heading, settings.Pitch, 0 }, settings.Zoom, 0)
end

function SelectHighestEngineerAndAssist()
local selection = GetSelectedUnits()

if selection then

local tech2 = EntityCategoryFilterDown(categories.TECH2 - categories.COMMAND, selection)
local tech3 = EntityCategoryFilterDown(categories.TECH3 - categories.COMMAND, selection)
local sACUs = EntityCategoryFilterDown(categories.SUBCOMMANDER - categories.COMMAND, selection)

if next(sACUs) then
SimCallback({ Func = 'SelectHighestEngineerAndAssist', Args = { TargetId = sACUs[1]:GetEntityId() } }, true)
SelectUnits(sACUs)
elseif next(tech3) then
SimCallback({ Func = 'SelectHighestEngineerAndAssist', Args = { TargetId = tech3[1]:GetEntityId() } }, true)
SelectUnits(tech3)
elseif next(tech2) then
SimCallback({ Func = 'SelectHighestEngineerAndAssist', Args = { TargetId = tech2[1]:GetEntityId() } }, true)
SelectUnits(tech2)
else
-- do nothing
end
end
end

local function SeparateDiveStatus(units)
local dummyUnitTable = {}
local categoriesSubmersible = categories.SUBMERSIBLE
Expand Down Expand Up @@ -711,12 +618,3 @@ SelectAllBuildingEngineers = function(onscreen)

SelectUnits(units)
end

SelectExternalFactory = function()
local selection = GetSelectedUnits()
if selection then
local unit = selection[1]
reprsl(GetAttachedUnitsList(selection))
SelectUnits(GetAttachedUnitsList(selection))
end
end
2 changes: 1 addition & 1 deletion lua/options/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ options = {
custom = {
states = {
{text = "<LOC _Off>Off", key = "off"},
{text = "<LOC _Off>On", key = "on"} -- only-storages-extractors full-suite
{text = "<LOC _On>On", key = "on"} -- only-storages-extractors full-suite
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion lua/sim/commands/copy-queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CopyOrders = function(units, target, clearCommands, doPrint)
return
end

if not target then
if (not target) or (IsDestroyed(target)) then
return
end

Expand Down
2 changes: 1 addition & 1 deletion lua/sim/commands/distribute-queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DistributeOrders = function(units, target, clearCommands, doPrint)
return
end

if not target then
if (not target) or (IsDestroyed(target)) then
return
end

Expand Down
1 change: 0 additions & 1 deletion lua/sim/commands/load-in-transport.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
--******************************************************************************************************

local AveragePositionOfUnitsXZ = import("/lua/sim/commands/shared.lua").AveragePositionOfUnitsXZ
local AveragePositionOfUnits = import("/lua/sim/commands/shared.lua").AveragePositionOfUnits
local SortUnitsByDistanceToPoint = import("/lua/sim/commands/shared.lua").SortUnitsByDistanceToPoint
local PointOnUnitCircle = import("/lua/sim/commands/shared.lua").PointOnUnitCircle

Expand Down
7 changes: 7 additions & 0 deletions lua/sim/commands/ring-extractor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ local TableGetn = table.getn
---@param engineers Unit[]
RingExtractor = function(extractor, engineers)

---------------------------------------------------------------------------
-- defensive programming

if (not extractor) or (IsDestroyed(extractor)) then
return
end

-- verify the storage
local storage = engineers[1].Blueprint.BlueprintId:sub(1, 2) .. 'b1106'
if (not __blueprints[storage]) or
Expand Down
Loading

0 comments on commit 2ebe4d0

Please sign in to comment.