-
-
Save SirEndii/ce4971245b20fb031ca9b65ec4fcb4d0 to your computer and use it in GitHub Desktop.
AR Controller draw .nfp api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local arg = {...} | |
| color_map = {} | |
| table.insert(color_map, 0xf0f0f0) | |
| table.insert(color_map, 0xf2b233) | |
| table.insert(color_map, 0xe57fd8) | |
| table.insert(color_map, 0x99b2f2) | |
| table.insert(color_map, 0xdede6c) | |
| table.insert(color_map, 0x7fcc19) | |
| table.insert(color_map, 0xf2b2cc) | |
| table.insert(color_map, 0x4c4c4c) | |
| table.insert(color_map, 0x999999) | |
| table.insert(color_map, 0x4c99b2) | |
| table.insert(color_map, 0xb266e5) | |
| table.insert(color_map, 0x3366cc) | |
| table.insert(color_map, 0x7f664c) | |
| table.insert(color_map, 0x57a64e) | |
| table.insert(color_map, 0xcc4c4c) | |
| table.insert(color_map, 0x111111) | |
| controller = peripheral.find("arController") | |
| if controller == nil then | |
| error("Can't find AR Controller") | |
| end | |
| if #arg < 3 then | |
| error("Required arguments: filePath (string), x (int), y (int)") | |
| end | |
| filePath = arg[1] | |
| if not fs.exists(filePath) then | |
| error("File not found") | |
| end | |
| fileHeight = 0 | |
| fileWidth = 0 | |
| file = fs.open(filePath, "r") | |
| repeat | |
| line = file.readLine() | |
| fileHeight = fileHeight + 1 | |
| if line ~= nil and #line > fileWidth then | |
| fileWidth = #line | |
| end | |
| until line == nil | |
| file.close() | |
| x = arg[2] | |
| y = arg[3] | |
| if #arg < 5 then | |
| uw = 5 | |
| uh = 7 | |
| else | |
| uw = math.ceil(arg[4] / fileWidth) | |
| uh = math.ceil(arg[5] / fileHeight) | |
| end | |
| file = fs.open(filePath, "r") | |
| c = file.read() | |
| xd = 0 | |
| yd = 0 | |
| repeat | |
| local i = tonumber(c, 16) | |
| if i ~= nil and i < 16 and i >= 0 then | |
| local col = color_map[i+1] | |
| controller.fill(x + xd, y + yd, x + xd + uw, y + yd + uh, col) | |
| end | |
| c = file.read() | |
| if c == "\n" then | |
| yd = yd + uh | |
| xd = 0 | |
| c = file.read() | |
| else | |
| xd = xd + uw | |
| end | |
| until c == nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment