-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolourTextParser.lua
More file actions
136 lines (131 loc) · 3.8 KB
/
colourTextParser.lua
File metadata and controls
136 lines (131 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
os.pullEvent = os.pullEventRaw;
function newLine(peripheral)
local peripheralSizeX, peripheralSizeY = peripheral.getSize();
local peripheralCursorPosX, peripheralCursorPosY = peripheral.getCursorPos();
if peripheralCursorPosY == peripheralSizeY then
peripheral.scroll(1);
peripheral.setCursorPos(1, peripheralCursorPosY);
else
peripheral.setCursorPos(1, peripheralCursorPosY+1);
end
end
function parseColours(data, peripheral)
local i = 1;
local index = 1;
local tables = {};
while true do
local a, b = data:find("|[a-p]&", i);
if a == nil then
tables[index] = string.sub(data, i) .. "";
break;
end
tables[index] = string.sub(data, i, a-1) .. "";
tables[index+1] = string.sub(data, a, b) .. "";
index = index + 2;
i = b+1;
end
for key,value in pairs(tables) do
if value:find("|[a-p]&") then
if value == "|b&" then
peripheral.setTextColour(2);
elseif value == "|c&" then
peripheral.setTextColour(4);
elseif value == "|d&" then
peripheral.setTextColour(8);
elseif value == "|e&" then
peripheral.setTextColour(16);
elseif value == "|f&" then
peripheral.setTextColour(32);
elseif value == "|g&" then
peripheral.setTextColour(64);
elseif value == "|h&" then
peripheral.setTextColour(128);
elseif value == "|i&" then
peripheral.setTextColour(256);
elseif value == "|j&" then
peripheral.setTextColour(512);
elseif value == "|k&" then
peripheral.setTextColour(1024);
elseif value == "|l&" then
peripheral.setTextColour(2048);
elseif value == "|m&" then
peripheral.setTextColour(4096);
elseif value == "|n&" then
peripheral.setTextColour(8192);
elseif value == "|o&" then
peripheral.setTextColour(16384);
elseif value == "|p&" then
peripheral.setTextColour(32768);
else
peripheral.setTextColour(1);
end
else
peripheral.write(value);
end
end
end
function readConfig(monitorList)
local file = fs.open("colourTextParser.config", "r");
local fileNames = {};
for num, name in ipairs(monitorList) do
table.insert(fileNames, file.readLine());
end
file.close();
return fileNames;
end
function getMonitor()
local sides = { "right", "left", "top", "bottom", "front", "back" };
local peripheralType;
local monitorList = {};
for _,aux in pairs(sides) do
peripheralType = peripheral.getType(aux);
print((peripheralType or "nothing") .. " detected to the " .. aux);
if peripheralType == "monitor" then
if peripheral.call(aux, "isColour") then
table.insert(monitorList, peripheral.wrap(aux));
else
print("The monitor doesn't supports colours", 0);
os.sleep(1);
os.reboot();
end
end
end
if monitorNumbers == 0 then
error("No monitor detected.", 0);
end
return(monitorList)
end
os.sleep(1);
local monitorList = getMonitor();
local rulesFiles = readConfig(monitorList);
for num, monitor in ipairs(monitorList) do
local rules = fs.open(rulesFiles[num], "r");
local textSize = tonumber(rules.readLine());
if textSize == nil then
error("The first line in the file must be a number between 0.5 and 5, but was blank!");
elseif not ((textSize >= 0.5) and (textSize <= 5.0)) then
error("The first line in the file must be the text size, the number must be between 0.5 and 5.0 but is " .. textSize,0);
end
monitor.setTextScale(textSize);
local monitorSizeX, monitorSizeY = monitor.getSize();
monitor.clear();
monitor.setCursorPos(1, monitorSizeY);
while true do
local line = rules.readLine();
if line == nil then break end
parseColours(line, monitor);
newLine(monitor);
end
rules.close();
end
print("Nyuryoku zokko suru ni wa anata no pasuwado");
while true do
local input = read();
if input == "Eguzairu - Tek-sha" then
print("Konpyutasheru wa shokyo.");
error("Bye!", 0);
else
print("Anata wa machigatte himitsu no kotoba o nyuryoku shimashita.");
sleep(5);
end
end