mirror of
https://github.com/kepler155c/opus
synced 2024-12-24 23:50:26 +00:00
new icon set + scanning miner
This commit is contained in:
parent
e6a98b34cb
commit
ecb3af4672
@ -144,14 +144,21 @@ function Point.calculateMoves(pta, ptb, distance)
|
||||
end
|
||||
end
|
||||
|
||||
if ptb.heading then
|
||||
if heading ~= ptb.heading then
|
||||
moves = moves + Point.calculateTurns(heading, ptb.heading)
|
||||
heading = ptb.heading
|
||||
end
|
||||
if not ptb.heading then
|
||||
return moves, heading, moves
|
||||
end
|
||||
|
||||
return moves, heading
|
||||
-- calc turns as slightly less than moves
|
||||
local weighted = moves
|
||||
if heading ~= ptb.heading then
|
||||
local turns = Point.calculateTurns(heading, ptb.heading)
|
||||
moves = moves + turns
|
||||
local wturns = { [0] = 0, [1] = .9, [2] = 1.9 }
|
||||
weighted = weighted + wturns[turns]
|
||||
heading = ptb.heading
|
||||
end
|
||||
|
||||
return moves, heading, weighted
|
||||
end
|
||||
|
||||
-- given a set of points, find the one taking the least moves
|
||||
@ -164,7 +171,7 @@ function Point.closest(reference, pts)
|
||||
for _,pt in pairs(pts) do
|
||||
local distance = Point.turtleDistance(reference, pt)
|
||||
if distance < lm then
|
||||
local m = Point.calculateMoves(reference, pt, distance)
|
||||
local _, _, m = Point.calculateMoves(reference, pt, distance)
|
||||
if m < lm then
|
||||
lpt = pt
|
||||
lm = m
|
||||
|
@ -32,9 +32,9 @@ local config = {
|
||||
Config.load('Overview', config)
|
||||
|
||||
local applications = { }
|
||||
local extSupport = Util.getVersion() >= 1.76
|
||||
|
||||
local function loadApplications()
|
||||
|
||||
local requirements = {
|
||||
turtle = function() return turtle end,
|
||||
advancedTurtle = function() return turtle and term.isColor() end,
|
||||
@ -117,7 +117,7 @@ local function parseIcon(iconText)
|
||||
icon = NFT.parse(iconText)
|
||||
if icon then
|
||||
if icon.height > 3 or icon.width > 8 then
|
||||
error('Invalid size')
|
||||
error('Must be an NFT image - 3 rows, 8 cols max')
|
||||
end
|
||||
end
|
||||
return icon
|
||||
@ -174,6 +174,10 @@ local page = UI.Page {
|
||||
},
|
||||
}
|
||||
|
||||
if extSupport then
|
||||
page.container.backgroundColor = colors.black
|
||||
end
|
||||
|
||||
UI.Icon = class(UI.Window)
|
||||
UI.Icon.defaults = {
|
||||
UIElement = 'Icon',
|
||||
@ -194,7 +198,6 @@ function UI.Icon:eventHandler(event)
|
||||
end
|
||||
|
||||
function page.container:setCategory(categoryName, animate)
|
||||
|
||||
-- reset the viewport window
|
||||
self.children = { }
|
||||
self.offy = 0
|
||||
@ -231,7 +234,10 @@ function page.container:setCategory(categoryName, animate)
|
||||
for _,program in ipairs(filtered) do
|
||||
|
||||
local icon
|
||||
if program.icon then
|
||||
if extSupport and program.iconExt then
|
||||
icon = parseIcon(program.iconExt)
|
||||
end
|
||||
if not icon and program.icon then
|
||||
icon = parseIcon(program.icon)
|
||||
end
|
||||
if not icon then
|
||||
@ -344,7 +350,6 @@ function page:resize()
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
|
||||
if event.type == 'tab_select' then
|
||||
self.container:setCategory(event.button.text, true)
|
||||
self.container:draw()
|
||||
@ -455,7 +460,10 @@ function editor:enable(app)
|
||||
self.form:setValues(app)
|
||||
|
||||
local icon
|
||||
if app.icon then
|
||||
if extSupport and app.iconExt then
|
||||
icon = parseIcon(app.iconExt)
|
||||
end
|
||||
if not icon and app.icon then
|
||||
icon = parseIcon(app.icon)
|
||||
end
|
||||
self.form.image:setImage(icon)
|
||||
@ -479,7 +487,6 @@ function editor:updateApplications(app)
|
||||
end
|
||||
|
||||
function editor:eventHandler(event)
|
||||
|
||||
if event.type == 'form_cancel' or event.type == 'cancel' then
|
||||
UI:setPreviousPage()
|
||||
|
||||
@ -501,13 +508,17 @@ function editor:eventHandler(event)
|
||||
local s, m = pcall(function()
|
||||
local iconLines = Util.readFile(fileName)
|
||||
if not iconLines then
|
||||
error('Unable to load file')
|
||||
error('Must be an NFT image - 3 rows, 8 cols max')
|
||||
end
|
||||
local icon, m = parseIcon(iconLines)
|
||||
if not icon then
|
||||
error(m)
|
||||
end
|
||||
self.form.values.icon = iconLines
|
||||
if extSupport then
|
||||
self.form.values.iconExt = iconLines
|
||||
else
|
||||
self.form.values.icon = iconLines
|
||||
end
|
||||
self.form.image:setImage(icon)
|
||||
self.form.image:draw()
|
||||
end)
|
||||
|
@ -1,10 +1,13 @@
|
||||
{
|
||||
[ "53ebc572b4a44802ba114729f07bdaaf5409a9d7" ] = {
|
||||
title = "Network",
|
||||
category = "Apps",
|
||||
icon = "\0304 \030 \
|
||||
\030f \0304 \0307 \030 \031 \031f)\
|
||||
\030f \0304 \0307 \030 \031f)",
|
||||
title = "Network",
|
||||
iconExt = "\030 \031f \0305\031f\140\030f\0315\137\144\
|
||||
\030 \031f\030f\0314\131\131\0304\031f\148\030 \0305\155\150\149\
|
||||
\030 \031f\030f\0310\147\0300\031f\141\0304\149\0307\0318\149\030 ",
|
||||
run = "Network.lua",
|
||||
},
|
||||
c7116629a6a855cb774d9c7c8ad822fd83c71fb5 = {
|
||||
@ -21,6 +24,9 @@
|
||||
icon = "\0301\03171\03180\030 \031 \
|
||||
\0301\03181\030 \031 \
|
||||
\0301\03170\03180\03171\0307\031f>",
|
||||
iconExt = "\031f\128\0315\152\131\131\132\031f\128\
|
||||
\0315\139\159\129\0305\031f\159\129\139\
|
||||
\031f\128\0315\136\0305\031f\143\143\030f\0315\134\031f\128",
|
||||
run = "http://pastebin.com/raw/UzGHLbNC",
|
||||
},
|
||||
c47ae15370cfe1ed2781eedc1dc2547d12d9e972 = {
|
||||
@ -29,6 +35,9 @@
|
||||
icon = " \031f?\031 \
|
||||
\031f?\031 \
|
||||
\031f?",
|
||||
iconExt = "\0300\031f\129\030f\0310\131\0300\031f\148\030f\0310\148\
|
||||
\030 \031 \0300\031f\131\030f\0310\142\129\
|
||||
\030 \031 \0300\031f\131\030f\128",
|
||||
run = "Help.lua",
|
||||
},
|
||||
b0832074630eb731d7fbe8074de48a90cd9bb220 = {
|
||||
@ -53,6 +62,9 @@
|
||||
icon = " \0307\031f| \
|
||||
\0307\031f---o\030 \031 \
|
||||
\0307\031f| ",
|
||||
iconExt = "\0318\138\0308\031f\130\0318\128\031f\129\030f\0318\133\
|
||||
\0318\143\0308\128\0317\143\0318\128\030f\143\
|
||||
\0318\138\135\143\139\133",
|
||||
run = "System.lua",
|
||||
},
|
||||
c5497bca58468ae64aed6c0fd921109217988db3 = {
|
||||
@ -69,6 +81,9 @@
|
||||
icon = "\030f\031f \0315/\
|
||||
\030f\031f \0315/\\/ \
|
||||
\030f\0315/\031f ",
|
||||
iconExt = "\031f\128\128\0305\159\030f\128\0305\159\030f\0315\134\031f\128\
|
||||
\031f\128\0315\152\129\137\0305\031f\158\139\030f\0315\144\
|
||||
\0315\134\031f\128\128\128\128\0305\154\030f\0315\144",
|
||||
run = "Tasks.lua",
|
||||
},
|
||||
[ "6ce6c512ea433a7fc5c8841628e7696cd0ff7f2b" ] = {
|
||||
@ -77,6 +92,9 @@
|
||||
icon = "\0300\0317==\031 \0307 \
|
||||
\0300\0317====\
|
||||
\0300\0317====",
|
||||
iconExt = "\030 \031f\0300\031f\136\140\132\0308\130\030f\0318\144\
|
||||
\030 \031f\030f\0310\157\0300\031f\147\030f\0310\142\143\149\
|
||||
\030 \031f\0300\031f\136\140\132\140\030f\0310\149",
|
||||
run = "Files.lua",
|
||||
},
|
||||
[ "7fddb7d8d1d60b1eeefa9af01082e0811d4b484d" ] = {
|
||||
@ -127,6 +145,9 @@
|
||||
icon = "\030d \030 \030e \030 \
|
||||
\030d \030 \
|
||||
\030d ",
|
||||
iconExt = "\030 \031f\0305\031f\151\030f\0315\135\131\0305\031f\146\
|
||||
\030 \031f\030f\0315\130\141\0305\031f\139\030f\0315\130\
|
||||
\030 \031f\0305\031f\146\143\030f\0315\158\031e\130",
|
||||
run = "/rom/programs/fun/worm",
|
||||
},
|
||||
[ "9f46ca3ef617166776ef6014a58d4e66859caa62" ] = {
|
||||
@ -135,6 +156,9 @@
|
||||
icon = " \030f \
|
||||
\030f \0307 \
|
||||
\030f \0307 \0300 ",
|
||||
iconExt = "\031f\128\0307\143\131\131\131\131\143\030f\128\
|
||||
\0307\031f\129\0317\128\0319\136\0309\031b\136\132\0307\0319\132\0317\128\031f\130\
|
||||
\0317\130\143\0307\128\128\128\128\030f\143\129",
|
||||
run = "/rom/programs/fun/dj",
|
||||
},
|
||||
}
|
||||
|
@ -662,11 +662,11 @@ function turtle._goto(pt)
|
||||
local dx, dy, dz, dh = pt.x, pt.y, pt.z, pt.heading
|
||||
if not turtle.gotoSingleTurn(dx, dy, dz, dh) then
|
||||
if not gotoMultiTurn(dx, dy, dz) then
|
||||
return false
|
||||
return false, 'Failed to reach location'
|
||||
end
|
||||
end
|
||||
turtle.setHeading(dh)
|
||||
return true
|
||||
return pt
|
||||
end
|
||||
|
||||
-- avoid lint errors
|
||||
@ -738,6 +738,8 @@ function turtle.getSlot(indexOrId, slots)
|
||||
}
|
||||
end
|
||||
|
||||
-- inconsistent return value
|
||||
-- null is returned if indexOrId is a string and no item is present
|
||||
return {
|
||||
qty = 0, -- deprecate
|
||||
count = 0,
|
||||
@ -794,8 +796,12 @@ function turtle.getSummedInventory()
|
||||
end
|
||||
|
||||
function turtle.has(item, count)
|
||||
local slot = turtle.getSummedInventory()[item]
|
||||
return slot and slot.count >= (count or 1)
|
||||
if item:match('.*:%d') then
|
||||
local slot = turtle.getSummedInventory()[item]
|
||||
return slot and slot.count >= (count or 1)
|
||||
end
|
||||
local slot = turtle.getSlot(item)
|
||||
return slot and slot.count > 0
|
||||
end
|
||||
|
||||
function turtle.getFilledSlots(startSlot)
|
||||
@ -966,6 +972,18 @@ function turtle.addWorldBlock(pt)
|
||||
Pathing.addBlock(pt)
|
||||
end
|
||||
|
||||
local movementStrategy = turtle.pathfind
|
||||
|
||||
function turtle.setMovementStrategy(strategy)
|
||||
if strategy == 'pathing' then
|
||||
movementStrategy = turtle.pathfind
|
||||
elseif strategy == 'goto' then
|
||||
movementStrategy = turtle._goto
|
||||
else
|
||||
error('Invalid movement strategy')
|
||||
end
|
||||
end
|
||||
|
||||
function turtle.faceAgainst(pt, options) -- 4 sided
|
||||
options = options or { }
|
||||
options.dest = { }
|
||||
@ -980,7 +998,7 @@ function turtle.faceAgainst(pt, options) -- 4 sided
|
||||
})
|
||||
end
|
||||
|
||||
return turtle.pathfind(Point.closest(turtle.point, options.dest), options)
|
||||
return movementStrategy(Point.closest(turtle.point, options.dest), options)
|
||||
end
|
||||
|
||||
-- move against this point
|
||||
@ -1012,7 +1030,7 @@ function turtle.moveAgainst(pt, options) -- 6 sided
|
||||
})
|
||||
end
|
||||
|
||||
return turtle.pathfind(Point.closest(turtle.point, options.dest), options)
|
||||
return movementStrategy(Point.closest(turtle.point, options.dest), options)
|
||||
end
|
||||
|
||||
local actionsAt = {
|
||||
@ -1097,7 +1115,7 @@ local function _actionAt(action, pt, ...)
|
||||
direction = 'up'
|
||||
end
|
||||
|
||||
if turtle.pathfind(apt) then
|
||||
if movementStrategy(apt) then
|
||||
return action[direction](...)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user