Author Topic: PyBLS (Blockland Save File Library for Python)  (Read 8085 times)

What it is
So if you have Python 2.7 or above (untested on lower versions) and you have a decent amount of knowledge of python this could become handy if your a lazy fatass. This basically is a 50 line class that you can use to write save files.

How to use
A quote from the example:

if __name__ == "__main__":
   import random
   bs = BlocklandSave('ASuperFunTest.bls',8437)
   cnt = 100
   size = 100
   data = "4x Cube"
   for i in range(cnt):
      pos = str(int(random.random() * size)) + " " + str(int(random.random() * size)) + " " + str(int(random.random() * size))
      bs.addBrickLine(data,pos,0,0,0,0,0,-1,1,1,1,8437)
   bs.finish()

I think you can figure it out yourself. :)
It's a zip file, since theres this long boring part i just call a prefix (prefix.txt) where you can change the colorsets and stuff, so you go to the colorset.txt of your colorset.


0.900 0.000 0.000 1.000
0.900 0.900 0.000 1.000
0.000 0.500 0.250 1.000
0.200 0.000 0.800 1.000
0.900 0.900 0.900 1.000
0.750 0.750 0.750 1.000
0.500 0.500 0.500 1.000
0.200 0.200 0.200 1.000
100 50 0 255
DIV:Standard

230 87 20 255
191 46 123 255
99 0 30 255
34 69 69 255
0 36 85 255
27 117 196 255
255 255 255 255
20 20 20 255
255 255 255 64
DIV:Bold

236 131 173 255
255 154 108 255
255 224 156 255
244 224 200 255
200 235 125 255
138 178 141 255
143 237 245 255
178 169 231 255
224 143 244 255
DIV:Soft

0.667 0.000 0.000 0.700
1.000 0.500 0.000 0.700
0.990 0.960 0.000 0.700
0.000 0.471 0.196 0.700
0.000 0.200 0.640 0.700
152 41 100 178
0.550 0.700 1.000 0.700
0.850 0.850 0.850 0.700
0.100 0.100 0.100 0.700
DIV:Transparent



Then you just remove the line breaks and the DIV lines, also make sure they are all in decimal format (i think that matters, do not know), by taking the hole numbers and dividing them by 255.
Then in the output you'll get something like...


0.898039 0.000000 0.000000 1.000000
0.898039 0.898039 0.000000 1.000000
0.000000 0.498039 0.247059 1.000000
0.200000 0.000000 0.800000 1.000000
0.898039 0.898039 0.898039 1.000000
0.749020 0.749020 0.749020 1.000000
0.498039 0.498039 0.498039 1.000000
0.200000 0.200000 0.200000 1.000000
0.392157 0.192157 0.000000 1.000000
0.901961 0.337255 0.078431 1.000000
0.749020 0.176471 0.482353 1.000000
0.384314 0.000000 0.113725 1.000000
0.129412 0.266667 0.266667 1.000000
0.000000 0.137255 0.329412 1.000000
0.101961 0.458824 0.764706 1.000000
1.000000 1.000000 1.000000 1.000000
0.078431 0.078431 0.078431 1.000000
1.000000 1.000000 1.000000 0.247059
0.921569 0.513726 0.674510 1.000000
1.000000 0.603922 0.419608 1.000000
1.000000 0.874510 0.611765 1.000000
0.956863 0.874510 0.784314 1.000000
0.784314 0.921569 0.486275 1.000000
0.537255 0.694118 0.549020 1.000000
0.556863 0.929412 0.956863 1.000000
0.694118 0.658824 0.901961 1.000000
0.874510 0.556863 0.956863 1.000000
0.666667 0.000000 0.000000 0.698039
1.000000 0.498039 0.000000 0.698039
0.988235 0.956863 0.000000 0.698039
0.000000 0.470588 0.192157 0.698039
0.000000 0.200000 0.639216 0.698039
0.592157 0.156863 0.392157 0.694118
0.549020 0.698039 1.000000 0.698039
0.847059 0.847059 0.847059 0.698039
0.098039 0.098039 0.098039 0.698039


Then for all the extra lines just add in a bunch of lines that say
1.000000 0.000000 1.000000 0.000000
Until the line count is exactly 64
So in the end you'll see

0.898039 0.000000 0.000000 1.000000
0.898039 0.898039 0.000000 1.000000
0.000000 0.498039 0.247059 1.000000
0.200000 0.000000 0.800000 1.000000
0.898039 0.898039 0.898039 1.000000
0.749020 0.749020 0.749020 1.000000
0.498039 0.498039 0.498039 1.000000
0.200000 0.200000 0.200000 1.000000
0.392157 0.192157 0.000000 1.000000
0.901961 0.337255 0.078431 1.000000
0.749020 0.176471 0.482353 1.000000
0.384314 0.000000 0.113725 1.000000
0.129412 0.266667 0.266667 1.000000
0.000000 0.137255 0.329412 1.000000
0.101961 0.458824 0.764706 1.000000
1.000000 1.000000 1.000000 1.000000
0.078431 0.078431 0.078431 1.000000
1.000000 1.000000 1.000000 0.247059
0.921569 0.513726 0.674510 1.000000
1.000000 0.603922 0.419608 1.000000
1.000000 0.874510 0.611765 1.000000
0.956863 0.874510 0.784314 1.000000
0.784314 0.921569 0.486275 1.000000
0.537255 0.694118 0.549020 1.000000
0.556863 0.929412 0.956863 1.000000
0.694118 0.658824 0.901961 1.000000
0.874510 0.556863 0.956863 1.000000
0.666667 0.000000 0.000000 0.698039
1.000000 0.498039 0.000000 0.698039
0.988235 0.956863 0.000000 0.698039
0.000000 0.470588 0.192157 0.698039
0.000000 0.200000 0.639216 0.698039
0.592157 0.156863 0.392157 0.694118
0.549020 0.698039 1.000000 0.698039
0.847059 0.847059 0.847059 0.698039
0.098039 0.098039 0.098039 0.698039
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000
1.000000 0.000000 1.000000 0.000000


Then go to the file thats titled prefix.txt, you'll see a bunch of lines similar to this, just replace them with the new colorsets, making sure not to remove the line break. Thats all.

Now where do I get this stuff?
Right here! It includes:
BlocklandSave.py - What you import
prefix.txt - Must be in same directory
ASuperFunTest.bls - A file generated with this.

Enjoy! (btw i wrote everything, incase you wondered)



So this is basically completely pointless?

So this is basically completely pointless?
;~; if you don't know/use pyhon, then duh. It's a python library type thing.

I mean, what could this be used for, it doesn't look like it does anything but randomly generating bricks and then saving them...

I mean, what could this be used for, it doesn't look like it does anything but randomly generating bricks and then saving them...
It makes making valid BLS files much loving easier. Instead of writing out a ton of this stupid file writing code, you can just initalize the object, use obj.addBrickLine(self,ui,pos,angle,baseplate,color,prnt,fx,shapefx,raycasting,colliding,rendering,owner) and to write it just do obj.finish(), and it automatically does the rest. :|

Or just build it

cuz thats alot easier

Or just build it

cuz thats alot easier
or maybe you don't really understand the concept of oh i dont know
this is in another language for script generated saves? Unless you can build that...

I understand the concept, but it seems it has no use besides generating the save, what about the bricks?

I understand the concept, but it seems it has no use besides generating the save, what about the bricks?
Thats what you input, it just converts it to a proper BLS file, which if you (like me) dont want to take the time to figure out then write a script to writeout, you can just have this nifty dynamic library do it for you.

Wouldn't this be more useful in Torquescript? That would be better for terrain generation and such.

Okay then.

Make a GUI for it and foolproof it into not making overlapping bricks and that would be cool.
Wouldn't this be more useful in Torquescript? That would be better for terrain generation and such.
Let's say you were using not blockland for generating saves for whatever strange reason
you could use this

TorqueScript is slower than python. Also at the same time Blockland is doing a ton of other things on top of your generations, in python unless your running anything else in python, python is only doing your code. Plus Python is neatest and easier to read, it's also much harder to make messy. GUI's would be handicapped because this is for people who want to use it in code, and it's nearly impossible to determine if the bricks are going to overlap since you use the UI name. :)

It is most certainly not impossible