SHOW:
|
|
- or go back to the newest paste.
1 | -- This program is for OpenCCSensors 0.1.2 | |
2 | ||
3 | os.loadAPI("ocs/apis/sensor") | |
4 | local sides = rs.getSides(); | |
5 | ||
6 | local width = 0 | |
7 | local height = 0 | |
8 | local monitor = nil | |
9 | ||
10 | local function findPeripheralSide(type) | |
11 | for key, side in pairs(sides) do | |
12 | if peripheral.isPresent(side) and peripheral.getType(side) == type then | |
13 | return side; | |
14 | end | |
15 | end | |
16 | end | |
17 | ||
18 | local function findMonitor() | |
19 | local side = findPeripheralSide("monitor") | |
20 | if side then | |
21 | return peripheral.wrap(side) | |
22 | end | |
23 | end | |
24 | ||
25 | local function findSensor() | |
26 | local side = findPeripheralSide("sensor") | |
27 | if side then | |
28 | return sensor.wrap(side) | |
29 | end | |
30 | end | |
31 | ||
32 | local function getColorIndex(x, y) | |
33 | return ((x-1) + (y-1) * 128) + 1 | |
34 | end | |
35 | ||
36 | local function drawPixel(x, y, color) | |
37 | monitor.setCursorPos(x, y) | |
38 | monitor.setBackgroundColor(color) | |
39 | monitor.write(" ") | |
40 | end | |
41 | ||
42 | local function displayMapColors(colors) | |
43 | for x=1, width do | |
44 | for y=1, height do | |
45 | local index = getColorIndex(x, y) | |
46 | local color = colors[index] | |
47 | drawPixel(x, y, color) | |
48 | end | |
49 | end | |
50 | end | |
51 | ||
52 | local function findPossibleTargets(sen) | |
53 | local maps = {}; | |
54 | for key, data in pairs(sen.getTargets()) do | |
55 | local details = sen.getTargetDetails(key) | |
56 | for slot, slotd in pairs(details.Slots) do | |
57 | if slotd.Name == "item.map" then | |
58 | table.insert(maps, { target = key, slot = slot }) | |
59 | end | |
60 | end | |
61 | end | |
62 | return maps; | |
63 | end | |
64 | ||
65 | while true do | |
66 | ||
67 | monitor = findMonitor(); | |
68 | monitor.setTextScale(0.5) | |
69 | if monitor == nil then | |
70 | error("no monitor attached") | |
71 | end | |
72 | ||
73 | width, height = monitor.getSize() | |
74 | ||
75 | local inventory = findSensor() | |
76 | if inventory == nil then | |
77 | error("no sensor attached") | |
78 | end | |
79 | ||
80 | local possibleMaps = findPossibleTargets(inventory) | |
81 | local firstMap = table.remove(possibleMaps, 1) | |
82 | ||
83 | if firstMap ~= nil then | |
84 | ||
85 | local width, height = monitor.getSize() | |
86 | ||
87 | local mapData = inventory.sensorCardCall("getMapData", firstMap.target, firstMap.slot) | |
88 | ||
89 | - | displayMapColors(mapData.Colors) |
89 | + | displayMapColors(mapData.Colors, offsetX, offsetY) |
90 | ||
91 | monitor.setCursorPos(1, height) | |
92 | monitor.setBackgroundColor(colors.black) | |
93 | - | sleep(0.1) |
93 | + | monitor.setTextColor(colors.white) |
94 | monitor.write(mapData.MapName) | |
95 | ||
96 | end | |
97 | ||
98 | sleep(5) | |
99 | ||
100 | end |