├── Examples
├── colony_integrator_list.lua
└── colony_integrator_status.lua
├── LICENSE
├── Lua Projects.iml
├── README.md
└── src
├── ME Autocraft
└── meautocraft.lua
├── ME Cpus
├── mecpus.cfg
└── mecpus.lua
├── ME Drives
└── medrives.lua
├── Programs.txt
├── Storage Requester
└── storagerequester.lua
├── api
├── bars.lua
└── button.lua
├── installer.lua
└── statusMonitor.lua
/Examples/colony_integrator_list.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Made for the Advanced Peripherals documentation
3 | --- Created by Srendi - Created by Srendi - https://github.com/SirEndii
4 | --- DateTime: 25.04.2021 20:44
5 | --- Link: https://docs.srendi.de/peripherals/colony_integrator/
6 | ---
7 |
8 |
9 | colony = peripheral.find("colonyIntegrator")
10 | mon = peripheral.wrap("left")
11 |
12 | function centerText(text, line, txtback, txtcolor, pos)
13 | monX, monY = mon.getSize()
14 | mon.setBackgroundColor(txtback)
15 | mon.setTextColor(txtcolor)
16 | length = string.len(text)
17 | dif = math.floor(monX-length)
18 | x = math.floor(dif/2)
19 |
20 | if pos == "head" then
21 | mon.setCursorPos(x+1, line)
22 | mon.write(text)
23 | elseif pos == "left" then
24 | mon.setCursorPos(2, line)
25 | mon.write(text)
26 | elseif pos == "right" then
27 | mon.setCursorPos(monX-length, line)
28 | mon.write(text)
29 | end
30 | end
31 |
32 | function prepareMonitor()
33 | mon.clear()
34 | mon.setTextScale(0.5)
35 | centerText("Citizens", 1, colors.black, colors.white, "head")
36 | end
37 |
38 | function printCitizens()
39 | row = 3
40 | useLeft = true
41 | for k, v in ipairs(colony.getCitizens()) do
42 | if row > 40 then
43 | useLeft = false
44 | row = 3
45 | end
46 |
47 | gender = ""
48 | if v.gender == "male" then
49 | gender = "M"
50 | else
51 | gender = "F"
52 | end
53 |
54 | if useLeft then
55 | centerText(v.name.. " - ".. gender, row, colors.black, colors.white, "left")
56 | else
57 | centerText(v.name.. " - ".. gender, row, colors.black, colors.white, "right")
58 | end
59 | row = row+1
60 | end
61 | end
62 |
63 | prepareMonitor()
64 |
65 | while true do
66 | printCitizens()
67 | sleep(10)
68 | end
69 |
--------------------------------------------------------------------------------
/Examples/colony_integrator_status.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Made for the Advanced Peripherals documentation
3 | --- Created by Srendi - Created by Srendi - https://github.com/SirEndii
4 | --- DateTime: 25.04.2021 20:44
5 | --- Link: https://docs.srendi.de/peripherals/colony_integrator/
6 | ---
7 |
8 | local colony = peripheral.wrap("back")
9 |
10 | print("Building Sites: ".. colony.amountOfConstructionSites())
11 | print("Citizens: ".. colony.amountOfCitizens())
12 | local underAttack = "No"
13 | if colony.isUnderAttack() then
14 | underAttack = "Yes"
15 | end
16 | print("Is under attack? ".. underAttack)
17 | print("Overall happiness: ".. math.floor(colony.getHappiness()))
18 | print("Amount of graves: ".. colony.amountOfGraves())
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Srendi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Lua Projects.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Lua-Projects
2 |
3 | These are my personal lua based projects for computercraft and [advanced peripherals](https://github.com/SirEndii/AdvancedPeripherals).
4 |
5 | I mainly made them to show examples for advanced peripherals.
6 |
7 | If you want to use one of the scripts, you're free to go.
8 | You can find specific instructions for the scripts online at our documentation, as example the [me bridge](https://docs.intelligence-modding.de/1.16/peripherals/me_bridge/).
9 |
10 | You can install all scripts via the installer. The installer will install the script and the needed libraries
11 |
12 | As example the automatic autocraft script for the me bridge
13 |
14 | - First you want to install the installer:
15 |
16 | `wget https://raw.githubusercontent.com/SirEndii/Lua-Projects/master/src/installer.lua installer`
17 |
18 | - To see all currently available scripts, you can run `installer list`
19 |
20 | 
21 |
22 | - Now install the script you want. As example the ME Autocraft script `installer install meautocraft` This will install the script and the needed libraries.
23 |
24 | 
25 |
26 | The script is located at `NAME/SCRIPT.lua`. For the autocraft script this would be `meautocraft/meautocraft.lua`
27 |
28 | It also creates an `startup` script for you. So you should delete any `startup` script you may have on your computer before installing the script.
29 |
--------------------------------------------------------------------------------
/src/ME Autocraft/meautocraft.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Made for the Advanced Peripherals documentation - Can be used in production
3 | --- Created by Srendi - https://github.com/SirEndii
4 | --- DateTime: 18.12.2022 04:00
5 | --- Link: https://docs.intelligence-modding.de/1.18/peripherals/me_bridge/
6 | --- Modified by Samamstar
7 | --- DateTime: 23.5.2023 03:00 MDT
8 | ---
9 |
10 | label = "Automatic"
11 |
12 | me = peripheral.find("meBridge") --MeBridge
13 | mon = peripheral.find("monitor") --Monitor
14 |
15 | --List of the items which should be checked
16 | --Display Name - Technical Name - Minimum Amount
17 | meItems = {
18 | [1] = {"Oak Planks", "minecraft:oak_planks", "180"},
19 | [2] = {"Diorite", "minecraft:polished_diorite", "100"},
20 | [3] = {"Wind Generator", "mekanismgenerators:wind_generator", "20"},
21 | [4] = {"Glass", "minecraft:glass", "500"},
22 | [5] = {"Stick", "minecraft:stick", "100"}
23 | }
24 |
25 | function checkMe(checkName, name, low)
26 | --Get item info from system
27 | meItem = me.getItem({name = checkName})
28 | --Typically caused by typo in item name
29 | if not meItem then
30 | print("Failed to locate meItem " .. checkName)
31 | return
32 | end
33 | if not meItem.count then
34 | size = 0
35 | else
36 | size = tostring(meItem.count)
37 | end
38 | ItemName = meItem.name
39 | row = row + 1
40 | CenterT(name, row, colors.black, colors.lightGray, "left", false)
41 | --Number of items in the system lower than the minimum amount?
42 | if tonumber(size) < tonumber(low) then
43 | --Craft us some delicious items
44 | CenterT(size .. "/" .. low, row, colors.black, colors.red, "right", true)
45 | --If the items is already being crafted - don't start a new crafting job
46 | if not me.isItemCrafting({name = checkName}) then
47 | --Prepare the table for "craftItem"
48 | craftedItem = {name = checkName, count = low - size}
49 | me.craftItem(craftedItem)
50 | print("Crafting some delicious " .. checkName .. " " .. craftedItem.count .. " times")
51 | end
52 | else
53 | --Everything is fine. Print the amount in green
54 | CenterT(size .. "/" .. low, row, colors.black, colors.green, "right", true)
55 | end
56 | end
57 |
58 | function checkTable()
59 | row = 2
60 | --Loop through our me items and check if they need to be crafted
61 | for i = 1, #meItems do
62 | checkName = meItems[i][2]
63 | name = meItems[i][1]
64 | low = meItems[i][3]
65 | checkMe(checkName, name, low)
66 | end
67 | end
68 |
69 | function prepareMonitor()
70 | mon.clear()
71 | CenterT(label, 1, colors.black, colors.white, "head", false)
72 | end
73 |
74 | --A util method to print text centered on the monitor
75 | function CenterT(text, line, txtback, txtcolor, pos, clear)
76 | monX, monY = mon.getSize()
77 | mon.setTextColor(txtcolor)
78 | length = string.len(text)
79 | dif = math.floor(monX - length)
80 | x = math.floor(dif / 2)
81 |
82 | if pos == "head" then
83 | mon.setCursorPos(x + 1, line)
84 | mon.write(text)
85 | elseif pos == "left" then
86 | if clear then
87 | clearBox(2, 2 + length, line, line)
88 | end
89 | mon.setCursorPos(2, line)
90 | mon.write(text)
91 | elseif pos == "right" then
92 | if clear then
93 | clearBox(monX - length - 8, monX, line, line)
94 | end
95 | mon.setCursorPos(monX - length, line)
96 | mon.write(text)
97 | end
98 | end
99 |
100 | --Clear a specific area, prevents flickering
101 | function clearBox(xMin, xMax, yMin, yMax)
102 | mon.setBackgroundColor(colors.black)
103 | for xPos = xMin, xMax, 1 do
104 | for yPos = yMin, yMax do
105 | mon.setCursorPos(xPos, yPos)
106 | mon.write(" ")
107 | end
108 | end
109 | end
110 |
111 | prepareMonitor()
112 |
113 | while true do
114 | checkTable()
115 | --Update every 3 seconds
116 | sleep(1)
117 | end
118 |
--------------------------------------------------------------------------------
/src/ME Cpus/mecpus.cfg:
--------------------------------------------------------------------------------
1 | {
2 | monitor = "top"
3 | modem = "right"
4 | }
--------------------------------------------------------------------------------
/src/ME Cpus/mecpus.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Made for the Advanced Peripherals documentation - Can be used in production
3 | --- Created by Srendi - Created by Srendi - https://github.com/SirEndii
4 | --- DateTime: I literally have no clue
5 | --- Link: https://docs.intelligence-modding.de/1.18/peripherals/me_bridge/
6 | ---
7 |
8 | mon = peripheral.find("monitor")
9 | me = peripheral.find("meBridge")
10 | data = {
11 | cpus = 0,
12 | oldCpus = 0,
13 | crafting = 0,
14 | bytes = 0,
15 | bytesUsed = 0
16 | }
17 |
18 | local firstStart = true
19 |
20 | local label = "ME Crafting CPUs"
21 |
22 | local monX, monY
23 |
24 | os.loadAPI("mecpus/api/bars.lua")
25 |
26 | function prepareMon()
27 | mon.clear()
28 | monX, monY = mon.getSize()
29 | if monX < 38 or monY < 25 then
30 | error("Monitor is too small, we need a size of 39x and 26y minimum.")
31 | end
32 | mon.setBackgroundColor(colors.black)
33 | mon.setCursorPos((monX/2)-(#label/2),1)
34 | mon.setTextScale(1)
35 | mon.write(label)
36 | mon.setCursorPos(1,1)
37 | drawBox(2, monX - 1, 3, monY - 10, "CPU's", colors.gray, colors.lightGray)
38 | drawBox(2, monX - 1, monY - 8, monY - 1, "Stats", colors.gray, colors.lightGray)
39 | addBars()
40 | end
41 |
42 | function addBars()
43 | cpus = me.getCraftingCPUs()
44 | for i=1, #cpus do
45 | x = 3*i
46 | full = (cpus[i].storage/65536) + cpus[i].coProcessors
47 | bars.add(""..i,"ver", full, cpus[i].coProcessors, 1+x, 5, 2, monY - 16, colors.purple, colors.lightBlue)
48 | mon.setCursorPos(x+1, monY - 11)
49 | --mon.write(string.format(i))
50 | end
51 | bars.construct(mon)
52 | bars.screen()
53 | end
54 |
55 |
56 | function drawBox(xMin, xMax, yMin, yMax, title, bcolor, tcolor)
57 | mon.setBackgroundColor(bcolor)
58 | for xPos = xMin, xMax, 1 do
59 | mon.setCursorPos(xPos, yMin)
60 | mon.write(" ")
61 | end
62 | for yPos = yMin, yMax, 1 do
63 | mon.setCursorPos(xMin, yPos)
64 | mon.write(" ")
65 | mon.setCursorPos(xMax, yPos)
66 | mon.write(" ")
67 |
68 | end
69 | for xPos = xMin, xMax, 1 do
70 | mon.setCursorPos(xPos, yMax)
71 | mon.write(" ")
72 | end
73 | mon.setCursorPos(xMin+2, yMin)
74 | mon.setBackgroundColor(colors.black)
75 | mon.setTextColor(tcolor)
76 | mon.write(" ")
77 | mon.write(title)
78 | mon.write(" ")
79 | mon.setTextColor(colors.white)
80 | end
81 |
82 | function clear(xMin,xMax, yMin, yMax)
83 | mon.setBackgroundColor(colors.black)
84 | for xPos = xMin, xMax, 1 do
85 | for yPos = yMin, yMax, 1 do
86 | mon.setCursorPos(xPos, yPos)
87 | mon.write(" ")
88 | end
89 | end
90 | end
91 |
92 | function tablelength(T)
93 | local count = 0
94 | for _ in pairs(T) do count = count + 1 end
95 | return count
96 | end
97 |
98 | function getUsage()
99 | return (data.crafting * 100) / data.cpus
100 | end
101 |
102 | function comma_value(n) -- credit http://richard.warburton.it
103 | local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
104 | return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
105 | end
106 |
107 | function updateStats()
108 | clear(3,monX - 3,monY - 5,monY - 2)
109 | print("CPUs: ".. data.cpus)
110 | print("busy: ".. data.crafting)
111 | mon.setCursorPos(4,monY-6)
112 | mon.write("CPUs: ".. data.cpus)
113 | mon.setCursorPos(4,monY-5)
114 | mon.write("Busy: ".. data.crafting)
115 | mon.setCursorPos(4,monY-4)
116 | mon.write("Busy in percent: ".. math.floor(getUsage()) .."%")
117 | mon.setCursorPos(4,monY-3)
118 | if monX > 39 then
119 | mon.write("Bytes(Used|Total): ".. comma_value(data.bytesUsed) .." | ".. comma_value(data.bytes))
120 | else
121 | mon.write("Bytes(Used|Total):")
122 | mon.setCursorPos(4,monY-2)
123 | mon.write(comma_value(data.bytesUsed) .." | ".. comma_value(data.bytes))
124 | end
125 | if tablelength(bars.getBars()) ~= data.cpus then
126 | clear(3,monX - 3,4,monY - 12)
127 | shell.run("reboot")
128 | end
129 | oldCpus = cpus
130 | firstStart = false
131 | end
132 |
133 | prepareMon()
134 |
135 | while true do
136 | cpus = {}
137 | for k in pairs(me.getCraftingCPUs()) do
138 | table.insert(cpus, k)
139 | end
140 | data.cpus = 0
141 | data.crafting = 0
142 | data.bytes = 0
143 | data.bytesUsed = 0
144 | table.sort(cpus)
145 | for i = 1, #cpus do
146 | local k, v = cpus[i], me.getCraftingCPUs()[cpus[i]]
147 | data.cpus = data.cpus+1
148 | data.bytes = data.bytes + v.storage
149 | if v.isBusy then
150 | data.bytesUsed = data.bytesUsed + v.storage
151 | data.crafting = data.crafting+1
152 | end
153 | -- print(i, v.coProcessors, v.isBusy, v.storage/65536)
154 | end
155 | updateStats()
156 | sleep(2)
157 | end
158 |
--------------------------------------------------------------------------------
/src/ME Drives/medrives.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Made for the Advanced Peripherals documentation - Can be used in production
3 | --- Created by Srendi - https://github.com/SirEndii
4 | --- DateTime: 24.12.2023 (No)
5 | --- Link: tbd
6 | ---
7 |
8 | mon = peripheral.find("monitor")
9 | me = peripheral.find("meBridge")
10 |
11 | data = {
12 | drives = 0,
13 | totalBytes = 0,
14 | usedBytes = 0,
15 | totalCells = 0,
16 | }
17 |
18 | local label = "ME Drives"
19 |
20 | local monX, monY
21 |
22 | os.loadAPI("medrives/api/bars.lua")
23 |
24 | function prepare()
25 | mon.clear()
26 | monX, monY = mon.getSize()
27 | if monX < 38 or monY < 25 then
28 | error("Monitor is too small, we need a size of 39x and 26y minimum.")
29 | end
30 | mon.setPaletteColor(colors.red, 0xba2525)
31 | mon.setBackgroundColor(colors.black)
32 | mon.setCursorPos((monX/2)-(#label/2),1)
33 | mon.setTextScale(1)
34 | mon.write(label)
35 | mon.setCursorPos(1,1)
36 | drawBox(2, monX - 1, 3, monY - 10, "Drives", colors.gray, colors.lightGray)
37 | drawBox(2, monX - 1, monY - 8, monY - 1, "Stats", colors.gray, colors.lightGray)
38 | addBars()
39 | end
40 |
41 | function addBars()
42 | drives = me.listDrives()
43 | data.drives = #drives
44 | for i=1, #drives do
45 | x = 3*i
46 | full = drives[i].totalBytes
47 | print(full)
48 | print(drives[i].usedBytes)
49 | bars.add(""..i,"ver", full, drives[i].usedBytes, 1+x, 5, 1, monY - 16, colors.red, colors.green)
50 | mon.setCursorPos(x+1, monY - 11)
51 | --mon.write(string.format(i))
52 | data.totalBytes = data.totalBytes + drives[i].totalBytes
53 | data.usedBytes = data.usedBytes + drives[i].usedBytes
54 | data.totalCells = data.totalCells + #drives[i].cells
55 | end
56 | bars.construct(mon)
57 | bars.screen()
58 | end
59 |
60 |
61 | function drawBox(xMin, xMax, yMin, yMax, title, bcolor, tcolor)
62 | mon.setBackgroundColor(bcolor)
63 | for xPos = xMin, xMax, 1 do
64 | mon.setCursorPos(xPos, yMin)
65 | mon.write(" ")
66 | end
67 | for yPos = yMin, yMax, 1 do
68 | mon.setCursorPos(xMin, yPos)
69 | mon.write(" ")
70 | mon.setCursorPos(xMax, yPos)
71 | mon.write(" ")
72 |
73 | end
74 | for xPos = xMin, xMax, 1 do
75 | mon.setCursorPos(xPos, yMax)
76 | mon.write(" ")
77 | end
78 | mon.setCursorPos(xMin+2, yMin)
79 | mon.setBackgroundColor(colors.black)
80 | mon.setTextColor(tcolor)
81 | mon.write(" ")
82 | mon.write(title)
83 | mon.write(" ")
84 | mon.setTextColor(colors.white)
85 | end
86 |
87 | function clear(xMin,xMax, yMin, yMax)
88 | mon.setBackgroundColor(colors.black)
89 | for xPos = xMin, xMax, 1 do
90 | for yPos = yMin, yMax, 1 do
91 | mon.setCursorPos(xPos, yPos)
92 | mon.write(" ")
93 | end
94 | end
95 | end
96 |
97 | function getUsage()
98 | return (data.usedBytes * 100) / data.totalBytes
99 | end
100 |
101 | function comma_value(n) -- credit http://richard.warburton.it
102 | local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
103 | return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
104 | end
105 |
106 | function roundToDecimal(num, decimalPlaces)
107 | local mult = 10^(decimalPlaces or 0)
108 | return math.floor(num * mult + 0.5) / mult
109 | end
110 |
111 | function updateStats()
112 | newDrives = me.listDrives()
113 | data.totalBytes = 0;
114 | data.usedBytes = 0;
115 | data.totalCells = 0;
116 |
117 | if newDrives == nil then
118 | data.drives = 0
119 | print("The given table is nil, but why?")
120 | return
121 | end
122 |
123 | if newDrives == nil or #newDrives == 0 then
124 | clear(3,monX - 3,4,monY - 12)
125 | mon.setCursorPos(4, 5);
126 | mon.write("Zero drives are better than -1 drives I guess")
127 | else
128 | for i=1, #newDrives do
129 | data.totalBytes = data.totalBytes + newDrives[i].totalBytes
130 | data.usedBytes = data.usedBytes + newDrives[i].usedBytes
131 | data.totalCells = data.totalCells + #newDrives[i].cells
132 |
133 | bars.set(""..i,"cur", newDrives[i].usedBytes)
134 | bars.set(""..i,"max", newDrives[i].totalBytes)
135 | end
136 | end
137 | bars.screen()
138 |
139 | clear(3,monX - 3,monY - 5,monY - 2)
140 | print("Drives: ".. data.drives)
141 | mon.setCursorPos(4,monY-6)
142 | mon.write("Drives: ".. data.drives)
143 | mon.setCursorPos(4,monY-5)
144 | mon.write("Full: ".. roundToDecimal(getUsage(), 2) .."%")
145 | mon.setCursorPos(4,monY-4)
146 | mon.write("Cells: ".. data.totalCells)
147 | mon.setCursorPos(4,monY-3)
148 | mon.write("Bytes(Total|Used):")
149 | mon.setCursorPos(23,monY-3)
150 | mon.write(comma_value(data.totalBytes) .." | ".. comma_value(data.usedBytes))
151 |
152 | if data.drives ~= #newDrives then
153 | clear(3,monX - 3,4,monY - 12)
154 | mon.setCursorPos(4, 5);
155 | mon.write("Found new Drive... Rebooting")
156 | shell.run("reboot")
157 | end
158 | end
159 |
160 | prepare()
161 |
162 | while true do
163 | updateStats()
164 | sleep(0.5)
165 | end
166 |
--------------------------------------------------------------------------------
/src/Programs.txt:
--------------------------------------------------------------------------------
1 | {
2 | mecpus = {
3 | name = "ME CPU Control",
4 | desc = "Program to control the applied energistics crafting cpus.",
5 | path = "mecpus",
6 | version = "1.0.0",
7 | startup = "shell.run('mecpus/mecpus.lua')",
8 | files = {
9 | {link="https://raw.githubusercontent.com/Seniorendi/Lua-Projects/master/src/ME%20Cpus/mecpus.cfg", name = "cfg", type = "config"},
10 | {link="https://raw.githubusercontent.com/Seniorendi/Lua-Projects/master/src/ME%20Cpus/mecpus.lua", name = "mecpus.lua", type = "program"},
11 | {link="https://raw.githubusercontent.com/Seniorendi/Lua-Projects/master/src/api/bars.lua", name = "bars.lua", type = "api"},
12 | },
13 | needs = {
14 | monitor = true,
15 | modem = true,
16 | }
17 | },
18 | meautocraft = {
19 | name = "ME Autocrafting Autocraft",
20 | desc = "Autocrafts specific items. Alternative for crafting cards.",
21 | path = "meautocraft",
22 | version = "1.0.0",
23 | startup = "shell.run('meautocraft/meautocraft.lua')",
24 | files = {
25 | {link="https://raw.githubusercontent.com/Seniorendi/Lua-Projects/master/src/ME%20Autocraft/meautocraft.lua", name = "meautocraft.lua", type = "program"},
26 | },
27 | needs = {
28 | monitor = true,
29 | modem = true,
30 | }
31 | },
32 | medrives = {
33 | name = "ME Drives Panel",
34 | desc = "Control and inspect your drives",
35 | path = "medrives",
36 | version = "1.0.0",
37 | startup = "shell.run('medrives/medrives.lua')",
38 | files = {
39 | {link="https://raw.githubusercontent.com/Seniorendi/Lua-Projects/master/src/ME%20Drives/medrives.lua", name = "medrives.lua", type = "program"},
40 | {link="https://raw.githubusercontent.com/Seniorendi/Lua-Projects/master/src/api/bars.lua", name = "bars.lua", type = "api"},
41 |
42 | },
43 | needs = {
44 | monitor = true,
45 | modem = true,
46 | }
47 | },
48 | storagerequester = {
49 | name = "Storage Requester",
50 | desc = "Auto Autocrafter for the ME and RS Bridge for 1.21.1 and 0.8",
51 | path = "storagerequester",
52 | version = "1.0.0",
53 | startup = "shell.run('storagerequester/storagerequester.lua')",
54 | files = {
55 | {link="https://raw.githubusercontent.com/SirEndii/Lua-Projects/refs/heads/master/src/Storage%20Requester/storagerequester.lua", name = "storagerequester.lua", type = "program"},
56 |
57 | },
58 | needs = {
59 | monitor = true,
60 | modem = true,
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/Storage Requester/storagerequester.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Made for the Advanced Peripherals documentation - Can be used in production
3 | --- Created by Srendi - https://github.com/SirEndii
4 | --- Link: https://docs.advanced-peripherals.de/0.7-bridges/guides/storage_system_functions/
5 | ---
6 |
7 | label = "Requester"
8 |
9 | bridge = peripheral.find("me_bridge") or peripheral.find("rs_bridge") --Bridge
10 | mon = peripheral.find("monitor") --Monitor
11 |
12 | --List of the resources which should be checked
13 | --Display Name - Resource Name - Minimum Amount
14 | resources = {
15 | {name = "Mek Hydrogen", rn = "mekanism:hydrogen", min = 6000, type = "chemical"},
16 | {name = "Stick", rn = "minecraft:stick", min = 100, type = "item"},
17 | {name = "Stone", rn = "minecraft:stone", min = 64, type = "item"},
18 | {name = "Sign", rn = "minecraft:oak_sign", min = 64, type = "item"},
19 | {name = "Planks", rn = "minecraft:oak_planks", min = 128, type = "item"}
20 | }
21 |
22 | function checkMe(toCraft)
23 | --Get item info from system
24 | isCraftable = bridge.isCraftable({name = toCraft.rn, type = toCraft.type})
25 | --Typically caused by typo in item name
26 | if not isCraftable then
27 | print("Is not craftable " .. toCraft.rn)
28 | return
29 | end
30 |
31 | local resource = nil
32 |
33 | if toCraft.type == "item" then
34 | resource = bridge.getItem({name = toCraft.rn, type = toCraft.type})
35 | elseif toCraft.type == "fluid" then
36 | resource = bridge.getFluid({name = toCraft.rn, type = toCraft.type})
37 | elseif toCraft.type == "chemical" then
38 | resource = bridge.getChemical({name = toCraft.rn, type = toCraft.type})
39 | end
40 |
41 | if not resource then
42 | size = 0
43 | else
44 | size = resource.count
45 | end
46 | row = row + 1
47 | local currentlyCrafting = 0
48 | local isCrafting = bridge.isCrafting({name = toCraft.rn, type = toCraft.type})
49 |
50 | if isCrafting then
51 | for k, v in ipairs(bridge.getCraftingTasks()) do
52 | local crafting = v.resource
53 | if crafting.name == toCraft.rn then
54 | -- This means that the crafted amount couldn't be calculated
55 | if (v.crafted == -1) then
56 | currentlyCrafting = currentlyCrafting + v.quantity
57 | else
58 | currentlyCrafting = currentlyCrafting + (v.quantity - v.crafted)
59 | end
60 | end
61 | end
62 | end
63 |
64 | centerT(toCraft.name, row, 0, colors.lightGray, "left", false, 0)
65 | --Number of items in the system lower than the minimum amount?
66 | if size < toCraft.min then
67 | --Craft us some delicious items
68 | printResource(size, toCraft.min, row, currentlyCrafting)
69 | --If the items is already being crafted - don't start a new crafting job
70 | if not isCrafting then
71 | --Prepare the table for "craftItem"
72 | local filter = {name = toCraft.rn, count = toCraft.min - size}
73 | if toCraft.type == "item" then
74 | bridge.craftItem(filter)
75 | elseif toCraft.type == "fluid" then
76 | bridge.craftFluid(filter)
77 | elseif toCraft.type == "chemical" then
78 | bridge.craftChemical(filter)
79 | end
80 | print("Crafting some delicious " .. toCraft.rn .. " " .. filter.count .. " times")
81 | end
82 | else
83 | --Everything is fine. Print the amount in green
84 | printResource(size, toCraft.min, row, currentlyCrafting)
85 | end
86 | end
87 |
88 | function checkTable()
89 | --Loop through our bridge items and check if they need to be crafted
90 | row = 4
91 | for i = 1, #resources do
92 | checkMe(resources[i])
93 | end
94 | end
95 |
96 | function prepareMonitor()
97 | mon.clear()
98 | monX, monY = mon.getSize()
99 | centerT(label, 1, 0, colors.white, "head", false, 0)
100 |
101 | drawBox(2, monX - 1, 3, monY -1, "To Craft", colors.gray, colors.lightGray)
102 | end
103 |
104 | --A util method to print text centered on the monitor
105 | function centerT(text, line, xOffset, txtcolor, pos, clear, extraClearChars)
106 | monX, monY = mon.getSize()
107 | mon.setTextColor(txtcolor)
108 | length = string.len(text)
109 | dif = math.floor(monX - length)
110 | x = math.floor(dif / 2)
111 |
112 | if pos == "head" then
113 | mon.setCursorPos(x + 1, line)
114 | mon.write(text)
115 | elseif pos == "left" then
116 | if clear then
117 | clearBox(2, 4 + extraClearChars + length + xOffset, line, line)
118 | end
119 | mon.setCursorPos(4 + xOffset, line)
120 | mon.write(text)
121 | elseif pos == "right" then
122 | if clear then
123 | clearBox(monX - extraClearChars - length + xOffset, monX - 2, line, line)
124 | end
125 | mon.setCursorPos(monX - length - 2 + xOffset, line)
126 | mon.write(text)
127 | end
128 | end
129 |
130 | function printResource(size, min, row, currentlyCrafting)
131 | if size < min and currentlyCrafting <= 0 then
132 | centerT(tostring(size) .. "/" .. tostring(min), row, 0, colors.red, "right", true, 8)
133 | elseif size < min and currentlyCrafting > 0 then
134 | centerT(tostring(size) .. "/" .. tostring(min), row, -(string.len(tostring(currentlyCrafting))+2), colors.red, "right", true, 6)
135 | centerT(" +" .. tostring(currentlyCrafting), row, 0, colors.blue, "right", true, 0)
136 | elseif size >= min and currentlyCrafting <= 0 then
137 | centerT(tostring(size) .. "/" .. tostring(min), row, 0, colors.green, "right", true, 8)
138 | elseif size >= min and currentlyCrafting > 0 then
139 | centerT(tostring(size) .. "/" .. tostring(min), row, -(string.len(tostring(currentlyCrafting))+2), colors.green, "right", true, 6)
140 | centerT(" +" .. tostring(currentlyCrafting), row, 0, colors.blue, "right", true, 0)
141 | end
142 | end
143 |
144 | --Clear a specific area, prevents flickering
145 | function clearBox(xMin, xMax, yMin, yMax)
146 | mon.setBackgroundColor(colors.black)
147 | for xPos = xMin, xMax, 1 do
148 | for yPos = yMin, yMax do
149 | mon.setCursorPos(xPos, yPos)
150 | mon.write(" ")
151 | end
152 | end
153 | end
154 |
155 | function drawBox(xMin, xMax, yMin, yMax, title, bcolor, tcolor)
156 | mon.setBackgroundColor(bcolor)
157 | for xPos = xMin, xMax, 1 do
158 | mon.setCursorPos(xPos, yMin)
159 | mon.write(" ")
160 | end
161 | for yPos = yMin, yMax, 1 do
162 | mon.setCursorPos(xMin, yPos)
163 | mon.write(" ")
164 | mon.setCursorPos(xMax, yPos)
165 | mon.write(" ")
166 |
167 | end
168 | for xPos = xMin, xMax, 1 do
169 | mon.setCursorPos(xPos, yMax)
170 | mon.write(" ")
171 | end
172 | mon.setCursorPos(xMin+2, yMin)
173 | mon.setBackgroundColor(colors.black)
174 | mon.setTextColor(tcolor)
175 | mon.write(" ")
176 | mon.write(title)
177 | mon.write(" ")
178 | mon.setTextColor(colors.white)
179 | end
180 |
181 | prepareMonitor()
182 |
183 | while true do
184 | checkTable()
185 | sleep(1)
186 | end
187 |
--------------------------------------------------------------------------------
/src/api/bars.lua:
--------------------------------------------------------------------------------
1 | -- Bars API - (c) monster010
2 |
3 | -- This program is made by monster010 - pastebin: mWcHuiKX
4 | local monitor
5 | local bar = {}
6 |
7 | function construct(montor)
8 | monitor = montor
9 | end
10 |
11 | function getBars()
12 | return bar
13 | end
14 |
15 | function add(name, typ, maxval, curval, x, y, width, height, clfill, clempty)
16 | if not clfill then clfill = colors.green end
17 | if not clempty then clempty = colors.gray end
18 |
19 | bar[name] = {}
20 | bar[name]["typ"] = typ
21 | bar[name]["max"] = maxval
22 | bar[name]["cur"] = curval
23 | bar[name]["xmin"] = x
24 | bar[name]["ymin"] = y
25 | bar[name]["xmax"] = x + width - 1
26 | bar[name]["ymax"] = y + height - 1
27 | bar[name]["clfill"] = clfill
28 | bar[name]["clempty"] = clempty
29 | end
30 |
31 | function clear()
32 | bars = {}
33 | end
34 |
35 | function screen()
36 | for name, data in pairs(bar) do
37 | print("bar: " .. name)
38 | fill(data)
39 | end
40 | end
41 |
42 | function set(name, key, val)
43 | if not bar[name] then
44 | return
45 | end
46 | bar[name][key] = val
47 | end
48 |
49 | function drawLine(x, y, length, color)
50 | local oldBgColor = monitor.getBackgroundColor() -- Get the current background color
51 | monitor.setBackgroundColor(color) -- Set the background color to the color
52 | for i = x, (length + x) do -- Start a loop starting at x and ending when x gets to x + length
53 | monitor.setCursorPos(i, y) -- Set the cursor position to i, y
54 | monitor.write(" ") -- Write that color to the screen
55 | end
56 | monitor.setBackgroundColor(oldBgColor) -- Reset the background color
57 | end
58 |
59 | function fill(data)
60 | local minX = data["xmin"]
61 | local minY = data["ymin"]
62 | local maxX = data["xmax"]
63 | local maxY = data["ymax"]
64 | local current = (data["cur"] * 100) / data["max"]
65 | local mode = data["typ"]
66 | local emptyColor = data["clempty"]
67 | local fillColor = data["clfill"]
68 | print("current: " .. current)
69 | local totalLength = maxX - minX
70 | local fillLength = math.floor((totalLength * current) / 100)
71 |
72 | if mode == "hor" then
73 | -- Horizontal mode
74 | -- Draw the empty part
75 | drawLine(minX, minY, totalLength, emptyColor)
76 |
77 | -- Draw the filled part
78 | drawLine(minX, minY, fillLength, fillColor)
79 | elseif mode == "ver" then
80 | -- Vertical mode
81 | -- Calculate the total height and the filled height
82 | local totalHeight = maxY - minY
83 | local fillHeight = math.floor((totalHeight * current) / 100)
84 |
85 | -- Draw the empty part
86 | for y = minY, maxY do
87 | drawLine(minX, y, totalLength, emptyColor)
88 | end
89 |
90 | -- Draw the filled part
91 | if current > 0 then
92 | for y = minY, (fillHeight + minY) do
93 | drawLine(minX, y, totalLength, fillColor)
94 | end
95 | end
96 | end
97 | end
98 |
--------------------------------------------------------------------------------
/src/api/button.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | The MIT License (MIT)
3 |
4 | Copyright (c) 2013 Lyqyd
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | --]]
24 |
25 | -- Original pastebin: https://pastebin.com/uhw8NuF3
26 |
27 | local function setupLabel(buttonLen, minY, maxY, name)
28 | local labelTable = {}
29 | if type(name) == "table" then
30 | for i = 1, #name do
31 | labelTable[i] = name[i]
32 | end
33 | name = name.label
34 | elseif type(name) == "string" then
35 | local buttonText = string.sub(name, 1, buttonLen - 2)
36 | if #buttonText < #name then
37 | buttonText = " "..buttonText.." "
38 | else
39 | local labelLine = string.rep(" ", math.floor((buttonLen - #buttonText) / 2))..buttonText
40 | buttonText = labelLine..string.rep(" ", buttonLen - #labelLine)
41 | end
42 | for i = 1, maxY - minY + 1 do
43 | if maxY == minY or i == math.floor((maxY - minY) / 2) + 1 then
44 | labelTable[i] = buttonText
45 | else
46 | labelTable[i] = string.rep(" ", buttonLen)
47 | end
48 | end
49 | end
50 | return labelTable, name
51 | end
52 |
53 | local Button = {
54 | draw = function(self)
55 | local old = term.redirect(self.mon)
56 | term.setTextColor(colors.white)
57 | term.setBackgroundColor(colors.black)
58 | term.clear()
59 | for name, buttonData in pairs(self.buttonList) do
60 | if buttonData.active then
61 | term.setBackgroundColor(buttonData.activeColor)
62 | term.setTextColor(buttonData.activeText)
63 | else
64 | term.setBackgroundColor(buttonData.inactiveColor)
65 | term.setTextColor(buttonData.inactiveText)
66 | end
67 | for i = buttonData.yMin, buttonData.yMax do
68 | term.setCursorPos(buttonData.xMin, i)
69 | term.write(buttonData.label[i - buttonData.yMin + 1])
70 | end
71 | end
72 | if old then
73 | term.redirect(old)
74 | else
75 | term.restore()
76 | end
77 | end,
78 | add = function(self, name, func, xMin, yMin, xMax, yMax, inactiveColor, activeColor, inactiveText, activeText)
79 | local label, name = setupLabel(xMax - xMin + 1, yMin, yMax, name)
80 | if self.buttonList[name] then error("button already exists", 2) end
81 | local x, y = self.mon.getSize()
82 | if xMin < 1 or yMin < 1 or xMax > x or yMax > y then error("button out of bounds", 2) end
83 | self.buttonList[name] = {
84 | func = func,
85 | xMin = xMin,
86 | yMin = yMin,
87 | xMax = xMax,
88 | yMax = yMax,
89 | active = false,
90 | inactiveColor = inactiveColor or colors.red,
91 | activeColor = activeColor or colors.lime,
92 | inactiveText = inactiveText or colors.white,
93 | activeText = activeText or colors.white,
94 | label = label,
95 | }
96 | for i = xMin, xMax do
97 | for j = yMin, yMax do
98 | if self.clickMap[i][j] ~= nil then
99 | --undo changes
100 | for k = xMin, xMax do
101 | for l = yMin, yMax do
102 | if self.clickMap[k][l] == name then
103 | self.clickMap[k][l] = nil
104 | end
105 | end
106 | end
107 | self.buttonList[name] = nil
108 | error("overlapping button", 2)
109 | end
110 | self.clickMap[i][j] = name
111 | end
112 | end
113 | end,
114 | remove = function(self, name)
115 | if self.buttonList[name] then
116 | local button = self.buttonList[name]
117 | for i = button.xMin, button.xMax do
118 | for j = button.yMin, button.yMax do
119 | self.clickMap[i][j] = nil
120 | end
121 | end
122 | self.buttonList[name] = nil
123 | end
124 | end,
125 | run = function(self)
126 | while true do
127 | self:draw()
128 | local event = {self:handleEvents(os.pullEvent(self.side == "term" and "mouse_click" or "monitor_touch"))}
129 | if event[1] == "button_click" then
130 | self.buttonList[event[2]].func()
131 | end
132 | end
133 | end,
134 | handleEvents = function(self, ...)
135 | local event = {...}
136 | if #event == 0 then event = {os.pullEvent()} end
137 | if (self.side == "term" and event[1] == "mouse_click") or (self.side ~= "term" and event[1] == "monitor_touch" and event[2] == self.side) then
138 | local clicked = self.clickMap[event[3]][event[4]]
139 | if clicked and self.buttonList[clicked] then
140 | return "button_click", clicked
141 | end
142 | end
143 | return unpack(event)
144 | end,
145 | toggleButton = function(self, name, noDraw)
146 | self.buttonList[name].active = not self.buttonList[name].active
147 | if not noDraw then self:draw() end
148 | end,
149 | flash = function(self, name, duration)
150 | self:toggleButton(name)
151 | sleep(tonumber(duration) or 0.15)
152 | self:toggleButton(name)
153 | end,
154 | rename = function(self, name, newName)
155 | self.buttonList[name].label, newName = setupLabel(self.buttonList[name].xMax - self.buttonList[name].xMin + 1, self.buttonList[name].yMin, self.buttonList[name].yMax, newName)
156 | if not self.buttonList[name] then error("no such button", 2) end
157 | if name ~= newName then
158 | self.buttonList[newName] = self.buttonList[name]
159 | self.buttonList[name] = nil
160 | for i = self.buttonList[newName].xMin, self.buttonList[newName].xMax do
161 | for j = self.buttonList[newName].yMin, self.buttonList[newName].yMax do
162 | self.clickMap[i][j] = newName
163 | end
164 | end
165 | end
166 | self:draw()
167 | end,
168 | }
169 |
170 | function new(monSide)
171 | local buttonInstance = {
172 | side = monSide or "term",
173 | mon = monSide and peripheral.wrap(monSide) or term.current(),
174 | buttonList = {},
175 | clickMap = {},
176 | }
177 | local x, y = buttonInstance.mon.getSize()
178 | for i = 1, x do
179 | buttonInstance.clickMap[i] = {}
180 | end
181 | setmetatable(buttonInstance, {__index = Button})
182 | return buttonInstance
183 | end
--------------------------------------------------------------------------------
/src/installer.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Generated by EmmyLua(https://github.com/EmmyLua)
3 | --- Created by info.
4 | --- DateTime: 02.05.2021 14:48
5 | ---
6 |
7 | --- This script really needs some love - everything is quite primitive and not smart, there are also small bugs with the commands. Also some versioning would be neat
8 |
9 | local githuburl = "https://raw.githubusercontent.com/SirEndii/Lua-Projects/refs/heads/master/src/Programs.txt"
10 |
11 | programs = {}
12 |
13 | local args = { ... }
14 |
15 | function exit(message, isError)
16 | term.setTextColor(isError and colors.red or colors.yellow)
17 | print(message)
18 | term.setTextColor(colors.white)
19 | if isError then
20 | error()
21 | end
22 | end
23 |
24 | function loadSources()
25 | local dl, error = http.get(githuburl)
26 | if dl then
27 | text = dl.readAll()
28 | text:gsub("\n", "")
29 | text:gsub("\\", "")
30 | programs = textutils.unserialize(text)
31 | end
32 | end
33 |
34 | function install(program)
35 | if program == nil then
36 | exit("Please specify a program!", true)
37 | end
38 |
39 | if programs[program] == nil then
40 | exit("Program '" .. program .. "' does not exists!", true)
41 | end
42 |
43 | local startup = programs[program]["startup"]
44 |
45 | if fs.exists(program) then
46 | exit("Program is already installed. Either use the 'delete' or 'update' command", true)
47 | end
48 |
49 | if fs.exists("startup") then
50 | fs.delete("startup")
51 | end
52 |
53 | local sfile = fs.open("startup", "w")
54 | sfile.write(startup)
55 | sfile.close()
56 |
57 | libraries = {}
58 |
59 | programName = ""
60 | programPath = ""
61 | for k, v in ipairs(programs[program]["files"]) do
62 | if v.type == "program" then
63 | programPath = v.link
64 | programName = v.name
65 | elseif v.type == "api" then
66 | table.insert(libraries, v)
67 | end
68 | end
69 |
70 | for k, v in ipairs(libraries) do
71 | term.setTextColor(colors.yellow)
72 | print("Downloading library ".. v.name .."...")
73 | shell.run("wget ".. v.link .." ".. program .."/api/".. v.name)
74 | end
75 |
76 | term.setTextColor(colors.yellow)
77 | print("Downloading program ".. program .."...")
78 | shell.run("wget ".. programPath .." ".. program .."/".. programName)
79 | term.setTextColor(colors.lime)
80 | print("Successfully installed ".. program)
81 | end
82 |
83 | function update(program)
84 | delete(program)
85 |
86 | print("Now installing the latest version from github...")
87 | install(program)
88 | end
89 |
90 | function delete(program)
91 | if program == nil then
92 | exit("Please specify a program!", true)
93 | end
94 |
95 | term.setTextColor(colors.yellow)
96 | print("WARNING: This option is quite primitive. It will uninstall all libraries used by this script even if they are used by others")
97 |
98 | print("Deleting program and libraries for '" .. program .. "'...")
99 |
100 | if programs[program] == nil then
101 | exit("Program '" .. program .. "' does not exists!", true)
102 | end
103 |
104 | if fs.exists("startup") then
105 | fs.delete("startup")
106 | end
107 |
108 | libraries = {}
109 |
110 | programName = ""
111 | programPath = ""
112 | for k, v in ipairs(programs[program]["files"]) do
113 | if v.type == "program" then
114 | programPath = v.link
115 | programName = v.name
116 | elseif v.type == "api" then
117 | print(v)
118 | table.insert(libraries, v)
119 | end
120 | end
121 |
122 | for k, v in ipairs(libraries) do
123 | term.setTextColor(colors.yellow)
124 | print("Deleting library ".. v.name .."...")
125 | shell.run("rm ".. program .."/api/".. v.name)
126 | term.setTextColor(colors.lime)
127 | print("Deleted library ".. v.name)
128 | end
129 |
130 | term.setTextColor(colors.yellow)
131 | print("Deleting program ".. program .."...")
132 | shell.run("rm ".. program .."/".. programName)
133 | shell.run("rm ".. program .."/")
134 | term.setTextColor(colors.lime)
135 | print("Successfully uninstalled ".. program)
136 | end
137 |
138 | function showHelp()
139 | term.setTextColor(colors.lightGray)
140 | print("---- [Installer] ----")
141 | term.setTextColor(colors.white)
142 | print("installer help - Shows this menu")
143 | print("installer list - Lists all available programs")
144 | print("installer install - Installs a program")
145 | print("installer update - Updates a program")
146 | print("installer delete - Deletes a program")
147 | print("installer config - Configures a program after it is installed")
148 | term.setTextColor(colors.lightGray)
149 | print("---- [=========] ----")
150 | term.setTextColor(colors.white)
151 | end
152 |
153 | function showList()
154 | for name, table in pairs(programs) do
155 | term.setTextColor(colors.green)
156 | write(name)
157 | term.setTextColor(colors.lightGray)
158 | write(" -- ")
159 | term.setTextColor(colors.cyan)
160 | write(table.desc .. "\n")
161 | end
162 | end
163 |
164 | function executeInput()
165 | if #args <= 0 then
166 | showHelp()
167 | end
168 | if #args >= 1 and args[1] == "help" then
169 | showHelp()
170 | elseif #args >= 1 and args[1] == "list" then
171 | showList()
172 | elseif #args >= 1 and args[1] == "install" then
173 | install(args[2])
174 | elseif #args >= 1 and args[1] == "update" then
175 | update(args[2])
176 | elseif #args >= 1 and args[1] == "delete" then
177 | delete(args[2])
178 | elseif #args >= 1 and args[1] == "config" then
179 | exit("Not implemented", false)
180 | elseif #args >= 1 then
181 | exit("Could not find command '" .. args[1] .. "' or you are missing arguments", false)
182 | end
183 | end
184 |
185 | loadSources()
186 | executeInput()
187 |
--------------------------------------------------------------------------------
/src/statusMonitor.lua:
--------------------------------------------------------------------------------
1 | ---
2 | --- Generated by EmmyLua(https://github.com/EmmyLua)
3 | --- Created by Srendi.
4 | --- DateTime: 01.05.2021 23:47
5 | ---
6 |
7 | -- Some shit I worked on in the past
8 | -- Does not have any usage currently
9 |
10 | function wrapPs(peripheralName)
11 | periTab={}
12 | sideTab={}
13 | if peripheralName==nil then
14 | print("Could not find".. peripheralName)
15 | end
16 | local peripherals = peripheral.getNames()
17 | local i2 = 1
18 | for i =1, #peripherals do
19 | if peripheral.getType(peripherals[i])==peripheralName then
20 | periTab[i2]=peripheral.wrap(peripherals[i])
21 | sideTab[i2]=peripherals[i]
22 | i2=i2+1
23 | end
24 | end
25 | if periTab~={} then
26 | return periTab,sideTab
27 | else
28 | return nil
29 | end
30 | end
31 |
32 | computers = wrapPs("computer")
33 |
34 | computerList = {
35 | me = {name="mecpu", label="Me CPUs", computer=nil}
36 | }
37 |
38 | monitor = peripheral.wrap("top")
39 |
40 | local label = "Cliff OS"
41 | local monX, monY
42 |
43 | function prepareComputers()
44 | for k, v in pairs(computers) do
45 | for k1, v1 in pairs(computerList) do
46 | if v.getLabel() == v1.name then
47 | print(v1.label)
48 | v1.computer = v
49 | end
50 | end
51 | end
52 | end
53 |
54 | function prepareMonitor()
55 | monitor.clear()
56 | monX, monY = monitor.getSize()
57 | monitor.setTextColor(colors.white)
58 | monitor.setBackgroundColor(colors.black)
59 | monitor.setCursorPos((monX/2)-(#label/2),1)
60 | monitor.setTextScale(1)
61 | monitor.write(label)
62 | monitor.setCursorPos(1,1)
63 | end
64 |
65 | function clear(xMin,xMax, yMin, yMax)
66 | monitor.setBackgroundColor(colors.black)
67 | for xPos = xMin, xMax, 1 do
68 | for yPos = yMin, yMax, 1 do
69 | monitor.setCursorPos(xPos, yPos)
70 | monitor.write(" ")
71 | end
72 | end
73 | end
74 |
75 | prepareComputers()
76 | prepareMonitor()
77 |
78 | while true do
79 | sleep(0.5)
80 | table.sort(computerList)
81 | for k, v in pairs(computerList) do
82 | --local k, v = computerList[i], computerList[i]
83 | local y = 3*1
84 | print(k, v)
85 | clear(1, monX, 3, monY)
86 | monitor.setTextColor(colors.white)
87 | monitor.setCursorPos(3, y)
88 | monitor.write(v.label ..".. ")
89 | if computer == nil then
90 | monitor.setTextColor(colors.red)
91 | monitor.write("Could not found")
92 | else
93 | monitor.setTextColor(v.computer.isOn() and colors.green or colors.red)
94 | monitor.write(v.computer.isOn() and "Online" or "Offline")
95 | end
96 | end
97 | end
--------------------------------------------------------------------------------