milo cleanup + shop

This commit is contained in:
kepler155c@gmail.com
2019-01-11 10:01:37 -05:00
parent 42e72cf3c8
commit bfa528756e
23 changed files with 1141 additions and 101 deletions

View File

@@ -31,7 +31,7 @@ function ExportTask:cycle(context)
if slot then
-- something is in the slot, find what we can export
for key in pairs(entry.filter) do
local filterItem = Milo:splitKey(key)
local filterItem = itemDB:splitKey(key)
if (slot.name == filterItem.name and
(entry.ignoreDamage or slot.damage == filterItem.damage) and
(entry.ignoreNbtHash or slot.nbtHash == filterItem.nbtHash)) then
@@ -50,7 +50,7 @@ function ExportTask:cycle(context)
-- slot is empty - export first matching item we have in storage
for key in pairs(entry.filter) do
local items = Milo:getMatches(Milo:splitKey(key), entry)
local items = Milo:getMatches(itemDB:splitKey(key), entry)
local _, item = next(items)
if item then
local count = math.min(item.count, itemDB:getMaxCount(item))

View File

@@ -17,12 +17,12 @@ function ImportTask:cycle(context)
local function itemMatchesFilter(item)
if not entry.ignoreDamage and not entry.ignoreNbtHash then
local key = Milo:uniqueKey(item)
local key = itemDB:makeKey(item)
return entry.filter[key]
end
for key in pairs(entry.filter) do
local v = Milo:splitKey(key)
local v = itemDB:splitKey(key)
if item.name == v.name and
(entry.ignoreDamage or item.damage == v.damage) and
(entry.ignoreNbtHash or item.nbtHash == v.nbtHash) then

View File

@@ -39,11 +39,12 @@ local manageTab = UI.Window {
}
function manageTab:setItem(item)
self.origItem = item
self.item = Util.shallowCopy(item)
self.res = item.resource or { }
self.item = item
self.res = Util.shallowCopy(context.resources[item.key] or { })
self.res.displayName = self.item.displayName
self.form:setValues(self.res)
-- TODO: ignore damage should not be active if there is not a maxDamage value
end
function manageTab:eventHandler(event)
@@ -51,19 +52,17 @@ function manageTab:eventHandler(event)
UI:setPreviousPage()
elseif event.type == 'form_complete' then
local item = self.item
if self.form:save() then
if self.res.displayName ~= self.origItem.displayName then
self.origItem.displayName = self.res.displayName
itemDB:add(self.origItem)
if self.res.displayName ~= self.item.displayName then
self.item.displayName = self.res.displayName
itemDB:add(self.item)
itemDB:flush()
-- TODO: ugh
if context.storage.cache[self.origItem.key] then
context.storage.cache[self.origItem.key].displayName = self.res.displayName
if context.storage.cache[self.item.key] then
context.storage.cache[self.item.key].displayName = self.res.displayName
end
--context.storage:setDirty()
end
self.res.displayName = nil
Util.prune(self.res, function(v)
if type(v) == 'boolean' then
@@ -75,20 +74,14 @@ function manageTab:eventHandler(event)
end)
local newKey = {
name = item.name,
damage = self.res.ignoreDamage and 0 or item.damage,
nbtHash = not self.res.ignoreNbtHash and item.nbtHash or nil,
name = self.item.name,
damage = self.res.ignoreDamage and 0 or self.item.damage,
nbtHash = not self.res.ignoreNbtHash and self.item.nbtHash or nil,
}
for k,v in pairs(context.resources) do
if v == self.res then
context.resources[k] = nil
break
end
end
context.resources[self.item.key] = nil
if not Util.empty(self.res) then
context.resources[Milo:uniqueKey(newKey)] = self.res
context.resources[itemDB:makeKey(newKey)] = self.res
end
Milo:saveResources()

View File

@@ -1,4 +1,5 @@
local Milo = require('milo')
local itemDB = require('itemDB')
local Milo = require('milo')
local LimitTask = {
name = 'limiter',
@@ -11,7 +12,7 @@ function LimitTask:cycle(context)
if trashcan then
for key,res in pairs(context.resources) do
if res.limit then
local items, count = Milo:getMatches(Milo:splitKey(key), res)
local items, count = Milo:getMatches(itemDB:splitKey(key), res)
if count > res.limit then
local amount = count - res.limit
for _, item in pairs(items) do

View File

@@ -111,7 +111,7 @@ function pages.confirmation:validate()
}
for k,v in pairs(inventory) do
recipe.ingredients[k] = Milo:uniqueKey(v)
recipe.ingredients[k] = itemDB:makeKey(v)
end
Milo:saveMachineRecipe(recipe, result, machine.name)

View File

@@ -25,7 +25,7 @@ function PotionImportTask:cycle(context)
if blazePowder then
context.storage:export(bs, 5, 1, blazePowder)
else
local item = itemDB:get(BLAZE_POWDER) or Milo:splitKey(BLAZE_POWDER)
local item = itemDB:get(BLAZE_POWDER) or itemDB:splitKey(BLAZE_POWDER)
item.requested = 1
Milo:requestCrafting(item)
end
@@ -35,7 +35,7 @@ function PotionImportTask:cycle(context)
-- brewing has completd
if self.brewQueue[bs.name] and list[1] then
local key = Milo:uniqueKey(list[1])
local key = itemDB:makeKey(list[1])
if not Craft.findRecipe(key) then
Milo:saveMachineRecipe(self.brewQueue[bs.name], list[1], bs.name)
end
@@ -68,7 +68,7 @@ function PotionImportTask:cycle(context)
if valid() then
for i = 1, 4 do
recipe.ingredients[i] = Milo:uniqueKey(list[i])
recipe.ingredients[i] = itemDB:makeKey(list[i])
end
self.brewQueue[bs.name] = recipe

View File

@@ -106,7 +106,7 @@ local function client(socket)
local slot = node.adapter.getItemMeta(slotNo)
if slot then
if context.storage:import(node, slotNo, slot.count, slot) > 0 then
local item = Milo:getItem(Milo:listItems(), slot)
local item = Milo:getItem(slot)
if item then
socket:write({
type = 'received',
@@ -127,7 +127,7 @@ local function client(socket)
if count == 'stack' then
count = itemDB:getMaxCount(data.item)
elseif count == 'all' then
local item = Milo:getItem(Milo:listItems(), data.item)
local item = Milo:getItem(data.item)
count = item and item.count or 0
end

View File

@@ -1,3 +1,4 @@
local itemDB = require('itemDB')
local Milo = require('milo')
local ReplenishTask = {
@@ -8,7 +9,7 @@ local ReplenishTask = {
function ReplenishTask:cycle(context)
for k,res in pairs(context.resources) do
if res.low then
local item = Milo:splitKey(k)
local item = itemDB:splitKey(k)
item.key = k
local _, count = Milo:getMatches(item, res)
@@ -27,7 +28,7 @@ function ReplenishTask:cycle(context)
replenish = true,
})
else
local request = context.craftingQueue[Milo:uniqueKey(item)]
local request = context.craftingQueue[itemDB:makeKey(item)]
if request and request.replenish then
--request.count = request.crafted
end

View File

@@ -8,7 +8,7 @@ local Util = require('util')
local colors = _G.colors
local os = _G.os
local config = Config.load('store')
local config = Config.load('shop')
--[[ Display ]]--
local function createPage(node)
@@ -123,18 +123,14 @@ local pages = { }
-- called when an item to sell has been changed
Event.on('store_refresh', function()
config = Config.load('store')
config = Config.load('shop')
end)
Event.on('store_provide', function(_, item, quantity)
local count = 0
for k, v in pairs(config) do
if v.name == item then
count = Milo:eject(itemDB:splitKey(k), quantity)
break
end
end
os.queueEvent('store_provided', item, count)
Event.on('store_provide', function(_, item, quantity, uid)
Milo:queueRequest({ }, function()
local count = Milo:eject(item, quantity)
os.queueEvent('store_provided', uid, count)
end)
end)
--[[ Task ]]--

View File

@@ -55,7 +55,7 @@ local function learnRecipe()
]]--
maxCount = 1
newRecipe.craftingTools[Milo:uniqueKey(tool)] = true
newRecipe.craftingTools[itemDB:makeKey(tool)] = true
v1.craftingTool = true
break
end
@@ -80,7 +80,7 @@ local function learnRecipe()
newRecipe.count = recipe.count
local key = Milo:uniqueKey(recipe)
local key = itemDB:makeKey(recipe)
if recipe.maxCount ~= 64 then
newRecipe.maxCount = recipe.maxCount
end
@@ -88,7 +88,7 @@ local function learnRecipe()
if ingredient.maxDamage > 0 then
-- ingredient.damage = '*' -- I don't think this is right
end
ingredients[k] = Milo:uniqueKey(ingredient)
ingredients[k] = itemDB:makeKey(ingredient)
end
Milo:updateRecipe(key, newRecipe)