1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-21 18:57:41 +00:00

builder upgrade

This commit is contained in:
kepler155c@gmail.com
2017-04-01 19:21:49 -04:00
parent 74e93068fb
commit 72bd16502b
14 changed files with 977 additions and 160 deletions

View File

@@ -96,15 +96,13 @@ function blockDB:seedDB(dir)
end
lastID = strId
local sep = string.find(line[2], ':')
if not sep then
nid = tonumber(line[2])
dmg = 0
else
nid = tonumber(string.sub(line[2], 1, sep - 1))
dmg = tonumber(string.sub(line[2], sep + 1, #line[2]))
local t = { }
string.gsub(line[2], '(%d+)', function(d) table.insert(t, d) end)
nid = tonumber(t[1])
dmg = 0
if t[2] then
dmg = tonumber(t[2])
end
self:add(nid, dmg, name, strId)
end
@@ -653,13 +651,13 @@ function blockTypeDB:seedDB()
})
blockTypeDB:addTemp('piston', { -- piston placement is broken in 1.7 -- need to add work around
{ 0, nil, 0, 'piston-down' },
{ 1, nil, 0 },
{ 1, nil, 0, 'piston-up' },
{ 2, nil, 0, 'piston-north' },
{ 3, nil, 0, 'piston-south' },
{ 4, nil, 0, 'piston-west' },
{ 5, nil, 0, 'piston-east' },
{ 8, nil, 0, 'piston-down' },
{ 9, nil, 0 },
{ 9, nil, 0, 'piston-up' },
{ 10, nil, 0, 'piston-north' },
{ 11, nil, 0, 'piston-south' },
{ 12, nil, 0, 'piston-west' },

View File

@@ -54,7 +54,9 @@ function ChestProvider:getItemInfo(id, dmg)
item.max_size = stack.max_size
end
end
return item
if item.name then
return item
end
end
function ChestProvider:craft(id, dmg, qty)
@@ -79,7 +81,13 @@ function ChestProvider:provide(item, qty, slot)
end
end
end
function ChestProvider:extract(slot, qty)
if self.p then
self.p.pushItem(self.direction, slot, qty)
end
end
function ChestProvider:insert(slot, qty)
if self.p then
local s, m = pcall(function() self.p.pullItem(self.direction, slot, qty) end)

View File

@@ -0,0 +1,103 @@
local class = require('class')
local Logger = require('logger')
local ChestProvider = class()
function ChestProvider:init(args)
args = args or { }
self.stacks = {}
self.name = 'chest'
self.direction = args.direction or 'up'
self.wrapSide = args.wrapSide or 'bottom'
self.p = peripheral.wrap(self.wrapSide)
end
function ChestProvider:isValid()
return self.p and self.p.list
end
function ChestProvider:refresh()
if self.p then
--self.p.condenseItems()
self.stacks = self.p.list()
local t = { }
for _,s in pairs(self.stacks) do
s.id = s.name
s.dmg = s.damage
s.qty = s.count
local key = s.id .. ':' .. s.dmg
if t[key] and t[key].qty < 64 then
t[key].max_size = t[key].qty
else
t[key] = {
qty = s.qty
}
end
end
for _,s in ipairs(self.stacks) do
local key = s.id .. ':' .. s.dmg
if t[key].max_size then
s.max_size = t[key].qty
else
s.max_size = 64
end
end
end
return self.stacks
end
function ChestProvider:getItemInfo(id, dmg)
local item = { id = id, dmg = dmg, qty = 0, max_size = 64 }
for k,stack in pairs(self.stacks) do
if stack.id == id and stack.dmg == dmg then
local meta = self.p.getItemMeta(k)
if meta then
item.name = meta.displayName
item.qty = item.qty + meta.count
item.max_size = meta.maxCount
end
end
end
if item.name then
return item
end
end
function ChestProvider:craft(id, dmg, qty)
return false
end
function ChestProvider:craftItems(items)
end
function ChestProvider:provide(item, qty, slot)
if self.p then
self:refresh()
for key,stack in pairs(self.stacks) do
if stack.id == item.id and stack.dmg == item.dmg then
local amount = math.min(qty, stack.qty)
self.p.pushItems(self.direction, key, amount, slot)
qty = qty - amount
if qty <= 0 then
break
end
end
end
end
end
function ChestProvider:extract(slot, qty)
if self.p then
self.p.pushItems(self.direction, slot, qty)
end
end
function ChestProvider:insert(slot, qty)
if self.p then
self.p.pullItems(self.direction, slot, qty)
end
end
return ChestProvider

View File

@@ -1,6 +1,21 @@
local Peripheral = { }
function Peripheral.addDevice(side)
local function getDeviceList()
if _G.device then
return _G.device
end
local deviceList = { }
for _,side in pairs(peripheral.getNames()) do
Peripheral.addDevice(deviceList, side)
end
return deviceList
end
function Peripheral.addDevice(deviceList, side)
local name = side
local ptype = peripheral.getType(side)
@@ -28,33 +43,33 @@ function Peripheral.addDevice(side)
if sides[name] then
local i = 1
local uniqueName = ptype
while device[uniqueName] do
while deviceList[uniqueName] do
uniqueName = ptype .. '_' .. i
i = i + 1
end
name = uniqueName
end
device[name] = peripheral.wrap(side)
Util.merge(device[name], {
deviceList[name] = peripheral.wrap(side)
Util.merge(deviceList[name], {
name = name,
type = ptype,
side = side,
})
return device[name]
return deviceList[name]
end
function Peripheral.getBySide(side)
return Util.find(device, 'side', side)
return Util.find(getDeviceList(), 'side', side)
end
function Peripheral.getByType(typeName)
return Util.find(device, 'type', typeName)
return Util.find(getDeviceList(), 'type', typeName)
end
function Peripheral.getByMethod(method)
for _,p in pairs(device) do
for _,p in pairs(getDeviceList()) do
if p[method] then
return p
end

View File

@@ -438,6 +438,7 @@ end
function Manager:pullEvents(...)
Event.pullEvents(...)
self.term:reset()
end
function Manager:exitPullEvents()
@@ -1075,7 +1076,7 @@ function UI.TransitionSlideLeft:update(device)
self.canvas:blit(device, {
x = self.x,
y = self.y,
ex = self.ex - x + self.x + 1,
ex = self.ex - x + self.x,
ey = self.ey },
{ x = x, y = self.y })
end
@@ -1108,13 +1109,13 @@ function UI.TransitionSlideRight:update(device)
self.lastScreen:blit(device, {
x = self.x,
y = self.y,
ex = self.ex - x + self.x + 1,
ex = self.ex - x + self.x,
ey = self.ey },
{ x = x, y = self.y })
self.canvas:blit(device, {
x = self.ex - x + self.x,
y = self.y,
ex = self.ex + 1,
ex = self.ex,
ey = self.ey },
{ x = self.x, y = self.y })
end
@@ -1431,8 +1432,6 @@ end
UI.Grid = class(UI.Window)
UI.Grid.defaults = {
UIElement = 'Grid',
x = 1,
y = 1,
index = 1,
inverseSort = false,
disableHeader = false,
@@ -2571,7 +2570,7 @@ UI.StatusBar.defaults = {
function UI.StatusBar:init(args)
local defaults = UI:getDefaults(UI.StatusBar, args)
UI.GridLayout.init(self, defaults)
self:setStatus(self.status)
self:setStatus(self.status, true)
end
function UI.StatusBar:setParent()
@@ -2583,12 +2582,15 @@ function UI.StatusBar:setParent()
end
end
function UI.StatusBar:setStatus(status)
function UI.StatusBar:setStatus(status, noDraw)
if type(status) == 'string' then
self.values[1] = { status = status }
else
self.values[1] = status
end
if not noDraw then
self:draw()
end
end
function UI.StatusBar:setValue(name, value)
@@ -2796,7 +2798,8 @@ function UI.TextEntry:updateScroll()
elseif self.pos < self.scroll then
self.scroll = self.pos
end
-- debug('p:%d s:%d w:%d l:%d', self.pos, self.scroll, self.width, self.limit)
--debug('p:%d s:%d w:%d l:%d', self.pos, self.scroll, self.width, self.limit)
end
function UI.TextEntry:draw()
@@ -2910,7 +2913,7 @@ function UI.TextEntry:eventHandler(event)
return true
elseif event.type == 'mouse_click' then
if self.focused then
if self.focused and event.x > 1 then
self.pos = event.x + self.scroll - 2
self:updateCursor()
return true
@@ -3166,7 +3169,7 @@ function UI.Dialog:init(args)
titleBar = UI.TitleBar({ previousPage = true, title = defaults.title }),
})
UI.setProperties(defaults, args)
--UI.setProperties(defaults, args)
UI.Page.init(self, defaults)
end
@@ -3266,8 +3269,8 @@ function UI.NftImage:setImage(image)
end
UI:loadTheme('config/ui.theme')
if _HOST and string.find(_HOST, 'CCEmuRedux') then
UI:loadTheme('config/ccemuredux.theme')
if os.getVersion() >= 1.79 then
UI:loadTheme('config/ext.theme')
end
UI:setDefaultDevice(UI.Device({ device = term.current() }))

View File

@@ -4,5 +4,5 @@ require = requireInjector(getfenv(1))
local Peripheral = require('peripheral')
for _,side in pairs(peripheral.getNames()) do
Peripheral.addDevice(side)
Peripheral.addDevice(device, side)
end

View File

@@ -90,6 +90,16 @@ function os.isPocket()
return not not pocket
end
function os.getVersion()
if _CC_VERSION then
return tonumber(_CC_VERSION)
end
if _HOST then
return tonumber(_HOST:gmatch('[%d]+%.?[%d][%d]', '%1')())
end
return 1.7
end
function os.registerApp(entry)
local apps = { }
Config.load('apps', apps)

View File

@@ -14,7 +14,7 @@ end
Event.addHandler('peripheral', function(event, side)
if side then
local dev = Peripheral.addDevice(side)
local dev = Peripheral.addDevice(device, side)
if dev then
term.setTextColor(attachColor)
Util.print('[%s] %s attached', dev.side, dev.name)