diff --git a/data/config.example.lua b/data/config.example.lua
index 6c10d2a..4abe712 100644
--- a/data/config.example.lua
+++ b/data/config.example.lua
@@ -6,6 +6,9 @@
storage = {
""
},
+ speaker = {
+ ""
+ },
self = "",
messages = {
noMetaname = "message=No metaname found! Refunding.",
diff --git a/data/pages/index.xml b/data/pages/index.xml
index 0a5ab43..95a0336 100644
--- a/data/pages/index.xml
+++ b/data/pages/index.xml
@@ -1,17 +1,17 @@
-
+
-
-
+
+
-
+
diff --git a/data/pages/widget.xml b/data/pages/widget.xml
index 91a3069..5badaf7 100644
--- a/data/pages/widget.xml
+++ b/data/pages/widget.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/src/backend.lua b/src/backend.lua
index 4922436..bff6da2 100644
--- a/src/backend.lua
+++ b/src/backend.lua
@@ -1,20 +1,16 @@
-settings.define("kristify.debug", {
- description = "If kristify should be debugging",
- default = false,
- type = "boolean"
-})
+local ctx = ({...})[1]
-local kristly = require("/src/libs/kristly")
-local utils = require("/src/utils")
-local logger = require("/src/logger"):new({ debugging = settings.get("kristify.debug") })
-local webhooks = require("/src/webhook")
-local speakerLib = require("/src/speaker")
+local kristly = ctx.kristly
+local utils = ctx.utils
+local logger = ctx.logger
+local webhooks = ctx.webhooks
+local speakerLib = ctx.speakerLib
logger:info("Starting Kristify! Thanks for choosing Kristify. <3")
logger:debug("Debugging mode is enabled!")
-local config = require("/data/config")
-local products = require("/data/products")
+local config = ctx.config
+local products = ctx.products
if config == nil or config.pkey == nil then
logger:error("Config not found! Check documentation for more info.")
@@ -51,7 +47,7 @@
logger:info("Configuration loaded. Indexing chests")
-local storage = require("/src/libs/inv")(config.storage)
+local storage = ctx.storage
storage.refreshStorage()
logger:info("Chests indexed.")
@@ -181,4 +177,4 @@
ws:start()
end
-parallel.waitForAny(startKristly, startListening)
+parallel.waitForAny(startKristly, startListening)
\ No newline at end of file
diff --git a/src/frontend.lua b/src/frontend.lua
index 163ab0f..1346bac 100644
--- a/src/frontend.lua
+++ b/src/frontend.lua
@@ -1,7 +1,7 @@
local ctx = ({...})[1]
local basalt = require("libs/basalt")
-local storage = require(fs.combine("libs", "inv"))(ctx.config.storage)
+local storage = ctx.storage
storage.refreshStorage()
local function searchObject(base, id)
diff --git a/src/init.lua b/src/init.lua
index f8a07b4..8f31478 100644
--- a/src/init.lua
+++ b/src/init.lua
@@ -11,7 +11,8 @@
ctx = { products = {}, theme = {}, config = {}, pages = {} }
ctx.path = {
page = sPage,
- src = sSrc
+ src = sSrc,
+ data = sData
}
-- [Pages]
@@ -56,21 +57,36 @@
local inferiorcol = col;
inferiorcol.gray = col.grey;
inferiorcol.lightGray = col.lightGrey
- local result = loadLuaFile(fs.combine(sPage, "theme.lua"), { colours = col, colors = inferiorcol })
+ local result = loadLuaFile(fs.combine(sPage,"theme.lua"), { colours = col, colors = inferiorcol })
if result then
ctx.theme = result
end
-- config
- result = loadLuaFile(fs.combine(sData, "config.lua"))
+ result = loadLuaFile(fs.combine(sData,"config.lua"))
if result then
ctx.config = result
end
-- products
- result = loadLuaFile(fs.combine(sData, "products.lua"))
+ result = loadLuaFile(fs.combine(sData,"products.lua"))
if result then
ctx.products = result
end
+ -- Set debug mode
+ settings.define("kristify.debug", {
+ description = "If kristify should be debugging",
+ default = false,
+ type = "boolean"
+ })
+
+ -- Load scripts
+ ctx.kristly = require(fs.combine("libs","kristly"))
+ ctx.utils = require("utils")
+ ctx.logger = require("logger"):new({ debugging = settings.get("kristify.debug") })
+ ctx.webhooks = require("webhook")
+ ctx.speakerLib = require("speaker")
+ ctx.storage = require(fs.combine("libs","inv"))(ctx.config.storage)
+
return ctx
end
@@ -85,10 +101,21 @@
end)
-- MAIN
-if noErrors then
- local frontend, err = loadfile(fs.combine(sSrc, "frontend.lua"), "t", _ENV)
- if not frontend then
+local function execFile(sPath)
+ local script, err = loadfile(sPath, "t", _ENV)
+ if not script then
printError(err)
end
- frontend(ctx)
+ script(ctx)
+end
+
+if noErrors then
+ parallel.waitForAny(
+ function()
+ execFile(fs.combine(sSrc, "backend.lua"))
+ end,
+ function()
+ execFile(fs.combine(sSrc, "frontend.lua"))
+ end
+ )
end
\ No newline at end of file
diff --git a/src/libs/inv.lua b/src/libs/inv.lua
index bd12ea9..df5c577 100644
--- a/src/libs/inv.lua
+++ b/src/libs/inv.lua
@@ -179,7 +179,7 @@
local deepCacheFunctions = {}
for _, inventory in pairs(inventories) do
emptySlotLUT[inventory] = {}
- for i = 1, peripheral.call(inventory, "size") do
+ for i = 1, (peripheral.call(inventory, "size") or 0) do
emptySlotLUT[inventory][i] = true
local slotnumber = #slotNumberLUT + 1
slotNumberLUT[slotnumber] = { inventory = inventory, slot = i }
@@ -188,7 +188,7 @@
end
inventoryLimit[inventory] = peripheral.call(inventory, "getItemLimit", 1) -- this should make transfers from/to this inventory parallel safe.
if not deep then
- for slot, item in pairs(peripheral.call(inventory, "list")) do
+ for slot, item in pairs(peripheral.call(inventory, "list") or {}) do
cacheItem(item, inventory, slot)
end
else