Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ПЕРЕМЕННЫЕ--
- local CurrentMonitor, Monitors
- local CursorPosX, CursorPosY = 1, 1
- local BGColor, TextColor, Scale = colors.black, colors.white, 3
- --ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ--
- function PointInRect(x, y, sx, sy, ex, ey)
- if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end
- return false
- end
- --ПРОГРАММА--
- --Получить относительные координаты точки по абсолютным координатам
- function GetRelativeCursorPos(ax, ay)
- local MonitorID, PosX, PosY
- for j = 1, Monitors["monitorsCountInHeight"], 1 do
- for i = 1, Monitors["monitorsCountInWidth"], 1 do
- if PointInRect(ax, ay, Monitors[j][i]["xStart"], Monitors[j][i]["yStart"], Monitors[j][i]["xEnd"], Monitors[j][i]["yEnd"]) then
- PosX = ax - Monitors[j][i]["xStart"] + 1
- PosY = ay - Monitors[j][i]["yStart"] + 1
- MonitorID = Monitors[j][i]["id"]
- return MonitorID, PosX, PosY, i, j
- end
- end
- end
- return nil
- end
- --Получить абсолютные координаты точки по относительным координатам
- function GetAbsoluteCursorPos(MonitorID, rx, ry)
- local PosX, PosY
- for j = 1, Monitors["monitorsCountInHeight"], 1 do
- for i = 1, Monitors["monitorsCountInWidth"], 1 do
- if Monitors[j][i]["id"] == MonitorID then
- PosX = Monitors[j][i]["xStart"] + rx - 1
- PosY = Monitors[j][i]["yStart"] + ry - 1
- return PosX, PosY, i, j
- end
- end
- end
- return nil
- end
- --Инициализация API
- function Init(ConfigFilePath)
- local _cfg = ConfigFilePath or "System/ClusterCalibration.cfg"
- if fs.exists(_cfg) then error("Configuration file not found.") end
- file = fs.open(_cfg, "r")
- local _data = file.readAll(monitors)
- file.close()
- Monitors = textutils.unserialise(_data)
- SetMonitorParameters(nil, nil, Monitors["monitorsScale"])
- SetCursorPos(CursorPosX, CursorPosY)
- end
- --Установка абсолютной точки
- function SetCursorPos(ax, ay)
- CursorPosX, CursorPosY = ax, ay
- local _m, _rx, _ry = GetRelativeCursorPos(CursorPosX, CursorPosY)
- CurrentMonitor = peripheral.wrap(_m)
- CurrentMonitor.setCursorPos(_rx, _ry)
- end
- --Вывод текста
- function WriteText(...)
- local str = ""
- for i = 1, #arg, 1 do
- str = str .. tostring(arg[i])
- end
- for s in str:gmatch(".") do
- if CursorPosY > Monitors["totalMonitorSizeY"] then
- break
- elseif s == '\n' then
- CursorPosX = 0
- CursorPosY = CursorPosY + 1
- SetCursorPos(CursorPosX, CursorPosY)
- elseif CursorPosX + 1 > Monitors["totalMonitorSizeX"] then
- CurrentMonitor.write(s)
- CursorPosX = 1
- CursorPosY = CursorPosY + 1
- SetCursorPos(CursorPosX, CursorPosY)
- else
- CurrentMonitor.write(s)
- CursorPosX = CursorPosX + 1
- SetCursorPos(CursorPosX, CursorPosY)
- end
- end
- end
- --Установка цветов\размера символов
- function SetMonitorParameters(backgroundcolor, textcolor, scale)
- BGColor = backgroundcolor or BGColor
- TextColor = textcolor or TextColor
- Scale = scale or Scale
- for j = 1, Monitors["monitorsCountInHeight"], 1 do
- for i = 1, Monitors["monitorsCountInWidth"], 1 do
- local _m = peripheral.wrap(Monitors[j][i]["id"])
- _m.setBackgroundColor(BGColor)
- _m.setTextColor(TextColor)
- _m.setTextScale(Scale)
- end
- end
- end
- --Очистка
- function ClearAll()
- for j = 1, Monitors["monitorsCountInHeight"], 1 do
- for i = 1, Monitors["monitorsCountInWidth"], 1 do
- local _m = peripheral.wrap(Monitors[j][i]["id"])
- _m.setBackgroundColor(BGColor)
- _m.setTextColor(TextColor)
- _m.clear()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement