Tekkit Telekom/Scripts: Difference between revisions
Appearance
Rezizdigus (talk | contribs) Created page with "This page contains various Lua scripts or functions used by the Tekkit Telekom == Utility ==" |
Rezizdigus (talk | contribs) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
== Utility == | == Utility == | ||
====== getCenterXPos ====== | |||
{{Code|function getCenterXPos(lenX, maxX) | |||
return math.ceil(maxX/2 - lenX/2) | |||
end|lang=lua|code=function getCenterXPos(lenX, maxX) | |||
return math.ceil(maxX/2 - lenX/2) | |||
end}} | |||
====== getCenterYPos ====== | |||
{{Code|function getCenterYPos(lenY, maxY) | |||
return math.ceil(maxY/2 - lenY/2) | |||
end|lang=lua}} | |||
====== drawCenterText ====== | |||
{{Code|1=function drawCenterText(text, posY, offX, maxX) | |||
local x, y = term.getSize() | |||
local length = string.len(text) | |||
term.setCursorPos(getCenterXPos(length, maxX) + offX, posY) | |||
term.write(text) | |||
term.setCursorPos(1, y) | |||
end|lang=lua}} | |||
====== drawCenterTextScreen ====== | |||
{{Code|1=function drawCenterTextScreen(text, posY) | |||
local x, y = term.getSize() | |||
return drawCenterText(text, posY, 0, x) | |||
end|lang=lua}} | |||
====== splitStringToLines ====== | |||
{{Code|1=-- | |||
-- THIS RETURNS AN ARRAY OF STRING | |||
-- does not truncate to "..." if maxY is 1 | |||
-- (sorry im too dumb to make it work without 1000 if statements) | |||
-- | |||
function splitStringToLines(string, maxX, maxY) | |||
local function tstring(str, maxLen) | |||
if string.len(str) <= maxLen then return str end | |||
local tStr = string.sub(str, 1, maxLen - 3) .. "..." | |||
return tStr | |||
end | |||
local function tstrings(stringsArr, lenX, lenY) | |||
local opStr = stringsArr[#stringsArr] | |||
if string.len(opStr) > lenX then | |||
local firstString = string.sub(opStr, 1, lenX) | |||
local secondString = string.sub(opStr, lenX + 1, string.len(opStr)) | |||
stringsArr[#stringsArr] = tstring(firstString, lenX) | |||
table.insert(stringsArr, secondString) | |||
if string.len(secondString) > lenX then | |||
if table.getn(stringsArr) + 1 > lenY then | |||
stringsArr[#stringsArr] = tstring(secondString, lenX) | |||
return stringsArr | |||
end | |||
return tstrings(stringsArr, lenX, lenY) | |||
else | |||
return stringsArr | |||
end | |||
else | |||
return stringsArr | |||
end | |||
end | |||
local strings = {} | |||
strings[1] = string | |||
return tstrings(strings, maxX, maxY) | |||
end|lang=lua}} | |||
====== drawBox ====== | |||
{{Code|1=function drawBox(content, startY) | |||
local maxX, maxY = term.getSize() | |||
local length = string.len(content) | |||
local strings = splitStringToLines(content, maxX - 5, maxY - startY - 5) | |||
local function renderBox(y, lenX, lenY) | |||
term.setBackgroundColor(colors.gray) | |||
for i = y + 1, lenY + y + 1, 1 do | |||
for j = (maxX/2 - lenX/2) + 1, lenX + (maxX/2 - lenX/2) + 1, 1 do | |||
term.setCursorPos(j, i) | |||
term.write(" ") | |||
end | |||
end | |||
term.setBackgroundColor(colors.lightGray) | |||
for i = y, lenY + y, 1 do | |||
for j = (maxX/2 - lenX/2), lenX + (maxX/2 - lenX/2), 1 do | |||
term.setCursorPos(j, i) | |||
term.write(" ") | |||
end | |||
end | |||
end | |||
local function renderContent(startPosY) | |||
local currPos = startPosY | |||
for _, str in pairs(strings) do | |||
drawCenterTextScreen(str, currPos) | |||
currPos = currPos + 1 | |||
end | |||
end | |||
local maxLenX = string.len(strings[1]) | |||
local maxLenY = table.getn(strings) | |||
if startY < 0 then | |||
local centerY = getCenterYPos(maxLenY, maxY) | |||
renderBox(centerY, maxLenX + 1, maxLenY + 1) | |||
renderContent(centerY + 1) | |||
else | |||
renderBox(startY, maxLenX + 1, maxLenY + 1) | |||
renderContent(startY + 1) | |||
end | |||
end|lang=lua}} | |||
====== drawBoxWithTitle ====== | |||
{{Code|1=function drawBoxWithTitle(title, content, startY) | |||
local maxX, maxY = term.getSize() | |||
local length = string.len(content) | |||
local strings = splitStringToLines(content, maxX - 5, maxY - startY - 5) | |||
local function renderBox(y, lenX, lenY) | |||
term.setBackgroundColor(colors.gray) | |||
for i = y + 1, lenY + y + 1, 1 do | |||
for j = (maxX/2 - lenX/2) + 1, lenX + (maxX/2 - lenX/2) + 1, 1 do | |||
term.setCursorPos(j, i) | |||
term.write(" ") | |||
end | |||
end | |||
term.setBackgroundColor(colors.lightGray) | |||
for i = y, lenY + y, 1 do | |||
for j = (maxX/2 - lenX/2), lenX + (maxX/2 - lenX/2), 1 do | |||
term.setCursorPos(j, i) | |||
term.write(" ") | |||
end | |||
end | |||
end | |||
local function renderContent(startPosY) | |||
local currPos = startPosY | |||
for _, str in pairs(strings) do | |||
drawCenterTextScreen(str, currPos) | |||
currPos = currPos + 1 | |||
end | |||
end | |||
local maxLenX = math.max(string.len(strings[1]), string.len(title)) | |||
local maxLenY = table.getn(strings) + 1 | |||
if startY < 0 then | |||
local centerY = getCenterYPos(maxLenY, maxY) | |||
renderBox(centerY, maxLenX + 1, maxLenY + 1) | |||
drawCenterTextScreen(title, centerY) | |||
renderContent(centerY + 1) | |||
else | |||
renderBox(startY, maxLenX + 1, maxLenY + 1) | |||
drawCenterTextScreen(title, startY) | |||
renderContent(startY + 1) | |||
end | |||
end|lang=lua}} | |||
====== drawBaseInterface ====== | |||
{{Code|function drawBaseInterface() | |||
term.setBackgroundColor(colors.blue) | |||
term.clear() | |||
drawCenterTextScreen("<interface title>", 1) | |||
end|lang=lua}} | |||
Latest revision as of 14:43, 23 May 2026
This page contains various Lua scripts or functions used by the Tekkit Telekom
Utility
getCenterXPos
function getCenterXPos(lenX, maxX)
return math.ceil(maxX/2 - lenX/2)
end
getCenterYPos
function getCenterYPos(lenY, maxY)
return math.ceil(maxY/2 - lenY/2)
end
drawCenterText
function drawCenterText(text, posY, offX, maxX)
local x, y = term.getSize()
local length = string.len(text)
term.setCursorPos(getCenterXPos(length, maxX) + offX, posY)
term.write(text)
term.setCursorPos(1, y)
end
drawCenterTextScreen
function drawCenterTextScreen(text, posY)
local x, y = term.getSize()
return drawCenterText(text, posY, 0, x)
end
splitStringToLines
--
-- THIS RETURNS AN ARRAY OF STRING
-- does not truncate to "..." if maxY is 1
-- (sorry im too dumb to make it work without 1000 if statements)
--
function splitStringToLines(string, maxX, maxY)
local function tstring(str, maxLen)
if string.len(str) <= maxLen then return str end
local tStr = string.sub(str, 1, maxLen - 3) .. "..."
return tStr
end
local function tstrings(stringsArr, lenX, lenY)
local opStr = stringsArr[#stringsArr]
if string.len(opStr) > lenX then
local firstString = string.sub(opStr, 1, lenX)
local secondString = string.sub(opStr, lenX + 1, string.len(opStr))
stringsArr[#stringsArr] = tstring(firstString, lenX)
table.insert(stringsArr, secondString)
if string.len(secondString) > lenX then
if table.getn(stringsArr) + 1 > lenY then
stringsArr[#stringsArr] = tstring(secondString, lenX)
return stringsArr
end
return tstrings(stringsArr, lenX, lenY)
else
return stringsArr
end
else
return stringsArr
end
end
local strings = {}
strings[1] = string
return tstrings(strings, maxX, maxY)
end
drawBox
function drawBox(content, startY)
local maxX, maxY = term.getSize()
local length = string.len(content)
local strings = splitStringToLines(content, maxX - 5, maxY - startY - 5)
local function renderBox(y, lenX, lenY)
term.setBackgroundColor(colors.gray)
for i = y + 1, lenY + y + 1, 1 do
for j = (maxX/2 - lenX/2) + 1, lenX + (maxX/2 - lenX/2) + 1, 1 do
term.setCursorPos(j, i)
term.write(" ")
end
end
term.setBackgroundColor(colors.lightGray)
for i = y, lenY + y, 1 do
for j = (maxX/2 - lenX/2), lenX + (maxX/2 - lenX/2), 1 do
term.setCursorPos(j, i)
term.write(" ")
end
end
end
local function renderContent(startPosY)
local currPos = startPosY
for _, str in pairs(strings) do
drawCenterTextScreen(str, currPos)
currPos = currPos + 1
end
end
local maxLenX = string.len(strings[1])
local maxLenY = table.getn(strings)
if startY < 0 then
local centerY = getCenterYPos(maxLenY, maxY)
renderBox(centerY, maxLenX + 1, maxLenY + 1)
renderContent(centerY + 1)
else
renderBox(startY, maxLenX + 1, maxLenY + 1)
renderContent(startY + 1)
end
end
drawBoxWithTitle
function drawBoxWithTitle(title, content, startY)
local maxX, maxY = term.getSize()
local length = string.len(content)
local strings = splitStringToLines(content, maxX - 5, maxY - startY - 5)
local function renderBox(y, lenX, lenY)
term.setBackgroundColor(colors.gray)
for i = y + 1, lenY + y + 1, 1 do
for j = (maxX/2 - lenX/2) + 1, lenX + (maxX/2 - lenX/2) + 1, 1 do
term.setCursorPos(j, i)
term.write(" ")
end
end
term.setBackgroundColor(colors.lightGray)
for i = y, lenY + y, 1 do
for j = (maxX/2 - lenX/2), lenX + (maxX/2 - lenX/2), 1 do
term.setCursorPos(j, i)
term.write(" ")
end
end
end
local function renderContent(startPosY)
local currPos = startPosY
for _, str in pairs(strings) do
drawCenterTextScreen(str, currPos)
currPos = currPos + 1
end
end
local maxLenX = math.max(string.len(strings[1]), string.len(title))
local maxLenY = table.getn(strings) + 1
if startY < 0 then
local centerY = getCenterYPos(maxLenY, maxY)
renderBox(centerY, maxLenX + 1, maxLenY + 1)
drawCenterTextScreen(title, centerY)
renderContent(centerY + 1)
else
renderBox(startY, maxLenX + 1, maxLenY + 1)
drawCenterTextScreen(title, startY)
renderContent(startY + 1)
end
end
drawBaseInterface
function drawBaseInterface()
term.setBackgroundColor(colors.blue)
term.clear()
drawCenterTextScreen("<interface title>", 1)
end