Access parcel snapshots with scripting

I would love to have the ability to revert to a snapshot through scripting, that would be super useful for a project I’m building.

Thank you and keep up the great work!!
Ricky

3 Likes

Heya, I really like this idea. So much in fact that I had already set it up so that it was easily doable.
I just tested it tonight using this script:

let p
fetch('https://www.cryptovoxels.com/api/parcels/670/snapshots.json').then((r)=>
  r.json()
).then((r)=>{
  let p=r.snapshots[0]
  parcel.setSnapshot(p) 
})

the parcel.setSnapshot() function is not yet available publicly, I just made it on local and it works great, I could probably push it tonight
However three things to remember:
One, when calling a snapshot via scripting, it will not save on the server. (only client can see) Note also that your script will be gone because it will be overwritten
Two, if you edit the parcel AFTER calling setSnapshot it will save the snapshot on the server.
Three, If you try to get the snapshot of another parcel, it will just “cut” all extra voxels that can’t fit in your parcel.
If you’re ok with this, I’ll write another post below for when this is released.

2 Likes

Ok, because the solution above had several security issues, I made something a bit more restricted.

I updated the wiki documentation: Scripting | Cryptovoxels Wiki
I also made a little example in that section:

function myCallback(snapshots){
  parcel.setSnapshot(snapshots[0].id)
}

feature.on('click',e=>{
  parcel.fetchSnapshots(myCallback)
})

These functions are throttled and limited to 500ms

This is out as of v7.15.0

3 Likes

Omg, this is incredible, thank you so much!!! :partying_face: you’re the best @Fayelure

3 Likes

Really awesome feature.

Just to clarify though, the integer reflects the placement of the snapshot on the snapshot list (from most recent), right?

Is this going to change every time a new snapshot is added then? Is there a way to prevent that?

2 Likes

Is just the placement in the list yes, I assume however that 0 is most recent snapshot.

if you don’t want to use the array index, you can just use the snapshot id
eg:

parcel.setSnapshot(15820)

I’m not sure there is a way you can accurately know the snapshot ID, so if you want I can add it next to the snapshot name in the UI

3 Likes

That would be really cool!

And sorry for the very late response…

1 Like

Sweet, it should show up next release
image

3 Likes