-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcpu.lua
84 lines (74 loc) · 2.02 KB
/
cpu.lua
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
local component = require("component")
local me = component.me_interface
local mod = {}
local function getSimpleInfo(cpu)
return {
cpu = {},
busy = cpu.busy,
coprocessors = cpu.coprocessors,
storage = cpu.storage,
id = cpu.name
}
end
local function simpleItemInfo(item)
if item == nil then return nil end
return {
name = item.name,
label = item.label,
damage = item.damage,
size = item.size,
aspect = item.aspect
}
end
local function simpleItemsInfo(items)
if items == nil then return end
for i, item in pairs(items) do
items[i] = simpleItemInfo(item)
end
end
local function removeEmptyItem(items)
if items == nil then return nil end
local newOne = {}
for _, item in pairs(items) do
if item.size ~= nil and item.size ~= 0 or item.amount ~= nil and item.amount ~= 0 then
table.insert(newOne, simpleItemInfo(item))
end
end
return newOne
end
local function getDetailInfo(cpu)
local sub = cpu.cpu
local result = {
activeItems = removeEmptyItem(sub.activeItems()),
finalOutput = sub.finalOutput(),
active = sub.isActive(),
busy = sub.isBusy(),
pendingItems = removeEmptyItem(sub.pendingItems()),
storedItems = removeEmptyItem(sub.storedItems())
}
return result
end
function mod.getCpuList(detail)
local cpus = me.getCpus()
if cpus == nil then return {} end
local result = {}
for _, cpu in pairs(cpus) do
local simple = getSimpleInfo(cpu)
if detail then simple.cpu = getDetailInfo(cpu) end
table.insert(result, simple)
end
return result
end
function mod.getCpuDetail(cpuName)
local cpus = me.getCpus()
if cpus == nil then return nil end
for _, cpu in pairs(cpus) do
if cpu.name == cpuName then
local result = getSimpleInfo(cpu)
result.cpu = getDetailInfo(cpu)
return result
end
end
return nil
end
return mod