recipe book selection

This commit is contained in:
kepler155c
2018-02-19 22:19:01 -05:00
parent 1bee7c97f7
commit 2cfa6c8c7f
17 changed files with 4254 additions and 4078 deletions

View File

@@ -5,6 +5,7 @@ local fs = _G.fs
local turtle = _G.turtle local turtle = _G.turtle
local RECIPES_DIR = 'usr/etc/recipes' local RECIPES_DIR = 'usr/etc/recipes'
local USER_RECIPES = 'usr/config/recipes.db'
local Craft = { } local Craft = { }
@@ -79,18 +80,17 @@ local function turtleCraft(recipe, qty, inventoryAdapter)
end end
function Craft.loadRecipes() function Craft.loadRecipes()
Craft.recipes = Util.readTable(fs.combine(RECIPES_DIR, 'minecraft.db')) or { } Craft.recipes = { }
local files = fs.list('usr/etc/recipes') Util.merge((Util.readTable(fs.combine(RECIPES_DIR, 'minecraft.db')) or { }).recipes)
table.sort(files)
Util.removeByValue(files, 'minecraft.db')
for _,file in ipairs(files) do local config = Util.readTable('usr/config/recipeBooks.db') or { }
local recipes = Util.readTable(fs.combine(RECIPES_DIR, file)) for _, book in pairs(config) do
Util.merge(Craft.recipes, recipes) local recipeFile = Util.readTable(book)
Util.merge(Craft.recipes, recipeFile.recipes)
end end
local recipes = Util.readTable('usr/config/recipes.db') or { } local recipes = Util.readTable(USER_RECIPES) or { }
Util.merge(Craft.recipes, recipes) Util.merge(Craft.recipes, recipes)
end end

View File

@@ -1,4 +1,4 @@
_G.requireInjector() _G.requireInjector(_ENV)
local Ansi = require('ansi') local Ansi = require('ansi')
local Event = require('event') local Event = require('event')

View File

@@ -58,6 +58,9 @@ if device.workbench then
end end
end end
--TODO : find out duck antenna type
duckAntenna = nil
local STATUS_INFO = 'info' local STATUS_INFO = 'info'
local STATUS_WARNING = 'warning' local STATUS_WARNING = 'warning'
local STATUS_ERROR = 'error' local STATUS_ERROR = 'error'

121
apps/recipeBook.lua Normal file
View File

@@ -0,0 +1,121 @@
_G.requireInjector(_ENV)
local Ansi = require('ansi')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local fs = _G.fs
local RECIPES_DIR = 'usr/etc/recipes'
local function getRecipeBooks()
local books = { }
local files = fs.list(RECIPES_DIR)
table.sort(files)
Util.removeByValue(files, 'minecraft.db')
for _,file in ipairs(files) do
local path = fs.combine(RECIPES_DIR, file)
local recipeFile = Util.readTable(path)
if recipeFile then
table.insert(books, {
path = path,
name = recipeFile.name,
version = recipeFile.version,
})
end
end
local config = Util.readTable('usr/config/recipeBooks.db') or { }
for _, book in pairs(config) do
local b = Util.find(books, 'path', book)
if b then
b.enabled = true
end
end
return books
end
local page = UI.Page {
info = UI.Window {
x = 2, ex = -2, y = 2, ey = 5,
button = UI.Button {
ex = -1, y = 2, width = 9,
text = 'Enable',
event = 'grid_select',
}
},
grid = UI.ScrollingGrid {
y = 6,
headerBackgroundColor = colors.black,
headerTextColor = colors.cyan,
columns = {
{ heading = 'Name', key = 'name' },
{ heading = 'Version', key = 'version' },
},
values = getRecipeBooks(),
sortColumn = 'name',
autospace = true,
},
accelerators = {
q = 'quit',
space = 'grid_select',
t = 'terminate',
},
}
function page.info:draw()
local book = self.parent.grid:getSelected()
self:clear()
if book then
self:setCursorPos(1, 1)
self:print(
string.format('Name: %s%s%s\n', Ansi.yellow, book.name, Ansi.reset))
self:print(
string.format('Version: %s%s%s\n', Ansi.yellow, book.version, Ansi.reset))
self.button.text = book.enabled and 'Disable' or 'Enable'
self.button:draw()
end
end
function page.grid:getRowTextColor(row, selected)
if row.enabled then
return colors.white
end
return selected and colors.lightGray or colors.gray
end
function page:save()
local t = { }
for _, book in pairs(self.grid.values) do
if book.enabled then
table.insert(t, book.path)
end
end
Util.writeTable('usr/config/recipeBooks.db', t)
end
function page:eventHandler(event)
if event.type == 'grid_select' then
local recipes = self.grid:getSelected()
recipes.enabled = not recipes.enabled
self.info:draw()
self.grid:draw()
self:save()
elseif event.type == 'grid_focus_row' then
self.info:draw()
elseif event.type == 'quit' then
UI:exitPullEvents()
end
UI.Page.eventHandler(self, event)
end
UI:setPage(page)
UI:pullEvents()

View File

@@ -1,4 +1,7 @@
{ {
name = "Applied Energistics",
version = "MC 1.8+",
recipes = {
[ "appliedenergistics2:quartz_glass:0" ] = { [ "appliedenergistics2:quartz_glass:0" ] = {
ingredients = { ingredients = {
"appliedenergistics2:material:2", "appliedenergistics2:material:2",
@@ -84,4 +87,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Botania",
version = "MC 1.8+",
recipes = {
[ "botania:vial:0" ] = { [ "botania:vial:0" ] = {
ingredients = { ingredients = {
"botania:manaGlass:0", "botania:manaGlass:0",
@@ -448,4 +451,5 @@
}, },
count = 2, count = 2,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Computercraft",
version = "MC 1.8+",
recipes = {
[ "computercraft:turtle_advanced:0" ] = { [ "computercraft:turtle_advanced:0" ] = {
ingredients = { ingredients = {
"minecraft:gold_ingot:0", "minecraft:gold_ingot:0",
@@ -84,4 +87,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "EnderIO",
version = "MC 1.8+",
recipes = {
[ "enderio:blockAlloySmelter:0" ] = { [ "enderio:blockAlloySmelter:0" ] = {
ingredients = { ingredients = {
"minecraft:iron_ingot:0", "minecraft:iron_ingot:0",
@@ -541,4 +544,5 @@
}, },
maxCount = 1, maxCount = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Ex Nihilo",
version = "MC 1.8+",
recipes = {
[ "exnihiloadscensio:blockBarrel1:0" ] = { [ "exnihiloadscensio:blockBarrel1:0" ] = {
ingredients = { ingredients = {
"minecraft:stone:0", "minecraft:stone:0",
@@ -40,4 +43,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Extra Utilities",
version = "MC 1.8+",
recipes = {
[ "extrautils2:decorativesolid:2" ] = { [ "extrautils2:decorativesolid:2" ] = {
ingredients = { ingredients = {
"minecraft:stonebrick:0", "minecraft:stonebrick:0",
@@ -165,4 +168,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Iron Chests",
version = "MC 1.8+",
recipes = {
[ "ironchest:BlockIronChest:0" ] = { [ "ironchest:BlockIronChest:0" ] = {
ingredients = { ingredients = {
"minecraft:iron_ingot:0", "minecraft:iron_ingot:0",
@@ -111,4 +114,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Mekanism",
version = "MC 1.8+",
recipes = {
[ "mekanism:EnergyTablet:0:3a153e5a66ba42a2d96ffd50ba64918b" ] = { [ "mekanism:EnergyTablet:0:3a153e5a66ba42a2d96ffd50ba64918b" ] = {
ingredients = { ingredients = {
"minecraft:redstone:0", "minecraft:redstone:0",
@@ -55,4 +58,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Minecraft",
version = "",
recipes = {
[ "minecraft:flint_and_steel:0" ] = { [ "minecraft:flint_and_steel:0" ] = {
count = 1, count = 1,
ingredients = { ingredients = {
@@ -2345,4 +2348,5 @@
[ 7 ] = "minecraft:planks:5", [ 7 ] = "minecraft:planks:5",
}, },
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Mystical Agriculture",
version = "MC 1.8+",
recipes = {
[ "mysticalagriculture:supremium_ingot:0" ] = { [ "mysticalagriculture:supremium_ingot:0" ] = {
ingredients = { ingredients = {
[ 10 ] = "mysticalagriculture:supremium_essence:0", [ 10 ] = "mysticalagriculture:supremium_essence:0",
@@ -175,4 +178,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "RFTools",
version = "MC 1.8+",
recipes = {
[ "rftools:crafter1:0" ] = { [ "rftools:crafter1:0" ] = {
ingredients = { ingredients = {
[ 10 ] = "minecraft:redstone_torch:0", [ 10 ] = "minecraft:redstone_torch:0",
@@ -123,4 +126,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Storage Drawers",
version = "MC 1.8+",
recipes = {
[ "storagedrawers:upgradeStorage:4" ] = { [ "storagedrawers:upgradeStorage:4" ] = {
ingredients = { ingredients = {
"minecraft:emerald:0", "minecraft:emerald:0",
@@ -27,4 +30,5 @@
}, },
count = 1, count = 1,
}, },
},
} }

View File

@@ -1,4 +1,7 @@
{ {
name = "Tinkers Construct",
version = "MC 1.8+",
recipes = {
[ "minecraft:book:0" ] = { [ "minecraft:book:0" ] = {
ingredients = { ingredients = {
"minecraft:paper:0", "minecraft:paper:0",
@@ -34,3 +37,4 @@
count = 8, count = 8,
}, },
} }
}