From 9055530715d77192e5a3242518f30b991ee3e85a Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Thu, 29 May 2025 20:31:45 +0200 Subject: [PATCH 1/4] refactor: :wastebasket: removed submodules Repos using this Module will need to be updated --- TestSuite-lib | 1 - 1 file changed, 1 deletion(-) delete mode 160000 TestSuite-lib diff --git a/TestSuite-lib b/TestSuite-lib deleted file mode 160000 index 9c995d3..0000000 --- a/TestSuite-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9c995d38644c35d8ff80d5628f167db808b2a03a From eb11696b415143e3574aff45707b7123fb518db0 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Thu, 29 May 2025 20:44:22 +0200 Subject: [PATCH 2/4] refactor: :wastebasket: removed submodules repos requireing this repo via submodules will need to be updated --- .github/workflows/test.yml | 16 +++++-------- .gitignore | 2 +- .gitmodules | 3 --- fetch-deps.sh | 42 +++++++++++++++++++++++++++++++++++ files.txt | 8 ++++++- inventory/chestInventory.lua | 4 ++-- inventory/inventory.lua | 4 ++-- inventory/turtleInventory.lua | 6 ++--- package.lua | 7 ------ tests/test_spec.lua | 10 ++++----- 10 files changed, 66 insertions(+), 36 deletions(-) delete mode 100644 .gitmodules create mode 100755 fetch-deps.sh delete mode 100644 package.lua diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9d0fab6..8a8b895 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,15 +7,9 @@ on: [push, pull_request] jobs: test: runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v2 - with: - submodules: true - - name: get lua - uses: leafo/gh-actions-lua@v10 + uses: leafo/gh-actions-lua@v11 with: luaVersion: "5.1" @@ -30,11 +24,11 @@ jobs: luarocks install luasocket luarocks install luasec - - name: Git Submodule Update + - name: fetch dependencies run: | - git pull --recurse-submodules - git submodule update --remote --recursive + chmod +x ./fetch-deps.sh + ./fetch-deps.sh - name: test run: | - busted . + busted vector diff --git a/.gitignore b/.gitignore index ea92fae..10ee637 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /config /.vscode /computer -/suits \ No newline at end of file +/libs \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index ffd6b6a..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "TestSuite-lib"] - path = TestSuite-lib - url = https://github.com/mc-cc-scripts/TestSuite-lib.git diff --git a/fetch-deps.sh b/fetch-deps.sh new file mode 100755 index 0000000..b1aa60b --- /dev/null +++ b/fetch-deps.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# ---- Whats happening ---- # + +# This fetches the dependencies listed in the "libs" variable and saves them in the targetFolder + + + +set -e + +libs=( + "helperFunctions-lib" + "eventCallStack-lib" + "ccClass-lib" + "testSuite-lib" +) + +# Basic setup variables +repo="mc-cc-scripts" +branch="master" +targetFolderName=libs + + +# fetch files.txt and save each file into the targetFolder +fetch() { + + files_txt=$(curl -fsSL "https://raw.githubusercontent.com/$repo/$1/$branch/files.txt") + if [ -z "$files_txt" ]; then + echo "Could not load files.txt for $1" + exit 1 + fi + while IFS= read -r FILE; do + rm -f $targetFolderName/$1.lua # rm existing file + curl -s "https://raw.githubusercontent.com/$repo/$1/$branch/$FILE" -o "$targetFolderName/$FILE" + done < <(echo "$files_txt") +} + +mkdir -p $targetFolderName + +for i in "${libs[@]}"; do + fetch "$i" +done \ No newline at end of file diff --git a/files.txt b/files.txt index 918ad4b..c8900e0 100644 --- a/files.txt +++ b/files.txt @@ -1,2 +1,8 @@ turtleEmulator.lua -turtleMock.lua \ No newline at end of file +turtleMock.lua +peripheral.lua +defaultInteraction.lua +defaultcheckActionValid.lua +inventory/chestInventory.lua +inventory/inventory.lua +inventory/turtleInventory.lua \ No newline at end of file diff --git a/inventory/chestInventory.lua b/inventory/chestInventory.lua index 8115614..5c9825a 100644 --- a/inventory/chestInventory.lua +++ b/inventory/chestInventory.lua @@ -1,5 +1,5 @@ -local class = require("./TestSuite-lib/ccClass/ccClass") -local inventory = require("../inventory/inventory") +local class = require("ccClass") +local inventory = require("inventory") ---@class ChestInventory : Inventory local chestInventory = class(inventory) diff --git a/inventory/inventory.lua b/inventory/inventory.lua index f1cc9d8..3ce9d96 100644 --- a/inventory/inventory.lua +++ b/inventory/inventory.lua @@ -18,8 +18,8 @@ --#endregion -local deepCopy = require("./TestSuite-lib/helperFunctions/helperFunctions").deepCopy -local class = require("./TestSuite-lib/ccClass/ccClass") +local deepCopy = require("helperFunctions").deepCopy +local class = require("ccClass") ---# inventory ---Inventory system emulated diff --git a/inventory/turtleInventory.lua b/inventory/turtleInventory.lua index ff15876..22d581c 100644 --- a/inventory/turtleInventory.lua +++ b/inventory/turtleInventory.lua @@ -1,6 +1,6 @@ -local class = require("./TestSuite-lib/ccClass/ccClass") -local inventory = require("../inventory/inventory") -local deepCopy = require("../TestSuite-lib/helperFunctions/helperFunctions").deepCopy +local class = require("ccClass") +local inventory = require("inventory") +local deepCopy = require("helperFunctions").deepCopy ---@class TurtleInventory : Inventory ---@field protected _base Inventory the base inventory class local turtleInventory = class(inventory, function (selfRef) diff --git a/package.lua b/package.lua deleted file mode 100644 index 37dccdf..0000000 --- a/package.lua +++ /dev/null @@ -1,7 +0,0 @@ -local spath = - debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$","") -package.path = spath.."?.lua;" - ..spath.."inventory/?.lua;" - ..package.path - -require(spath.."TestSuite-lib/package") \ No newline at end of file diff --git a/tests/test_spec.lua b/tests/test_spec.lua index 9c723c1..c0432fc 100644 --- a/tests/test_spec.lua +++ b/tests/test_spec.lua @@ -29,12 +29,10 @@ ---@field equal function assert = assert -local spath = - debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$",""):gsub("/tests", ""):gsub("tests", "") - if spath == "" then - spath = "./" - end -require(spath .. "package") +package.path = package.path + ..";inventory/?.lua;" + .."libs/?.lua;" + .."libs/?/?.lua;" -- load the other suits local vector = require("vector") From 775eebc56d62792a4dcaea9ada6680fabf1a7abb Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Thu, 29 May 2025 20:58:43 +0200 Subject: [PATCH 3/4] test-fix --- .github/workflows/test.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8a8b895..9001aaf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,15 +1,17 @@ name: Busted - on: [push, pull_request] - jobs: test: runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + - name: get lua - uses: leafo/gh-actions-lua@v11 + uses: leafo/gh-actions-lua@v10 with: luaVersion: "5.1" @@ -31,4 +33,4 @@ jobs: - name: test run: | - busted vector + busted . \ No newline at end of file From 6881d6847b19518c7144ece1798edc4652e63e3e Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Thu, 29 May 2025 21:34:40 +0200 Subject: [PATCH 4/4] reduced codebase --- cc/pretty.lua | 8 ------- defaultBehaviour/defaultcheckActionValid.lua | 14 ------------- ...tInteraction.lua => defaultInteraction.lua | 2 +- files.txt | 7 +++---- tests/test_spec.lua | 11 +--------- turtleEmulator.lua | 21 +++++++++++++++++-- turtleMock.lua | 3 ++- 7 files changed, 26 insertions(+), 40 deletions(-) delete mode 100644 cc/pretty.lua delete mode 100644 defaultBehaviour/defaultcheckActionValid.lua rename defaultBehaviour/defaultInteraction.lua => defaultInteraction.lua (97%) diff --git a/cc/pretty.lua b/cc/pretty.lua deleted file mode 100644 index 037b1ce..0000000 --- a/cc/pretty.lua +++ /dev/null @@ -1,8 +0,0 @@ -local pretty = { - pretty_print = function (t) - for k, v in pairs(t) do - print(k, v) - end - end -} -return pretty \ No newline at end of file diff --git a/defaultBehaviour/defaultcheckActionValid.lua b/defaultBehaviour/defaultcheckActionValid.lua deleted file mode 100644 index eec4fd0..0000000 --- a/defaultBehaviour/defaultcheckActionValid.lua +++ /dev/null @@ -1,14 +0,0 @@ --- This is the default checkActionValid function ----@type checkActionValidFunc -local defaultcheckActionValid = function(turtle, action, block) - -- example use cases: - -- - -- if turtle.equipslots.left and turtle.equipslots.left.name == "" then end - -- if action == "dig" then end - -- if block.item.name == "" then end - - - return true -end - -return defaultcheckActionValid \ No newline at end of file diff --git a/defaultBehaviour/defaultInteraction.lua b/defaultInteraction.lua similarity index 97% rename from defaultBehaviour/defaultInteraction.lua rename to defaultInteraction.lua index 63bd5d1..54934c9 100644 --- a/defaultBehaviour/defaultInteraction.lua +++ b/defaultInteraction.lua @@ -23,4 +23,4 @@ local function defaultInteration(turtle, block, action) end end -return defaultInteration +return defaultInteration \ No newline at end of file diff --git a/files.txt b/files.txt index 8d747a0..bb7d1b3 100644 --- a/files.txt +++ b/files.txt @@ -1,11 +1,10 @@ -<<<<<<< HEAD turtleEmulator.lua turtleMock.lua peripheral.lua defaultInteraction.lua -defaultcheckActionValid.lua inventory/chestInventory.lua inventory/inventory.lua inventory/turtleInventory.lua -======= ->>>>>>> master +peripherals/geoScanner.lua +peripherals/modem.lua +peripherals/peripheral.lua \ No newline at end of file diff --git a/tests/test_spec.lua b/tests/test_spec.lua index b9eb277..9d98c65 100644 --- a/tests/test_spec.lua +++ b/tests/test_spec.lua @@ -29,20 +29,11 @@ ---@field equal function assert = assert -<<<<<<< HEAD package.path = package.path ..";inventory/?.lua;" .."libs/?.lua;" .."libs/?/?.lua;" -======= -local spath = - debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$",""):gsub("/tests", ""):gsub("tests", "") -if spath == "" then - spath = "./" -end -local package = spath.."ccPackage" -require(package) ->>>>>>> master + .."peripherals/?.lua" -- load the other suits local vector = require("vector") diff --git a/turtleEmulator.lua b/turtleEmulator.lua index 7bfcbc7..9506d28 100644 --- a/turtleEmulator.lua +++ b/turtleEmulator.lua @@ -31,12 +31,29 @@ ---@type TurtleMock local turtleM = require("turtleMock") -local defaultInteraction = require("defaultInteraction") -local defaultcheckActionValid = require("defaultcheckActionValid") local chestInventory = require("chestInventory") ---@type Vector local vector = require("vector") +local defaultInteraction = require("defaultInteraction") + +---ment to be replaced if required +---@param turtle TurtleMock +---@param action any +---@param block block +---@return boolean +local defaultcheckActionValid = function(turtle, action, block) + -- example use cases: + -- + -- if turtle.equipslots.left and turtle.equipslots.left.name == "" then end + -- if action == "dig" then end + -- if block.item.name == "" then end + + + return true +end + + ---comment ---@param position Vector ---@param item Item diff --git a/turtleMock.lua b/turtleMock.lua index 64fd6b5..09bec8f 100644 --- a/turtleMock.lua +++ b/turtleMock.lua @@ -74,12 +74,13 @@ local peripheral = require("peripheral") -local defaultInteraction = require("defaultInteraction") local turtleInventory = require("turtleInventory") ---@type Vector local vector = require("vector") +local defaultInteraction = require("defaultInteraction") local deepCopy = require("helperFunctions").deepCopy + --- this class should not be used directly, use the createMock of the turtleEmulator function instead, which will set the proxy ---@type TurtleMock ---@diagnostic disable-next-line: missing-fields