1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-25 16:10:26 +00:00

version checking + ui cleanup

This commit is contained in:
kepler155c@gmail.com 2017-10-12 17:58:35 -04:00
parent 3460dd68b2
commit a9634cb438
6 changed files with 48 additions and 37 deletions

View File

@ -226,7 +226,7 @@ local function pathTo(dest, options)
-- use single turn method so the turtle doesn't turn around -- use single turn method so the turtle doesn't turn around
-- when encountering obstacles -- IS THIS RIGHT ?? -- when encountering obstacles -- IS THIS RIGHT ??
if not turtle.gotoSingleTurn(pt.x, pt.z, pt.y, node.heading) then if not turtle.gotoSingleTurn(pt.x, pt.z, pt.y) then
table.insert(blocks, pt) table.insert(blocks, pt)
--if device.turtlesensorenvironment then --if device.turtlesensorenvironment then
-- addSensorBlocks(blocks, device.turtlesensorenvironment.sonicScan()) -- addSensorBlocks(blocks, device.turtlesensorenvironment.sonicScan())

View File

@ -453,21 +453,12 @@ end
function Manager:getDefaults(element, args) function Manager:getDefaults(element, args)
local defaults = Util.deepCopy(element.defaults) local defaults = Util.deepCopy(element.defaults)
if args then if args then
Manager:setProperties(defaults, args) Manager:mergeProperties(defaults, args)
end end
return defaults return defaults
end end
function Manager:pullEvents(...) function Manager:mergeProperties(obj, args)
Event.pullEvents(...)
self.term:reset()
end
function Manager:exitPullEvents()
Event.exitPullEvents()
end
function Manager:setProperties(obj, args)
if args then if args then
for k,v in pairs(args) do for k,v in pairs(args) do
if k == 'accelerators' then if k == 'accelerators' then
@ -483,6 +474,15 @@ function Manager:setProperties(obj, args)
end end
end end
function Manager:pullEvents(...)
Event.pullEvents(...)
self.term:reset()
end
function Manager:exitPullEvents()
Event.exitPullEvents()
end
function Manager:dump(inEl) function Manager:dump(inEl)
if inEl then if inEl then
local function clean(el) local function clean(el)
@ -526,12 +526,12 @@ UI.Window.defaults = {
function UI.Window:init(args) function UI.Window:init(args)
-- merge defaults for all subclasses -- merge defaults for all subclasses
local defaults = args local defaults = args
local m = self local m = getmetatable(self) -- get the class for this instance
repeat repeat
defaults = UI:getDefaults(m, defaults) defaults = UI:getDefaults(m, defaults)
m = m._base m = m._base
until not m until not m
UI:setProperties(self, defaults) UI:mergeProperties(self, defaults)
-- each element has a unique ID -- each element has a unique ID
self.uid = UI.Window.uid self.uid = UI.Window.uid
@ -546,13 +546,8 @@ function UI.Window:init(args)
local lpi local lpi
repeat repeat
if m.postInit and m.postInit ~= lpi then if m.postInit and m.postInit ~= lpi then
--debug('calling ' .. m.defaults.UIElement)
--debug(rawget(m, 'postInit'))
m.postInit(self) m.postInit(self)
lpi = m.postInit lpi = m.postInit
-- else
--debug('skipping ' .. m.defaults.UIElement)
--debug(rawget(m, 'postInit'))
end end
m = m._base m = m._base
until not m until not m
@ -661,7 +656,7 @@ function UI.Window:resize()
end end
function UI.Window:add(children) function UI.Window:add(children)
UI:setProperties(self, children) UI:mergeProperties(self, children)
self:initChildren() self:initChildren()
end end
@ -2007,7 +2002,7 @@ function UI.MenuBar:addButtons(buttons)
centered = false, centered = false,
} }
self.lastx = self.lastx + buttonProperties.width self.lastx = self.lastx + buttonProperties.width
UI:setProperties(buttonProperties, button) UI:mergeProperties(buttonProperties, button)
button = UI[self.buttonClass](buttonProperties) button = UI[self.buttonClass](buttonProperties)
if button.name then if button.name then
@ -3158,7 +3153,7 @@ function UI.NftImage:setImage(image)
end end
UI:loadTheme('usr/config/ui.theme') UI:loadTheme('usr/config/ui.theme')
if Util.getVersion() >= 1.79 then if Util.getVersion() >= 1.76 then
UI:loadTheme('sys/etc/ext.theme') UI:loadTheme('sys/etc/ext.theme')
end end

View File

@ -79,15 +79,36 @@ function Util.getVersion()
local version local version
if _G._CC_VERSION then if _G._CC_VERSION then
version = tonumber(_G._CC_VERSION:gmatch('[%d]+%.?[%d][%d]', '%1')()) version = tonumber(_G._CC_VERSION:match('[%d]+%.?[%d][%d]'))
end end
if not version and _G._HOST then if not version and _G._HOST then
version = tonumber(_G._HOST:gmatch('[%d]+%.?[%d][%d]', '%1')()) version = tonumber(_G._HOST:match('[%d]+%.?[%d][%d]'))
end end
return version or 1.7 return version or 1.7
end end
function Util.getMinecraftVersion()
local mcVersion = _G._MC_VERSION or 'unknown'
if _G._HOST then
local version = _G._HOST:match('%S+ %S+ %((%S.+)%)')
if version then
mcVersion = version:match('Minecraft (%S+)') or version
end
end
return mcVersion
end
function Util.checkMinecraftVersion(minVersion)
local version = Util.getMinecraftVersion()
local function convert(v)
local m1, m2, m3 = v:match('(%d)%.(%d)%.?(%d?)')
return tonumber(m1) * 10000 + tonumber(m2) * 100 + (tonumber(m3) or 0)
end
return convert(version) >= convert(tostring(minVersion))
end
-- http://lua-users.org/wiki/SimpleRound -- http://lua-users.org/wiki/SimpleRound
function Util.round(num, idp) function Util.round(num, idp)
local mult = 10^(idp or 0) local mult = 10^(idp or 0)

View File

@ -15,14 +15,6 @@ local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'System') multishell.setTitle(multishell.getCurrent(), 'System')
UI:configure('System', ...) UI:configure('System', ...)
local mcVersion = _G._MC_VERSION or 'unknown'
if _G._HOST then
local version = _G._HOST:match('%S+ %S+ %((%S.+)%)')
if version then
mcVersion = version:match('Minecraft (%S+)') or version
end
end
local env = { local env = {
path = shell.path(), path = shell.path(),
aliases = shell.aliases(), aliases = shell.aliases(),
@ -129,7 +121,7 @@ local systemPage = UI.Page {
{ name = '', value = '' }, { name = '', value = '' },
{ name = 'CC version', value = Util.getVersion() }, { name = 'CC version', value = Util.getVersion() },
{ name = 'Lua version', value = _VERSION }, { name = 'Lua version', value = _VERSION },
{ name = 'MC version', value = mcVersion }, { name = 'MC version', value = Util.getMinecraftVersion() },
{ name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) }, { name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) },
{ name = 'Computer ID', value = tostring(os.getComputerID()) }, { name = 'Computer ID', value = tostring(os.getComputerID()) },
{ name = 'Day', value = tostring(os.day()) }, { name = 'Day', value = tostring(os.day()) },

View File

@ -246,10 +246,10 @@
[ "a2accffe95b2c8be30e8a05e0c6ab7e8f5966f43" ] = { [ "a2accffe95b2c8be30e8a05e0c6ab7e8f5966f43" ] = {
title = "Strafe", title = "Strafe",
category = "Games", category = "Games",
icon = "\030f\031f \03131\0308\031f \030f\031d2\ icon = "\0308\031f \0300 \0308 \
\030f\031f \031d2\03131\0308\031f \030f\03131\ \0308\031f \0300 \030f \
\030f\03131\0308\031f \030f\03131\031e3", \0300\031f \030f ",
run = "https://pastebin.com/raw/bj3qj1Pj", run = "https://pastebin.com/raw/jyDH7mLH",
}, },
[ "48d6857f6b2869d031f463b13aa34df47e18c548" ] = { [ "48d6857f6b2869d031f463b13aa34df47e18c548" ] = {
title = "Breakout", title = "Breakout",

View File

@ -695,6 +695,9 @@ function turtle.goto(dx, dz, dy, dh)
return true return true
end end
-- avoid lint errors
turtle._goto = turtle.goto
function turtle.gotoX(dx) function turtle.gotoX(dx)
turtle.headTowardsX(dx) turtle.headTowardsX(dx)