diff --git a/DefaultLayout.lua b/DefaultLayout.lua index 50984df..30572df 100644 --- a/DefaultLayout.lua +++ b/DefaultLayout.lua @@ -11,6 +11,7 @@ local useCanvas = hooks.useCanvas local Button = require("components.Button") +local BasicButton = require("components.BasicButton") local SmolButton = require("components.SmolButton") local BigText = require("components.BigText") local bigFont = require("fonts.bigfont") @@ -29,7 +30,7 @@ local function render(canvas, display, props, theme, version) local elements = {} - + local selectedProduct, setSelectedProduct = Solyd.useState("") local categories = renderHelpers.getCategories(props.shopState.products) local selectedCategory = props.shopState.selectedCategory @@ -101,6 +102,9 @@ if footerMessage:find("%%version%%") then footerMessage = footerMessage:gsub("%%version%%", version) end + if selectedProduct and #selectedProduct > 0 and footerMessage:find("") then + footerMessage = footerMessage:gsub("", selectedProduct) + end if props.shopState.selectedCurrency then local footer @@ -241,8 +245,17 @@ kristpayHelperText = product.address .. "@" .. props.shopState.selectedCurrency.name end local productBgColor = theme.colors.productBgColors[((i-1) % #theme.colors.productBgColors) + 1] + local productClickFunction = function() + setSelectedProduct(product.address) + if props.configState.eventHooks and props.configState.eventHooks.onProductSelected then + eventHook.execute(props.configState.eventHooks.onProductSelected, product, currency) + end + if props.configState.config.settings.playSounds then + sound.playSound(props.peripherals.speaker, props.configState.config.sounds.button) + end + end if layout == "large" then - table.insert(elements, BigText { + table.insert(elements, Button { key="qty-"..catName..tostring(product.id), display=display, text=tostring(product.quantity), @@ -251,9 +264,10 @@ align="center", bg=productBgColor, color=qtyColor, - width=maxQtyWidth + width=maxQtyWidth, + onClick=productClickFunction }) - table.insert(elements, BigText { + table.insert(elements, Button { key="name-"..catName..tostring(product.id), display=display, text=product.name, @@ -262,9 +276,10 @@ align=theme.formatting.productNameAlign, bg=productBgColor, color=productNameColor, - width=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth-maxQtyWidth + width=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth-maxQtyWidth, + onClick=productClickFunction }) - table.insert(elements, BigText { + table.insert(elements, Button { key="price-"..catName..tostring(product.id), display=display, text=tostring(productPrice) .. currencySymbol, @@ -273,9 +288,10 @@ align="right", bg=productBgColor, color=theme.colors.priceColor, - width=maxPriceWidth + width=maxPriceWidth, + onClick=productClickFunction }) - table.insert(elements, BigText { + table.insert(elements, Button { key="addr-"..catName..tostring(product.id), display=display, text=productAddr, @@ -284,7 +300,8 @@ align="right", bg=productBgColor, color=theme.colors.addressColor, - width=maxAddrWidth+4 + width=maxAddrWidth+4, + onClick=productClickFunction }) table.insert(elements, BasicText { key="invis-" .. catName .. tostring(product.id), @@ -298,7 +315,7 @@ width=#(kristpayHelperText) }) elseif layout == "medium" then - table.insert(elements, SmolText { + table.insert(elements, SmolButton { key="qty-"..catName..tostring(product.id), display=display, text=tostring(product.quantity), @@ -307,9 +324,10 @@ align="center", bg=productBgColor, color=qtyColor, - width=maxQtyWidth + width=maxQtyWidth, + onClick=productClickFunction }) - table.insert(elements, SmolText { + table.insert(elements, SmolButton { key="name-"..catName..tostring(product.id), display=display, text=product.name, @@ -318,9 +336,10 @@ align=theme.formatting.productNameAlign, bg=productBgColor, color=productNameColor, - width=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth-maxQtyWidth + width=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth-maxQtyWidth, + onClick=productClickFunction }) - table.insert(elements, SmolText { + table.insert(elements, SmolButton { key="price-"..catName..tostring(product.id), display=display, text=tostring(productPrice) .. currencySymbol, @@ -329,9 +348,10 @@ align="right", bg=productBgColor, color=theme.colors.priceColor, - width=maxPriceWidth + width=maxPriceWidth, + onClick=productClickFunction }) - table.insert(elements, SmolText { + table.insert(elements, SmolButton { ey="addr-"..catName..tostring(product.id), display=display, text=productAddr, @@ -340,7 +360,8 @@ align="right", bg=productBgColor, color=theme.colors.addressColor, - width=maxAddrWidth+4 + width=maxAddrWidth+4, + onClick=productClickFunction }) table.insert(elements, BasicText { key="invis-" .. catName .. tostring(product.id), @@ -354,7 +375,7 @@ width=#(kristpayHelperText) }) else - table.insert(elements, BasicText { + table.insert(elements, BasicButton { key="qty-"..catName..tostring(product.id), display=display, text=tostring(product.quantity), @@ -363,9 +384,10 @@ align="center", bg=productBgColor, color=qtyColor, - width=maxQtyWidth + width=maxQtyWidth, + onClick=productClickFunction }) - table.insert(elements, BasicText { + table.insert(elements, BasicButton { key="name-"..catName..tostring(product.id), display=display, text=product.name, @@ -374,9 +396,10 @@ align=theme.formatting.productNameAlign, bg=productBgColor, color=productNameColor, - width=(display.bgCanvas.width/2)-1-maxAddrWidth-maxPriceWidth-maxQtyWidth + width=(display.bgCanvas.width/2)-1-maxAddrWidth-maxPriceWidth-maxQtyWidth, + onClick=productClickFunction }) - table.insert(elements, BasicText { + table.insert(elements, BasicButton { key="price-"..catName..tostring(product.id), display=display, text=tostring(productPrice) .. currencySymbol, @@ -385,9 +408,10 @@ align="right", bg=productBgColor, color=theme.colors.priceColor, - width=maxPriceWidth + width=maxPriceWidth, + onClick=productClickFunction }) - table.insert(elements, BasicText { + table.insert(elements, BasicButton { key="addr-"..catName..tostring(product.id), display=display, text=productAddr, @@ -396,7 +420,8 @@ align="right", bg=productBgColor, color=theme.colors.addressColor, - width=maxAddrWidth+2 + width=maxAddrWidth+2, + onClick=productClickFunction }) end end @@ -454,6 +479,7 @@ width = categoryWidth, onClick = function() props.shopState.selectedCategory = i + setSelectedProduct("") props.shopState.lastTouched = os.epoch("utc") if props.configState.config.settings.playSounds then sound.playSound(props.peripherals.speaker, props.configState.config.sounds.button) diff --git a/core/ShopRunner.lua b/core/ShopRunner.lua index e1a789f..deee4b2 100644 --- a/core/ShopRunner.lua +++ b/core/ShopRunner.lua @@ -13,7 +13,7 @@ end local function launchShop(shopState, mainFunction) - parallel.waitForAny(function() ShopState.runShop(shopState) end, mainFunction) + parallel.waitForAny(function() shopState:runShop() end, mainFunction) -- local shopCoroutine = coroutine.create(function() ShopState.runShop(shopState) end) -- local mainCoroutine = coroutine.create(mainFunction) diff --git a/core/ShopState.lua b/core/ShopState.lua index bab77ee..e9a77af 100644 --- a/core/ShopState.lua +++ b/core/ShopState.lua @@ -95,13 +95,13 @@ end end -local function handlePurchase(transaction, meta, sentMetaname, transactionCurrency, transactionCurrency, state) +function ShopState:handlePurchase(transaction, meta, sentMetaname, transactionCurrency) local purchasedProduct = nil - if state.eventHooks and state.eventHooks.preProduct then - purchasedProduct = eventHook.execute(state.eventHooks.preProduct, transaction, transactionCurrency, meta, sentMetaname, state.products) + if self.eventHooks and self.eventHooks.preProduct then + purchasedProduct = eventHook.execute(self.eventHooks.preProduct, transaction, transactionCurrency, meta, sentMetaname, self.products) end if purchasedProduct == nil then - for _, product in ipairs(state.products) do + for _, product in ipairs(self.products) do if product.address:lower() == sentMetaname:lower() or product.name:gsub(" ", ""):lower() == sentMetaname:lower() then purchasedProduct = product break @@ -111,6 +111,9 @@ if purchasedProduct then local productPrice = Pricing.getProductPrice(purchasedProduct, transactionCurrency) local amountPurchased = math.floor(transaction.value / productPrice) + if productPrice == 0 then + amountPurchased = math.max(transaction.value, 1) + end if purchasedProduct.maxQuantity then amountPurchased = math.min(amountPurchased, purchasedProduct.maxQuantity) end @@ -121,7 +124,7 @@ end if purchasedProduct.bundle and #purchasedProduct.bundle > 0 then for _, bundleProduct in ipairs(purchasedProduct.bundle) do - for _, product in ipairs(state.products) do + for _, product in ipairs(self.products) do if product.address:lower() == bundleProduct.product:lower() or product.name:lower() == bundleProduct.product:lower() or (product.productId and product.productId:lower() == bundleProduct.product:lower()) then local productFound = false for _, productPurchased in ipairs(productsPurchased) do @@ -141,7 +144,7 @@ end local available = amountPurchased for _, productPurchased in ipairs(productsPurchased) do - local productSources, productAvailable = ScanInventory.findProductItems(state.products, productPurchased.product, productPurchased.quantity * amountPurchased) + local productSources, productAvailable = ScanInventory.findProductItems(self.products, productPurchased.product, productPurchased.quantity * amountPurchased) available = math.min(available, math.floor(productAvailable / productPurchased.quantity)) productPurchased.sources = productSources if available == 0 then @@ -154,35 +157,35 @@ local allowPurchase = true local err local errMessage - if state.eventHooks and state.eventHooks.prePurchase then - allowPurchase, err, errMessage = eventHook.execute(state.eventHooks.prePurchase, purchasedProduct, available, refundAmount, transaction, transactionCurrency) + if self.eventHooks and self.eventHooks.prePurchase then + allowPurchase, err, errMessage = eventHook.execute(self.eventHooks.prePurchase, purchasedProduct, available, refundAmount, transaction, transactionCurrency) end if allowPurchase ~= false then print("Purchased " .. available .. " of " .. purchasedProduct.name .. " for " .. transaction.from .. " for " .. transaction.value .. " " .. transactionCurrency.id .. " (refund " .. refundAmount .. ")") for _, productPurchased in ipairs(productsPurchased) do for _, productSource in ipairs(productPurchased.sources) do - if state.config.peripherals.outputChest == "self" then + if self.config.peripherals.outputChest == "self" then if not turtle then error("Self output but not a turtle!") end - if not state.peripherals.modem.getNameLocal() then + if not self.peripherals.modem.getNameLocal() then error("Modem is not connected! Try right clicking it") end if turtle.getSelectedSlot() ~= 1 then turtle.select(1) end - peripheral.call(productSource.inventory, "pushItems", state.peripherals.modem.getNameLocal(), productSource.slot, productSource.amount, 1) - if state.config.settings.dropDirection == "forward" then + peripheral.call(productSource.inventory, "pushItems", self.peripherals.modem.getNameLocal(), productSource.slot, productSource.amount, 1) + if self.config.settings.dropDirection == "forward" then turtle.drop(productSource.amount) - elseif state.config.settings.dropDirection == "up" then + elseif self.config.settings.dropDirection == "up" then turtle.dropUp(productSource.amount) - elseif state.config.settings.dropDirection == "down" then + elseif self.config.settings.dropDirection == "down" then turtle.dropDown(productSource.amount) else - error("Invalid drop direction: " .. state.config.settings.dropDirection) + error("Invalid drop direction: " .. self.config.settings.dropDirection) end else - peripheral.call(productSource.inventory, "pushItems", state.config.peripherals.outputChest, productSource.slot, productSource.amount, 1) + peripheral.call(productSource.inventory, "pushItems", self.config.peripherals.outputChest, productSource.slot, productSource.amount, 1) --peripheral.call(state.config.peripherals.outputChest, "drop", 1, productSource.amount, state.config.settings.dropDirection) end end @@ -192,53 +195,53 @@ purchasedProduct.quantity = math.max(0, purchasedProduct.quantity - available) end if refundAmount > 0 then - refund(transactionCurrency, transaction.from, meta, refundAmount, state.config.lang.refundRemaining) + refund(transactionCurrency, transaction.from, meta, refundAmount, self.config.lang.refundRemaining) end - if state.config.settings.playSounds then - sound.playSound(state.peripherals.speaker, state.config.sounds.purchase) + if self.config.settings.playSounds then + sound.playSound(self.peripherals.speaker, self.config.sounds.purchase) end - if state.eventHooks and state.eventHooks.purchase then - eventHook.execute(state.eventHooks.purchase, purchasedProduct, available, refundAmount, transaction, transactionCurrency) + if self.eventHooks and self.eventHooks.purchase then + eventHook.execute(self.eventHooks.purchase, purchasedProduct, available, refundAmount, transaction, transactionCurrency) end else - refund(transactionCurrency, transaction.from, meta, transaction.value, errMessage or state.config.lang.refundDenied, err) - if state.eventHooks and state.eventHooks.failedPurchase then - eventHook.execute(state.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, errMessage or state.config.lang.refundDenied, err) + refund(transactionCurrency, transaction.from, meta, transaction.value, errMessage or self.config.lang.refundDenied, err) + if self.eventHooks and self.eventHooks.failedPurchase then + eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, errMessage or self.config.lang.refundDenied, err) end end else - refund(transactionCurrency, transaction.from, meta, transaction.value, state.config.lang.refundOutOfStock) - if state.eventHooks and state.eventHooks.failedPurchase then - eventHook.execute(state.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, state.config.lang.refundOutOfStock) + refund(transactionCurrency, transaction.from, meta, transaction.value, self.config.lang.refundOutOfStock) + if self.eventHooks and self.eventHooks.failedPurchase then + eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, self.config.lang.refundOutOfStock) end end else - refund(transactionCurrency, transaction.from, meta, transaction.value, state.config.lang.refundOutOfStock) - if state.eventHooks and state.eventHooks.failedPurchase then - eventHook.execute(state.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, state.config.lang.refundOutOfStock) + refund(transactionCurrency, transaction.from, meta, transaction.value, self.config.lang.refundOutOfStock) + if self.eventHooks and self.eventHooks.failedPurchase then + eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, self.config.lang.refundOutOfStock) end end else - refund(transactionCurrency, transaction.from, meta, transaction.value, state.config.lang.refundAtLeastOne, true) - if state.eventHooks and state.eventHooks.failedPurchase then - eventHook.execute(state.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, state.config.lang.refundAtLeastOne) + refund(transactionCurrency, transaction.from, meta, transaction.value, self.config.lang.refundAtLeastOne, true) + if self.eventHooks and self.eventHooks.failedPurchase then + eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, purchasedProduct, self.config.lang.refundAtLeastOne) end end else - if state.config.settings.refundInvalidMetaname then - refund(transactionCurrency, transaction.from, meta, transaction.value, state.config.lang.refundInvalidProduct, true) + if self.config.settings.refundInvalidMetaname then + refund(transactionCurrency, transaction.from, meta, transaction.value, self.config.lang.refundInvalidProduct, true) end - if state.eventHooks and state.eventHooks.failedPurchase then - eventHook.execute(state.eventHooks.failedPurchase, transaction, transactionCurrency, nil, state.config.lang.refundInvalidProduct) + if self.eventHooks and self.eventHooks.failedPurchase then + eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, nil, self.config.lang.refundInvalidProduct) end end end -local function setupKrypton(state) - state.selectedCurrency = state.config.currencies[1] - state.currencies = {} - state.kryptonListeners = {} - for _, currency in ipairs(state.config.currencies) do +function ShopState:setupKrypton() + self.selectedCurrency = self.config.currencies[1] + self.currencies = {} + self.kryptonListeners = {} + for _, currency in ipairs(self.config.currencies) do if currency.name == "" then currency.name = nil end @@ -259,7 +262,7 @@ end currency.host = currency.krypton:makev2address(pkey) currency.krypton.privateKey = pkey - table.insert(state.currencies, currency) + table.insert(self.currencies, currency) local kryptonWs = currency.krypton:connect() kryptonWs:subscribe("ownTransactions") kryptonWs:getSelf() @@ -276,27 +279,27 @@ error("Name " .. currency.name .. " is not owned by " .. currency.host .. "!") end end - table.insert(state.kryptonListeners, function() kryptonWs:listen() end) - state.kryptonReady = true + table.insert(self.kryptonListeners, function() kryptonWs:listen() end) + self.kryptonReady = true end end -- Anytime the shop state is resumed, animation should be finished instantly. (call animation finish hooks) ----@param state ShopState -local function runShop(state) +---@param self ShopState +function ShopState:runShop() -- Shop is starting -- Wait for config ready - while not state.config.ready do sleep(0.5) end - state.running = true - state.currencies = {} - state.kryptonListeners = {} - setupKrypton(state) + while not self.config.ready do sleep(0.5) end + self.running = true + self.currencies = {} + self.kryptonListeners = {} + self:setupKrypton() parallel.waitForAny(function() while true do local event, transactionEvent = os.pullEvent("transaction") if event == "transaction" then local transactionCurrency = nil - for _, currency in ipairs(state.currencies) do + for _, currency in ipairs(self.currencies) do if currency.krypton.id == transactionEvent.source then transactionCurrency = currency break @@ -316,22 +319,22 @@ sentMetaname = meta[1] end if sentMetaname then - local success, err = pcall(handlePurchase, transaction, meta, sentMetaname, transactionCurrency, transactionCurrency, state) + local success, err = pcall(ShopState.handlePurchase, self, transaction, meta, sentMetaname, transactionCurrency) if success then -- Success :D else - refund(transactionCurrency, transaction.from, meta, transaction.value, state.config.lang.refundError, true) - if state.eventHooks and state.eventHooks.failedPurchase then - eventHook.execute(state.eventHooks.failedPurchase, transaction, transactionCurrency, nil, state.config.lang.refundError) + refund(transactionCurrency, transaction.from, meta, transaction.value, self.config.lang.refundError, true) + if self.eventHooks and self.eventHooks.failedPurchase then + eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, nil, self.config.lang.refundError) end error(err) end else - if state.config.settings.refundInvalidMetaname then - refund(transactionCurrency, transaction.from, meta, transaction.value, state.config.lang.refundNoProduct, true) + if self.config.settings.refundInvalidMetaname then + refund(transactionCurrency, transaction.from, meta, transaction.value, self.config.lang.refundNoProduct, true) end - if state.eventHooks and state.eventHooks.failedPurchase then - eventHook.execute(state.eventHooks.failedPurchase, transaction, transactionCurrency, nil, state.config.lang.refundNoProduct) + if self.eventHooks and self.eventHooks.failedPurchase then + eventHook.execute(self.eventHooks.failedPurchase, transaction, transactionCurrency, nil, self.config.lang.refundNoProduct) end end end @@ -339,47 +342,47 @@ end end end, function() - while state.running do + while self.running do local onInventoryRefresh = nil - if state.eventHooks and state.eventHooks.onInventoryRefresh then - onInventoryRefresh = state.eventHooks.onInventoryRefresh + if self.eventHooks and self.eventHooks.onInventoryRefresh then + onInventoryRefresh = self.eventHooks.onInventoryRefresh end - ScanInventory.updateProductInventory(state.products, onInventoryRefresh) - if state.config.settings.hideUnavailableProducts then - state.productsChanged = true + ScanInventory.updateProductInventory(self.products, onInventoryRefresh) + if self.config.settings.hideUnavailableProducts then + self.productsChanged = true end - sleep(state.config.settings.pollFrequency) + sleep(self.config.settings.pollFrequency) end end, function() - while state.running do - if state.config.settings.categoryCycleFrequency > 0 and os.epoch("utc") > state.lastTouched + (state.config.settings.activityTimeout * 1000) then - state.selectedCategory = state.selectedCategory + 1 - if state.selectedCategory > state.numCategories then - state.selectedCategory = 1 + while self.running do + if self.config.settings.categoryCycleFrequency > 0 and os.epoch("utc") > self.lastTouched + (self.config.settings.activityTimeout * 1000) then + self.selectedCategory = self.selectedCategory + 1 + if self.selectedCategory > self.numCategories then + self.selectedCategory = 1 end - state.productsChanged = true + self.productsChanged = true end - sleep(math.min(1, state.config.settings.categoryCycleFrequency)) + sleep(math.min(1, self.config.settings.categoryCycleFrequency)) end end, function() local blinkState = false - while state.running do + while self.running do blinkState = not blinkState - if state.config.peripherals.blinker then - redstone.setOutput(state.config.peripherals.blinker, blinkState) + if self.config.peripherals.blinker then + redstone.setOutput(self.config.peripherals.blinker, blinkState) end - if state.eventHooks and state.eventHooks.blink then - eventHook.execute(state.eventHooks.blink, blinkState) + if self.eventHooks and self.eventHooks.blink then + eventHook.execute(self.eventHooks.blink, blinkState) end sleep(blinkFrequency) end end, function() - while state.running do + while self.running do sleep(shopSyncFrequency) - if state.config.shopSync and state.config.shopSync.enabled and state.peripherals.shopSyncModem then + if self.config.shopSync and self.config.shopSync.enabled and self.peripherals.shopSyncModem then local items = {} - for i = 1, #state.products do - local product = state.products[i] + for i = 1, #self.products do + local product = self.products[i] local prices = {} local nbt = nil local predicates = nil @@ -387,8 +390,8 @@ nbt = "" predicates = product.predicates end - for j = 1, #state.config.currencies do - local currency = state.config.currencies[j] + for j = 1, #self.config.currencies do + local currency = self.config.currencies[j] local currencyName = "KST" if currency.krypton and currency.krypton.currency and currency.krypton.currency.currency_symbol then currencyName = currency.krypton.currency.currency_symbol @@ -417,17 +420,17 @@ } }) end - state.peripherals.shopSyncModem.transmit(shopSyncChannel, os.getComputerID(), { + self.peripherals.shopSyncModem.transmit(shopSyncChannel, os.getComputerID(), { type = "ShopSync", info = { - name = state.config.shopSync.name, - description = state.config.shopSync.description, - owner = state.config.shopSync.owner, + name = self.config.shopSync.name, + description = self.config.shopSync.description, + owner = self.config.shopSync.owner, software = { name = "Radon", - version = state.version + version = self.version }, - location = state.config.shopSync.location, + location = self.config.shopSync.location, }, items = { @@ -436,38 +439,38 @@ end end end, function() - while state.running do - if state.changedCurrencies and state.oldConfig then - state.changedCurrencies = false - state.kryptonReady = false - for i = 1, #state.oldConfig.currencies do - local currency = state.oldConfig.currencies[i] + while self.running do + if self.changedCurrencies and self.oldConfig then + self.changedCurrencies = false + self.kryptonReady = false + for i = 1, #self.oldConfig.currencies do + local currency = self.oldConfig.currencies[i] if (currency.krypton and currency.krypton.ws) then currency.krypton.ws:disconnect() currency.krypton = nil end end - for i = 1, #state.currencies do - local currency = state.currencies[i] + for i = 1, #self.currencies do + local currency = self.currencies[i] if (currency.krypton and currency.krypton.ws) then currency.krypton.ws:disconnect() currency.krypton = nil end end - setupKrypton(state) - state.kryptonReady = true - state.oldConfig = nil + setupKrypton(self) + self.kryptonReady = true + self.oldConfig = nil end sleep(0.5) end end, function() - while state.running do - if state.kryptonReady then + while self.running do + if self.kryptonReady then parallel.waitForAny(function() - while state.kryptonReady do + while self.kryptonReady do sleep(0.5) end - end, unpack(state.kryptonListeners)) + end, unpack(self.kryptonListeners)) end sleep(0.5) end @@ -475,6 +478,5 @@ end return { - ShopState = ShopState, - runShop = runShop, + ShopState = ShopState } \ No newline at end of file diff --git a/eventHooks.lua b/eventHooks.lua index 56b6933..5408aa6 100644 --- a/eventHooks.lua +++ b/eventHooks.lua @@ -1,5 +1,5 @@ return { - start = nil, -- function(version, config, products) + start = nil, -- function(version, config, products, shopState) preProduct = nil, -- function(transaction, transactionCurrency, meta, productAddress, products) returns product -- If product is nil, product will be selected by the shop, -- If product is false, customer will be refunded for no product found. @@ -11,4 +11,5 @@ configSaved = nil, -- function(config) called when config is edited (replaced) productsSaved = nil, -- function(products) called when products object is edited (replaced) onInventoryRefresh = nil, -- function(products, items) called when inventory is refreshed, product quantity can be set through products table + onProductSelected = nil, -- function(product, currency) called when product is clicked on the shop screen } \ No newline at end of file diff --git a/radon.lua b/radon.lua index 54f679a..74fb195 100644 --- a/radon.lua +++ b/radon.lua @@ -1,4 +1,4 @@ -local version = "1.3.16" +local version = "1.3.17" local configHelpers = require "util.configHelpers" local schemas = require "core.schemas" local oldPullEvent = os.pullEvent @@ -432,7 +432,7 @@ -- Profiler:activate() print("Radon " .. version .. " started") if eventHooks and eventHooks.start then - eventHook.execute(eventHooks.start, version, config, products) + eventHook.execute(eventHooks.start, version, config, products, shopState) end while true do -- add t = t if we need animations