Last active
December 14, 2015 10:39
-
-
Save refset/5073986 to your computer and use it in GitHub Desktop.
Enter this in the console to save your voxel creations :D ...and then in the distant future some kind soul can work out how to import it so you can look at it again! (this was working with voxel.jit.su on ~2 March 2013)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myobj = [] | |
crunch = {} | |
chunkCache = [] | |
crunch.encode = function(chunk, cb) { | |
var runs = []; | |
var i = 0; | |
while(i<chunk.length) { | |
var v = chunk[i] | |
, l = 0; | |
while(i < chunk.length && chunk[i] === v) { | |
++i; | |
++l; | |
} | |
while(l >= 128) { | |
runs.push(128 + (l&0x7f)); | |
l >>>= 7; | |
} | |
runs.push(l); | |
runs.push(v); | |
} | |
return new Uint8Array(runs); | |
} | |
function sendInitialChunks(emitter) { | |
Object.keys(game.voxels.chunks).map(function(chunkID) { | |
var chunk = game.voxels.chunks[chunkID] | |
var encoded = chunkCache[chunkID] | |
if (!encoded) { | |
encoded = crunch.encode(chunk.voxels) | |
chunkCache[chunkID] = encoded | |
} | |
myobj.push(encoded) | |
}) | |
} | |
sendInitialChunks() | |
JSON.stringify(myobj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment