Make and label supergroups for the items

This commit is contained in:
Empathic Qubit 2021-06-19 21:08:07 -04:00
parent e161a2ae2a
commit e7f51c04e4
2 changed files with 81 additions and 22 deletions

View file

@ -18,10 +18,8 @@ String[] Function GetChildNames()
ChildNamesInitialized = True ChildNamesInitialized = True
While(i < Children.Length) While(i < Children.Length)
Debug.Trace(i)
If Children[i] != None If Children[i] != None
names[i] = GetSortName(Children[i].GetName()) names[i] = GetSortName(Children[i].GetName())
Debug.Trace(names[i])
Else Else
names[i] = "" names[i] = ""
EndIf EndIf
@ -124,16 +122,26 @@ Function SortByNameRecursive()
EndWhile EndWhile
EndFunction EndFunction
Function PrintNamesRecursive() Function IndentTrace(String line, Int indentLevel = 0)
Int i = 0
String indent = ""
While i < indentLevel
indent += " "
i += 1
EndWhile
Debug.Trace(indent + line)
EndFunction
Function PrintNamesRecursive(Int level = 0)
Int childIndex = 0 Int childIndex = 0
While childIndex < Children.Length While childIndex < Children.Length
Form child = Children[childIndex] Form child = Children[childIndex]
_EQ_ItemRoulette_FormChunks subChunk = (child as _EQ_ItemRoulette_FormChunks) _EQ_ItemRoulette_FormChunks subChunk = (child as _EQ_ItemRoulette_FormChunks)
If(subChunk != None) If(subChunk != None)
Debug.Trace("Chunk " + subChunk.ChunkName) IndentTrace("Chunk " + subChunk.ChunkName, level)
subChunk.PrintNamesRecursive() subChunk.PrintNamesRecursive(level + 1)
ElseIf child != None ElseIf child != None
Debug.Trace(child.GetName()) IndentTrace(child.GetName(), level)
EndIf EndIf
childIndex += 1 childIndex += 1
EndWhile EndWhile
@ -162,10 +170,10 @@ String Function Disambiguate(String source, String prev, String next)
i += 1 i += 1
EndWhile EndWhile
return StringUtil.Substring(source, 0, i) return StringUtil.Substring(source, 0, sourceLength)
EndFunction EndFunction
Function FinishLastChunk(_EQ_ItemRoulette_FormChunks prevChunk, _EQ_ItemRoulette_FormChunks newChunk) Function NameNewChunk(_EQ_ItemRoulette_FormChunks prevChunk, _EQ_ItemRoulette_FormChunks newChunk)
String prevChunkEndName = "" String prevChunkEndName = ""
if prevChunk != None if prevChunk != None
prevChunkEndName = prevChunk.EndName prevChunkEndName = prevChunk.EndName
@ -173,6 +181,16 @@ Function FinishLastChunk(_EQ_ItemRoulette_FormChunks prevChunk, _EQ_ItemRoulette
newChunk.ChunkName = Disambiguate(newChunk.StartName, prevChunkEndName, newChunk.EndName) newChunk.ChunkName = Disambiguate(newChunk.StartName, prevChunkEndName, newChunk.EndName)
EndFunction EndFunction
Function NamePreviousChunk(_EQ_ItemRoulette_FormChunks prevChunk, _EQ_ItemRoulette_FormChunks newChunk)
String newChunkStartName = ""
If prevChunk != None
If newChunk != None
newChunkStartName = newChunk.StartName
EndIf
prevChunk.ChunkName += "-" + Disambiguate(prevChunk.EndName, prevChunk.StartName, newChunkStartName)
EndIf
EndFunction
Int Function FindMinIndex(Int[] indices, String[] names) Int Function FindMinIndex(Int[] indices, String[] names)
Form currentItem Form currentItem
Int minIndex = -1 Int minIndex = -1
@ -203,8 +221,8 @@ Int Function FindMinIndex(Int[] indices, String[] names)
EndFunction EndFunction
_EQ_ItemRoulette_FormChunks Function GroupByName(ObjectReference placer) _EQ_ItemRoulette_FormChunks Function GroupByName(ObjectReference placer)
_EQ_ItemRoulette_FormChunks groupChunks = ((placer.PlaceAtMe(FormChunks) as Form) as _EQ_ItemRoulette_FormChunks) Int MAX_ITEMS = 5
groupChunks.Children = new Form[127] Form[] groupChunks = new Form[127]
Int[] indices = new Int[127] Int[] indices = new Int[127]
Int i = 0 Int i = 0
@ -225,7 +243,7 @@ _EQ_ItemRoulette_FormChunks Function GroupByName(ObjectReference placer)
i += 1 i += 1
EndWhile EndWhile
Int chunkItemIndex = 5 Int chunkItemIndex = MAX_ITEMS
Int chunkIndex = -1 Int chunkIndex = -1
Bool finishedScanningIndices = False Bool finishedScanningIndices = False
Int index Int index
@ -238,26 +256,24 @@ _EQ_ItemRoulette_FormChunks Function GroupByName(ObjectReference placer)
minIndex = FindMinIndex(indices, names) minIndex = FindMinIndex(indices, names)
If minIndex > -1 If minIndex > -1
finishedScanningIndices = False finishedScanningIndices = False
If chunkItemIndex >= 5 If chunkItemIndex >= MAX_ITEMS
chunkItemIndex = 0 chunkItemIndex = 0
chunkIndex += 1 chunkIndex += 1
prevChunk = newChunk prevChunk = newChunk
newChunk = ((placer.PlaceAtMe(FormChunks) as Form) as _EQ_ItemRoulette_FormChunks) newChunk = ((placer.PlaceAtMe(FormChunks) as Form) as _EQ_ItemRoulette_FormChunks)
newChunk.Children = new Form[5] newChunk.Children = new Form[5]
groupChunks.Children[chunkIndex] = newChunk groupChunks[chunkIndex] = newChunk
EndIf EndIf
index = indices[minIndex] index = indices[minIndex]
currentItem = (Children[minIndex] as _EQ_ItemRoulette_FormChunks).Children[index] currentItem = (Children[minIndex] as _EQ_ItemRoulette_FormChunks).Children[index]
newChunk.Children[chunkItemIndex] = currentItem newChunk.Children[chunkItemIndex] = currentItem
if chunkItemIndex == 0 If chunkItemIndex == 0
newChunk.StartName = names[minIndex] newChunk.StartName = names[minIndex]
if prevChunk != None NamePreviousChunk(prevChunk, newChunk)
prevChunk.ChunkName += "-" + Disambiguate(prevChunk.EndName, prevChunk.StartName, newChunk.StartName)
EndIf
ElseIf chunkItemIndex == newChunk.Children.Length - 1 ElseIf chunkItemIndex == newChunk.Children.Length - 1
newChunk.EndName = names[minIndex] newChunk.EndName = names[minIndex]
FinishLastChunk(prevChunk, newChunk) NameNewChunk(prevChunk, newChunk)
EndIf EndIf
indices[minIndex] = index + 1 indices[minIndex] = index + 1
@ -271,7 +287,50 @@ _EQ_ItemRoulette_FormChunks Function GroupByName(ObjectReference placer)
chunkItemIndex += 1 chunkItemIndex += 1
EndIf EndIf
EndWhile EndWhile
FinishLastChunk(prevChunk, newChunk) NameNewChunk(prevChunk, newChunk)
Return groupChunks Form[] currentChunks = groupChunks
Int currentChunkIndex
Int currentChunksLength = chunkIndex
If chunkItemIndex == 0
currentChunksLength = chunkIndex - 1
EndIf
Form[] newChunks
newChunk = None
prevChunk = None
While currentChunksLength > MAX_ITEMS
chunkIndex = 0
chunkItemIndex = 0
currentChunkIndex = 0
newChunks = new Form[127]
While currentChunkIndex < currentChunksLength
prevChunk = newChunk
newChunk = ((placer.PlaceAtMe(FormChunks) as Form) as _EQ_ItemRoulette_FormChunks)
newChunk.Children = new Form[5]
chunkItemIndex = 0
While currentChunkIndex < currentChunksLength && chunkItemIndex < newChunk.Children.Length
oldChunk = currentChunks[currentChunkIndex] as _EQ_ItemRoulette_FormChunks
newChunk.Children[chunkItemIndex] = currentChunks[currentChunkIndex]
If chunkItemIndex == 0
newChunk.StartName = oldChunk.StartName
NamePreviousChunk(prevChunk, newChunk)
EndIf
chunkItemIndex += 1
currentChunkIndex += 1
EndWhile
newChunks[chunkIndex] = newChunk
newChunk.EndName = oldChunk.EndName
NameNewChunk(prevChunk, newChunk)
chunkIndex += 1
EndWhile
currentChunks = newChunks
currentChunksLength = chunkIndex
EndWhile
NamePreviousChunk(newChunk, None)
_EQ_ItemRoulette_FormChunks finalChunks = ((placer.PlaceAtMe(FormChunks) as Form) as _EQ_ItemRoulette_FormChunks)
finalChunks.Children = currentChunks
Return finalChunks
EndFunction EndFunction

View file

@ -139,12 +139,12 @@ Function SortInventoryItems()
Debug.Trace("Sorting") Debug.Trace("Sorting")
sortChunks.SortByNameRecursive() sortChunks.SortByNameRecursive()
Debug.Trace("Printing") Debug.Trace("Printing")
sortChunks.PrintNamesRecursive() sortChunks.PrintNamesRecursive(0)
Debug.Trace("Grouping") Debug.Trace("Grouping")
_EQ_ItemRoulette_FormChunks groupChunks = sortChunks.GroupByName(Roulette) _EQ_ItemRoulette_FormChunks groupChunks = sortChunks.GroupByName(Roulette)
Debug.Trace("Printing") Debug.Trace("Printing")
Debug.StopStackProfiling() Debug.StopStackProfiling()
groupChunks.PrintNamesRecursive() groupChunks.PrintNamesRecursive(0)
EndFunction EndFunction
Function PlayerItemAdded(Form baseItem, Int itemCount, ObjectReference itemRef, ObjectReference destContainer) Function PlayerItemAdded(Form baseItem, Int itemCount, ObjectReference itemRef, ObjectReference destContainer)