Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
luarocks install luasocket
luarocks install luasec
- name: Git Submodule Update
- name: fetch dependencies
run: |
git pull --recurse-submodules
git submodule update --init --remote --recursive
chmod +x ./fetch-deps.sh
./fetch-deps.sh
- name: test
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/libs
8 changes: 0 additions & 8 deletions .gitmodules

This file was deleted.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ builder help
```lua
-- Builds a floor with the specified size.
-- Uses the Item in Slot 1 as Buildingblock!
builder floor -w <width> -l <length> -m <"left"|"right">
builder floor -w <width> -l <length> -mH <"left"|"right">
```

# Dev - Documentaion
### clearArea

### Submodules used
- turtleControler-lib
- turtleEmulator-lib
- - plus submodules
```lua
-- clears an Area of the specifed size
builder clearArea -w <width> -l <length> -h <height> -mH <"left"|"right"> -mV <"up"|"down">
```
130 changes: 105 additions & 25 deletions builder-lib.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---@class Builder_Lib
local Builder_Lib = {
movementDirection = {
height = "bottom",
height = "up",
width = "right"
}
}
Expand Down Expand Up @@ -36,34 +36,44 @@ local function placeDownItem(itemname)
if not succ then error(txt) end
end

local function returnToStartingPos()
local function getTurningDirection(builderRef ,cHorizontal, cVertical, maxWidth)
assert(type(builderRef) == "table", "needs self reference!")
cHorizontal = cHorizontal or 1
cVertical = cVertical or 1
maxWidth = maxWidth or 2 -- default is even

end
local hModulo = cHorizontal % 2
local vModulo = cVertical % 2

-- if odd, pretent to always be at base y-level and CONTINUE the left / right toggle
-- making vModulo static
if (maxWidth % 2 == 1) then
vModulo = 1
end

---builds the floor with the given size
---@param length number
---@param width number
function Builder_Lib:floor(length, width)
if builderRef.movementDirection.width == "left" then
hModulo = 1 - hModulo -- invert 1 <=> 0
end

local t
if self.movementDirection.width == "right" then
t = function(modulo)
if modulo == 1 then
turtle.turnRight()
else
turtle.turnLeft()
end
end
if (hModulo == vModulo) then
turtle.turnRight()
else
t = function(modulo)
if modulo == 1 then
turtle.turnLeft()
else
turtle.turnRight()
end
end
turtle.turnLeft()
end

end

local function returnToStartingPos()

end

---builds the floor with the given size
---@param length number | nil
---@param width number | nil
---@return boolean success
function Builder_Lib:floor(length, width)
length = length or 1
width = width or 1
turtle.select(1)
local block = turtle.getItemDetail()
if block == nil then error("No block at item slot 1") end
Expand All @@ -74,11 +84,81 @@ function Builder_Lib:floor(length, width)
end
placeDownItem(block.name)
if (j < width) then
t(j % 2)
getTurningDirection(self, j)
turtleController:goStraight(1)
t(j % 2)
getTurningDirection(self, j)
end
end
returnToStartingPos()
return true
end

---clears an area with of specified size
---@param length number | nil
---@param width number | nil
---@param height number | nil
---@return boolean success
function Builder_Lib:clearArea(length, width, height)
local upDownDig = function(cHeight, maxHeight)
if Builder_Lib.movementDirection.height == "up" then
if(cHeight < maxHeight) then
turtleController:tryAction("digU")
end
if(cHeight > 1) then
turtleController:tryAction("digD")
end
else
if(cHeight < maxHeight) then
turtleController:tryAction("digD")
end
if(cHeight > 1) then
turtleController:tryAction("digU")
end
end
end
length = length or 1
width = width or 1
height = height or 1


local currentHeight = 1
local k = 1
while true do
for j = 1, width, 1 do
for i = 1, length - 1, 1 do
upDownDig(currentHeight, height)
turtleController:goStraight(1)
end
upDownDig(currentHeight, height)
if (j < width) then
getTurningDirection(self, j, k, width)
turtleController:goStraight(1)
getTurningDirection(self, j, k, width)
else
end
end
upDownDig(currentHeight, height)

-- go up 3 blocks
local diff = height - currentHeight
if diff > 3 then
diff = 3
end
if diff <= 1 then
break
end
if self.movementDirection.height == "up" then
turtleController:goUp(diff)
else
turtleController:goDown(diff)
end
currentHeight = currentHeight + diff

k = k + 1
turtleController:tryMove("tA")
end

returnToStartingPos()
return true
end
return Builder_Lib
39 changes: 28 additions & 11 deletions builder.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
--- UI for Builder

---@class Builder_Lib
local builder = require("/progs/builder-prog/builder-lib")
local builder = require("builder-lib")


local function help()
print("Usage:")
print("builder <command> <options>")
print("")
print("Commands: ")
print("- 'floor'")
print("")
print("'floor'")
print("'clearArea'")
print("Options:")
print("-m[movementDirection] <'left'|'right'> [default: right]")
print("-mH[movementDir. Horizon] <'left'|'right'> [default: right]")
print("-mV[movementDir. Vertical] <'down'|'up'> [default: up]")
print("-w[width] <number>")
print("-l[length] <number>")
print("-h[help]")
print("-h[height] <number>")
print("-help")
end
if #arg == 0 then
help()
Expand All @@ -26,16 +27,20 @@ end
local stopExec = false

local size = {
["length"] = 0,
["width"] = 0,
["height"] = 0
["length"] = nil,
["width"] = nil,
["height"] = nil
}

local argsSwitch = {
["-m"] = function(no)
["-mH"] = function(no)
no[1] = no[1] + 1
builder.movementDirection.width = arg[no[1]]
end,
["-mV"] = function (no)
no[1] = no[1] + 1
builder.movementDirection.height = arg[no[1]]
end,
["-l"] = function(no)
no[1] = no[1] + 1
size["length"] = tonumber(arg[no[1]]) or error("length not valid")
Expand All @@ -44,7 +49,16 @@ local argsSwitch = {
no[1] = no[1] + 1
size["width"] = tonumber(arg[no[1]]) or error("width not valid")
end,
["-h"] = function()
["-h"] = function(no)
no[1] = no[1] + 1
if not tonumber(arg[no[1]]) then
help()
stopExec = true
return
end
size["height"] = tonumber(arg[no[1]])
end,
["-help"] = function()
help()
stopExec = true
end,
Expand All @@ -56,6 +70,9 @@ local argsSwitch = {
local commands = {
["floor"] = function()
builder:floor(size["length"], size["width"])
end,
["clearArea"] = function()
builder:clearArea(size["length"], size["width"], size["height"])
end
}

Expand Down
6 changes: 0 additions & 6 deletions ccPackage.lua

This file was deleted.

54 changes: 54 additions & 0 deletions fetch-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# ---- Whats happening ---- #

# This fetches the dependencies listed in the "libs" variable and saves them in the targetFolder



set -e

libs=(
"helperFunctions-lib"
"ccClass-lib"
"testSuite-lib"
"turtleEmulator-lib"
"turtleController-lib"
"eventHandler-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
url="https://raw.githubusercontent.com/$repo/$1/$branch/$FILE"

mkdir -p "$(dirname "$targetFolderName/$FILE")" # create the folder (and subfolders specified in the files.txt)
rm -f $targetFolderName/$FILE.lua # rm existing file
if ! curl -s -o "$targetFolderName/$FILE" "$url"; then
echo "could not get / write the file $i: '$FILE' to the folder '$targetFolderName'"
exit 1
fi
# echo "saved $1: '$FILE' in '$targetFolderName'"
done < <(echo "$files_txt")
}

if [[ $# -eq 0 ]]; then
# No arguments given, fetch all
for i in "${libs[@]}"; do
fetch "$i"
done
else
# Argument given, fetch arguemt
fetch "$1"
fi
Loading
Loading