Fixed bugs, improved installer.

This commit is contained in:
Andrew Lalis 2023-04-27 12:30:58 +02:00
parent d3da86c95e
commit f9a9398c74
3 changed files with 23 additions and 5 deletions

View File

@ -22,6 +22,15 @@ function buildscript.runWithItem(ms_script, filterExpr)
end end
end end
-- Runs a movescript script, while selecting random items that match a filter.
function buildscript.runWithRandomItems(ms_script, filterExpr)
local instructions = movescript.parse(ms_script)
for idx, instruction in pairs(instructions) do
itemscript.selectRandomOrWait(filterExpr)
movescript.executeInstruction(instruction)
end
end
-- Parses a value for an argument specification from a raw value. -- Parses a value for an argument specification from a raw value.
local function parseArgValue(argSpec, arg) local function parseArgValue(argSpec, arg)
if argSpec.required and (not arg or #arg < 1) then if argSpec.required and (not arg or #arg < 1) then

View File

@ -59,7 +59,6 @@ end
]]-- ]]--
function itemscript.parseFilterExpression(str) function itemscript.parseFilterExpression(str)
str = str:gsub("^%s*(.-)%s*$", "%1") -- Trim whitespace from the beginning and end of the string. str = str:gsub("^%s*(.-)%s*$", "%1") -- Trim whitespace from the beginning and end of the string.
print("Parsing expr: " .. str)
-- Parse group constructs -- Parse group constructs
local ignoreRange = nil local ignoreRange = nil
@ -70,7 +69,6 @@ function itemscript.parseFilterExpression(str)
end end
-- If the group is the whole expression, parse it. Otherwise, defer parsing to later. -- If the group is the whole expression, parse it. Otherwise, defer parsing to later.
if idx2 == #str then if idx2 == #str then
print("Found GROUP")
return itemscript.parseFilterExpression(string.sub(str, idx1 + 1, idx2 - 1)) return itemscript.parseFilterExpression(string.sub(str, idx1 + 1, idx2 - 1))
else else
ignoreRange = {idx1, idx2} ignoreRange = {idx1, idx2}
@ -85,7 +83,6 @@ function itemscript.parseFilterExpression(str)
for _, operator in pairs(logicalGroupOperators) do for _, operator in pairs(logicalGroupOperators) do
local idx = string.find(str, operator.token) local idx = string.find(str, operator.token)
if idx ~= nil and (ignoreRange == nil or idx < ignoreRange[1] or idx > ignoreRange[2]) then if idx ~= nil and (ignoreRange == nil or idx < ignoreRange[1] or idx > ignoreRange[2]) then
print("Found " .. operator.name)
return { return {
type = operator.name, type = operator.name,
children = { children = {
@ -108,7 +105,6 @@ function itemscript.parseFilterExpression(str)
for typeName, token in pairs(arithmeticOperators) do for typeName, token in pairs(arithmeticOperators) do
local idx = string.find(str, token) local idx = string.find(str, token)
if idx ~= nil and (ignoreRange == nil or idx < ignoreRange[1] or idx > ignoreRange[2]) then if idx ~= nil and (ignoreRange == nil or idx < ignoreRange[1] or idx > ignoreRange[2]) then
print("Found " .. typeName)
local subExpr = itemscript.parseFilterExpression(string.sub(str, 1, idx - 1)) local subExpr = itemscript.parseFilterExpression(string.sub(str, 1, idx - 1))
local numberExprIdx1, numberExprIdx2 = string.find(str, "%d+", idx + 1) local numberExprIdx1, numberExprIdx2 = string.find(str, "%d+", idx + 1)
if numberExprIdx1 == nil then if numberExprIdx1 == nil then
@ -128,7 +124,6 @@ function itemscript.parseFilterExpression(str)
-- Parse NOT operator. -- Parse NOT operator.
if string.sub(str, 1, 1) == "!" then if string.sub(str, 1, 1) == "!" then
print("Found NOT")
return { return {
type = "NOT", type = "NOT",
expr = itemscript.parseFilterExpression(string.sub(str, 2, -1)) expr = itemscript.parseFilterExpression(string.sub(str, 2, -1))
@ -308,6 +303,15 @@ function itemscript.selectOrWait(filterExpr, minCount)
end end
end end
function itemscript.selectRandomOrWait(filterExpr, minCount)
minCount = minCount or 1
local filter = itemscript.filterize(filterExpr)
while itemscript.totalCount(filter) < minCount do
print("Couldn't find at least " .. minCount .. " item(s) matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
os.pullEvent("turtle_inventory")
end
end
-- Selects an empty slot. -- Selects an empty slot.
function itemscript.selectEmpty() function itemscript.selectEmpty()
for i = 1, 16 do for i = 1, 16 do

View File

@ -11,6 +11,7 @@ local libs = {
local BASE_URL = "https://andrewlalis.github.io/movescript/scripts/" local BASE_URL = "https://andrewlalis.github.io/movescript/scripts/"
print("Running Movescript installer") print("Running Movescript installer")
print("----------------------------")
for _, lib in pairs(libs) do for _, lib in pairs(libs) do
if fs.exists(lib) then if fs.exists(lib) then
fs.delete(lib) fs.delete(lib)
@ -23,3 +24,7 @@ for _, lib in pairs(libs) do
print("Downloaded " .. lib) print("Downloaded " .. lib)
end end
print("Done!") print("Done!")
for _, lib in pairs(libs) do
local m = require(lib)
print(" " .. lib .. " installed with version " .. m.VERSION)
end