Skip to content

Commit

Permalink
Update Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Jan 20, 2024
1 parent a77fc96 commit 18287d7
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 75 deletions.
4 changes: 2 additions & 2 deletions src/lua/FactorioTools/AddElectricPoles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
end
end

return KnapcodeFactorioTools.SetHandling.ToReadOnlySet(electricPoles:getKeys(), context)
return KnapcodeFactorioTools.CollectionExtensions.ToReadOnlySet(electricPoles:getKeys(), context)
end
RemoveExtraElectricPoles = function (context, poweredEntities, electricPoles)
local poleCenterToCoveredCenters, coveredCenterToPoleCenters = KnapcodeOilField.Helpers.GetElectricPoleCoverage(context, poweredEntities, electricPoles:getKeys()):Deconstruct()
Expand Down Expand Up @@ -686,7 +686,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
end
GetElectricPoleGroups = function (context, electricPoles)
local groups = ListILocationSet()
local remaining = KnapcodeFactorioTools.SetHandling.ToSet(electricPoles:getKeys(), context, true)
local remaining = KnapcodeFactorioTools.CollectionExtensions.ToSet(electricPoles:getKeys(), context, true)
while remaining:getCount() > 0 do
local current = KnapcodeFactorioTools.CollectionExtensions.First(remaining:EnumerateItems(), KnapcodeOilField.Location)
remaining:Remove(current)
Expand Down
14 changes: 7 additions & 7 deletions src/lua/FactorioTools/AddPipes_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
break
end

context.CenterToTerminals = KnapcodeFactorioTools.SetHandling.ToDictionary(originalCenterToTerminals:EnumeratePairs(), context, function (x)
context.CenterToTerminals = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(originalCenterToTerminals:EnumeratePairs(), context, function (x)
return x[1]
end, function (x)
return KnapcodeFactorioTools.CollectionExtensions.ToList(x[2], KnapcodeOilField.TerminalLocation)
end, KeyValuePairLocationListTerminalLocation, ListTerminalLocation)
context.LocationToTerminals = KnapcodeFactorioTools.SetHandling.ToDictionary(originalLocationToTerminals:EnumeratePairs(), context, function (x)
context.LocationToTerminals = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(originalLocationToTerminals:EnumeratePairs(), context, function (x)
return x[1]
end, function (x)
return KnapcodeFactorioTools.CollectionExtensions.ToList(x[2], KnapcodeOilField.TerminalLocation)
Expand Down Expand Up @@ -555,12 +555,12 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)

local optimizedPipes = pipes
if context.Options.OptimizePipes then
context.CenterToTerminals = KnapcodeFactorioTools.SetHandling.ToDictionary(originalCenterToTerminals:EnumeratePairs(), context, function (x)
context.CenterToTerminals = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(originalCenterToTerminals:EnumeratePairs(), context, function (x)
return x[1]
end, function (x)
return KnapcodeFactorioTools.CollectionExtensions.ToList(x[2], KnapcodeOilField.TerminalLocation)
end, KeyValuePairLocationListTerminalLocation, ListTerminalLocation)
context.LocationToTerminals = KnapcodeFactorioTools.SetHandling.ToDictionary(originalLocationToTerminals:EnumeratePairs(), context, function (x)
context.LocationToTerminals = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(originalLocationToTerminals:EnumeratePairs(), context, function (x)
return x[1]
end, function (x)
return KnapcodeFactorioTools.CollectionExtensions.ToList(x[2], KnapcodeOilField.TerminalLocation)
Expand Down Expand Up @@ -590,12 +590,12 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
else
local solutionA = GetSolution(context, strategy, true, centerToConnectedCenters, optimizedPipes)

context.CenterToTerminals = KnapcodeFactorioTools.SetHandling.ToDictionary(originalCenterToTerminals:EnumeratePairs(), context, function (x)
context.CenterToTerminals = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(originalCenterToTerminals:EnumeratePairs(), context, function (x)
return x[1]
end, function (x)
return KnapcodeFactorioTools.CollectionExtensions.ToList(x[2], KnapcodeOilField.TerminalLocation)
end, KeyValuePairLocationListTerminalLocation, ListTerminalLocation)
context.LocationToTerminals = KnapcodeFactorioTools.SetHandling.ToDictionary(originalLocationToTerminals:EnumeratePairs(), context, function (x)
context.LocationToTerminals = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(originalLocationToTerminals:EnumeratePairs(), context, function (x)
return x[1]
end, function (x)
return KnapcodeFactorioTools.CollectionExtensions.ToList(x[2], KnapcodeOilField.TerminalLocation)
Expand Down Expand Up @@ -657,7 +657,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
return default
end
EliminateStrandedTerminals = function (context)
local locationsToExplore = KnapcodeFactorioTools.SetHandling.ToReadOnlySet1(context.LocationToTerminals:getKeys(), context, true)
local locationsToExplore = KnapcodeFactorioTools.CollectionExtensions.ToReadOnlySet1(context.LocationToTerminals:getKeys(), context, true)

while locationsToExplore:getCount() > 0 do
local goals = context:GetLocationSet(locationsToExplore)
Expand Down
4 changes: 2 additions & 2 deletions src/lua/FactorioTools/AddPipes_1_FBE.lua
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
-- GENERATE GROUPS
local groups = ListGroup()
local addedPumpjacks = ListTerminalLocation()
local leftoverPumpjacks = KnapcodeFactorioTools.SetHandling.ToSet(context.Centers, context, true)
local leftoverPumpjacks = KnapcodeFactorioTools.CollectionExtensions.ToSet(context.Centers, context, true)
while #lines > 0 do
local line = GetNextLine(lines, addedPumpjacks)

Expand Down Expand Up @@ -462,7 +462,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
break
end

local locationToGroup = KnapcodeFactorioTools.SetHandling.ToDictionary(groups, context, function (x)
local locationToGroup = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(groups, context, function (x)
return x.Location
end, function (x)
return x
Expand Down
10 changes: 5 additions & 5 deletions src/lua/FactorioTools/AddPipes_2_ConnectedCenters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
this._centerToConnectedCenters = centerToConnectedCenters
this._allIncludedCenters = allIncludedCenters

this.IncludedCenters = KnapcodeFactorioTools.SetHandling.ToReadOnlySet1(includedCenters, context, true)
this.IncludedCenters = KnapcodeFactorioTools.CollectionExtensions.ToReadOnlySet1(includedCenters, context, true)

this.FrontierCenters = context:GetLocationSet2(true)
this.IncludedCenterToChildCenters = context:GetLocationDictionary(KnapcodeOilField.ILocationSet)

this.Pipes = KnapcodeFactorioTools.SetHandling.ToSet(pipes, context, true)
this.Pipes = KnapcodeFactorioTools.CollectionExtensions.ToSet(pipes, context, true)

UpdateFrontierCenters(this)
UpdateIncludedCenterToChildCenters(this)
Expand Down Expand Up @@ -245,7 +245,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)

-- Check that nodes are not collinear
if KnapcodeOilField.Helpers.AreLocationsCollinear(centers) then
local connected = KnapcodeFactorioTools.SetHandling.ToDictionary(centers, context, function (c)
local connected = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(centers, context, function (c)
return c
end, function (c)
return context:GetLocationSet2(true)
Expand Down Expand Up @@ -774,7 +774,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
return visited
end
GetTrunkCandidates = function (context, centerToConnectedCenters)
local centerToMaxX = KnapcodeFactorioTools.SetHandling.ToDictionary(context.Centers, context, function (c)
local centerToMaxX = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(context.Centers, context, function (c)
return c
end, function (c)
return KnapcodeFactorioTools.CollectionExtensions.Max(centerToConnectedCenters:get(c):EnumerateItems(), function (c)
Expand All @@ -783,7 +783,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
end, KnapcodeOilField.TerminalLocation, System.Int32)
end, KnapcodeOilField.Location, System.Int32)
end, KnapcodeOilField.Location, System.Int32)
local centerToMaxY = KnapcodeFactorioTools.SetHandling.ToDictionary(context.Centers, context, function (c)
local centerToMaxY = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(context.Centers, context, function (c)
return c
end, function (c)
return KnapcodeFactorioTools.CollectionExtensions.Max(centerToConnectedCenters:get(c):EnumerateItems(), function (c)
Expand Down
4 changes: 2 additions & 2 deletions src/lua/FactorioTools/AddPipes_3_ConnectedCenters_DT.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
local ExecuteWithDelaunay, ExecuteWithDelaunayMst, GetDelauntator
ExecuteWithDelaunay = function (context, centers)
local delaunator = GetDelauntator(centers)
local dlGraph = KnapcodeFactorioTools.SetHandling.ToDictionary(centers, context, function (c)
local dlGraph = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(centers, context, function (c)
return c
end, function (c)
return context:GetLocationSet2(true)
Expand All @@ -35,7 +35,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
end
ExecuteWithDelaunayMst = function (context, centers)
local delaunator = GetDelauntator(centers)
local dlGraph = KnapcodeFactorioTools.SetHandling.ToDictionary(centers, context, function (c)
local dlGraph = KnapcodeFactorioTools.CollectionExtensions.ToDictionary(centers, context, function (c)
return c
end, function (c)
return context:GetLocationDictionary(System.Int32)
Expand Down
41 changes: 39 additions & 2 deletions src/lua/FactorioTools/CollectionExtensions.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
-- Generated by CSharp.lua Compiler
local System = System
local KnapcodeFactorioTools
local KnapcodeOilField
local ListLocation
System.import(function (out)
KnapcodeFactorioTools = Knapcode.FactorioTools
KnapcodeOilField = Knapcode.FactorioTools.OilField
ListLocation = System.List(KnapcodeOilField.Location)
end)
System.namespace("Knapcode.FactorioTools", function (namespace)
namespace.class("CollectionExtensions", function (namespace)
local MaxBy, Max, MinBy, Min, ToList, Single, Single1, First,
First1, FirstOrDefault, Average, SequenceEqual, Sum
local ToDictionary, Distinct, ToSet, ToReadOnlySet, ToReadOnlySet1, MaxBy, Max, MinBy,
Min, ToList, Single, Single1, First, First1, FirstOrDefault, Average,
SequenceEqual, Sum
ToDictionary = function (items, context, keySelector, valueSelector, TItem, TValue)
local dictionary = context:GetLocationDictionary1(items:getCount(), TValue)
for _, item in System.each(items) do
dictionary:Add(keySelector(item, TItem), valueSelector(item, TItem, TValue))
end

return dictionary
end
Distinct = function (locations, context)
local set = context:GetLocationSet5(locations:getCount())
local output = ListLocation(locations:getCount())
for _, location in System.each(locations) do
if set:Add(location) then
output:Add(location)
end
end
return output
end
ToSet = function (locations, context, allowEnumerate)
return context:GetLocationSet10(locations, allowEnumerate)
end
ToReadOnlySet = function (locations, context)
return context:GetReadOnlyLocationSet(locations)
end
ToReadOnlySet1 = function (locations, context, allowEnumerate)
return context:GetReadOnlyLocationSet1(locations, allowEnumerate)
end
MaxBy = function (source, keySelector, TSource, TKey)
local maxKey = System.default(TKey)
local max = System.default(TSource)
Expand Down Expand Up @@ -193,6 +225,11 @@ System.namespace("Knapcode.FactorioTools", function (namespace)
return sum
end
return {
ToDictionary = ToDictionary,
Distinct = Distinct,
ToSet = ToSet,
ToReadOnlySet = ToReadOnlySet,
ToReadOnlySet1 = ToReadOnlySet1,
MaxBy = MaxBy,
Max = Max,
MinBy = MinBy,
Expand Down
2 changes: 1 addition & 1 deletion src/lua/FactorioTools/Helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
break
end
end
local unusedProviders = KnapcodeFactorioTools.SetHandling.ToReadOnlySet1(providers:getKeys(), context, removeUnused)
local unusedProviders = KnapcodeFactorioTools.CollectionExtensions.ToReadOnlySet1(providers:getKeys(), context, removeUnused)

for i = 0, #recipients - 1 do
local continue
Expand Down
50 changes: 0 additions & 50 deletions src/lua/FactorioTools/SetHandling.lua

This file was deleted.

2 changes: 1 addition & 1 deletion src/lua/FactorioTools/Validate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ System.namespace("Knapcode.FactorioTools.OilField", function (namespace)
end
UndergroundPipesArePipes = function (context, pipes, locationToDirection)
if context.Options.ValidateSolution then
local missing = KnapcodeFactorioTools.SetHandling.ToSet(locationToDirection:getKeys(), context, true)
local missing = KnapcodeFactorioTools.CollectionExtensions.ToSet(locationToDirection:getKeys(), context, true)
missing:ExceptWith(pipes)

if missing:getCount() > 0 then
Expand Down
4 changes: 1 addition & 3 deletions src/lua/FactorioTools/manifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ return function (path)
"PumpjackSide",
"Result",
"RotateOptimize",
"SetHandling",
"SharedInstances",
"SignalID",
"SignalTypes",
Expand Down Expand Up @@ -206,8 +205,7 @@ return function (path)
"Knapcode.FactorioTools.OilField.TerminalLocation",
"Knapcode.FactorioTools.OilField.UndergroundPipe",
"Knapcode.FactorioTools.OilField.Validate",
"Knapcode.FactorioTools.Result_1",
"Knapcode.FactorioTools.SetHandling"
"Knapcode.FactorioTools.Result_1"
}
})
end
Expand Down

0 comments on commit 18287d7

Please sign in to comment.