prettySplit function to re-split command on commas and parens
This commit is contained in:
parent
4ab7f09ce9
commit
c3ede6965d
16
mce.py
16
mce.py
@ -7,6 +7,8 @@ from numpy import zeros, bincount
|
|||||||
import logging
|
import logging
|
||||||
import itertools
|
import itertools
|
||||||
import traceback
|
import traceback
|
||||||
|
import shlex
|
||||||
|
from math import floor
|
||||||
|
|
||||||
class UsageError(RuntimeError): pass
|
class UsageError(RuntimeError): pass
|
||||||
class BlockMatchError(RuntimeError): pass
|
class BlockMatchError(RuntimeError): pass
|
||||||
@ -122,14 +124,27 @@ class mce(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise UsageError, "Cannot understand numeric input"
|
raise UsageError, "Cannot understand numeric input"
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
def prettySplit(self, command):
|
||||||
|
cmdstring = " ".join(command);
|
||||||
|
|
||||||
|
lex = shlex.shlex(cmdstring);
|
||||||
|
lex.whitespace += "(),"
|
||||||
|
|
||||||
|
command[:] = list(lex)
|
||||||
|
|
||||||
def readBox(self, command):
|
def readBox(self, command):
|
||||||
|
self.prettySplit(command)
|
||||||
|
|
||||||
sourcePoint = self.readIntPoint(command)
|
sourcePoint = self.readIntPoint(command)
|
||||||
if command[0].lower() == "to":
|
if command[0].lower() == "to":
|
||||||
command.pop(0)
|
command.pop(0)
|
||||||
sourcePoint2 = self.readIntPoint(command)
|
sourcePoint2 = self.readIntPoint(command)
|
||||||
|
sourceSize = map(operator.sub, sourcePoint2, sourcePoint)
|
||||||
else:
|
else:
|
||||||
sourceSize = self.readIntPoint(command, isPoint = False)
|
sourceSize = self.readIntPoint(command, isPoint = False)
|
||||||
|
if len([p for p in sourceSize if p <= 0]):
|
||||||
|
raise UsageError, "Box size cannot be zero or negative"
|
||||||
box = BoundingBox(sourcePoint, sourceSize)
|
box = BoundingBox(sourcePoint, sourceSize)
|
||||||
return box
|
return box
|
||||||
|
|
||||||
@ -139,6 +154,7 @@ class mce(object):
|
|||||||
return point
|
return point
|
||||||
|
|
||||||
def readPoint(self, command, isPoint = True):
|
def readPoint(self, command, isPoint = True):
|
||||||
|
self.prettySplit(command)
|
||||||
try:
|
try:
|
||||||
word = command.pop(0)
|
word = command.pop(0)
|
||||||
if isPoint and (word in self.level.players):
|
if isPoint and (word in self.level.players):
|
||||||
|
Reference in New Issue
Block a user