mirror of
https://github.com/kepler155c/opus
synced 2025-10-21 10:47:40 +00:00
transitions and Lua improvements
This commit is contained in:
38
apps/Lua.lua
38
apps/Lua.lua
@@ -15,7 +15,7 @@ UI:configure('Lua', ...)
|
||||
local command = ''
|
||||
local history = History.load('.lua_history', 25)
|
||||
|
||||
local resultsPage = UI.Page({
|
||||
local page = UI.Page({
|
||||
menuBar = UI.MenuBar({
|
||||
buttons = {
|
||||
{ text = 'Local', event = 'local' },
|
||||
@@ -47,7 +47,7 @@ local resultsPage = UI.Page({
|
||||
notification = UI.Notification(),
|
||||
})
|
||||
|
||||
function resultsPage:setPrompt(value, focus)
|
||||
function page:setPrompt(value, focus)
|
||||
self.prompt:setValue(value)
|
||||
self.prompt.scroll = 0
|
||||
self.prompt:setPosition(#value)
|
||||
@@ -59,29 +59,29 @@ function resultsPage:setPrompt(value, focus)
|
||||
|
||||
self.prompt:draw()
|
||||
if focus then
|
||||
resultsPage:setFocus(self.prompt)
|
||||
page:setFocus(self.prompt)
|
||||
end
|
||||
end
|
||||
|
||||
function resultsPage:enable()
|
||||
function page:enable()
|
||||
self:setFocus(self.prompt)
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
|
||||
function resultsPage:eventHandler(event)
|
||||
function page:eventHandler(event)
|
||||
|
||||
if event.type == 'global' then
|
||||
resultsPage:setPrompt('', true)
|
||||
page:setPrompt('', true)
|
||||
self:executeStatement('getfenv(0)')
|
||||
command = nil
|
||||
|
||||
elseif event.type == 'local' then
|
||||
resultsPage:setPrompt('', true)
|
||||
page:setPrompt('', true)
|
||||
self:executeStatement('getfenv(1)')
|
||||
command = nil
|
||||
|
||||
elseif event.type == 'device' then
|
||||
resultsPage:setPrompt('device', true)
|
||||
page:setPrompt('device', true)
|
||||
self:executeStatement('device')
|
||||
|
||||
elseif event.type == 'history_back' then
|
||||
@@ -128,7 +128,7 @@ function resultsPage:eventHandler(event)
|
||||
return true
|
||||
end
|
||||
|
||||
function resultsPage:setResult(result)
|
||||
function page:setResult(result)
|
||||
local t = { }
|
||||
|
||||
local function safeValue(v)
|
||||
@@ -169,7 +169,7 @@ function resultsPage:setResult(result)
|
||||
self:draw()
|
||||
end
|
||||
|
||||
function resultsPage.grid:eventHandler(event)
|
||||
function page.grid:eventHandler(event)
|
||||
|
||||
local entry = self:getSelected()
|
||||
|
||||
@@ -199,18 +199,18 @@ function resultsPage.grid:eventHandler(event)
|
||||
|
||||
if event.type == 'grid_focus_row' then
|
||||
if self.focused then
|
||||
resultsPage:setPrompt(commandAppend())
|
||||
page:setPrompt(commandAppend())
|
||||
end
|
||||
elseif event.type == 'grid_select' then
|
||||
resultsPage:setPrompt(commandAppend(), true)
|
||||
resultsPage:executeStatement(commandAppend())
|
||||
page:setPrompt(commandAppend(), true)
|
||||
page:executeStatement(commandAppend())
|
||||
else
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function resultsPage:rawExecute(s)
|
||||
function page:rawExecute(s)
|
||||
|
||||
local fn, m = loadstring("return (" .. s .. ')', 'lua')
|
||||
if not fn then
|
||||
@@ -225,7 +225,7 @@ function resultsPage:rawExecute(s)
|
||||
return fn, m
|
||||
end
|
||||
|
||||
function resultsPage:executeStatement(statement)
|
||||
function page:executeStatement(statement)
|
||||
|
||||
command = statement
|
||||
|
||||
@@ -242,6 +242,12 @@ function resultsPage:executeStatement(statement)
|
||||
end
|
||||
end
|
||||
|
||||
UI:setPage(resultsPage)
|
||||
sandboxEnv.args = { ... }
|
||||
if sandboxEnv.args[1] then
|
||||
command = 'args[1]'
|
||||
page:setResult(sandboxEnv.args[1])
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
Event.pullEvents()
|
||||
UI.term:reset()
|
||||
|
@@ -75,7 +75,7 @@ local systemPage = UI.Page {
|
||||
value = 'Label'
|
||||
},
|
||||
label = UI.TextEntry {
|
||||
x = 9, y = 2, rex = -12,
|
||||
x = 9, y = 2, rex = -4,
|
||||
limit = 32,
|
||||
value = os.getComputerLabel(),
|
||||
backgroundFocusColor = colors.black,
|
||||
|
@@ -212,7 +212,7 @@ function enderChestUnload()
|
||||
|
||||
turtle.select(1)
|
||||
turtle.drop(64)
|
||||
turtle.digDown()
|
||||
turtle.digDown()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -246,8 +246,9 @@ function makeWalkableTunnel(action, tpt, pt)
|
||||
if action ~= 'turn' and not Point.compare(tpt, { x = 0, z = 0 }) then -- not at source
|
||||
if not Point.compare(tpt, pt) then -- not at dest
|
||||
local r, block = turtle.inspectUp()
|
||||
if r and block.name ~= 'minecraft:cobblestone' then
|
||||
if block.name ~= 'minecraft:chest' then
|
||||
if r and not turtle.isTurtleAtSide('top') then
|
||||
if block.name ~= 'minecraft:cobblestone' and
|
||||
block.name ~= 'minecraft:chest' then
|
||||
turtle.digUp()
|
||||
end
|
||||
end
|
||||
@@ -483,7 +484,10 @@ function boreCommand()
|
||||
|
||||
turtle.clearMoveCallback()
|
||||
|
||||
-- location is either mined, currently being mined or is the
|
||||
-- dropoff point for a turtle
|
||||
if inspect(turtle.getAction('up'), 'minecraft:cobblestone') or
|
||||
inspect(turtle.getAction('up'), 'minecraft:chest') or
|
||||
inspect(turtle.getAction('down'), 'minecraft:cobblestone') then
|
||||
return true
|
||||
end
|
||||
|
Reference in New Issue
Block a user