diff --git a/lama.lua b/lama.lua index 31e7875..0f55c5c 100644 --- a/lama.lua +++ b/lama.lua @@ -21,6 +21,7 @@ local env = getfenv() local fuel = {} local facing = {} local position = {} +local equipment = {} --Fuel tracking fuel.load = function() --loading fuel data @@ -84,6 +85,21 @@ facing.load = function() --loads facing / current movement direction end end +--equipment tracking +equipment.save = function() + local file = fs.open(".lama/equipment","w") + file.write(textutils.serialize({equipment.left,equipment.right}) +end + +equipment.load = function() + if fs.exists(".lama/equipment") then + local file = fs.open(".lama/equipment", "r") + equipment.left, equipment.right = unpack(textutils.unserialize(file.readAll())) + else + equipment = {left={},right={}} --assume nothing + end +end + --position tracking position.save = function() --saves position (x, y, z) position.update() --update the position based on direction and fuel level, then save it to a file @@ -198,6 +214,24 @@ env.refuel = function( n ) --needed because we depend on fuel level return false --otherwise, return false end +env.equipLeft = function() + local tData = turtle.getItemDetail() + local bOk = turtle.equipLeft() + if bOk then + equipment.left = tData + equipment.save + end +end + +env.equipRight = function() + local tData = turtle.getItemDetail() + local bOk = turtle.equipRight() + if bOk then + equipment.right = tData + equipment.save + end +end + env.overwrite = function( t ) --writes env values into the table given t = t or _G.turtle --or, if no value was given, _G.turtle for k, v in pairs( env ) do @@ -231,4 +265,4 @@ fuel.load() fuel.save() position.save() -facing.save() \ No newline at end of file +facing.save()