diff --git a/Applications.cfg b/Applications.cfg index 4e06f582..def8eefc 100644 --- a/Applications.cfg +++ b/Applications.cfg @@ -964,7 +964,7 @@ about="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/TurretControl/About/", icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/TurretControl/Icon.pic", createShortcut="desktop", - version=1.01, + version=1.02, resources={ { path="/Turret.pic", diff --git a/Applications/TurretControl/TurretControl.lua b/Applications/TurretControl/TurretControl.lua index e9928aac..cf3d8b93 100644 --- a/Applications/TurretControl/TurretControl.lua +++ b/Applications/TurretControl/TurretControl.lua @@ -29,8 +29,8 @@ local spaceBetweenTurretsHorizontal = 2 local spaceBetweenTurretsVertical = 1 local turretHeight = turretImage[2] + 12 local turretWidth = turretImage[1] + 8 -local countOfTurretsCanBeShowByWidth = math.floor(buffer.screen.width / (turretWidth + spaceBetweenTurretsHorizontal)) -local xTurrets = math.floor(buffer.screen.width / 2 - (countOfTurretsCanBeShowByWidth * (turretWidth + spaceBetweenTurretsHorizontal)) / 2 ) + math.floor(spaceBetweenTurretsHorizontal / 2) +local countOfTurretsCanBeShowByWidth = math.floor(buffer.width / (turretWidth + spaceBetweenTurretsHorizontal)) +local xTurrets = math.floor(buffer.width / 2 - (countOfTurretsCanBeShowByWidth * (turretWidth + spaceBetweenTurretsHorizontal)) / 2 ) + math.floor(spaceBetweenTurretsHorizontal / 2) local yellowColor = 0xFFDB40 @@ -95,8 +95,8 @@ local function drawTurrets(y) if #turrets <= 0 then local text = "Подключите турели из мода OpenModularTurrets" - local x = math.floor(buffer.screen.width / 2 - unicode.len(text) / 2) - buffer.text(x, math.floor(buffer.screen.height / 2 - 2), yellowColor, text) + local x = math.floor(buffer.width / 2 - unicode.len(text) / 2) + buffer.text(x, math.floor(buffer.height / 2 - 2), yellowColor, text) return end @@ -130,7 +130,7 @@ local function drawTurrets(y) end local function drawSeparator(y) - buffer.text(1, y, yellowColor, string.rep("─", buffer.screen.width)) + buffer.text(1, y, yellowColor, string.rep("─", buffer.width)) end local function drawButtonWithState(x, y, width, height, text, state) @@ -145,18 +145,18 @@ end local function drawBottomBar() local height = 6 - local y = buffer.screen.height - height + 1 - buffer.square(1, y, buffer.screen.width, height, 0x000000, yellowColor, " ") + local y = buffer.height - height + 1 + buffer.square(1, y, buffer.width, height, 0x000000, yellowColor, " ") drawSeparator(y) local text = " ECS® Security Systems™ " - local x = math.floor(buffer.screen.width / 2 - unicode.len(text) / 2) + local x = math.floor(buffer.width / 2 - unicode.len(text) / 2) buffer.text(x, y, yellowColor, text) y = y + 2 local widthOfButton = 19 local totalWidth = (widthOfButton + 2) * 6 - local x = math.floor(buffer.screen.width / 2 - totalWidth / 2) + 1 + local x = math.floor(buffer.width / 2 - totalWidth / 2) + 1 newObj("BottomButtons", "On", x, y, x + widthOfButton - 1, y + 2) x = drawButtonWithState(x, y, widthOfButton, 3, turretConfig.turretsOn and "Турели ВКЛ" or "Турели ВЫКЛ", turretConfig.turretsOn) diff --git a/lib/advancedLua.lua b/lib/advancedLua.lua index 736459c5..d7c6c8ed 100755 --- a/lib/advancedLua.lua +++ b/lib/advancedLua.lua @@ -1,6 +1,6 @@ --[[ - + Advanced Lua Library v1.1 by ECS This library extends a lot of default Lua methods @@ -70,7 +70,7 @@ end -- Split nubmer to it's own bytes with specified count of bytes (0xAABB, 5 -> {0x00, 0x00, 0x00, 0xAA, 0xBB}) function bit32.numberToFixedSizeByteArray(number, size) local byteArray, counter = {}, 0 - + repeat table.insert(byteArray, 1, bit32.band(number, 0xFF)) number = bit32.rshift(number, 8) @@ -100,12 +100,13 @@ function bit32.bitArrayToByte(bitArray) for i = 1, #bitArray do number = bit32.bor(bitArray[i], bit32.lshift(number, 1)) end + return number end -------------------------------------------------- Math extensions -------------------------------------------------- -function math.round(num) +function math.round(num) if num >= 0 then return math.floor(num + 0.5) else @@ -207,7 +208,7 @@ function filesystem.sortedList(path, sortingMethod, showHiddenFiles) currentExtensionList, currentExtension = {fileList[i][1]}, fileList[i][2] end end - + table.sort(currentExtensionList, function(a, b) return a < b end) for j = 1, #currentExtensionList do table.insert(sortedFileList, currentExtensionList[j]) @@ -251,7 +252,7 @@ function filesystem.directorySize(path) size = size + filesystem.size(path .. file) end end - + return size end @@ -260,7 +261,7 @@ end local function doSerialize(array, prettyLook, indentationSymbol, indentationSymbolAdder, equalsSymbol, currentRecusrionStack, recursionStackLimit) local text, keyType, valueType, stringValue = {"{"} table.insert(text, (prettyLook and "\n" or nil)) - + for key, value in pairs(array) do keyType, valueType, stringValue = type(key), type(value), tostring(value) @@ -270,7 +271,7 @@ local function doSerialize(array, prettyLook, indentationSymbol, indentationSymb table.insert(text, (keyType == "string" and table.concat({"\"", key, "\""}) or key)) table.insert(text, "]") table.insert(text, equalsSymbol) - + if valueType == "number" or valueType == "boolean" or valueType == "nil" then table.insert(text, stringValue) elseif valueType == "string" or valueType == "function" then @@ -285,7 +286,7 @@ local function doSerialize(array, prettyLook, indentationSymbol, indentationSymb table.insert(text, "...") end end - + table.insert(text, ",") table.insert(text, (prettyLook and "\n" or nil)) end @@ -416,7 +417,7 @@ end function table.indexOf(t, object) for i = 1, #t do - if t[i] == object then + if t[i] == object then return i end end @@ -459,7 +460,7 @@ function string.optimizeForURLRequests(code) end) code = string.gsub(code, " ", "+") end - return code + return code end function string.unicodeFind(str, pattern, init, plain) @@ -470,9 +471,9 @@ function string.unicodeFind(str, pattern, init, plain) init = #unicode.sub(str, 1, init - 1) + 1 end end - + a, b = string.find(str, pattern, init, plain) - + if a then local ap, bp = str:sub(1, a - 1), str:sub(a,b) a = unicode.len(ap) + 1 @@ -527,7 +528,7 @@ function string.wrap(strings, limit) strings[currentString + 1] = right .. " " .. strings[currentString + 1] else strings[currentString + 1] = right - end + end end break else @@ -578,5 +579,3 @@ end ------------------------------------------------------------------------------------------------------------------ return {loaded = true} - -