Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB commands, Add conditional commands to chain. #672

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def transformConfig(self):
self.reset()
return

"""if version == "1.1.2.0":
if self.config.get("Commands","sorting") == "xz":
self.config.set("Commands","Sorting","xyz")
elif self.config.get("Commands","sorting") == "zx":
self.config.set("Commands","Sorting","zyx")
elif self.config.get("Commands","sorting") == "chain":
self.config.set("Commands","Sorting","xyz")
else:
self.config.set("Commands","Sorting","xyz")
version = "1.1.2.1"
self.config.set("Version", "version", version)
self.save()"""
if version == "1.1.1.1":
n = 1
for (name, value) in self.config.items("Keys"):
Expand Down Expand Up @@ -600,7 +612,11 @@ def copy(self):
("override", "Override", False)
],
("commands", "Commands"): [
("sorting", "Sorting", "chain"),
("sorting", "Sorting","xyz"),
("invertX", "Invert X", False),
("invertY", "Invert Y", False),
("invertZ", "Invert Z", False),
("groupchains", "Group Chains", True),
("space", "Space", True),
("fileFormat", "File Format", "txt")
],
Expand Down
65 changes: 56 additions & 9 deletions editortools/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,17 +1231,39 @@ def openCommands(self):
file = open(filename, 'w')
first = True
space = config.commands.space.get()
sorting = config.commands.sorting.get()
from collections import namedtuple
SortingTuple=namedtuple('sorting','order invertX invertY invertZ')
GroupingTuple=namedtuple('grouping','chains')
sorting=SortingTuple(
order = config.commands.sorting.get(),
invertX = config.commands.invertX.get(),
invertY = config.commands.invertY.get(),
invertZ = config.commands.invertZ.get()
)
grouping = GroupingTuple(chains=config.commands.groupchains.get())
edit = fileEdit(filename, os.path.getmtime(filename), self.editor.selectionBox(), self.editor,
self.editor.level)

order = []
if sorting == "chain":
if grouping.chains:
skip = []
done = []
chainStored = []
for coords in GetSort(self.editor.selectionBox(), sorting):
(x, y, z) = coords
if sorting.order == "xyz":
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I may have the order backwards. I was very confused on the sort order when writing this. Should sort XYZ currently does ittertool.product(z,y,x). Meaning we move across X axis first, rather than last.

I am pretty sure this is backwards, but when looking at the CB on the screen it's what I seem to think it means.

(z, y, x) = coords
elif sorting.order == "xzy":
(y, z, x) = coords
elif sorting.order == "yxz":
(z, x, y) = coords
elif sorting.order == "yzx":
(x, z, y) = coords
elif sorting.order == "zxy":
(y, x, z) = coords
elif sorting.order == "zyx":
(x, y, z) = coords
else:
(z, y, x) = coords
if (x,y,z) in skip:
skip.remove((x,y,z))
continue
Expand All @@ -1250,22 +1272,32 @@ def openCommands(self):
chainStored.append((x, y, z))
continue
if blockID == 137 or blockID == 210:
edit.writeCommandInFile(first, space, (x,y,z), file, skip, True, done, order)
edit.writeCommandInFile(first, space, (x,y,z), file, skip, True, done, order, grouping)
first = False
for (x, y, z) in chainStored:
if (x, y, z) in done:
continue
edit.writeCommandInFile(first, space, (x,y,z), file, skip, True, done, order)
edit.writeCommandInFile(first, space, (x,y,z), file, skip, True, done, order, grouping)

else:
for coords in GetSort(self.editor.selectionBox(), sorting):
if sorting == "xz":
if sorting.order == "xyz":
(z, y, x) = coords
elif sorting.order == "xzy":
(y, z, x) = coords
elif sorting.order == "yxz":
(z, x, y) = coords
elif sorting.order == "yzx":
(x, z, y) = coords
elif sorting.order == "zxy":
(y, x, z) = coords
elif sorting.order == "zyx":
(x, y, z) = coords
else:
(z, y, x) = coords
blockID = self.editor.level.blockAt(x, y, z)
if blockID == 137 or blockID == 210 or blockID == 211:
edit.writeCommandInFile(first, space, (x,y,z), file, None, False, None, order)
edit.writeCommandInFile(first, space, (x,y,z), file, None, False, None, order, grouping)
first = False
file.close()
if first:
Expand Down Expand Up @@ -1293,9 +1325,24 @@ def __init__(self):

empty = Label("")

self.sorting = ChoiceButton(["chain", "xz", "zx"], choose=self.changeSorting)
self.sorting = ChoiceButton(["xyz", "xzy","yxz", "yzx","zxy", "zyx"], choose=self.changeSorting)
self.sorting.selectedChoice = config.commands.sorting.get()
sortingRow = Row((Label("Sort Order"), self.sorting))
sortingInvert = Row((Label("Invert:"),CheckBoxLabel("X",
tooltipText="Sort from Positive X to Negative X",
ref=config.commands.invertX),
CheckBoxLabel("Y",
tooltipText="Sort from Positive Y to Negative Y",
ref=config.commands.invertY),
CheckBoxLabel("Z",
tooltipText="Sort from Positive Z to Negative Z",
ref=config.commands.invertZ)))
# Grouping Methods. Perhaps multiple can be used simultaneously?
groupchain = Row((Label("Group"),
CheckBoxLabel("Chains",
tooltipText="Group chain command blocks, in execution order. NOTE: An initiating impulse or repeating block must be present for grouping to work.",
ref=config.commands.groupchains)))

space = CheckBoxLabel("Space between lines",
tooltipText="Make space between the lines",
ref=config.commands.space)
Expand All @@ -1304,7 +1351,7 @@ def __init__(self):
ref=config.commands.fileFormat)
okButton = Button("OK", action=self.dismiss)

col = Column((Label("Command Blocks Commands Options"), sortingRow, empty, space, empty, fileFormat, okButton),
col = Column((Label("Command Blocks Commands Options"), sortingRow, sortingInvert, groupchain, empty, space, empty, fileFormat, okButton),
spacing=2)

self.add(col)
Expand Down
99 changes: 83 additions & 16 deletions fileEdits.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def makeChanges(self):
if op.canUndo:
self.editor.addUnsavedEdit()

def writeCommandInFile(self, first, space, (x,y,z), fileTemp, skip, chain, done, order):
def writeCommandInFile(self, first, space, (x,y,z), fileTemp, skip, chain, done, order, grouping):
block = self.editor.level.tileEntityAt(x, y, z)
if chain:
if not block or (x, y, z) in done:
Expand All @@ -59,27 +59,46 @@ def writeCommandInFile(self, first, space, (x,y,z), fileTemp, skip, chain, done,
order.append((x,y,z))
fileTemp.write(text.encode('utf-8'))

if chain:
if grouping.chains:
done.append((x, y, z))
blockData = self.editor.level.blockDataAt(x, y, z)
if blockData == 0 and self.level.blockAt(x, y-1, z) == 211:
skip.append((x,y-1,z))
self.writeCommandInFile(False, space, (x, y-1, z), fileTemp, skip, True, done, order)
self.writeCommandInFile(False, space, (x, y-1, z), fileTemp, skip, True, done, order, grouping)
elif blockData == 1 and self.level.blockAt(x, y+1, z) == 211:
skip.append((x,y+1,z))
self.writeCommandInFile(False, space, (x, y+1, z), fileTemp, skip, True, done, order)
self.writeCommandInFile(False, space, (x, y+1, z), fileTemp, skip, True, done, order, grouping)
elif blockData == 2 and self.level.blockAt(x, y, z-1) == 211:
skip.append((x,y,z-1))
self.writeCommandInFile(False, space, (x, y, z-1), fileTemp, skip, True, done, order)
self.writeCommandInFile(False, space, (x, y, z-1), fileTemp, skip, True, done, order, grouping)
elif blockData == 3 and self.level.blockAt(x, y, z+1) == 211:
skip.append((x,y,z+1))
self.writeCommandInFile(False, space, (x, y, z+1), fileTemp, skip, True, done, order)
self.writeCommandInFile(False, space, (x, y, z+1), fileTemp, skip, True, done, order, grouping)
elif blockData == 4 and self.level.blockAt(x-1, y, z) == 211:
skip.append((x-1,y,z))
self.writeCommandInFile(False, space, (x-1, y, z), fileTemp, skip, True, done, order)
self.writeCommandInFile(False, space, (x-1, y, z), fileTemp, skip, True, done, order, grouping)
elif blockData == 5 and self.level.blockAt(x+1, y, z) == 211:
skip.append((x+1,y,z))
self.writeCommandInFile(False, space, (x+1, y, z), fileTemp, skip, True, done, order)
self.writeCommandInFile(False, space, (x+1, y, z), fileTemp, skip, True, done, order, grouping)
# Blockdata 6 and 7 are unused. 8-13 are conditional
elif blockData == 8 and self.level.blockAt(x, y-1, z) == 211:
skip.append((x,y-1,z))
self.writeCommandInFile(False, space, (x, y-1, z), fileTemp, skip, True, done, order, grouping)
elif blockData == 9 and self.level.blockAt(x, y+1, z) == 211:
skip.append((x,y+1,z))
self.writeCommandInFile(False, space, (x, y+1, z), fileTemp, skip, True, done, order, grouping)
elif blockData == 10 and self.level.blockAt(x, y, z-1) == 211:
skip.append((x,y,z-1))
self.writeCommandInFile(False, space, (x, y, z-1), fileTemp, skip, True, done, order, grouping)
elif blockData == 11 and self.level.blockAt(x, y, z+1) == 211:
skip.append((x,y,z+1))
self.writeCommandInFile(False, space, (x, y, z+1), fileTemp, skip, True, done, order, grouping)
elif blockData == 12 and self.level.blockAt(x-1, y, z) == 211:
skip.append((x-1,y,z))
self.writeCommandInFile(False, space, (x-1, y, z), fileTemp, skip, True, done, order, grouping)
elif blockData == 13 and self.level.blockAt(x+1, y, z) == 211:
skip.append((x+1,y,z))
self.writeCommandInFile(False, space, (x+1, y, z), fileTemp, skip, True, done, order, grouping)


class FileEditsOperation(Operation):
Expand Down Expand Up @@ -117,15 +136,63 @@ def dirtyBox(self):


def GetSort(box, sorting):
if sorting == "xz" or sorting == "chain":
if sorting.invertX:
xlist = reversed(xrange(box.minx, box.maxx))
#xlist = xrange(box.maxx, box.minx -1,-1) #Untested alternative if reversed is not available. First -1 may be unneeded
else:
xlist = xrange(box.minx, box.maxx)

if sorting.invertY:
ylist = reversed(xrange(box.miny, box.maxy))
else:
ylist = xrange(box.miny, box.maxy)

if sorting.invertZ:
zlist = reversed(xrange(box.minz, box.maxz))
else:
zlist = xrange(box.minz, box.maxz)

# ittertools.product. Last axis advances every itteration.
if sorting.order == "xyz":
return itertools.product(
xrange(box.minx, box.maxx),
xrange(box.miny, box.maxy),
xrange(box.minz, box.maxz)
zlist,
ylist,
xlist
)
else:
elif sorting.order == "xzy":
return itertools.product(
ylist,
zlist,
xlist
)
elif sorting.order == "yxz":
return itertools.product(
zlist,
xlist,
ylist
)
elif sorting.order == "yzx":
return itertools.product(
xlist,
zlist,
ylist
)
elif sorting.order == "zxy":
return itertools.product(
ylist,
xlist,
zlist
)
elif sorting.order == "zyx":
return itertools.product(
xlist,
ylist,
zlist
)
else: # Some Error occured, defualt to xyz
alert("Invalid sort order '" + sorting.order + "'. Defaulting to xyz")
return itertools.product(
xrange(box.minz, box.maxz),
xrange(box.miny, box.maxy),
xrange(box.minx, box.maxx)
zlist,
ylist,
xlist
)