Profile
- Name
- Restore State
- ID
- 45180
- Shared with
- Public
- Parent
- None
- Children
- Created on
- January 14, 2013 at 11:12 AM UTC
- Updated on
- January 14, 2013 at 11:12 AM UTC
- Description
Restores frozens, secondary structure and bands from chosen save slot.
Best for
Code
safePoint=1
saveSlot=2
restoreStructs=true
restoreFrozens=true
restoreBands=true
segs=structure.GetCount()
bands={}
frozens={}
sheets={}
helices={}
function GetSegFromDist(seg, dist)
for i=1, segs do
if structure.GetDistance(i,seg)==dist then return i end
end
end
function GetBands()
for i=1, band.GetCount() do
rope=band.AddToBandEndpoint(safePoint,i)
len1=band.GetLength(i)
len2=band.GetLength(rope)
band.Delete(rope)
bandEnd1=GetSegFromDist(1, len2)
bandEnd2=GetSegFromDist(bandEnd1, len1)
table.insert(bands,{bandEnd1, bandEnd2})
end
end
function RestoreSheets()
for i=1, #sheets do selection.Select(sheets[i]) end
structure.SetSecondaryStructureSelected('e')
selection.DeselectAll()
end
function RestoreHelices()
for i=1, #helices do selection.Select(helices[i]) end
structure.SetSecondaryStructureSelected('h')
selection.DeselectAll()
end
function GetStructs()
for i=1, segs do
local s=structure.GetSecondaryStructure(i)
if s=='E' then table.insert(sheets, i)
elseif s=='H' then table.insert(helices, i)
end
end
end
function GetFrozens()
for i=1, segs do
b, s=freeze.IsFrozen(i)
if b or s then table.insert(frozens, {i, b, s}) end
end
end
function RestoreFrozens()
for i=1, #frozens do
freeze.Unfreeze(frozens[i][1], frozens[i][2], frozens[i][3])
end
end
function RestoreBands()
for i=1, #bands do
band.AddBetweenSegments(bands[i][1], bands[i][2])
end
end
function main()
AskOptions()
save.Quicksave(1)
save.Quickload(saveSlot)
if restoreBands then GetBands() end
if restoreStructs then GetStructs() end
if restoreFrozens then GetFrozens() end
save.Quickload(1)
if restoreBands and #bands>0 then RestoreBands() end
if restoreStructs then
if #helices>0 then RestoreHelices() end
if #sheets>0 then RestoreSheets() end
end
if restoreFrozens and #frozens>0 then RestoreFrozens() end
end
function AskOptions()
local ask=dialog.CreateDialog('Restore State')
ask.l2=dialog.AddLabel('Choose a save slot from 1-99')
ask.saveSlot=dialog.AddSlider('Save slot', saveSlot, 1, 99, 0)
ask.restoreStructs=dialog.AddCheckbox('Restore structs', restoreStructs)
ask.restoreFrozens=dialog.AddCheckbox('Restore frozens', restoreFrozens)
ask.restoreBands=dialog.AddCheckbox('Restore bands', restoreBands)
ask.l2=dialog.AddLabel('Choose a segment with no bands')
ask.safePoint=dialog.AddSlider('Safe point', safePoint, 1, segs, 0)
ask.OK = dialog.AddButton("OK",1)
ask.Cancel = dialog.AddButton("Cancel",0)
if dialog.Show(ask)>0 then
safePoint=ask.safePoint.value
saveSlot=ask.saveSlot.value
restoreStructs=ask.restoreStructs.value
restoreFrozens=ask.restoreFrozens.value
restoreBands=ask.restoreBands.value
end
end
main()