added FlipVertical to blockrotation.py, called it from MCSchematic.flipVertical
This commit is contained in:
parent
887092de05
commit
6cac9bb5fa
@ -1,6 +1,14 @@
|
||||
from materials import alphaMaterials
|
||||
from numpy import array, arange, zeros
|
||||
|
||||
def genericVerticalFlip(cls):
|
||||
rotation = arange(16, dtype='uint8')
|
||||
if hasattr(cls, "Up") and hasattr(cls, "Down"):
|
||||
rotation[cls.Up] = cls.Down
|
||||
rotation[cls.Down] = cls.Up
|
||||
|
||||
return rotation
|
||||
|
||||
def genericRotation(cls):
|
||||
rotation = arange(16, dtype='uint8')
|
||||
rotation[cls.North] = cls.West
|
||||
@ -25,6 +33,8 @@ rotationClasses = [];
|
||||
|
||||
def genericFlipRotation(cls):
|
||||
cls.rotateLeft = genericRotation(cls)
|
||||
|
||||
cls.flipVertical = genericVerticalFlip(cls)
|
||||
cls.flipEastWest = genericEastWestFlip(cls)
|
||||
cls.flipNorthSouth = genericNorthSouthFlip(cls)
|
||||
rotationClasses.append(cls)
|
||||
@ -300,10 +310,13 @@ applyPistonBit = applyBit8
|
||||
class PistonBody:
|
||||
blocktypes = [alphaMaterials.StickyPiston.ID, alphaMaterials.Piston.ID]
|
||||
|
||||
Down = 0
|
||||
Up = 1
|
||||
East = 2
|
||||
West = 3
|
||||
North = 4
|
||||
South = 5
|
||||
|
||||
genericFlipRotation(PistonBody)
|
||||
applyPistonBit(PistonBody.rotateLeft)
|
||||
applyPistonBit(PistonBody.flipEastWest)
|
||||
@ -313,23 +326,28 @@ class PistonHead(PistonBody):
|
||||
blocktypes = [alphaMaterials.PistonHead.ID]
|
||||
rotationClasses.append(PistonHead)
|
||||
|
||||
def masterRotationTable(rotationFunc):
|
||||
def masterRotationTable(attrname):
|
||||
# compute a 256x16 table mapping each possible blocktype/data combination to
|
||||
# the resulting data when the block is rotated
|
||||
table = zeros((256, 16), dtype='uint8')
|
||||
table[:] = arange(16, dtype='uint8')
|
||||
for cls in rotationClasses:
|
||||
for blocktype in cls.blocktypes:
|
||||
table[blocktype] = rotationFunc(cls)
|
||||
if hasattr(cls, attrname):
|
||||
blocktable = getattr(cls, attrname)
|
||||
for blocktype in cls.blocktypes:
|
||||
table[blocktype] = blocktable
|
||||
|
||||
return table
|
||||
|
||||
class BlockRotation:
|
||||
rotateLeft = masterRotationTable(lambda cls:cls.rotateLeft);
|
||||
flipEastWest = masterRotationTable(lambda cls:cls.flipEastWest);
|
||||
flipNorthSouth = masterRotationTable(lambda cls:cls.flipNorthSouth);
|
||||
rotateLeft = masterRotationTable("rotateLeft");
|
||||
flipEastWest = masterRotationTable("flipEastWest");
|
||||
flipNorthSouth = masterRotationTable("flipNorthSouth");
|
||||
flipVertical = masterRotationTable("flipVertical");
|
||||
|
||||
|
||||
def FlipVertical(blocks, data):
|
||||
data[:] = BlockRotation.flipVertical[blocks, data]
|
||||
|
||||
def FlipNorthSouth(blocks, data):
|
||||
data[:] = BlockRotation.flipNorthSouth[blocks, data]
|
||||
|
@ -268,6 +268,7 @@ class MCSchematic (MCLevel):
|
||||
|
||||
def flipVertical(self):
|
||||
" xxx delete stuff "
|
||||
blockrotation.FlipVertical(self.Blocks, self.Data);
|
||||
self.Blocks = self.Blocks[:, :, ::-1]; #y=-y
|
||||
self.Data = self.Data[:, :, ::-1];
|
||||
|
||||
@ -475,6 +476,9 @@ def extractZipSchematicFrom(sourceLevel, box, zipfilename=None, entities=True):
|
||||
#converts classic blocks to alpha
|
||||
#probably should only apply to alpha levels
|
||||
|
||||
if zipfilename is None:
|
||||
zipfilename = tempfile.mktemp("zipschematic")
|
||||
|
||||
p = sourceLevel.adjustExtractionParameters(box);
|
||||
if p is None: return
|
||||
sourceBox, destPoint = p
|
||||
@ -515,6 +519,8 @@ def extractZipSchematicFrom(sourceLevel, box, zipfilename=None, entities=True):
|
||||
|
||||
import shutil
|
||||
shutil.rmtree(filename)
|
||||
import mclevel
|
||||
return mclevel.fromFile(zipfilename)
|
||||
|
||||
MCLevel.extractZipSchematic = extractZipSchematicFrom
|
||||
|
||||
|
13
tests.py
13
tests.py
@ -177,6 +177,7 @@ class TestSchematics(unittest.TestCase):
|
||||
def setUp(self):
|
||||
#self.alphaLevel = TempLevel("Dojo_64_64_128.dat")
|
||||
self.indevlevel = TempLevel("hell.mclevel")
|
||||
self.alphalevel = TempLevel("PyTestWorld")
|
||||
|
||||
def testCreate(self):
|
||||
#info("Schematic from indev")
|
||||
@ -184,7 +185,6 @@ class TestSchematics(unittest.TestCase):
|
||||
size = (64, 64, 64)
|
||||
schematic = MCSchematic(shape=size, filename="hell.schematic", mats='Classic');
|
||||
level = self.indevlevel.level
|
||||
schematic.rotateLeft();
|
||||
|
||||
self.failUnlessRaises(ValueError, lambda:(
|
||||
schematic.copyBlocksFrom(level, BoundingBox((-32, -32, -32), (64, 64, 64,)), (0, 0, 0))
|
||||
@ -213,6 +213,17 @@ class TestSchematics(unittest.TestCase):
|
||||
except ValueError:
|
||||
pass
|
||||
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
|
||||
def testRotate(self):
|
||||
level = self.indevlevel.level
|
||||
schematic = level.extractSchematic(level.bounds)
|
||||
schematic.rotateLeft()
|
||||
schematic.flipNorthSouth()
|
||||
schematic.flipVertical()
|
||||
|
||||
def testZipSchematic(self):
|
||||
level = self.alphalevel.level
|
||||
zs = level.extractZipSchematic(level.bounds)
|
||||
assert(level.chunkCount == zs.chunkCount)
|
||||
|
||||
def testINVEditChests(self):
|
||||
info("INVEdit chest")
|
||||
|
Reference in New Issue
Block a user