-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfts.lua
More file actions
285 lines (253 loc) · 10.2 KB
/
fts.lua
File metadata and controls
285 lines (253 loc) · 10.2 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
local Utils = require("utils")
-- globales
local currentLine = 1
local function printWithCursor(text)
term.setCursorPos(1, currentLine)
print(text)
currentLine = currentLine + 1
end
local function paginado(lista, elementosPorPagina, titulo)
elementosPorPagina = elementosPorPagina or 10
local fullList = lista
local currentList = fullList
local totalElementos = #currentList
local totalPaginas = math.ceil(totalElementos / elementosPorPagina)
local paginaActual = 1
while true do
term.clear() -- Limpia toda la pantalla
term.setCursorPos(1, 1)
if titulo then
print(titulo)
print("-------------------------------------")
end
print("Pagina " .. paginaActual .. " de " .. totalPaginas)
print("-------------------------------------")
local inicio = (paginaActual - 1) * elementosPorPagina + 1
local fin = math.min(inicio + elementosPorPagina - 1, totalElementos)
for i = inicio, fin do
print(i .. ". " .. currentList[i])
end
Utils:clearLineAt(currentLine + 1)
print("\n[N] Siguiente pagina | [P] Pagina anterior | [S] Seleccionar elemento | [B] Buscar | [C] Cancelar")
print("Ingrese una opcion:")
local input = read():lower()
term.clear() -- Limpia toda la pantalla
term.setCursorPos(1, 1)
if input == "n" and paginaActual < totalPaginas then
paginaActual = paginaActual + 1
elseif input == "p" and paginaActual > 1 then
paginaActual = paginaActual - 1
elseif input == "s" then
print("Ingresa el numero del elemento a seleccionar:")
local seleccion = tonumber(read())
if seleccion and currentList[seleccion] then
for index, value in ipairs(fullList) do
if value == currentList[seleccion] then
return index
end
end
else
Utils:clearLineAt(currentLine) -- Limpia mensaje de error
print("Seleccion invalida. Presiona ENTER para intentar de nuevo.")
read()
end
elseif input == "b" then
print("Ingresa el termino a buscar:")
local termino = read():lower()
if termino == "" then
currentList = fullList
else
currentList = {}
for _, item in ipairs(fullList) do
if string.find(item:lower(), termino, 1, true) then
table.insert(currentList, item)
end
end
if #currentList == 0 then
Utils:clearLineAt(currentLine) -- Limpiar el mensaje
print("No se encontraron resultados. Presiona ENTER para continuar.")
read()
currentList = fullList
end
end
totalElementos = #currentList
totalPaginas = math.ceil(totalElementos / elementosPorPagina)
paginaActual = 1
elseif input == "c" then
return nil
else
Utils:clearLineAt(currentLine) -- Limpia mensaje de error
print("Opcion no valida. Presiona ENTER para intentar de nuevo.")
read()
end
end
end
local function firstTimeSetup(utils)
term.clear()
term.setCursorPos(1, 1)
print("=====================================")
print(" Asistente de Configuracion Inicial")
print("=====================================")
print("Este asistente lo guiara a traves de la configuracion del sistema.")
print("Presione ENTER para continuar...")
read()
-- Detectar perifericos de la red
local peripherals = peripheral.getNames()
local chests = {}
local monitors = {}
for _, name in ipairs(peripherals) do
local tipo = peripheral.getType(name)
if tipo == "minecraft:chest" or tipo == "minecraft:barrel" or tipo == "storagedrawers:basicdrawers" then
table.insert(chests, name)
elseif tipo == "monitor" then
table.insert(monitors, name)
end
end
if #chests == 0 then
print("No se detectaron cofres conectados. Conecte al menos un cofre y reinicie el programa.")
return false
end
-- Seleccionar el cofre central
local centralChestName = nil
while not centralChestName do
local titulo = "=====================================\n Seleccion del Cofre Central\n=====================================\nSeleccione el cofre central (donde depositara los items para almacenar):\n"
local seleccion = paginado(chests, 10, titulo)
if seleccion then
centralChestName = chests[seleccion]
else
print("Seleccion cancelada. Presione ENTER para intentarlo de nuevo.")
read()
end
end
-- Seleccionar el monitor
local monitorName = nil
if #monitors > 0 then
local monitorSelected = false
while not monitorSelected do
local titulo = "=====================================\n Seleccion del Monitor\n=====================================\nMonitores detectados:\n"
local seleccion = paginado(monitors, 10, titulo)
if seleccion then
monitorName = monitors[seleccion]
monitorSelected = true
else
print("Desea omitir la configuracion del monitor? (s/n)")
local input = read()
if input:lower() == "s" then
monitorSelected = true
end
end
end
else
print("No se detectaron monitores conectados. Continuando sin configurar el monitor.")
print("Presione ENTER para continuar.")
read()
end
-- Configurar categorias
local categories = {}
local categoriesData = {}
while true do
term.clear()
term.setCursorPos(1, 1)
print("=====================================")
print(" Configuracion de Categoria")
print("=====================================")
print("Desea agregar una nueva categoria? (s/n)")
local addCategory = read()
if addCategory:lower() ~= "s" then
break
end
print("Ingrese el nombre de la categoria:")
local categoryName = read()
while categoryName == "" do
print("El nombre de la categoria no puede estar vacio. Presione ENTER para intentarlo de nuevo.")
read()
print("Ingrese el nombre de la categoria:")
categoryName = read()
end
local categoryChests = {}
while true do
local titulo = "=====================================\n Asignacion de Cofres a Categoria\n=====================================\nCofres disponibles para asignar a la categoria '" .. categoryName .. "':\n"
local disponibles = {}
for _, chestName in ipairs(chests) do
if not categories[categoryName] or not utils:contains(categories[categoryName], chestName) then
table.insert(disponibles, chestName)
end
end
if #disponibles == 0 then
print("No hay cofres disponibles para asignar.")
print("Presiona ENTER para continuar.")
read()
break
end
local seleccion = paginado(disponibles, 10, titulo)
if seleccion then
local chestName = disponibles[seleccion]
table.insert(categoryChests, chestName)
print("Cofre '" .. chestName .. "' asignado a la categoria. Presiona ENTER para continuar.")
read()
else
if #categoryChests == 0 then
print("Debe asignar al menos un cofre a la categoria. Presiona ENTER para continuar.")
read()
else
break
end
end
end
local items = {}
print("Ingrese los items para la categoria '" .. categoryName .. "' separados por comas:")
local itemsInput = read()
for item in string.gmatch(itemsInput, '([^,]+)') do
table.insert(items, item:match("^%s*(.-)%s*$"))
end
categories[categoryName] = categoryChests
table.insert(categoriesData, {name = categoryName, items = items})
end
-- Configurar categoria de items aleatorios
local randomChests = {}
while true do
local titulo = "=====================================\n Configuracion de 'randomItems'\n=====================================\nCofres disponibles para 'randomItems':\n"
local disponibles = {}
for _, chestName in ipairs(chests) do
if not utils:contains(randomChests, chestName) then
table.insert(disponibles, chestName)
end
end
if #disponibles == 0 then
print("No hay cofres disponibles para asignar a 'randomItems'.")
print("Presiona ENTER para continuar.")
read()
break
end
local seleccion = paginado(disponibles, 10, titulo)
if seleccion then
local chestName = disponibles[seleccion]
table.insert(randomChests, chestName)
print("Cofre '" .. chestName .. "' asignado a 'randomItems'. Presiona ENTER para continuar.")
read()
else
if #randomChests == 0 then
print("Debe asignar al menos un cofre a 'randomItems'. Presiona ENTER para continuar.")
read()
else
break
end
end
end
-- Configuracion final
local config = {
centralChest = centralChestName,
monitor = monitorName,
categories = categories
}
config.categories["randomItems"] = randomChests
-- Guardar configuracion y categorias
utils:saveData("config.txt", config)
utils:saveData("categories.txt", categoriesData)
print("\nConfiguracion completada exitosamente. Presione ENTER para continuar.")
read()
return true
end
return {
firstTimeSetup = firstTimeSetup
}