diff --git a/components/ConfigEditor.lua b/components/ConfigEditor.lua index 6e8e6f5..02bd263 100644 --- a/components/ConfigEditor.lua +++ b/components/ConfigEditor.lua @@ -388,12 +388,12 @@ if textY >= props.y + 1 and textY <= props.y + props.height then if v:sub(1, 6) == "string" or v:sub(1,5) == "regex" or v:sub(1,4) == "file" or v:sub(1,5) == "modem" or v:sub(1,7) == "speaker" or v:sub(1,5) == "chest" then - local inputStateValue = configDiffs[fullPath] or subConfig[k] + local inputStateValue = configDiffs[fullPath] or subConfig[k] or subConfig[tonumber(k)] if inputStateValue == "%nil%" then inputStateValue = nil end table.insert(elements, TextInput { - key = "config-value-"..k, + key = "config-value-"..fullPath, display = props.display, align = "left", x = props.x + xOffset, @@ -420,7 +420,7 @@ toggleStartValue = subConfig[k] end table.insert(elements, Rect { - key = "config-value-" .. k .. "-bg", + key = "config-value-" .. fullPath .. "-bg", display = props.display, x = (props.x*2)-1 + xOffset*2, y = (textY*3)-2, @@ -450,7 +450,7 @@ }) elseif v:sub(1, 6) == "number" then table.insert(elements, Rect { - key = "config-value-" .. k .. "-bg", + key = "config-value-" .. fullPath .. "-bg", display = props.display, x = (props.x*2)-1 + 12*2 + xOffset*2, y = (textY*3)-2, @@ -473,7 +473,7 @@ bg = theme.inputBgColor, height = 1, width = 12, - inputState = { value = configDiffs[fullPath] or subConfig[k] }, + inputState = { value = configDiffs[fullPath] or subConfig[k] or subConfig[tonumber(k)] }, onChange = function(value) configDiffs[fullPath] = value setConfigDiffs(configDiffs) @@ -485,7 +485,7 @@ elseif v:sub(1, 5) == "color" then lastSelect = true table.insert(elements, Select { - key = "config-value-"..k, + key = "config-value-"..fullPath, display = props.display, x = props.x + xOffset, y = textY, @@ -531,7 +531,7 @@ table.insert(options, { value = enumValue, text = enumValue }) end table.insert(elements, Select { - key = "config-value-"..k, + key = "config-value-"..fullPath, display = props.display, x = props.x + xOffset, y = textY, @@ -584,7 +584,7 @@ width = #buttonText + 2, text = buttonText, onClick = function() - arrayAdds[props.terminalState.configPath .. "." .. tostring(numKeys)] = true + arrayAdds[props.terminalState.configPath .. "." .. tostring(numKeys)] = subSchema.__entry setArrayAdds(arrayAdds) setUpdates(updates + 1) local newConfig = configHelpers.getNewConfig(props.config, configDiffs, arrayAdds, arrayRemoves) diff --git a/components/TextInput.lua b/components/TextInput.lua index e5d2ffe..568347b 100644 --- a/components/TextInput.lua +++ b/components/TextInput.lua @@ -47,12 +47,12 @@ if inputState.value:find("%.") then return end - elseif char:match("%D") then - return elseif char == "-" then if inputState.cursorPos ~= 1 or inputState.value:find("%-") then return end + elseif char:match("%D") then + return end elseif props.type == "colorpicker" then if char == "x" then @@ -98,6 +98,7 @@ color = props.color, width = props.width, }, +---@diagnostic disable-next-line: redundant-return-value { -- canvas = canvas, aabb = useBoundingBox((props.x*2)-1, (props.y*3)-2, (props.width)*2, (props.height)*3, @@ -205,7 +206,11 @@ function(contents) -- On paste if props.type == "number" then - contents = contents:gsub("[^%d]", "") + if contents:sub(1, 1) == "-" then + contents = "-" .. contents:gsub("[^%d]", "") + else + contents = contents:gsub("[^%d]", "") + end elseif props.type == "colorpicker" then if contents:sub(1, 1) ~= "#" or contents:sub(1,2):find("x") then contents = "#" .. contents:gsub("[^%x]", "") diff --git a/config.lua b/config.lua index 956852d..734dfdc 100644 --- a/config.lua +++ b/config.lua @@ -250,6 +250,17 @@ value = 0.1 -- Default scaling on item prices, can be overridden on a per-item basis },--]] }, + shopSync = { + enabled = true, + name = "Radon Shop", + description = "A radon Shop", + owner = nil, + location = { + coordinates = nil, + description = nil, + dimension = "overworld" + } + }, peripherals = { monitor = nil, -- Monitor to display on, if not specified, will use the first monitor found modem = nil, -- Modem for inventories, if not specified, will use the first wired modem found diff --git a/configDefaults.lua b/configDefaults.lua index f49b446..071adbd 100644 --- a/configDefaults.lua +++ b/configDefaults.lua @@ -178,6 +178,17 @@ pitch = 2 }, }, + shopSync = { + enabled = true, + name = "Radon Shop", + description = "A radon Shop", + owner = nil, + location = { + coordinates = {nil, nil, nil}, + description = nil, + dimension = "overworld" + } + }, peripherals = { monitor = nil, -- Monitor to display on, if not specified, will use the first monitor found modem = nil, -- Modem for inventories, if not specified, will use the first wired modem found diff --git a/core/ShopState.lua b/core/ShopState.lua index 938dfcb..c608a5e 100644 --- a/core/ShopState.lua +++ b/core/ShopState.lua @@ -435,7 +435,7 @@ local nbt = nil local predicates = nil if product.predicates then - nbt = "" + nbt = nil -- TODO: Can we get an nbt hash? predicates = product.predicates end for j = 1, #self.config.currencies do @@ -455,17 +455,20 @@ value = product.price / currency.value, currency = currencyName, address = address, - --requiredMeta = requiredMeta + requiredMeta = requiredMeta }) end table.insert(items, { - price = prices, + prices = prices, item = { name = product.modid, displayName = product.name, nbt = nbt, --predicates = predicates - } + }, + dynamicPrice = false, + stock = product.quantity, + madeOnDemand = false, }) end self.peripherals.shopSyncModem.transmit(shopSyncChannel, os.getComputerID(), { @@ -474,15 +477,14 @@ name = self.config.shopSync.name, description = self.config.shopSync.description, owner = self.config.shopSync.owner, + computerID = os.getComputerID(), software = { name = "Radon", version = self.version }, location = self.config.shopSync.location, }, - items = { - - } + items = items }) end end diff --git a/core/schemas.lua b/core/schemas.lua index ce428d5..2e78a6e 100644 --- a/core/schemas.lua +++ b/core/schemas.lua @@ -191,22 +191,22 @@ exchangeChest = "chest?", outputChest = "chest", }, - -- shopSync = { - -- enabled = "boolean?", - -- name = "string?", - -- description = "string?", - -- owner = "string?", - -- location = { - -- coordinates = { - -- __type = "array?", - -- __min = 3, - -- __max = 3, - -- __entry = "number" - -- }, - -- description = "string?", - -- dimension = "enum<'overworld' | 'nether' | 'end'>?: dimension" - -- } - -- }, + shopSync = { + enabled = "boolean?", + name = "string?", + description = "string?", + owner = "string?", + location = { + coordinates = { + __type = "array", + __min = 3, + __max = 3, + __entry = "number" + }, + description = "string?", + dimension = "enum<'overworld' | 'nether' | 'end'>?: dimension" + } + }, exchange = { enabled = "boolean", node = "string" diff --git a/radon.lua b/radon.lua index ccbe56f..e855481 100644 --- a/radon.lua +++ b/radon.lua @@ -1,4 +1,4 @@ -local version = "1.3.29" +local version = "1.3.30" local configHelpers = require "util.configHelpers" local schemas = require "core.schemas" local ScanInventory = require("core.inventory.ScanInventory") @@ -78,9 +78,9 @@ local peripherals = {} configHelpers.getPeripherals(config, peripherals) -if config.shopSync and config.shopSync.enabled and not config.shopSync.force then - error("ShopSync is not yet finalized, please update Radon to use this feature, or set config.shopSync.force to true to use current ShopSync spec") -end +-- if config.shopSync and config.shopSync.enabled and not config.shopSync.force then +-- error("ShopSync is not yet finalized, please update Radon to use this feature, or set config.shopSync.force to true to use current ShopSync spec") +-- end local display = Display.new({theme=config.theme, monitor=config.peripherals.monitor}) local terminal = Display.new({theme=config.terminalTheme, monitor=term}) diff --git a/util/configHelpers.lua b/util/configHelpers.lua index b61b833..ec6f947 100644 --- a/util/configHelpers.lua +++ b/util/configHelpers.lua @@ -78,7 +78,7 @@ function getNewConfig(config, configDiffs, arrayAdds, arrayRemoves) local newConfig = score.copyDeep(config) - for k, _ in pairs(arrayAdds) do + for k, addSchema in pairs(arrayAdds) do local subConfig = newConfig for path in k:gmatch("([^%[?%]?%.?]+)") do if path:match("%d+") then @@ -87,7 +87,11 @@ if subConfig[path] then subConfig = subConfig[path] else - subConfig[path] = {} + if addSchema:sub(1,6) == "number" then + subConfig[path] = 0 + else + subConfig[path] = {} + end subConfig = subConfig[path] end end