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

Admin Point List cleanup Compromise #19

Merged
merged 6 commits into from
Sep 23, 2022
Merged
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
8 changes: 4 additions & 4 deletions ChallengeModConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

<Element dependency="storage" genericFunc="addDependentPoint" unitTextFunc="VOLUME_TEXT" name="totalStorage" default="1" />
<Element dependency="bales" genericFunc="addDependentPoint" unitTextFunc="VOLUME_TEXT" name="totalBales" default="1" />
<Element dependency="pallets" genericFunc="addDependentPoint" unitTextFunc="VOLUME_TEXT" name="totalPallets" default="1" />
<!--Element dependency="pallets" genericFunc="addDependentPoint" unitTextFunc="VOLUME_TEXT" name="totalPallets" default="1" /-->
<Element dependency="animals" genericFunc="addDependentPoint" unitTextFunc="ANIMAL_TEXT" name="totalAnimals" default="1" />
</Category>
<Category name="storage">
<Element genericFunc="addStorageFactors" unitTextFunc="VOLUME_TEXT" default="1" />
<Element genericFunc="addFillTypeFactors" unitTextFunc="VOLUME_TEXT" default="1" />
</Category>
<Category name="bales">
<Element genericFunc="addBaleFactors" unitTextFunc="VOLUME_TEXT" default="1" />
</Category>
<Category name="pallets">
<!--Category name="pallets">
<Element genericFunc="addPalletFactors" unitTextFunc="VOLUME_TEXT" default="1" />
</Category>
</Category-->
<Category name="animals">
<Element genericFunc="addAnimalFactors" unitTextFunc="ANIMAL_TEXT" default="1"/>
</Category>
Expand Down
9 changes: 8 additions & 1 deletion gui/ScoreBoardFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,14 @@ end
function ScoreBoardFrame:onTextInputChangeValue(text, clickOk, element)
if clickOk then
if text ~= nil and element ~= nil then
element:onTextInput(text)
local sx, ix = self.leftList:getSelectedPath()
local list = self.managers[sx]()
for _, category in pairs(list:getElements()) do
local elementToUpdate = category:getElementByName(element:getName())
if elementToUpdate ~= nil then
elementToUpdate:onTextInput(text)
end
end
self:updateLists()
end
end
Expand Down
3 changes: 0 additions & 3 deletions scripts/VictoryPoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,4 @@ function VictoryPoint.readStream(categoryName, categoryId, name, value, ix)
local element = g_victoryPointManager:getList():getElementByName(categoryName, name)
element:setFactor(value)
return element
print("getList: " .. tostring(g_victoryPointManager:getList()))
print("get element: " .. tostring(g_victoryPointManager:getList():getElementByName(categoryName, name)))
print("setFactor: " .. tostring(g_victoryPointManager:getList():getElementByName(categoryName, name):setFactor(value)))
end
7 changes: 7 additions & 0 deletions scripts/VictoryPointManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ function VictoryPointManager:readStream(streamId, connection)
self.victoryGoal = streamReadInt32(streamId)
end

function VictoryPointManager:addFillTypeFactors(category, factorData, farmId)
local maxFillLevel = g_ruleManager:getGeneralRuleValue("maxFillLevel")
local fillLevels = VictoryPointsUtil.getStorageAmount(farmId, maxFillLevel)
fillLevels = VictoryPointsUtil.getPalletAmount(farmId, maxFillLevel, fillLevels)
VictoryPointsUtil.addFillTypeFactors(fillLevels, category, factorData)
end

function VictoryPointManager:addStorageFactors(category, factorData, farmId)
local maxFillLevel = g_ruleManager:getGeneralRuleValue("maxFillLevel")
local fillLevels = VictoryPointsUtil.getStorageAmount(farmId, maxFillLevel)
Expand Down
12 changes: 6 additions & 6 deletions scripts/VictoryPointsUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function VictoryPointsUtil.getBaleAmount(farmId, maxFillLevel)
return fillTypes
end
maxFillLevel = maxFillLevel == Rule.MAX_FILL_LEVEL_DISABLED and math.huge or maxFillLevel

local baleFillLevels = {}
for _, object in pairs(g_currentMission.nodeToObject) do
if object:isa(Bale) and object:getOwnerFarmId(farmId) == farmId and not object.isMissionBale then
Expand All @@ -63,24 +64,23 @@ function VictoryPointsUtil.getBaleAmount(farmId, maxFillLevel)
return baleFillLevels
end

function VictoryPointsUtil.getPalletAmount(farmId, maxFillLevel)
function VictoryPointsUtil.getPalletAmount(farmId, maxFillLevel, totalFillLevels)
if farmId == nil then
return VictoryPointsUtil.getFillTypes()
end
maxFillLevel = maxFillLevel == Rule.MAX_FILL_LEVEL_DISABLED and math.huge or maxFillLevel
local palletFillLevels = {}
for _, object in pairs(g_currentMission.vehicles) do
if object.spec_pallet and object:getOwnerFarmId(farmId) == farmId then
local fillUnitIndex = object.spec_pallet.fillUnitIndex
local fillLevel = object:getFillUnitFillLevel(fillUnitIndex)
local fillType = object:getFillUnitFillType(fillUnitIndex)
if palletFillLevels[fillType] == nil then
palletFillLevels[fillType] = 0
if totalFillLevels[fillType] == nil then
totalFillLevels[fillType] = 0
end
palletFillLevels[fillType] = palletFillLevels[fillType] + math.min(fillLevel, maxFillLevel)
totalFillLevels[fillType] = totalFillLevels[fillType] + math.min(fillLevel, maxFillLevel)
end
end
return palletFillLevels
return totalFillLevels
end

function VictoryPointsUtil.getAnimalAmount(farmId, maxNumberOfAnimals)
Expand Down