This repository was archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPLWD-CacheAnalyzer.lua
More file actions
140 lines (118 loc) · 4.12 KB
/
Copy pathAPLWD-CacheAnalyzer.lua
File metadata and controls
140 lines (118 loc) · 4.12 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
137
138
139
140
-- //AUTO-GENERATED-CODE//
local APLibPath = settings.get('APLibPath')
assert( -- check if setup was done before, if not return with an error
type(APLibPath) == 'string',
'Couldn\'t open APLib through path: '..tostring(
APLibPath
)..'; probably you haven\'t completed Lib setup via \'LIBFILE setup\' or the setup failed'
)
assert( -- check if Lib is still there, if not return with an error
fs.exists(APLibPath),
'Couldn\'t open APLib through path: '..tostring(
APLibPath
)..'; remember that if you move the Lib\'s folder you must set it up again via \'LIBFILE setup\''
)
os.loadAPI(APLibPath) -- load Lib with CraftOS's built-in feature
APLibPath = fs.getName(APLibPath)
if APLibPath:sub(#APLibPath - 3) == '.lua' then APLibPath = APLibPath:sub(1, #APLibPath - 4); end
local APLib = _ENV[APLibPath]
APLib.APLibPath = APLibPath
APLibPath = nil
-- //MAIN-PROGRAM//
APLib.bClear()
tArgs = { ... }
if tArgs[1] == '/help' then
print('Args: modemName, senderName [, receiveTimeout]')
return
end
APLib.APLWD.enable(true)
APLib.APLWD.connect(tArgs[1], tArgs[2])
tArgs[3] = tonumber(tArgs[3])
if not tArgs[3] then
tArgs[3] = 10
end
while true do
term.setTextColor(colors.red)
print('Press any key to Receive & Analyze')
print(' or press Backspace to exit.')
print()
local event = {os.pullEventRaw('key')}
if event[2] == 14 then
APLib.APLWD.close()
break
end
local received, state = APLib.APLWD.receiveCache(tArgs[3])
if not received then
if APLib.APLWD.enabled then
APLib.APLWD.close()
term.setTextColor(colors.red)
print("Didn't get any message in "..tostring(tArgs[3])..' Seconds')
else
term.setTextColor(colors.red)
print('The other user disconnected')
end
break
end
local bClears = {}
local Backgrounds = {}
local Texts = {}
local Points = {}
local Rectangles = {}
for key, value in pairs(APLib.APLWD.cache) do
if value.type == 'bClear' then
table.insert(bClears, value)
elseif value.type == 'background' then
table.insert(Backgrounds, value)
elseif value.type == 'text' then
table.insert(Texts, value)
elseif value.type == 'point' then
table.insert(Points, value)
elseif value.type == 'rectangle' then
table.insert(Rectangles, value)
end
end
term.setTextColor(colors.yellow)
print('Collected data:')
term.setTextColor(colors.green)
print(' b[C]lears received: '..tostring(#bClears))
print(' [B]ackgrounds received: '..tostring(#Backgrounds))
print(' [T]exts received: '..tostring(#Texts))
print(' [P]oints received: '..tostring(#Points))
print(' [R]ectangles received: '..tostring(#Rectangles))
term.setTextColor(colors.red)
print('\nPress ENTER to save data to APLWDCA.log')
print(' or press any other key to continue.\n')
event = {os.pullEventRaw('key')}
term.setTextColor(colors.green)
if event[2] == 46 then -- 'C'
print('bClears:\n'..textutils.serialize(bClears)..'\n')
elseif event[2] == 48 then -- 'B'
print('Backgrounds:\n'..textutils.serialize(Backgrounds)..'\n')
elseif event[2] == 20 then -- 'T'
print('Texts:\n'..textutils.serialize(Texts)..'\n')
elseif event[2] == 25 then -- 'P'
print('Points:\n'..textutils.serialize(Points)..'\n')
elseif event[2] == 19 then -- 'R'
print('Rectangles:\n'..textutils.serialize(Rectangles)..'\n')
elseif event[2] == 28 then -- ENTER
print('Saving data...')
local File = fs.open('APLWDCA.log', 'w')
File.write(textutils.serialize(
{
bClears = bClears,
Backgrounds = Backgrounds,
Texts = Texts,
Points = Points,
Rectangles = Rectangles
}
))
File.close()
term.setTextColor(colors.yellow)
print('Data saved!\n')
end
end
APLib.setBackground(colors.black)
APLib.bClear()
-- //AUTO-GENERATED-CODE//
os.unloadAPI(APLib.APLibPath)
-- //--//