From f9a9398c7498b36d422b49645d4350e823eecd0a Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Thu, 27 Apr 2023 12:30:58 +0200 Subject: [PATCH] Fixed bugs, improved installer. --- src/buildscript.lua | 9 +++++++++ src/itemscript.lua | 14 +++++++++----- src/ms-installer.lua | 5 +++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/buildscript.lua b/src/buildscript.lua index beed809..44a04ad 100644 --- a/src/buildscript.lua +++ b/src/buildscript.lua @@ -22,6 +22,15 @@ function buildscript.runWithItem(ms_script, filterExpr) 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. local function parseArgValue(argSpec, arg) if argSpec.required and (not arg or #arg < 1) then diff --git a/src/itemscript.lua b/src/itemscript.lua index 18875fa..df621d1 100644 --- a/src/itemscript.lua +++ b/src/itemscript.lua @@ -59,7 +59,6 @@ end ]]-- function itemscript.parseFilterExpression(str) str = str:gsub("^%s*(.-)%s*$", "%1") -- Trim whitespace from the beginning and end of the string. - print("Parsing expr: " .. str) -- Parse group constructs local ignoreRange = nil @@ -70,7 +69,6 @@ function itemscript.parseFilterExpression(str) end -- If the group is the whole expression, parse it. Otherwise, defer parsing to later. if idx2 == #str then - print("Found GROUP") return itemscript.parseFilterExpression(string.sub(str, idx1 + 1, idx2 - 1)) else ignoreRange = {idx1, idx2} @@ -85,7 +83,6 @@ function itemscript.parseFilterExpression(str) for _, operator in pairs(logicalGroupOperators) do local idx = string.find(str, operator.token) if idx ~= nil and (ignoreRange == nil or idx < ignoreRange[1] or idx > ignoreRange[2]) then - print("Found " .. operator.name) return { type = operator.name, children = { @@ -108,7 +105,6 @@ function itemscript.parseFilterExpression(str) for typeName, token in pairs(arithmeticOperators) do local idx = string.find(str, token) 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 numberExprIdx1, numberExprIdx2 = string.find(str, "%d+", idx + 1) if numberExprIdx1 == nil then @@ -128,7 +124,6 @@ function itemscript.parseFilterExpression(str) -- Parse NOT operator. if string.sub(str, 1, 1) == "!" then - print("Found NOT") return { type = "NOT", expr = itemscript.parseFilterExpression(string.sub(str, 2, -1)) @@ -308,6 +303,15 @@ function itemscript.selectOrWait(filterExpr, minCount) 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. function itemscript.selectEmpty() for i = 1, 16 do diff --git a/src/ms-installer.lua b/src/ms-installer.lua index 4d1e965..3c6df0f 100644 --- a/src/ms-installer.lua +++ b/src/ms-installer.lua @@ -11,6 +11,7 @@ local libs = { local BASE_URL = "https://andrewlalis.github.io/movescript/scripts/" print("Running Movescript installer") +print("----------------------------") for _, lib in pairs(libs) do if fs.exists(lib) then fs.delete(lib) @@ -23,3 +24,7 @@ for _, lib in pairs(libs) do print("Downloaded " .. lib) end print("Done!") +for _, lib in pairs(libs) do + local m = require(lib) + print(" " .. lib .. " installed with version " .. m.VERSION) +end