Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local obsidianOS = {}
- -- Encryption function
- function obsidianOS.encrypt(data, key)
- local encrypted = {}
- for i = 1, #data do
- local char = string.byte(data, i)
- local kchar = string.byte(key, (i - 1) % #key + 1)
- table.insert(encrypted, string.char(bit.bxor(char, kchar)))
- end
- return table.concat(encrypted)
- end
- -- Decryption function
- function obsidianOS.decrypt(data, key)
- return obsidianOS.encrypt(data, key) -- Symmetric encryption
- end
- -- Compression function
- function obsidianOS.compress(data)
- return textutils.serializeJSON(textutils.unserialize(data))
- end
- -- Decompression function
- function obsidianOS.decompress(data)
- return textutils.serialize(textutils.unserializeJSON(data))
- end
- -- Write Tixel function
- function obsidianOS.writeTixel(x, y, color, monitor)
- monitor = monitor or term
- monitor.setCursorPos(x, y)
- monitor.setBackgroundColor(color)
- monitor.write(" ")
- monitor.setBackgroundColor(colors.black) -- Reset background color
- end
- -- Draw Box function
- function obsidianOS.drawBox(x1, y1, x2, y2, color, monitor)
- monitor = monitor or term
- local minX, maxX = math.min(x1, x2), math.max(x1, x2)
- local minY, maxY = math.min(y1, y2), math.max(y1, y2)
- for y = minY, maxY do
- for x = minX, maxX do
- obsidianOS.writeTixel(x, y, color, monitor)
- end
- end
- end
- -- Button creation function
- function obsidianOS.createButton(x, y, x2, y2, text, color, outlineColor, textColor, textBackgroundColor, callOnClick)
- local button = {
- x = x,
- y = y,
- x2 = x2,
- y2 = y2,
- text = text,
- color = color,
- outlineColor = outlineColor,
- textColor = textColor or colors.white,
- textBackgroundColor = textBackgroundColor or color,
- callOnClick = callOnClick
- }
- return button
- end
- -- Function to draw a button
- function obsidianOS.drawButton(button, monitor)
- monitor = monitor or term
- -- Draw outline
- for x = button.x, button.x2 do
- obsidianOS.writeTixel(x, button.y, button.outlineColor, monitor)
- obsidianOS.writeTixel(x, button.y2, button.outlineColor, monitor)
- end
- for y = button.y, button.y2 do
- obsidianOS.writeTixel(button.x, y, button.outlineColor, monitor)
- obsidianOS.writeTixel(button.x2, y, button.outlineColor, monitor)
- end
- -- Fill button area
- for y = button.y + 1, button.y2 - 1 do
- for x = button.x + 1, button.x2 - 1 do
- obsidianOS.writeTixel(x, y, button.color, monitor)
- end
- end
- -- Draw text centered
- local textX = button.x + math.floor((button.x2 - button.x - #button.text) / 2)
- local textY = button.y + math.floor((button.y2 - button.y) / 2)
- monitor.setBackgroundColor(button.textBackgroundColor)
- monitor.setTextColor(button.textColor)
- monitor.setCursorPos(textX, textY)
- monitor.write(button.text)
- end
- -- Function to handle button clicks
- function obsidianOS.handleButtonClick(buttons, x, y, monitor)
- monitor = monitor or term
- x, y = obsidianOS.getAbsoluteCoordinates(monitor, x, y)
- for _, button in ipairs(buttons) do
- if x >= button.x and x <= button.x2 and y >= button.y and y <= button.y2 then
- button.callOnClick()
- return true
- end
- end
- return false
- end
- -- Function to get absolute coordinates on the screen from monitor-relative coordinates
- function obsidianOS.getAbsoluteCoordinates(monitor, x, y)
- local monitorX, monitorY = monitor.getPosition()
- return x + monitorX - 1, y + monitorY - 1
- end
- return obsidianOS
Advertisement
Add Comment
Please, Sign In to add comment