diff --git a/src/huds/baleHud.lua b/src/huds/baleHud.lua index 167eaa2..d41cf15 100644 --- a/src/huds/baleHud.lua +++ b/src/huds/baleHud.lua @@ -92,7 +92,7 @@ function BaleHud:setData(data) self.squareBaleLengthText:setText(string.format("%.1f m", data.baleLength)) end self.massText:setText(string.format("%d kg", data.mass)) - self.ownerIcon:setColor(Utility.getFarmColor(data.ownerFarmId)) + self.ownerIcon:setColor(GameplayUtility.getFarmColor(data.ownerFarmId)) self.fillLevelText:setText(string.format("%d l", data.fillLevel)) self:setFillTypeIconsVisibility(false) local fillTypeIcon = self.fillTypesIcons[data.fillType] diff --git a/src/huds/palletHud.lua b/src/huds/palletHud.lua index d3b66f2..28f17da 100644 --- a/src/huds/palletHud.lua +++ b/src/huds/palletHud.lua @@ -48,7 +48,7 @@ end function PalletHud:setData(data) if data ~= nil then self.massText:setText(string.format("%d kg", data.mass)) - self.ownerIcon:setColor(Utility.getFarmColor(data.ownerFarmId)) + self.ownerIcon:setColor(GameplayUtility.getFarmColor(data.ownerFarmId)) self.fillLevelText:setText(string.format("%d l", data.fillLevel)) self:setFillTypeIconsVisibility(false) local fillTypeIcon = self.fillTypesIcons[data.fillType] diff --git a/src/huds/vehicleHud.lua b/src/huds/vehicleHud.lua index 848723f..b4d7e01 100644 --- a/src/huds/vehicleHud.lua +++ b/src/huds/vehicleHud.lua @@ -75,8 +75,8 @@ function VehicleHud:setData(data) self.row2.text:setText(string.format("%.0f %%", data.condition)) self.row3.text:setText(string.format("%.0f %%", data.damage)) self.row4.text:setText(string.format("%.0f kg", data.mass)) - self.row5.text:setText(string.format("%s", Utility.getFarmName(data.ownerFarmId) or self.notDefinedText)) - self.row5.text:setColor(Utility.getFarmColor(data.ownerFarmId)) + self.row5.text:setText(string.format("%s", GameplayUtility.getFarmName(data.ownerFarmId) or self.notDefinedText)) + self.row5.text:setColor(GameplayUtility.getFarmColor(data.ownerFarmId)) end end diff --git a/src/infoDisplay.lua b/src/infoDisplay.lua index 0cec4d2..dfb6197 100644 --- a/src/infoDisplay.lua +++ b/src/infoDisplay.lua @@ -99,6 +99,7 @@ function InfoDisplay:onReadStream(streamId) end function InfoDisplay:onUpdate(dt) + --DebugUtility.renderTable(0.45, 0.99, 0.008, {missionInfo = g_currentMission.missionInfo}) end function InfoDisplay:onUpdateTick(dt) diff --git a/src/lib/utility/Array.lua b/src/lib/utility/Array.lua new file mode 100644 index 0000000..8361ef8 --- /dev/null +++ b/src/lib/utility/Array.lua @@ -0,0 +1,46 @@ +--- Royal Utility + +---@author Royal Modding +---@version 1.9.0.0 +---@date 26/02/2021 + +---@alias Array table tables with numeric indexes only, always ordered and sequential + +--- Array utilities class built with performances in mind (with 'array' we mean tables with numeric indexes only, always ordered and sequential) +---@class ArrayUtility +ArrayUtility = ArrayUtility or {} + +--- Remove matching elements from an array +---@param array Array +---@param removeFunc fun(array: Array, index: number, moveAt: number): boolean | "function(array, index, moveAt) local element = array[index] return true end" +---@return Array +function ArrayUtility.remove(array, removeFunc) + local moveAt, length = 1, #array + for index = 1, length do + if removeFunc(array, index, moveAt) then + array[index] = nil + else + -- move kept element's value to moveAt's position, if it's not already there + if (index ~= moveAt) then + array[moveAt] = array[index] + array[index] = nil + end + -- increment position of where we'll place the next kept value + moveAt = moveAt + 1 + end + end + return array +end + +--- Remove element at the given index from an array +---@param array Array +---@param index number +---@return Array +function ArrayUtility.removeAt(array, index) + ArrayUtility.remove( + array, + function(_, i) + return index == i + end + ) +end diff --git a/src/lib/utility/UtilityDebug.lua b/src/lib/utility/Debug.lua similarity index 67% rename from src/lib/utility/UtilityDebug.lua rename to src/lib/utility/Debug.lua index fbade21..83f6559 100644 --- a/src/lib/utility/UtilityDebug.lua +++ b/src/lib/utility/Debug.lua @@ -1,9 +1,12 @@ --- Royal Utility ---@author Royal Modding ----@version 1.8.0.0 +---@version 1.9.0.0 ---@date 05/01/2021 +---@class DebugUtility +DebugUtility = DebugUtility or {} + --- Render a table (for debugging purpose) ---@param posX number ---@param posY number @@ -11,7 +14,7 @@ ---@param inputTable table ---@param maxDepth integer|nil ---@param hideFunc boolean|nil -function Utility.renderTable(posX, posY, textSize, inputTable, maxDepth, hideFunc) +function DebugUtility.renderTable(posX, posY, textSize, inputTable, maxDepth, hideFunc) inputTable = inputTable or {tableIs = "nil"} hideFunc = hideFunc or false maxDepth = maxDepth or 2 @@ -67,7 +70,7 @@ end ---@param textSize number ---@param inputNode integer ---@param maxDepth integer|nil -function Utility.renderNodeHierarchy(posX, posY, textSize, inputNode, maxDepth) +function DebugUtility.renderNodeHierarchy(posX, posY, textSize, inputNode, maxDepth) if inputNode == nil or inputNode == 0 then return end @@ -79,7 +82,7 @@ function Utility.renderNodeHierarchy(posX, posY, textSize, inputNode, maxDepth) return i end local offset = i * textSize * 1.05 - local _, className = Utility.getObjectClass(node) + local _, className = EntityUtility.getObjectClass(node) renderText(x, posY - offset, textSize, string.format("%s (%s)", getName(node), className)) i = i + 1 for ni = 0, getNumOfChildren(node) - 1 do @@ -92,7 +95,7 @@ function Utility.renderNodeHierarchy(posX, posY, textSize, inputNode, maxDepth) setTextColor(1, 1, 1, 1) setTextBold(false) textSize = getCorrectTextSize(textSize) - local _, className = Utility.getObjectClass(inputNode) + local _, className = EntityUtility.getObjectClass(inputNode) renderText(posX, posY, textSize, string.format("%s (%s)", getName(inputNode), className)) for ni = 0, getNumOfChildren(inputNode) - 1 do i = renderNodeHierarchyRecursively(posX + textSize * 1.8, getChildAt(inputNode, ni), 1, i) @@ -115,7 +118,7 @@ end ---@param ag number g color if active ---@param ab number b color if active ---@param active boolean active? -function Utility.drawDebugRectangle(node, minX, maxX, minZ, maxZ, yOffset, alignToGround, r, g, b, ar, ag, ab, active) +function DebugUtility.drawDebugRectangle(node, minX, maxX, minZ, maxZ, yOffset, alignToGround, r, g, b, ar, ag, ab, active) if active then r, g, b = ar, ag, ab end @@ -149,7 +152,7 @@ end ---@param ag number g color if active ---@param ab number b color if active ---@param active boolean active? -function Utility.drawDebugCube(node, size, r, g, b, ar, ag, ab, active) +function DebugUtility.drawDebugCube(node, size, r, g, b, ar, ag, ab, active) if active then r, g, b = ar, ag, ab end @@ -174,31 +177,31 @@ function Utility.drawDebugCube(node, size, r, g, b, ar, ag, ab, active) corners[7] = {x - offsets, y - offsets, z - offsets} corners[8] = {x - offsets, y - offsets, z + offsets} - Utility.drawDebugLine(corners[1], corners[2], 0, 0, 0) - Utility.drawDebugLine(corners[2], corners[3], 0, 0, 0) - Utility.drawDebugLine(corners[3], corners[4], 0, 0, 0) - Utility.drawDebugLine(corners[4], corners[1], 0, 0, 0) - Utility.drawDebugLine(corners[1], corners[5], 0, 0, 0) - Utility.drawDebugLine(corners[2], corners[6], 0, 0, 0) - Utility.drawDebugLine(corners[3], corners[7], 0, 0, 0) - Utility.drawDebugLine(corners[4], corners[8], 0, 0, 0) - Utility.drawDebugLine(corners[5], corners[6], 0, 0, 0) - Utility.drawDebugLine(corners[6], corners[7], 0, 0, 0) - Utility.drawDebugLine(corners[7], corners[8], 0, 0, 0) - Utility.drawDebugLine(corners[8], corners[5], 0, 0, 0) + DebugUtility.drawDebugLine(corners[1], corners[2], 0, 0, 0) + DebugUtility.drawDebugLine(corners[2], corners[3], 0, 0, 0) + DebugUtility.drawDebugLine(corners[3], corners[4], 0, 0, 0) + DebugUtility.drawDebugLine(corners[4], corners[1], 0, 0, 0) + DebugUtility.drawDebugLine(corners[1], corners[5], 0, 0, 0) + DebugUtility.drawDebugLine(corners[2], corners[6], 0, 0, 0) + DebugUtility.drawDebugLine(corners[3], corners[7], 0, 0, 0) + DebugUtility.drawDebugLine(corners[4], corners[8], 0, 0, 0) + DebugUtility.drawDebugLine(corners[5], corners[6], 0, 0, 0) + DebugUtility.drawDebugLine(corners[6], corners[7], 0, 0, 0) + DebugUtility.drawDebugLine(corners[7], corners[8], 0, 0, 0) + DebugUtility.drawDebugLine(corners[8], corners[5], 0, 0, 0) - Utility.drawDebugTriangle(corners[3], corners[2], corners[1], r, g, b) - Utility.drawDebugTriangle(corners[1], corners[4], corners[3], r, g, b) - Utility.drawDebugTriangle(corners[4], corners[1], corners[5], r, g, b) - Utility.drawDebugTriangle(corners[5], corners[8], corners[4], r, g, b) - Utility.drawDebugTriangle(corners[8], corners[5], corners[6], r, g, b) - Utility.drawDebugTriangle(corners[6], corners[7], corners[8], r, g, b) - Utility.drawDebugTriangle(corners[7], corners[6], corners[2], r, g, b) - Utility.drawDebugTriangle(corners[2], corners[3], corners[7], r, g, b) - Utility.drawDebugTriangle(corners[2], corners[6], corners[5], r, g, b) - Utility.drawDebugTriangle(corners[5], corners[1], corners[2], r, g, b) - Utility.drawDebugTriangle(corners[4], corners[8], corners[7], r, g, b) - Utility.drawDebugTriangle(corners[7], corners[3], corners[4], r, g, b) + DebugUtility.drawDebugTriangle(corners[3], corners[2], corners[1], r, g, b) + DebugUtility.drawDebugTriangle(corners[1], corners[4], corners[3], r, g, b) + DebugUtility.drawDebugTriangle(corners[4], corners[1], corners[5], r, g, b) + DebugUtility.drawDebugTriangle(corners[5], corners[8], corners[4], r, g, b) + DebugUtility.drawDebugTriangle(corners[8], corners[5], corners[6], r, g, b) + DebugUtility.drawDebugTriangle(corners[6], corners[7], corners[8], r, g, b) + DebugUtility.drawDebugTriangle(corners[7], corners[6], corners[2], r, g, b) + DebugUtility.drawDebugTriangle(corners[2], corners[3], corners[7], r, g, b) + DebugUtility.drawDebugTriangle(corners[2], corners[6], corners[5], r, g, b) + DebugUtility.drawDebugTriangle(corners[5], corners[1], corners[2], r, g, b) + DebugUtility.drawDebugTriangle(corners[4], corners[8], corners[7], r, g, b) + DebugUtility.drawDebugTriangle(corners[7], corners[3], corners[4], r, g, b) end --- Draw a triangle (for debugging purpose) @@ -208,7 +211,7 @@ end ---@param r number r ---@param g number g ---@param b number b -function Utility.drawDebugTriangle(c1, c2, c3, r, g, b) +function DebugUtility.drawDebugTriangle(c1, c2, c3, r, g, b) drawDebugTriangle(c1[1], c1[2], c1[3], c2[1], c2[2], c2[3], c3[1], c3[2], c3[3], r, g, b, 1, false) end @@ -218,7 +221,7 @@ end ---@param r number r ---@param g number g ---@param b number b -function Utility.drawDebugLine(p1, p2, r, g, b) +function DebugUtility.drawDebugLine(p1, p2, r, g, b) drawDebugLine(p1[1], p1[2], p1[3], r, g, b, p2[1], p2[2], p2[3], r, g, b) end @@ -229,7 +232,7 @@ end ---@param h number height ---@param curve table AnimCurve object ---@param numPointsToShow? integer number of points to render -function Utility.renderAnimCurve(x, y, w, h, curve, numPointsToShow) +function DebugUtility.renderAnimCurve(x, y, w, h, curve, numPointsToShow) local graph = curve.debugGraph local numPoints = numPointsToShow or #curve.keyframes local minTime = 0 @@ -261,16 +264,16 @@ end --- Get the loading speed meter object ---@return LoadingSpeedMeter loadingSpeedMeter -function Utility.getVehicleLoadingSpeedMeter() - if Utility.loadingSpeedMeter == nil then +function DebugUtility.getVehicleLoadingSpeedMeter() + if DebugUtility.loadingSpeedMeter == nil then ---@class LoadingSpeedMeter - Utility.loadingSpeedMeter = {} - Utility.loadingSpeedMeter.vehicles = {} - Utility.loadingSpeedMeter.filters = {} + DebugUtility.loadingSpeedMeter = {} + DebugUtility.loadingSpeedMeter.vehicles = {} + DebugUtility.loadingSpeedMeter.filters = {} --- Add a new filter ---@param filterFunction function | 'function(vehicleData) return true, "meter name" end' - Utility.loadingSpeedMeter.addFilter = function(filterFunction) - table.insert(Utility.loadingSpeedMeter.filters, filterFunction) + DebugUtility.loadingSpeedMeter.addFilter = function(filterFunction) + table.insert(DebugUtility.loadingSpeedMeter.filters, filterFunction) end Utility.overwrittenFunction( Vehicle, @@ -278,7 +281,7 @@ function Utility.getVehicleLoadingSpeedMeter() function(self, superFunc, vehicleData, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments) local smEnabled = false local smName = "" - for _, filter in ipairs(Utility.loadingSpeedMeter.filters) do + for _, filter in ipairs(DebugUtility.loadingSpeedMeter.filters) do smEnabled, smName = filter(vehicleData) if smEnabled then break @@ -286,20 +289,20 @@ function Utility.getVehicleLoadingSpeedMeter() end if smEnabled then - Utility.loadingSpeedMeter.vehicles[self] = {} - Utility.loadingSpeedMeter.vehicles[self].smName = smName - Utility.loadingSpeedMeter.vehicles[self].totalStartTime = getTimeSec() + DebugUtility.loadingSpeedMeter.vehicles[self] = {} + DebugUtility.loadingSpeedMeter.vehicles[self].smName = smName + DebugUtility.loadingSpeedMeter.vehicles[self].totalStartTime = getTimeSec() end local state = superFunc(self, vehicleData, asyncCallbackFunction, asyncCallbackObject, asyncCallbackArguments) if smEnabled then - Utility.loadingSpeedMeter.vehicles[self].totalTime = getTimeSec() - Utility.loadingSpeedMeter.vehicles[self].totalStartTime - print(string.format("[%s] Pre time: %.4f ms", Utility.loadingSpeedMeter.vehicles[self].smName, (Utility.loadingSpeedMeter.vehicles[self].preLoadTime or 0) * 1000)) - print(string.format("[%s] Load time: %.4f ms", Utility.loadingSpeedMeter.vehicles[self].smName, (Utility.loadingSpeedMeter.vehicles[self].loadTime or 0) * 1000)) - print(string.format("[%s] Post time: %.4f ms", Utility.loadingSpeedMeter.vehicles[self].smName, (Utility.loadingSpeedMeter.vehicles[self].postLoadTime or 0) * 1000)) - print(string.format("[%s] Total time: %.4f ms", Utility.loadingSpeedMeter.vehicles[self].smName, (Utility.loadingSpeedMeter.vehicles[self].totalTime or 0) * 1000)) - Utility.loadingSpeedMeter.vehicles[self] = nil + DebugUtility.loadingSpeedMeter.vehicles[self].totalTime = getTimeSec() - DebugUtility.loadingSpeedMeter.vehicles[self].totalStartTime + print(string.format("[%s] Pre time: %.4f ms", DebugUtility.loadingSpeedMeter.vehicles[self].smName, (DebugUtility.loadingSpeedMeter.vehicles[self].preLoadTime or 0) * 1000)) + print(string.format("[%s] Load time: %.4f ms", DebugUtility.loadingSpeedMeter.vehicles[self].smName, (DebugUtility.loadingSpeedMeter.vehicles[self].loadTime or 0) * 1000)) + print(string.format("[%s] Post time: %.4f ms", DebugUtility.loadingSpeedMeter.vehicles[self].smName, (DebugUtility.loadingSpeedMeter.vehicles[self].postLoadTime or 0) * 1000)) + print(string.format("[%s] Total time: %.4f ms", DebugUtility.loadingSpeedMeter.vehicles[self].smName, (DebugUtility.loadingSpeedMeter.vehicles[self].totalTime or 0) * 1000)) + DebugUtility.loadingSpeedMeter.vehicles[self] = nil end return state end @@ -308,21 +311,21 @@ function Utility.getVehicleLoadingSpeedMeter() SpecializationUtil, "raiseEvent", function(superFunc, vehicle, eventName, ...) - if Utility.loadingSpeedMeter.vehicles[vehicle] ~= nil then + if DebugUtility.loadingSpeedMeter.vehicles[vehicle] ~= nil then if eventName == "onPreLoad" then - Utility.loadingSpeedMeter.vehicles[vehicle].preLoadStartTime = getTimeSec() + DebugUtility.loadingSpeedMeter.vehicles[vehicle].preLoadStartTime = getTimeSec() superFunc(vehicle, eventName, ...) - Utility.loadingSpeedMeter.vehicles[vehicle].preLoadTime = getTimeSec() - Utility.loadingSpeedMeter.vehicles[vehicle].preLoadStartTime + DebugUtility.loadingSpeedMeter.vehicles[vehicle].preLoadTime = getTimeSec() - DebugUtility.loadingSpeedMeter.vehicles[vehicle].preLoadStartTime end if eventName == "onLoad" then - Utility.loadingSpeedMeter.vehicles[vehicle].loadStartTime = getTimeSec() + DebugUtility.loadingSpeedMeter.vehicles[vehicle].loadStartTime = getTimeSec() superFunc(vehicle, eventName, ...) - Utility.loadingSpeedMeter.vehicles[vehicle].loadTime = getTimeSec() - Utility.loadingSpeedMeter.vehicles[vehicle].loadStartTime + DebugUtility.loadingSpeedMeter.vehicles[vehicle].loadTime = getTimeSec() - DebugUtility.loadingSpeedMeter.vehicles[vehicle].loadStartTime end if eventName == "onPostLoad" then - Utility.loadingSpeedMeter.vehicles[vehicle].postLoadStartTime = getTimeSec() + DebugUtility.loadingSpeedMeter.vehicles[vehicle].postLoadStartTime = getTimeSec() superFunc(vehicle, eventName, ...) - Utility.loadingSpeedMeter.vehicles[vehicle].postLoadTime = getTimeSec() - Utility.loadingSpeedMeter.vehicles[vehicle].postLoadStartTime + DebugUtility.loadingSpeedMeter.vehicles[vehicle].postLoadTime = getTimeSec() - DebugUtility.loadingSpeedMeter.vehicles[vehicle].postLoadStartTime end else superFunc(vehicle, eventName, ...) @@ -330,5 +333,5 @@ function Utility.getVehicleLoadingSpeedMeter() end ) end - return Utility.loadingSpeedMeter + return DebugUtility.loadingSpeedMeter end diff --git a/src/lib/utility/UtilityEntity.lua b/src/lib/utility/Entity.lua similarity index 88% rename from src/lib/utility/UtilityEntity.lua rename to src/lib/utility/Entity.lua index bd9891d..0237187 100644 --- a/src/lib/utility/UtilityEntity.lua +++ b/src/lib/utility/Entity.lua @@ -1,14 +1,17 @@ --- Royal Utility ---@author Royal Modding ----@version 1.8.0.0 +---@version 1.9.0.0 ---@date 05/01/2021 +---@class EntityUtility +EntityUtility = EntityUtility or {} + --- Get the class id and name of an onject ---@param objectId integer ---@return integer classId class id ---@return string className class name -function Utility.getObjectClass(objectId) +function EntityUtility.getObjectClass(objectId) if objectId == nil then return nil, nil end @@ -23,7 +26,7 @@ end ---@param childNode integer ---@param parentNode integer ---@return boolean -function Utility.isChildOf(childNode, parentNode) +function EntityUtility.isChildOf(childNode, parentNode) if childNode == nil or childNode == 0 or parentNode == nil or parentNode == 0 then return false end @@ -41,9 +44,9 @@ end ---@param nodeId integer id of node ---@param rootId integer id of root node ---@return string nodeIndex index of node -function Utility.nodeToIndex(nodeId, rootId) +function EntityUtility.nodeToIndex(nodeId, rootId) local index = "" - if nodeId ~= nil and entityExists(nodeId) and rootId ~= nil and entityExists(rootId) and Utility.isChildOf(nodeId, rootId) then + if nodeId ~= nil and entityExists(nodeId) and rootId ~= nil and entityExists(rootId) and EntityUtility.isChildOf(nodeId, rootId) then index = tostring(getChildIndex(nodeId)) local pNode = getParent(nodeId) while pNode ~= rootId and pNode ~= 0 do @@ -58,7 +61,7 @@ end ---@param nodeIndex string index of node ---@param rootId integer id of root node ---@return integer nodeId id of node -function Utility.indexToNode(nodeIndex, rootId) +function EntityUtility.indexToNode(nodeIndex, rootId) if nodeIndex == nil or rootId == nil or not entityExists(rootId) then return nil end @@ -82,7 +85,7 @@ end --- Queries a node hierarchy ---@param inputNode integer ---@param func function | "function(node, name, depth) end" -function Utility.queryNodeHierarchy(inputNode, func) +function EntityUtility.queryNodeHierarchy(inputNode, func) if not type(inputNode) == "number" or not entityExists(inputNode) or func == nil then return end @@ -104,7 +107,7 @@ end ---@param parent integer ---@param md5 boolean ---@return string hash hash of the node hierarchy -function Utility.getNodeHierarchyHash(node, parent, md5) +function EntityUtility.getNodeHierarchyHash(node, parent, md5) if not type(node) == "number" or not entityExists(node) or not type(parent) == "number" or not entityExists(parent) then return string.format("Invalid hash node:%s parent:%s", node, parent) end @@ -125,7 +128,7 @@ function Utility.getNodeHierarchyHash(node, parent, md5) local isDyna = false - Utility.queryNodeHierarchy( + EntityUtility.queryNodeHierarchy( node, function(n, name) local rbt = getRigidBodyType(n) @@ -139,7 +142,7 @@ function Utility.getNodeHierarchyHash(node, parent, md5) rot = floatsToString(getWorldRotation(n)) end local sca = floatsToString(getScale(n)) - local index = Utility.nodeToIndex(node, parent) + local index = EntityUtility.nodeToIndex(node, parent) local vis = getVisibility(n) hash = string.format("%s>->%s->%s->%s->%s->%s->%s->%s", hash, name, pos, rot, sca, index, rbt, vis) nodeCount = nodeCount + 1 @@ -155,7 +158,7 @@ end --- Queries node parents (return false to break the loop) ---@param inputNode integer ---@param func function | "function(node, name, depth) return true end" -function Utility.queryNodeParents(inputNode, func) +function EntityUtility.queryNodeParents(inputNode, func) if not type(inputNode) == "number" or not entityExists(inputNode) or func == nil then return end diff --git a/src/lib/utility/UtilityGameplay.lua b/src/lib/utility/Gameplay.lua similarity index 85% rename from src/lib/utility/UtilityGameplay.lua rename to src/lib/utility/Gameplay.lua index 35b4634..7aed06b 100644 --- a/src/lib/utility/UtilityGameplay.lua +++ b/src/lib/utility/Gameplay.lua @@ -1,14 +1,17 @@ --- Royal Utility ---@author Royal Modding ----@version 1.8.0.0 +---@version 1.9.0.0 ---@date 05/01/2021 +---@class GameplayUtility +GameplayUtility = GameplayUtility or {} + --- Get value of a trunk (splitshape) ---@param id integer ---@param splitType table ---@return number, number, number, number -function Utility.getTrunkValue(id, splitType) +function GameplayUtility.getTrunkValue(id, splitType) if splitType == nil then splitType = g_splitTypeManager:getSplitTypeByIndex(getSplitType(id)) end @@ -50,13 +53,15 @@ function Utility.getTrunkValue(id, splitType) defoliageScale = MathUtil.lerp(1, defoliageScale, g_currentMission.missionInfo.economicDifficulty / 3) - return volume * 1000 * splitType.pricePerLiter * qualityScale * defoliageScale * lengthScale, qualityScale, defoliageScale, lengthScale + local sellPriceMultiplier = g_currentMission.missionInfo.sellPriceMultiplier + + return volume * 1000 * splitType.pricePerLiter * qualityScale * defoliageScale * lengthScale * sellPriceMultiplier, qualityScale, defoliageScale, lengthScale end --- Get the farm color ---@param farmId number ---@return number[] -function Utility.getFarmColor(farmId) +function GameplayUtility.getFarmColor(farmId) local farm = g_farmManager:getFarmById(farmId) if farm ~= nil then local color = Farm.COLORS[farm.color] @@ -70,7 +75,7 @@ end --- Get the farm name ---@param farmId number ---@return string -function Utility.getFarmName(farmId) +function GameplayUtility.getFarmName(farmId) local farm = g_farmManager:getFarmById(farmId) if farm ~= nil then return farm.name diff --git a/src/lib/utility/UtilityInterpolator.lua b/src/lib/utility/Interpolator.lua similarity index 99% rename from src/lib/utility/UtilityInterpolator.lua rename to src/lib/utility/Interpolator.lua index fb04e4a..5668e48 100644 --- a/src/lib/utility/UtilityInterpolator.lua +++ b/src/lib/utility/Interpolator.lua @@ -1,7 +1,7 @@ --- Royal Utility ---@author Royal Modding ----@version 1.8.0.0 +---@version 1.9.0.0 ---@date 11/01/2021 --- Interpolators utilities class diff --git a/src/lib/utility/Main.lua b/src/lib/utility/Main.lua index 2357e2a..8f8a9c8 100644 --- a/src/lib/utility/Main.lua +++ b/src/lib/utility/Main.lua @@ -1,19 +1,20 @@ --- Royal Utility ---@author Royal Modding ----@version 1.8.0.0 +---@version 1.9.0.0 ---@date 21/11/2020 --- Initialize RoyalUtility ---@param utilityDirectory string function InitRoyalUtility(utilityDirectory) source(Utils.getFilename("Utility.lua", utilityDirectory)) - source(Utils.getFilename("UtilityDebug.lua", utilityDirectory)) - source(Utils.getFilename("UtilityEntity.lua", utilityDirectory)) - source(Utils.getFilename("UtilityGameplay.lua", utilityDirectory)) - source(Utils.getFilename("UtilityString.lua", utilityDirectory)) - source(Utils.getFilename("UtilityTable.lua", utilityDirectory)) - source(Utils.getFilename("UtilityInterpolator.lua", utilityDirectory)) + source(Utils.getFilename("Debug.lua", utilityDirectory)) + source(Utils.getFilename("Entity.lua", utilityDirectory)) + source(Utils.getFilename("Gameplay.lua", utilityDirectory)) + source(Utils.getFilename("String.lua", utilityDirectory)) + source(Utils.getFilename("Table.lua", utilityDirectory)) + source(Utils.getFilename("Interpolator.lua", utilityDirectory)) + source(Utils.getFilename("Array.lua", utilityDirectory)) g_logManager:devInfo("Royal Utility loaded successfully by " .. g_currentModName) return true end diff --git a/src/lib/utility/UtilityString.lua b/src/lib/utility/String.lua similarity index 98% rename from src/lib/utility/UtilityString.lua rename to src/lib/utility/String.lua index 0759525..803b69d 100644 --- a/src/lib/utility/UtilityString.lua +++ b/src/lib/utility/String.lua @@ -1,7 +1,7 @@ --- Royal Utility ---@author Royal Modding ----@version 1.8.0.0 +---@version 1.9.0.0 ---@date 05/01/2021 --- String utilities class diff --git a/src/lib/utility/UtilityTable.lua b/src/lib/utility/Table.lua similarity index 99% rename from src/lib/utility/UtilityTable.lua rename to src/lib/utility/Table.lua index 6482312..8890699 100644 --- a/src/lib/utility/UtilityTable.lua +++ b/src/lib/utility/Table.lua @@ -1,7 +1,7 @@ --- Royal Utility ---@author Royal Modding ----@version 1.8.0.0 +---@version 1.9.0.0 ---@date 05/01/2021 --- Table utilities class diff --git a/src/lib/utility/Utility.lua b/src/lib/utility/Utility.lua index c2e2d83..599dc3c 100644 --- a/src/lib/utility/Utility.lua +++ b/src/lib/utility/Utility.lua @@ -1,7 +1,7 @@ --- Royal Utility ---@author Royal Modding ----@version 1.8.0.0 +---@version 1.9.0.0 ---@date 09/11/2020 --- Utilities class diff --git a/src/modDesc.xml b/src/modDesc.xml index 1be1efb..5b020a6 100644 --- a/src/modDesc.xml +++ b/src/modDesc.xml @@ -268,7 +268,7 @@ Changelog ${version}: Etat CondiciĆ³n Condizione - Stan + Stan Damage diff --git a/src/playerExtension.lua b/src/playerExtension.lua index 3af5b40..55803da 100644 --- a/src/playerExtension.lua +++ b/src/playerExtension.lua @@ -19,14 +19,14 @@ function PlayerExtension:draw(superFunc) if self.isEntered then if self.renderInfo then if InfoDisplay.debug then - Utility.renderTable(0.1, 0.95, 0.009, self.infoObject, 3, false) + DebugUtility.renderTable(0.1, 0.95, 0.009, self.infoObject, 3, false) end if PlayerExtension.huds[self.infoObject.type] ~= nil then PlayerExtension.huds[self.infoObject.type]:render() end else if InfoDisplay.debug and self.raycastHitted then - Utility.renderTable(0.1, 0.95, 0.009, self.objectToDebug, 1, false) + DebugUtility.renderTable(0.1, 0.95, 0.009, self.objectToDebug, 1, false) end end end @@ -46,7 +46,7 @@ end function PlayerExtension:infoObjectRaycastCallback(hitObjectId, _, _, _, _) if hitObjectId ~= self.rootNode then - local id, _ = Utility.getObjectClass(hitObjectId) + local id, _ = EntityUtility.getObjectClass(hitObjectId) if id == ClassIds.SHAPE then self.raycastHitted = true if self.objectToDebug == nil and InfoDisplay.debug then @@ -219,7 +219,7 @@ function PlayerExtension.getTreeInfo(objectId) info.pricePerLiter = splitType.pricePerLiter info.woodChipsPerLiter = splitType.pricePerLiter info.woodChips = info.volume * info.woodChipsPerLiter - info.price, info.qualityScale, info.defoliageScale, info.lengthScale = Utility.getTrunkValue(objectId, splitType) + info.price, info.qualityScale, info.defoliageScale, info.lengthScale = GameplayUtility.getTrunkValue(objectId, splitType) if g_firewood ~= nil then info.firewood = g_firewood.FirewoodTool.getChoppingVolume(info.volume) or -1 end