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