Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------
- -- Programm: LayerManager --
- -- Author: JaggerDer --
- -- Created: --.--.14 --
- ----------------------------
- --Зпрегестрированные слои
- local tLayers = {}
- --Зарагестрировать слой
- RegisterLayer = function(aloLayer)
- if (type(aloLayer) ~= "table" or not aloLayer:GetParameters()) then
- error("Error: expected LayerObj.")
- end
- table.insert(tLayers, aloLayer)
- return #tLayers
- end
- --Удалить слой
- UnregisterLayer = function(anID)
- if (type(anID) ~= "number") then
- error("Error: expected number, got " .. type(anID) .. ".")
- elseif (anID > #tLayers or anID < 1) then
- error("ID out of range: [layers] > [id] > 0")
- end
- table.remove(tLayers, anID)
- end
- --Отобразить все слои на экране
- DrawLayers = function(aDevice)
- for i, v in pairs(tLayers) do
- local _, _lr = next(tLayers, i)
- DrawLayer(v, _lr, aDevice)
- end
- end
- --Отобразить конкретный слой на экране
- DrawLayer = function(aloLayer, aloNextLayer, aDevice)
- local _nNextColor = 0
- if (type(aloLayer) ~= "table" or not aloLayer:GetParameters()) then
- error("Error: expected LayerObj.")
- end
- local _, _nWidth, _nHeight, _nXs, _nYs, _bVis = aloLayer:GetParameters()
- if (bVis == false) then return end
- for y = 1, _nHeight, 1 do
- for x = 1, _nWidth, 1 do
- local _sText, _nTextColor, _nColor = aloLayer:GetPixel(x, y)
- if (aloNextLayer ~= nil) then
- _, _, _nNextColor = aloNextLayer:GetPixel(x, y)
- end
- if (_nColor > 0 and _nNextColor == 0) then
- aDevice.setCursorPos(x + _nXs, y + _nYs)
- aDevice.setTextColor(_nTextColor)
- aDevice.setBackgroundColor(_nColor)
- aDevice.write(_sText)
- end
- end
- end
- end
- --Сдвиг слоя по z координате
- ShiftLayer = function(anID, asDir, anStep)
- if (type(anID) ~= "number" or type(asDir) ~= "string" or type(anStep) ~= "number") then
- error("Usage: <number> <string> <number>")
- elseif ( (anID > #tLayers or anID < 1) or (asDir ~= "left" and asDir ~= "right") or ( (asDir == "right" and anID+anStep > #tLayers) or ( asDir == "left" and anID-anStep < 1) ) ) then
- error("Arguments out of range: [layers] > [ID] > 0 ; shift direction only left or right; [steps]+[id] > [layers] and [steps]-[id] > 0")
- end
- _loBf = tLayers[anID]
- if (asDir == "left") then
- tLayers[anID] = tLayers[anID-anStep]
- tLayers[anID-anStep] = _loBf
- elseif (asDir == "right") then
- tLayers[anID] = tLayers[anID+anStep]
- tLayers[anID+anStep] = _loBf
- end
- end
- --Новое событие
- LayerClick = function(anX, anY)
- if (type(anX) ~= "number" or type(anY) ~= "number") then
- error("Usage: <number> <number>.")
- end
- for i = #tLayers, 1, -1 do
- local _sName, _, _, _nXs, _nXs = tLayers[i]:GetParameters()
- local _sText, _nTextColor, _nColor = tLayers[i]:GetPixel(anX + _nXs, anY + _nYs)
- if (_nColor > 0) then return _sName, _sText, _nTextColor, _nColor end
- end
- end
- --Дебаг
- Info = function()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 1)
- term.clear()
- for i, v in pairs(tLayers) do
- print("ID: ", i, ". Name: ", v:GetParameters(), ".")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement