Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --A foreword: This is a REALLY FUCKING UGLY program.
- --Terminal Glasses Box
- local modem = peripheral.wrap("right")
- local glass = peripheral.wrap("top")
- glass.clear()
- local FORMAT_CHAR = "\194\167"
- local FORMAT_BOLD = FORMAT_CHAR .. 'l'
- local keyboardActive = false
- local file = nil
- local file = fs.open("ieMap","r")
- local fullMap = file.readAll()
- fullMap = textutils.unserialize(fullMap)
- if fullMap == nil then
- fullMap = { }
- end
- file.close()
- --This is stupid
- file = fs.open("ieMap","w")
- local gColors = {
- red = 0xff3333,
- blue = 0x7dd2e4,
- yellow = 0xffff4d,
- green = 0x4dff4d,
- gray = 0xe0e0e0,
- textGray = 0x818181,
- text = 0x606060,
- rain = 0x2e679f
- }
- local depositTypes = {
- {
- name = "None",
- color = 0xffffff,
- { name = "None", id = "minecraft:stone", meta = 0, percent = 1.0 }
- },
- {
- name = "Bauxite",
- color = 0x999cc6,
- { name = "Aluminum", id = "ImmersiveEngineering:metal", meta = 1, percent = 1.0 }
- },
- {
- name = "Cassiterite",
- color = 0xb3b4b5,
- { name = "Tin", id = "RotaryCraft:rotarycraft_item_modingots", meta = 0, percent = 1.0 }
- },
- {
- name = "Coal",
- color = 0x303045,
- { name = "Coal", id = "minecraft:coal", meta = 0, percent = 0.9684 },
- { name = "Diamond", id = "minecraft:diamond", meta = 0, percent = 0.0158 },
- { name = "Emerald", id = "minecraft:emerald", meta = 0, percent = 0.0158 }
- },
- {
- name = "Copper",
- color = 0xb87333,
- { name = "Copper", id = "ImmersiveEngineering:metal", meta = 0, percent = 0.6842 },
- { name = "Gold", id = "minecraft:gold_ingot", meta = 0, percent = 0.2632 },
- { name = "Nickel", id ="ImmersiveEngineering:metal", meta = 4, percent = 0.0526 }
- },
- {
- name = "Galena",
- color = 0x7788bb,
- { name = "Lead", id ="ImmersiveEngineering:metal", meta = 2, percent = 0.5 },
- { name = "Silver", id ="ImmersiveEngineering:metal", meta = 3, percent = 0.5 }
- },
- {
- name = "Gold",
- color = 0xdec900,
- { name = "Gold", id = "minecraft:gold_ingot", meta = 0, percent = 0.6842 },
- { name = "Copper", id = "ImmersiveEngineering:metal", meta = 0, percent = 0.2632 },
- { name = "Nickel", id ="ImmersiveEngineering:metal", meta = 4, percent = 0.0526 }
- },
- {
- name = "Iron",
- color = 0x6c7b8b,
- { name = "Iron", id = "minecraft:iron_ingot", meta = 0, percent = 0.5263 },
- { name = "Nickel", id ="ImmersiveEngineering:metal", meta = 4, percent = 0.2632 },
- { name = "Tin", id = "RotaryCraft:rotarycraft_item_modingots", meta = 0, percent = 0.2105 }
- },
- {
- name = "Lapis",
- color = 0x26619c,
- { name = "Lapis", id = "minecraft:dye", meta = 4, percent = 0.7027 },
- { name = "Iron", id = "minecraft:iron_ingot", meta = 0, percent = 0.2973 }
- },
- {
- name = "Lead",
- color = 0x5e5c59,
- { name = "Lead", id ="ImmersiveEngineering:metal", meta = 2, percent = 0.5789 },
- { name = "Silver", id ="ImmersiveEngineering:metal", meta = 3, percent = 0.4211 }
- },
- {
- name = "Magnetite",
- color = 0xcdbe70,
- { name = "Iron", id = "minecraft:iron_ingot", meta = 0, percent = 0.85 },
- { name = "Gold", id = "minecraft:gold_ingot", meta = 0, percent = 0.15 }
- },
- {
- name = "Nickel",
- color = 0xb8b8b6,
- { name = "Nickel", id ="ImmersiveEngineering:metal", meta = 4, percent = 0.8947 },
- { name = "Platinum", id = "RotaryCraft:rotarycraft_item_modingots", meta = 44, percent = 0.0526 },
- { name = "Iron", id = "minecraft:iron_ingot", meta = 0, percent = 0.0527 }
- },
- {
- name = "Platinum",
- color = 0xafafae,
- { name = "Platinum", id = "RotaryCraft:rotarycraft_item_modingots", meta = 44, percent = 0.5625 },
- { name = "Nickel", id ="ImmersiveEngineering:metal", meta = 4, percent = 0.4375 }
- },
- {
- name = "Pyrite",
- color = 0xADA67E,
- { name = "Iron", id = "minecraft:iron_ingot", meta = 0, percent = 1.0 }
- },
- {
- name = "Quarzite",
- color = 0xaa98a9,
- { name = "Quartz", id = "minecraft:quartz", meta = 0, percent = 1.0 }
- },
- {
- name = "Silver",
- color = 0xc0c0c0,
- { name = "Silver", id ="ImmersiveEngineering:metal", meta = 3, percent = 0.5789 },
- { name = "Lead", id ="ImmersiveEngineering:metal", meta = 2, percent = 0.4211 }
- },
- {
- name = "Uranium",
- color = 0x5dca31,
- { name = "Uranium", id = "RotaryCraft:rotarycraft_item_modingots", meta = 10, percent = 0.6471 },
- { name = "Lead", id ="ImmersiveEngineering:metal", meta = 2, percent = 0.3529 }
- }
- }
- term.clear()
- term.setCursorPos(1,1)
- --Create the ore buttons
- local buttons = { }
- local depositColors = { }
- local btnlabels = { }
- local graphs = { }
- local graphBase = { }
- local nDeposits = #depositTypes
- local textHeight = 16
- local itr = 1
- local currentOre = 0
- local dbugtext = glass.addText(5,5,"",gColors.red)
- dbugtext.setScreenAnchor("middle","middle")
- local tDetails = glass.addText(3,30,"",gColors.yellow)
- local tIcons = {
- glass.addIcon(3,48,0,0),
- glass.addIcon(21,48,0,0),
- glass.addIcon(39,48,0,0)
- }
- local tDeposit = glass.addText(3,66,"",gColors.yellow)
- --Create the chunk grid
- local chunkGrid = { }
- local chunkContents = { }
- -- Size of each chunk in px
- local chunkSize = 15
- local chunkDisplayOffset = 15
- local cgridSize = 7 * (chunkSize + 1) + 1
- local pmax = chunkDisplayOffset + 8 * (1 + chunkSize)
- local pmin = chunkDisplayOffset + 1 + chunkSize
- for k,v in ipairs(depositTypes) do
- graphs[k] = { icons = { }, bars = { }, text = { } }
- local posY = textHeight * itr
- buttons[k] = glass.addBox(8, posY, 100, 15, gColors.text, 0.6)
- buttons[k].setZ(5)
- buttons[k].setUserdata(k)
- buttons[k].setScreenAnchor("left","top")
- buttons[k].setObjectAnchor("left","top")
- btnlabels[k] = glass.addText(16, posY + 4, v.name, v.color)
- btnlabels[k].setScreenAnchor("left","top")
- btnlabels[k].setZ(1)
- depositColors[k] = glass.addBox(109, posY, 15, 15, v.color, 0.9)
- depositColors[k].setZ(6)
- depositColors[k].setScreenAnchor("left","top")
- graphs[k].icons = { }
- for item = 1, #v do
- local posX = 75 + 18 * (item - 1)
- graphs[k].icons[item] = glass.addIcon(-24 * (4 - item) - 69, -68 ,v[item].id,v[item].meta)
- graphs[k].icons[item].setScreenAnchor("right","bottom")
- graphs[k].icons[item].setVisible(false)
- local barheight = math.floor(100 * v[item].percent) + 1
- graphs[k].bars[item] = glass.addBox(-24 * (4 - item) - 69, -70 - barheight, 16, barheight, gColors.green, 0.75)
- graphs[k].bars[item].setScreenAnchor("right","bottom")
- graphs[k].bars[item].setVisible(false)
- graphs[k].text[item] = glass.addText(-24 * (4 - item) - 60, -50, v[item].name, gColors.yellow)
- graphs[k].text[item].setRotation(45)
- graphs[k].text[item].setScreenAnchor("right","bottom")
- graphs[k].text[item].setVisible(false)
- end
- itr = itr + 1
- end
- graphBase.color = gColors.green
- for bar = 1, 8 do
- pos = chunkDisplayOffset + bar * (1 + chunkSize)
- hor = 2 * bar
- ver = hor - 1
- chunkGrid[ver] = glass.addBox(-pmax,pos,cgridSize,1,gColors.text,0.75)
- chunkGrid[ver].setScreenAnchor("right","top")
- chunkGrid[ver].setVisible(false)
- chunkGrid[hor] = glass.addBox(-pos,pmin,1,cgridSize,gColors.text,0.75)
- chunkGrid[hor].setScreenAnchor("right","top")
- chunkGrid[hor].setVisible(false)
- end
- local pl = { x = 0, y = 0, box = nil }
- pl.x = -pmin - 4 * (1 + chunkSize) + 1
- pl.y = chunkDisplayOffset + 4 * (1 + chunkSize) + 1
- pl.box = glass.addBox(pl.x,pl.y,1,1,0xff0000,1.0)
- pl.box.setScreenAnchor("right","top")
- for i = -3, 3 do
- chunkContents[i] = { }
- for j = -3, 3 do
- local xxx = -pmin - (4 + i) * (1 + chunkSize) + 1
- local yyy = chunkDisplayOffset + (4 + j) * (1 + chunkSize) + 1
- chunkContents[i][j] = glass.addBox(xxx,yyy,chunkSize,chunkSize,0x000000,0.9)
- chunkContents[i][j].setScreenAnchor("right","top")
- chunkContents[i][j].setVisible(false)
- end
- end
- local graphOffset = -pmax
- graphBase.xAxis = glass.addBox(graphOffset - 1, -70, 73, 1, graphBase.color, 0.75)
- graphBase.xAxis.setScreenAnchor("right","bottom")
- graphBase.xAxis.setVisible(false)
- graphBase.yAxis = glass.addBox(graphOffset - 2, -70 - 101, 1, 102, graphBase.color, 0.75)
- graphBase.yAxis.setScreenAnchor("right","bottom")
- graphBase.yAxis.setVisible(false)
- local increments = 10
- local incrementBy = 100 / increments
- graphBase.notches = { }
- graphBase.notchText = { }
- for i = 1, increments do
- local offset = i * incrementBy
- graphBase.notches[i] = glass.addBox(graphOffset - 1, -70 - offset - 1, 2, 1, graphBase.color, 0.75)
- graphBase.notches[i].setScreenAnchor("right","bottom")
- graphBase.notches[i].setVisible(false)
- end
- --Make sure that these match the Pocket's channels
- --Send must be Pocket's reply and vice versa
- local sendChannel = 1554
- local replyChannel = 1555
- modem.open(sendChannel)
- modem.open(replyChannel)
- local chunk = {x = nil, z = nil}
- local timeout = 5 -- Timeout in seconds
- local timer = os.startTimer(timeout)
- local function updateChunkMap()
- if chunk.x ~= nil and chunk.z ~= nil then
- for i = -3, 3 do
- for j = -3, 3 do
- index = { x = chunk.x - i, z = chunk.z + j }
- indstr = index.x..","..index.z
- code = fullMap[indstr]
- if code == nil then
- chunkContents[i][j].setOpacity(0)
- else
- chunkContents[i][j].setOpacity(0.75)
- chunkContents[i][j].setColor(depositTypes[code].color)
- end
- end
- end
- else
- for i = -3, 3 do
- for j = -3, 3 do
- chunkContents[i][j].setOpacity(0)
- end
- end
- end
- end
- local function updateGraphVisibility(visible)
- pl.box.setVisible(visible)
- for k,v in ipairs(depositTypes) do
- for item = 1, #v do
- graphs[k].icons[item].setVisible(visible and k == currentOre)
- graphs[k].bars[item].setVisible(visible and k == currentOre)
- graphs[k].text[item].setVisible(visible and k == currentOre)
- if currentOre == nil then currentOre = -1 end
- graphBase.xAxis.setVisible(visible and currentOre > 0)
- graphBase.yAxis.setVisible(visible and currentOre > 0)
- end
- end
- for i = 1, increments do
- graphBase.notches[i].setVisible(visible and currentOre > 0)
- end
- for k,v in ipairs(chunkGrid) do
- v.setVisible(visible)
- end
- for i = -3, 3 do
- for j = -3, 3 do
- chunkContents[i][j].setVisible(visible)
- end
- end
- updateChunkMap()
- glass.sync()
- end
- local function setKeyboardMode(visible)
- for k,v in ipairs(depositTypes) do
- buttons[k].setVisible(visible)
- depositColors[k].setVisible(visible)
- btnlabels[k].setVisible(visible)
- end
- tDetails.setVisible(not visible)
- for i = 1, 3 do
- tIcons[i].setVisible((not visible) and i <= #depositTypes[i])
- end
- tDeposit.setVisible(not visible)
- updateGraphVisibility(visible)
- end
- local function handleTimer()
- tDetails.setText(FORMAT_BOLD.."GPS not found")
- tDetails.setColor(gColors.red)
- timer = os.startTimer(timeout)
- glass.sync()
- end
- local function handleMessage(event)
- local pos = textutils.unserialize(event[5])
- if pos == nil or pos.x == nil or pos.y == nil or pos.z == nil then
- tDetails.setText("Out of range!")
- else
- pl.box.setX(pl.x + math.floor(pos.x) % 16 - 1)
- pl.box.setY(pl.y + math.floor(pos.z) % 16 - 1)
- chunk.x = math.floor(pos.x / 16)
- chunk.z = math.floor(pos.z / 16)
- tDetails.setText("Chunk: x="..chunk.x.." z="..chunk.z)
- tDetails.setColor(gColors.text)
- entry = fullMap[chunk.x..","..chunk.z]
- if entry == nil then
- tDeposit.setText("")
- tDeposit.setVisible(false)
- for i = 1, 3 do
- tIcons[i].setVisible(false)
- end
- else
- tDeposit.setText(depositTypes[entry].name)
- tDeposit.setVisible(true)
- for i = 1, 3 do
- if depositTypes[entry][i] == nil then
- tIcons[i].setVisible(false)
- else
- tIcons[i].setVisible(true)
- tIcons[i].setItemId(depositTypes[entry][i].id)
- tIcons[i].setMeta(depositTypes[entry][i].meta)
- end
- end
- end
- end
- glass.sync()
- end
- --Handles a player using the wireless keyboard
- local function handleOpenKeyboard(event)
- keyboardActive = true
- setKeyboardMode(true)
- end
- local function handleCloseKeyboard(event)
- setKeyboardMode(false)
- keyboardActive = false
- currentOre = 0
- end
- local function handleComponentClick(event)
- component = glass.getObjectById(event[5])
- currentOre = component.getUserdata()
- glass.sync()
- if chunk.x ~= nil and chunk.z ~= nil then
- index = chunk.x..","..chunk.z
- fullMap[index] = currentOre
- file.flush()
- end
- updateGraphVisibility(true)
- end
- setKeyboardMode(false)
- --Main loop
- while true do
- glass.sync()
- local event = {os.pullEvent()}
- if event[1] ~= "timer" then
- timer = os.startTimer(timeout)
- end
- if event[1] == "timer" and event[2] == timer then
- handleTimer()
- elseif event[1] == "glasses_capture" then
- handleOpenKeyboard(event)
- elseif event[1] == "glasses_release" then
- handleCloseKeyboard(event)
- elseif event[1] == "glasses_component_mouse_down" then
- handleComponentClick(event)
- elseif event[1] == "modem_message" and not keyboardActive then
- handleMessage(event)
- elseif event[1] == "key" then
- modem.transmit(sendChannel,replyChannel,"s")
- break
- end
- modem.transmit(sendChannel,replyChannel,"ack")
- end
- glass.clear()
- glass.sync()
- fullMap = textutils.serialize(fullMap)
- file.write(fullMap)
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement