diff --git a/config.lua b/config.lua index 25273f6..e335a83 100644 --- a/config.lua +++ b/config.lua @@ -1,113 +1,114 @@ -return { - branding = { - title = "Radon Shop" - }, - settings = { - hideUnavailableProducts = false, - pollFrequency = 30, - categoryCycleFrequency = -1, - activityTimeout = 60, - dropDirection = "forward" - }, - lang = { - footer = "/pay @%name% ", - refundRemaining = "Here is the funds remaining after your purchase!", - refundOutofStock = "Sorry, that item is out of stock!", - refundAtLeastOne = "You must purchase at least one of this product!", - refundInvalidProduct = "You must supply a valid product to purchase!", - refundNoProduct = "You must supply a product to purchase!", - refundError = "An error occurred while processing your purchase!" - }, - theme = { - formatting = { - headerAlign = "center", - footerAlign = "center", - productNameAlign = "center", - productTextSize = "auto" - }, - colors = { - bgColor = colors.lightGray, - headerBgColor = colors.red, - headerColor = colors.white, - footerBgColor = colors.red, - footerColor = colors.white, - productBgColor = colors.blue, - outOfStockQtyColor = colors.red, - lowQtyColor = colors.orange, - warningQtyColor = colors.yellow, - normalQtyColor = colors.white, - productNameColor = colors.white, - outOfStockNameColor = colors.lightGray, - priceColor = colors.lime, - addressColor = colors.white, - currencyTextColor = colors.white, - currency1Color = colors.green, - currency2Color = colors.pink, - currency3Color = colors.lightBlue, - currency4Color = colors.yellow, - catagoryTextColor = colors.white, - category1Color = colors.pink, - category2Color = colors.orange, - category3Color = colors.lime, - category4Color = colors.lightBlue, - activeCategoryColor = colors.black, - }, - palette = { - [colors.black] = 0x181818, - [colors.blue] = 0x182B52, - [colors.purple] = 0x7E2553, - [colors.green] = 0x008751, - [colors.brown] = 0xAB5136, - [colors.gray] = 0x565656, - [colors.lightGray] = 0x9D9D9D, - [colors.red] = 0xFF004C, - [colors.orange] = 0xFFA300, - [colors.yellow] = 0xFFEC23, - [colors.lime] = 0x00A23C, - [colors.cyan] = 0x29ADFF, - [colors.magenta] = 0x82769C, - [colors.pink] = 0xFF77A9, - [colors.lightBlue] = 0x3D7EDB, - [colors.white] = 0xECECEC - } - }, - currencies = { - { - id = "krist", -- if not krist or tenebra, must supply endpoint - -- node = "https://krist.dev" - host = "ksbangelco", - name = "radon.kst", - pkey = "", - pkeyFormat = "raw", -- Either 'raw' or 'kristwallet', defaults to 'raw' - -- NOTE: It is not recommended to use kwallet, the best practice is to convert your pkey (using - -- kwallet format) to raw pkey yourself first, and then use that here. Thus improving security. - value = 1.0 -- Default scaling on item prices, can be overridden on a per-item basis - }, - { - id = "tenebra", -- if not krist or tenebra, must supply endpoint - -- node = "https://krist.dev" - host = "tttttttttt", - name = "radon.tst", - pkey = "", - pkeyFormat = "raw", -- Either 'raw' or 'kristwallet', defaults to 'raw' - -- NOTE: It is not recommended to use kwallet, the best practice is to convert your pkey (using - -- kwallet format) to raw pkey yourself first, and then use that here. Thus improving security. - value = 0.1 -- Default scaling on item prices, can be overridden on a per-item basis - }, - }, - peripherals = { - monitor = nil, - self = "west", -- Cardinal direction or network name of the turtle - -- relative to storage chest(s) used - -- only required if output chest is "self" - -- or a relative position - -- ex: "west", "turtle_1" - selfRelativeOutput = nil, -- Same as above but for output chest - exchangeChest = nil, - outputChest = "self", -- Chest peripheral or self - }, - exchange = { - enabled = true, - node = "https://localhost:8000/" - } -} \ No newline at end of file +return { + branding = { + title = "Radon Shop" + }, + settings = { + hideUnavailableProducts = false, + pollFrequency = 30, + categoryCycleFrequency = -1, + activityTimeout = 60, + dropDirection = "forward", + smallTextKristPayCompatability = true, + }, + lang = { + footer = "/pay @%name% ", + refundRemaining = "Here is the funds remaining after your purchase!", + refundOutofStock = "Sorry, that item is out of stock!", + refundAtLeastOne = "You must purchase at least one of this product!", + refundInvalidProduct = "You must supply a valid product to purchase!", + refundNoProduct = "You must supply a product to purchase!", + refundError = "An error occurred while processing your purchase!" + }, + theme = { + formatting = { + headerAlign = "center", + footerAlign = "center", + productNameAlign = "center", + productTextSize = "auto" + }, + colors = { + bgColor = colors.lightGray, + headerBgColor = colors.red, + headerColor = colors.white, + footerBgColor = colors.red, + footerColor = colors.white, + productBgColor = colors.blue, + outOfStockQtyColor = colors.red, + lowQtyColor = colors.orange, + warningQtyColor = colors.yellow, + normalQtyColor = colors.white, + productNameColor = colors.white, + outOfStockNameColor = colors.lightGray, + priceColor = colors.lime, + addressColor = colors.white, + currencyTextColor = colors.white, + currency1Color = colors.green, + currency2Color = colors.pink, + currency3Color = colors.lightBlue, + currency4Color = colors.yellow, + catagoryTextColor = colors.white, + category1Color = colors.pink, + category2Color = colors.orange, + category3Color = colors.lime, + category4Color = colors.lightBlue, + activeCategoryColor = colors.black, + }, + palette = { + [colors.black] = 0x181818, + [colors.blue] = 0x182B52, + [colors.purple] = 0x7E2553, + [colors.green] = 0x008751, + [colors.brown] = 0xAB5136, + [colors.gray] = 0x565656, + [colors.lightGray] = 0x9D9D9D, + [colors.red] = 0xFF004C, + [colors.orange] = 0xFFA300, + [colors.yellow] = 0xFFEC23, + [colors.lime] = 0x00A23C, + [colors.cyan] = 0x29ADFF, + [colors.magenta] = 0x82769C, + [colors.pink] = 0xFF77A9, + [colors.lightBlue] = 0x3D7EDB, + [colors.white] = 0xECECEC + } + }, + currencies = { + { + id = "krist", -- if not krist or tenebra, must supply endpoint + -- node = "https://krist.dev" + host = "ksbangelco", + name = "radon.kst", + pkey = "", + pkeyFormat = "raw", -- Either 'raw' or 'kristwallet', defaults to 'raw' + -- NOTE: It is not recommended to use kwallet, the best practice is to convert your pkey (using + -- kwallet format) to raw pkey yourself first, and then use that here. Thus improving security. + value = 1.0 -- Default scaling on item prices, can be overridden on a per-item basis + }, + { + id = "tenebra", -- if not krist or tenebra, must supply endpoint + -- node = "https://krist.dev" + host = "tttttttttt", + name = "radon.tst", + pkey = "", + pkeyFormat = "raw", -- Either 'raw' or 'kristwallet', defaults to 'raw' + -- NOTE: It is not recommended to use kwallet, the best practice is to convert your pkey (using + -- kwallet format) to raw pkey yourself first, and then use that here. Thus improving security. + value = 0.1 -- Default scaling on item prices, can be overridden on a per-item basis + }, + }, + peripherals = { + monitor = nil, + self = "west", -- Cardinal direction or network name of the turtle + -- relative to storage chest(s) used + -- only required if output chest is "self" + -- or a relative position + -- ex: "west", "turtle_1" + selfRelativeOutput = nil, -- Same as above but for output chest + exchangeChest = nil, + outputChest = "self", -- Chest peripheral or self + }, + exchange = { + enabled = true, + node = "https://localhost:8000/" + } +} diff --git a/core/ConfigValidator.lua b/core/ConfigValidator.lua index 88f606e..f91fa09 100644 --- a/core/ConfigValidator.lua +++ b/core/ConfigValidator.lua @@ -9,7 +9,8 @@ pollFrequency = "number", categoryCycleFrequency = "number", activityTimeout = "number", - dropDirection = "enum<'forward' | 'up' | 'down' | 'north' | 'south' | 'east' | 'west'>: direction" + dropDirection = "enum<'forward' | 'up' | 'down' | 'north' | 'south' | 'east' | 'west'>: direction", + smallTextKristPayCompatability = "boolean", }, lang = { footer = "string", diff --git a/core/ShopState.lua b/core/ShopState.lua index 8fbc792..686f2b4 100644 --- a/core/ShopState.lua +++ b/core/ShopState.lua @@ -79,7 +79,7 @@ local function handlePurchase(transaction, meta, sentMetaname, transactionCurrency, transactionCurrency, state) local purchasedProduct = nil for _, product in ipairs(state.products) do - if product.address:lower() == sentMetaname:lower() then + if product.address:lower() == sentMetaname:lower() or product.name:gsub(" ", ""):lower() == sentMetaname:lower() then purchasedProduct = product break end diff --git a/radon.lua b/radon.lua index 4e6aed1..9affbe5 100644 --- a/radon.lua +++ b/radon.lua @@ -152,18 +152,26 @@ local currencySymbol = getCurrencySymbol(currency, productTextSize) for i = 1, #shopProducts do local product = shopProducts[i] + local productAddr = product.address .. "@" + if productTextSize == "small" then + if props.config.settings.smallTextKristPayCompatability then + productAddr = product.address .. "@" .. props.shopState.selectedCurrency.name + else + productAddr = product.address .. "@ " + end + end product.quantity = product.quantity or 0 local productPrice = Pricing.getProductPrice(product, props.shopState.selectedCurrency) if productTextSize == "large" then - maxAddrWidth = math.max(maxAddrWidth, bigFont:getWidth(product.address .. "@")+2) + maxAddrWidth = math.max(maxAddrWidth, bigFont:getWidth(productAddr)+2) maxQtyWidth = math.max(maxQtyWidth, bigFont:getWidth(tostring(product.quantity))+4) maxPriceWidth = math.max(maxPriceWidth, bigFont:getWidth(tostring(productPrice) .. currencySymbol)+2) elseif productTextSize == "medium" then - maxAddrWidth = math.max(maxAddrWidth, smolFont:getWidth(product.address .. "@")+2) + maxAddrWidth = math.max(maxAddrWidth, smolFont:getWidth(productAddr)+2) maxQtyWidth = math.max(maxQtyWidth, smolFont:getWidth(tostring(product.quantity))+4) maxPriceWidth = math.max(maxPriceWidth, smolFont:getWidth(tostring(productPrice) .. currencySymbol)+2) else - maxAddrWidth = math.max(maxAddrWidth, #(product.address .. "@")+1) + maxAddrWidth = math.max(maxAddrWidth, #(productAddr)+1) maxQtyWidth = math.max(maxQtyWidth, #tostring(product.quantity)+2) maxPriceWidth = math.max(maxPriceWidth, #(tostring(productPrice) .. currencySymbol)+1) end @@ -186,21 +194,171 @@ if product.quantity == 0 then productNameColor = theme.colors.outOfStockNameColor end + local productAddr = product.address .. "@" + if productTextSize == "small" then + if props.config.settings.smallTextKristPayCompatability then + productAddr = product.address .. "@" .. props.shopState.selectedCurrency.name + else + productAddr = product.address .. "@ " + end + end if productTextSize == "large" then - table.insert(flatCanvas, BigText { key="qty-"..catName..tostring(product.id), display=display, text=tostring(product.quantity), x=1, y=17+((i-1)*15), align="center", bg=theme.colors.productBgColor, color=qtyColor, width=maxQtyWidth }) - table.insert(flatCanvas, BigText { key="name-"..catName..tostring(product.id), display=display, text=product.name, x=maxQtyWidth+1, y=17+((i-1)*15), align=theme.formatting.productNameAlign, bg=theme.colors.productBgColor, color=productNameColor, width=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth-maxQtyWidth }) - table.insert(flatCanvas, BigText { key="price-"..catName..tostring(product.id), display=display, text=tostring(productPrice) .. currencySymbol, x=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth, y=17+((i-1)*15), align="right", bg=theme.colors.productBgColor, color=theme.colors.priceColor, width=maxPriceWidth }) - table.insert(flatCanvas, BigText { key="addr-"..catName..tostring(product.id), display=display, text=product.address .. "@", x=display.bgCanvas.width-3-maxAddrWidth, y=17+((i-1)*15), align="right", bg=theme.colors.productBgColor, color=theme.colors.addressColor, width=maxAddrWidth+4 }) + table.insert(flatCanvas, BigText { + key="qty-"..catName..tostring(product.id), + display=display, + text=tostring(product.quantity), + x=1, + y=17+((i-1)*15), + align="center", + bg=theme.colors.productBgColor, + color=qtyColor, + width=maxQtyWidth + }) + table.insert(flatCanvas, BigText { + key="name-"..catName..tostring(product.id), + display=display, + text=product.name, + x=maxQtyWidth+1, + y=17+((i-1)*15), + align=theme.formatting.productNameAlign, + bg=theme.colors.productBgColor, + color=productNameColor, + width=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth-maxQtyWidth + }) + table.insert(flatCanvas, BigText { + key="price-"..catName..tostring(product.id), + display=display, + text=tostring(productPrice) .. currencySymbol, + x=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth, + y=17+((i-1)*15), + align="right", + bg=theme.colors.productBgColor, + color=theme.colors.priceColor, + width=maxPriceWidth + }) + table.insert(flatCanvas, BigText { + key="addr-"..catName..tostring(product.id), + display=display, + text=productAddr, + x=display.bgCanvas.width-3-maxAddrWidth, + y=17+((i-1)*15), + align="right", + bg=theme.colors.productBgColor, + color=theme.colors.addressColor, + width=maxAddrWidth+4 + }) + table.insert(flatCanvas, BasicText { + key="invis-" .. catName .. tostring(product.id), + display=display, + text=product.address .. "@" .. props.shopState.selectedCurrency.name, + x=1, + y=1+(i*5), + align="center", + bg=theme.colors.productBgColor, + color=theme.colors.productBgColor, + width=#(product.address .. "@" .. props.shopState.selectedCurrency.name) + }) elseif productTextSize == "medium" then - table.insert(flatCanvas, SmolText { key="qty-"..catName..tostring(product.id), display=display, text=tostring(product.quantity), x=1, y=17+((i-1)*9), align="center", bg=theme.colors.productBgColor, color=qtyColor, width=maxQtyWidth }) - table.insert(flatCanvas, SmolText { key="name-"..catName..tostring(product.id), display=display, text=product.name, x=maxQtyWidth+1, y=17+((i-1)*9), align=theme.formatting.productNameAlign, bg=theme.colors.productBgColor, color=productNameColor, width=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth-maxQtyWidth }) - table.insert(flatCanvas, SmolText { key="price-"..catName..tostring(product.id), display=display, text=tostring(productPrice) .. currencySymbol, x=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth, y=17+((i-1)*9), align="right", bg=theme.colors.productBgColor, color=theme.colors.priceColor, width=maxPriceWidth }) - table.insert(flatCanvas, SmolText { key="addr-"..catName..tostring(product.id), display=display, text=product.address .. "@", x=display.bgCanvas.width-3-maxAddrWidth, y=17+((i-1)*9), align="right", bg=theme.colors.productBgColor, color=theme.colors.addressColor, width=maxAddrWidth+4 }) + table.insert(flatCanvas, SmolText { + key="qty-"..catName..tostring(product.id), + display=display, + text=tostring(product.quantity), + x=1, + y=17+((i-1)*9), + align="center", + bg=theme.colors.productBgColor, + color=qtyColor, + width=maxQtyWidth + }) + table.insert(flatCanvas, SmolText { + key="name-"..catName..tostring(product.id), + display=display, + text=product.name, + x=maxQtyWidth+1, + y=17+((i-1)*9), + align=theme.formatting.productNameAlign, + bg=theme.colors.productBgColor, + color=productNameColor, + width=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth-maxQtyWidth + }) + table.insert(flatCanvas, SmolText { + key="price-"..catName..tostring(product.id), + display=display, + text=tostring(productPrice) .. currencySymbol, + x=display.bgCanvas.width-3-maxAddrWidth-maxPriceWidth, + y=17+((i-1)*9), + align="right", + bg=theme.colors.productBgColor, + color=theme.colors.priceColor, + width=maxPriceWidth + }) + table.insert(flatCanvas, SmolText { + ey="addr-"..catName..tostring(product.id), + display=display, + text=productAddr, + x=display.bgCanvas.width-3-maxAddrWidth, + y=17+((i-1)*9), + align="right", + bg=theme.colors.productBgColor, + color=theme.colors.addressColor, + width=maxAddrWidth+4 + }) + table.insert(flatCanvas, BasicText { + key="invis-" .. catName .. tostring(product.id), + display=display, + text=product.address .. "@" .. props.shopState.selectedCurrency.name, + x=1, + y=3+(i*3), + align="center", + bg=theme.colors.productBgColor, + color=theme.colors.productBgColor, + width=#(product.address .. "@" .. props.shopState.selectedCurrency.name) + }) else - table.insert(flatCanvas, BasicText { key="qty-"..catName..tostring(product.id), display=display, text=tostring(product.quantity), x=1, y=6+((i-1)*1), align="center", bg=theme.colors.productBgColor, color=qtyColor, width=maxQtyWidth }) - table.insert(flatCanvas, BasicText { key="name-"..catName..tostring(product.id), display=display, text=product.name, x=maxQtyWidth+1, y=6+((i-1)*1), align=theme.formatting.productNameAlign, bg=theme.colors.productBgColor, color=productNameColor, width=(display.bgCanvas.width/2)-1-maxAddrWidth-maxPriceWidth-maxQtyWidth }) - table.insert(flatCanvas, BasicText { key="price-"..catName..tostring(product.id), display=display, text=tostring(productPrice) .. currencySymbol, x=(display.bgCanvas.width/2)-1-maxAddrWidth-maxPriceWidth, y=6+((i-1)*1), align="right", bg=theme.colors.productBgColor, color=theme.colors.priceColor, width=maxPriceWidth }) - table.insert(flatCanvas, BasicText { key="addr-"..catName..tostring(product.id), display=display, text=product.address .. "@ ", x=(display.bgCanvas.width/2)-1-maxAddrWidth, y=6+((i-1)*1), align="right", bg=theme.colors.productBgColor, color=theme.colors.addressColor, width=maxAddrWidth+2 }) + table.insert(flatCanvas, BasicText { + key="qty-"..catName..tostring(product.id), + display=display, + text=tostring(product.quantity), + x=1, + y=6+((i-1)*1), + align="center", + bg=theme.colors.productBgColor, + color=qtyColor, + width=maxQtyWidth + }) + table.insert(flatCanvas, BasicText { + key="name-"..catName..tostring(product.id), + display=display, + text=product.name, + x=maxQtyWidth+1, + y=6+((i-1)*1), + align=theme.formatting.productNameAlign, + bg=theme.colors.productBgColor, + color=productNameColor, + width=(display.bgCanvas.width/2)-1-maxAddrWidth-maxPriceWidth-maxQtyWidth + }) + table.insert(flatCanvas, BasicText { + key="price-"..catName..tostring(product.id), + display=display, + text=tostring(productPrice) .. currencySymbol, + x=(display.bgCanvas.width/2)-1-maxAddrWidth-maxPriceWidth, + y=6+((i-1)*1), + align="right", + bg=theme.colors.productBgColor, + color=theme.colors.priceColor, + width=maxPriceWidth + }) + table.insert(flatCanvas, BasicText { + key="addr-"..catName..tostring(product.id), + display=display, + text=productAddr, + x=(display.bgCanvas.width/2)-1-maxAddrWidth, + y=6+((i-1)*1), + align="right", + bg=theme.colors.productBgColor, + color=theme.colors.addressColor, + width=maxAddrWidth+2 + }) end end