Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev General 2 #67

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mods/4SB/modules/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ end
function FormatNumber(n)
if n == nil then return "" end

if MathAbs(n) < 1000 then
local an = MathAbs(n)
if an < 1000 then
return ("%01.0f"):format(n)
elseif MathAbs(n) < 10000 then
elseif an < 10000 then
return ("%01.1fk"):format(n / 1000)
elseif MathAbs(n) < 1000000 then
elseif an < 1000000 then
return ("%01.0fk"):format(n / 1000)
else
return ("%01.1fm"):format(n / 1000000)
Expand Down
54 changes: 54 additions & 0 deletions mods/ASE/hook/lua/ui/game/gamemain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,59 @@ do
category = 'Advanced Selection Extension',
})

KeyMapper.SetUserKeyAction("NAVAL > LAND > AIR",
{
action = "UI_Lua import('/mods/ASE/modules/Selection.lua').SetDomain(1)",
category = 'Advanced Selection Extension',
})
KeyMapper.SetUserKeyAction("NAVAL > AIR > LAND",
{
action = "UI_Lua import('/mods/ASE/modules/Selection.lua').SetDomain(2)",
category = 'Advanced Selection Extension',
})
KeyMapper.SetUserKeyAction("LAND > AIR > NAVAL",
{
action = "UI_Lua import('/mods/ASE/modules/Selection.lua').SetDomain(3)",
category = 'Advanced Selection Extension',
})
KeyMapper.SetUserKeyAction("LAND > NAVAL > AIR",
{
action = "UI_Lua import('/mods/ASE/modules/Selection.lua').SetDomain(4)",
category = 'Advanced Selection Extension',
})
KeyMapper.SetUserKeyAction("AIR > LAND > NAVAL",
{
action = "UI_Lua import('/mods/ASE/modules/Selection.lua').SetDomain(5)",
category = 'Advanced Selection Extension',
})
KeyMapper.SetUserKeyAction("AIR > NAVAL > LAND",
{
action = "UI_Lua import('/mods/ASE/modules/Selection.lua').SetDomain(6)",
category = 'Advanced Selection Extension',
})

KeyMapper.SetUserKeyAction('Rotate Domain order',
{
action = "UI_Lua import('/mods/ASE/modules/Selection.lua').RotateDomains()",
category = 'Advanced Selection Extension',
})

KeyMapper.SetUserKeyAction("Toggle Domain Filter",
{
action = "UI_Lua import('/mods/ASE/modules/Main.lua').ToggleLayerFilter()",
category = "Advanced Selection Extension"
})

KeyMapper.SetUserKeyAction("Toggle Exotic Filter",
{
action = "UI_Lua import('/mods/ASE/modules/Main.lua').ToggleExoticFilter()",
category = "Advanced Selection Extension"
})

KeyMapper.SetUserKeyAction("Toggle Assisters Filter",
{
action = "UI_Lua import('/mods/ASE/modules/Main.lua').ToggleAssisterFilter()",
category = "Advanced Selection Extension"
})

end
4 changes: 2 additions & 2 deletions mods/ASE/mod_info.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "Advanced Selection Extension"
version = 1
version = 2
uid = "advanced-selection-extension-v02"
copyright = ""
description = [[QoL Selection functions:
- deselection of assisting land scouts, mobile shields and deceiver
Expand All @@ -12,7 +13,6 @@ Required UI Mod Tools.
]]
author = "4z0t"
url = ""
uid = "advanced-selection-extension-v01"
icon = "/mods/ASE/icon.png"
selectable = true
enabled = true
Expand Down
28 changes: 27 additions & 1 deletion mods/ASE/modules/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ function BindOptions()
end)
end

function ToggleLayerFilter()
layer = not layer
if layer then
print "ASE: Domain filter ON"
else
print "ASE: Domain filter OFF"
end
end

function ToggleExoticFilter()
exotic = not exotic
if exotic then
print "ASE: Exotic filter ON"
else
print "ASE: Exotic filter OFF"
end
end

function ToggleAssisterFilter()
assisters = not assisters
if assisters then
print "ASE: Assisters filter ON"
else
print "ASE: Assisters filter OFF"
end
end

function Main(_isReplay)
isReplay = _isReplay
if isReplay then return end
Expand All @@ -59,7 +86,6 @@ function Main(_isReplay)
Lock.Main(_isReplay)
Selection.Main(_isReplay)
BindOptions()

end

function SelectionChanged(oldSelection, newSelection, added, removed)
Expand Down
25 changes: 14 additions & 11 deletions mods/ASE/modules/Selection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,14 @@ local exoticUnitsCategory = categories.ALLUNITS - categories.ALLUNITS

function FilterExotic(selection)
local filtered = EntityCategoryFilterOut(exoticUnitsCategory, selection)
if TableGetN(filtered) == TableGetN(selection) or TableEmpty(filtered) then
if TableEmpty(filtered) or TableGetN(filtered) == TableGetN(selection) then
return selection, false
end
return filtered, true
end

local currentDomainOrder = 3
local currentDomainOrderOption = UMT.OptionVar.Create("ASE", "currentDomainOrderOption", 3)
local currentDomainOrder = currentDomainOrderOption()
local domainsOrders =
{
{ key = "NAVAL > LAND > AIR", value = { "NAVAL", "LAND", "AIR" } },
Expand All @@ -221,16 +222,18 @@ local function UpdateDomainsCursor()
cursor.domains:SetDomainsOrder(domainsOrders[currentDomainOrder].value)
end

function SetDomain(i)
currentDomainOrder = i
print(domainsOrders[i].key)
currentDomainOrderOption:Set(i)
currentDomainOrderOption:Save()

-- UpdateDomainsCursor()
end

function RotateDomains()
local k, v = next(domainsOrders, currentDomainOrder)
if k == nil then
k = 1
v = domainsOrders[1]
end
print(v.key)
currentDomainOrder = k

UpdateDomainsCursor()
SetDomain(k or 1)
end

function FilterLayer(selection)
Expand Down Expand Up @@ -322,5 +325,5 @@ function Main(_isReplay)

InitOptionsExoticCategories()

UpdateDomainsCursor()
-- UpdateDomainsCursor()
end
56 changes: 32 additions & 24 deletions mods/UMT/modules/LayoutFunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ end
---@param n2 NumberVar
---@return NumberFunction
function Mult(n1, n2)
if iscallable(n1) and iscallable(n2) then
local iscallable1 = iscallable(n1)
local iscallable2 = iscallable(n2)
if iscallable1 and iscallable2 then
return function() return n1() * n2() end
end
if iscallable(n1) then return _MultVarAndValue(n1, n2) end
if iscallable(n2) then return _MultVarAndValue(n2, n1) end
if iscallable1 then return _MultVarAndValue(n1, n2) end
if iscallable2 then return _MultVarAndValue(n2, n1) end
return n1 * n2
end

Expand All @@ -47,22 +49,20 @@ end
---@param n2 NumberVar
---@return NumberFunction
function Div(n1, n2)
if iscallable(n1) and iscallable(n2) then
local iscallable1 = iscallable(n1)
local iscallable2 = iscallable(n2)
if iscallable1 and iscallable2 then
return function() return n1() / n2() end
end
if iscallable(n1) then
if iscallable1 then
assert(n2 ~= 0, "Attempt to divide by zero")
return function()
return n1() / n2
end
return function() return n1() / n2 end
end
if iscallable(n2) then
if iscallable2 then
if n1 == 0 then
return 0
end
return function()
return n1 / n2()
end
return function() return n1 / n2() end
end
return n1 / n2
end
Expand Down Expand Up @@ -90,11 +90,13 @@ end
---@param scale? FunctionalNumber # defaults to pixel scale factor defined in interface options
---@return NumberFunction
function Max(n1, n2, scale)
if iscallable(n1) and iscallable(n2) then
local iscallable1 = iscallable(n1)
local iscallable2 = iscallable(n2)
if iscallable1 and iscallable2 then
return function() return math.max(n1(), n2()) end
end
if iscallable(n1) then return _MaxVarOrValue(n1, n2, scale) end
if iscallable(n2) then return _MaxVarOrValue(n2, n1, scale) end
if iscallable1 then return _MaxVarOrValue(n1, n2, scale) end
if iscallable2 then return _MaxVarOrValue(n2, n1, scale) end

scale = scale or defaultScaleFactor
return Mult(math.max(n1, n2), scale)
Expand Down Expand Up @@ -123,11 +125,13 @@ end
---@param scale? FunctionalNumber # defaults to pixel scale factor defined in interface options
---@return NumberFunction
function Min(n1, n2, scale)
if iscallable(n1) and iscallable(n2) then
local iscallable1 = iscallable(n1)
local iscallable2 = iscallable(n2)
if iscallable1 and iscallable2 then
return function() return math.min(n1(), n2()) end
end
if iscallable(n1) then return _MinVarOrValue(n1, n2, scale) end
if iscallable(n2) then return _MinVarOrValue(n2, n1, scale) end
if iscallable1 then return _MinVarOrValue(n1, n2, scale) end
if iscallable2 then return _MinVarOrValue(n2, n1, scale) end

scale = scale or defaultScaleFactor
return Mult(math.min(n1, n2), scale)
Expand Down Expand Up @@ -172,11 +176,13 @@ end
---@param scale? FunctionalNumber # defaults to pixel scale factor defined in interface options
---@return NumberFunction
function Diff(n1, n2, scale)
if iscallable(n1) and iscallable(n2) then
local iscallable1 = iscallable(n1)
local iscallable2 = iscallable(n2)
if iscallable1 and iscallable2 then
return function() return n1() - n2() end
end
if iscallable(n1) then return _DiffVarAndValue(n1, n2, scale) end
if iscallable(n2) then return _DiffValueAndVar(n1, n2, scale) end
if iscallable1 then return _DiffVarAndValue(n1, n2, scale) end
if iscallable2 then return _DiffValueAndVar(n1, n2, scale) end

scale = scale or defaultScaleFactor
return Mult(n1 - n2, scale)
Expand Down Expand Up @@ -207,11 +213,13 @@ end
---@param scale? FunctionalNumber # defaults to pixel scale factor defined in interface options
---@return NumberFunction
function Sum(n1, n2, scale)
if iscallable(n1) and iscallable(n2) then
local iscallable1 = iscallable(n1)
local iscallable2 = iscallable(n2)
if iscallable1 and iscallable2 then
return function() return n1() + n2() end
end
if iscallable(n1) then return _SumVarAndValue(n1, n2, scale) end
if iscallable(n2) then return _SumVarAndValue(n2, n1, scale) end
if iscallable1 then return _SumVarAndValue(n1, n2, scale) end
if iscallable2 then return _SumVarAndValue(n2, n1, scale) end

scale = scale or defaultScaleFactor
return Mult(n1 + n2, scale)
Expand Down
62 changes: 58 additions & 4 deletions mods/UMT/modules/LuaQ.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
local TableInsert = table.insert
local ipairs = ipairs
local setmetatable = setmetatable
local TableSort = table.sort
local TableGetN = table.getn
local type = type
local iscallable = iscallable

---@class BORTable : table
---@operator bor(table):table
Expand Down Expand Up @@ -125,7 +129,7 @@ where = CreatePipe(LuaQWhere, LuaQWhereKV)
---@class LuaQSortPipeTable : Comparator
LuaQSort = MakePipe(function(tbl, self)
local func = PopFn(self)
table.sort(tbl, func)
TableSort(tbl, func)
return tbl
end)
---@type LuaQSortPipeTable
Expand Down Expand Up @@ -398,7 +402,7 @@ first = CreatePipe(LuaQFirst)

---Returns index of the first value satisfying the condition, if none - nil
---```lua
--- ... | first(function(v) return v > 0 end)
--- ... | firstIndex(function(v) return v > 0 end)
---```
---@class LuaQFirstIPipeTable : Conditional
LuaQFirstI = MakePipe(function(tbl, self)
Expand All @@ -415,10 +419,60 @@ end)
---@type LuaQFirstIPipeTable
firstIndex = CreatePipe(LuaQFirstI)

---Returns the last value that satisfy the condition, if none - nil
---```lua
--- ... | last(function(v) return v > 0 end)
---```
---@class LuaQLastPipeTable : Conditional
LuaQLast = MakePipe(function(tbl, self)
local condition = PopFn(self)

for i = TableGetN(tbl), 1, -1 do
local v = tbl[i]
if condition(v) then
return v
end
end

return nil
end)
---@type LuaQLastPipeTable
last = CreatePipe(LuaQLast)

---Returns index of the last value satisfying the condition, if none - nil
---```lua
--- ... | lastIndex(function(v) return v > 0 end)
---```
---@class LuaQLastIPipeTable : Conditional
LuaQLastI = MakePipe(function(tbl, self)
local condition = PopFn(self)

for i = TableGetN(tbl), 1, -1 do
local v = tbl[i]
if condition(v) then
return i
end
end

return nil
end)
---@type LuaQLastIPipeTable
lastIndex = CreatePipe(LuaQLastI)

---Returns table of distinct values of given table
---@class LuaQDistinctPipeTable
LuaQDistinct = BORPipe(function(tbl, self)
return tbl | toSet | keys
local result = {}
local _set = {}

for _, v in tbl do
if not _set[v] then
TableInsert(result, v)
_set[v] = true
end
end

return result
end)
---@type LuaQDistinctPipeTable
distinct = CreatePipe(LuaQDistinct)
Expand Down Expand Up @@ -468,7 +522,7 @@ LuaQCount = MakePipe(function(tbl, self)
local condition = PopFn(self)

if not condition then
return table.getn(tbl)
return TableGetN(tbl)
end

local count = 0
Expand Down