Skip to content

Commit 72a1934

Browse files
committed
feat: Init Floor
1 parent 8350b01 commit 72a1934

File tree

11 files changed

+451
-0
lines changed

11 files changed

+451
-0
lines changed

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Busted
2+
3+
4+
on: [push, pull_request]
5+
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: checkout
13+
uses: actions/checkout@v2
14+
with:
15+
submodules: true
16+
17+
- name: get lua
18+
uses: leafo/gh-actions-lua@v10
19+
with:
20+
luaVersion: "5.1"
21+
22+
- name: get luarocks
23+
uses: leafo/gh-actions-luarocks@v4
24+
with:
25+
luaVersion: "5.1"
26+
27+
- name: get busted and luasocket
28+
run: |
29+
luarocks install busted
30+
luarocks install luasocket
31+
luarocks install luasec
32+
33+
- name: Git Submodule Update
34+
run: |
35+
git pull --recurse-submodules
36+
git submodule update --init --remote --recursive
37+
38+
- name: test
39+
run: |
40+
busted tests

.gitmodules

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[submodule "turtleController-lib"]
2+
path = turtleController-lib
3+
url = https://github.com/mc-cc-scripts/turtleController-lib.git
4+
branch = master
5+
[submodule "turtleEmulator-lib"]
6+
path = turtleEmulator-lib
7+
url = https://github.com/mc-cc-scripts/turtleEmulator-lib.git
8+
branch = master

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Lua.diagnostics.globals": [
3+
"describe",
4+
"before_each",
5+
"it",
6+
"xit",
7+
"pending"
8+
]
9+
}

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
11
# builder-prog
22
Will be our all in one building program
3+
4+
# Current Functions
5+
6+
7+
8+
### help
9+
10+
11+
```lua
12+
-- Returns all available commands
13+
builder help
14+
```
15+
16+
### floor
17+
18+
```lua
19+
-- Builds a floor with the specified size.
20+
-- Uses the Item in Slot 1 as Buildingblock!
21+
builder floor -w <width> -l <length> -m <"left"|"right">
22+
```
23+
24+
# Dev - Documentaion
25+
26+
### Submodules used
27+
- turtleControler-lib
28+
- turtleEmulator-lib
29+
- - plus submodules

builder-lib.lua

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---@class Builder_Lib
2+
local Builder_Lib = {
3+
movementDirection = {
4+
height = "bottom",
5+
width = "right"
6+
}
7+
}
8+
9+
10+
---@class SCM
11+
local scm = require("scm")
12+
13+
---@class turtleController
14+
local turtleController = scm:load("turtleController")
15+
16+
turtleController.canBreakBlocks = true
17+
18+
local function selectItemToPlace(itemname)
19+
local item = turtle.getItemDetail()
20+
if item == nil or item.name ~= itemname then
21+
local slot = turtleController:findItemInInventory(itemname)
22+
if slot == nil then
23+
error("No more blocks available to build")
24+
end
25+
turtle.select(slot)
26+
end
27+
end
28+
29+
local function placeDownItem(itemname)
30+
selectItemToPlace(itemname)
31+
if turtle.detectDown() then
32+
local _, down = turtle.inspectDown()
33+
print("Fond block to replace: ", down.name)
34+
turtleController:tryAction("digD")
35+
end
36+
local succ, txt = turtle.placeDown()
37+
if not succ then error(txt) end
38+
end
39+
40+
local function returnToStartingPos()
41+
42+
end
43+
44+
---builds the floor with the given size
45+
---@param length number
46+
---@param width number
47+
function Builder_Lib:floor(length, width)
48+
49+
local t
50+
if self.movementDirection.width == "right" then
51+
t = function(modulo)
52+
if modulo == 1 then
53+
turtle.turnRight()
54+
else
55+
turtle.turnLeft()
56+
end
57+
end
58+
else
59+
t = function(modulo)
60+
if modulo == 1 then
61+
turtle.turnLeft()
62+
else
63+
turtle.turnRight()
64+
end
65+
end
66+
end
67+
68+
turtle.select(1)
69+
local block = turtle.getItemDetail()
70+
if block == nil then error("No block at item slot 1") end
71+
for j = 1, width, 1 do
72+
for i = 1, length - 1, 1 do
73+
placeDownItem(block.name)
74+
turtleController:goStraight(1)
75+
end
76+
placeDownItem(block.name)
77+
if (j < width) then
78+
t(j % 2)
79+
turtleController:goStraight(1)
80+
t(j % 2)
81+
end
82+
end
83+
returnToStartingPos()
84+
end
85+
return Builder_Lib

builder.lua

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
--- UI for Builder
2+
3+
---@class SCM
4+
local scm = require("scm")
5+
6+
---@class Builder_Lib
7+
local builder = require("/libs/builder-prog/builder-lib")
8+
9+
10+
local function help()
11+
print("Usage:")
12+
print("builder <command> <options>")
13+
print("")
14+
print("Commands: ")
15+
print("- 'floor'")
16+
print("")
17+
print("Options:")
18+
print("-m[movementDirection] <'left'|'right'> [default: right]")
19+
print("-w[width] <number>")
20+
print("-l[length] <number>")
21+
print("-h[help]")
22+
end
23+
if #arg == 0 then
24+
help()
25+
return
26+
end
27+
28+
29+
local stopExec = false
30+
31+
local size = {
32+
["length"] = 0,
33+
["width"] = 0,
34+
["height"] = 0
35+
}
36+
37+
local argsSwitch = {
38+
["-m"] = function(no)
39+
no[1] = no[1] + 1
40+
builder.movementDirection.width = arg[no[1]]
41+
end,
42+
["-l"] = function(no)
43+
no[1] = no[1] + 1
44+
size["length"] = tonumber(arg[no[1]]) or error("length not valid")
45+
end,
46+
["-w"] = function(no)
47+
no[1] = no[1] + 1
48+
size["width"] = tonumber(arg[no[1]]) or error("width not valid")
49+
end,
50+
["-h"] = function()
51+
help()
52+
stopExec = true
53+
end,
54+
["help"] = function()
55+
help()
56+
stopExec = true
57+
end
58+
}
59+
local commands = {
60+
["floor"] = function()
61+
builder:floor(size["length"], size["width"])
62+
end
63+
}
64+
65+
66+
local function main()
67+
-- table to allow manipulation in argsSwitch
68+
local currentArgNo = {2}
69+
while currentArgNo[1] <= #arg do
70+
if argsSwitch[arg[currentArgNo[1]]] == nil then
71+
help()
72+
return
73+
end
74+
argsSwitch[arg[currentArgNo[1]]](currentArgNo)
75+
currentArgNo[1] = currentArgNo[1] + 1
76+
end
77+
if stopExec then return end
78+
79+
if commands[arg[1]] == nil then
80+
help()
81+
return
82+
end
83+
commands[arg[1]]()
84+
end
85+
86+
main()

ccPackage.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local spath =
2+
debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$","")
3+
package.path = spath.."?.lua;"
4+
.. spath.."turtleController-lib/?.lua;"
5+
.. package.path
6+
require(spath.."turtleEmulator-lib/ccPackage")

files.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
builder.lua
2+
builder-lib.lua

0 commit comments

Comments
 (0)