fix cut/paste accidentally cloning stuff we don't actually want to clone
This commit is contained in:
parent
d8baf72cf6
commit
d8c8d6b825
25
scripting.py
25
scripting.py
|
@ -20,6 +20,7 @@ from util import *
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import itertools
|
import itertools
|
||||||
import random
|
import random
|
||||||
|
import inspect
|
||||||
|
|
||||||
# sobj -- generic hungarian for any object that is usable in scripts
|
# sobj -- generic hungarian for any object that is usable in scripts
|
||||||
# stmt -- statement; a synt that can be used as a line in a SyntBlock
|
# stmt -- statement; a synt that can be used as a line in a SyntBlock
|
||||||
|
@ -66,7 +67,7 @@ class Defs(TPrs):
|
||||||
class Vm(TPrs):
|
class Vm(TPrs):
|
||||||
def InitPersistent(self, defs):
|
def InitPersistent(self, defs):
|
||||||
self.defs = defs
|
self.defs = defs
|
||||||
self.mpflagdef = { flagdef: flagdef.value for flagdef in defs.rgflagdef }
|
self.mpflagdef = {}
|
||||||
self.mpbotdef = { botdef: Rbot(botdef) for botdef in defs.rgbotdef if not botdef.fPlayer }
|
self.mpbotdef = { botdef: Rbot(botdef) for botdef in defs.rgbotdef if not botdef.fPlayer }
|
||||||
self.rgrbotPlayer = []
|
self.rgrbotPlayer = []
|
||||||
|
|
||||||
|
@ -208,6 +209,20 @@ class Synt(Typeable):
|
||||||
"Return the stype that should be applied to the given child."
|
"Return the stype that should be applied to the given child."
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def Clone(self):
|
||||||
|
synt = self.ShallowClone()
|
||||||
|
synt.rgsynt = [child.Clone().WithParent(synt) for child in self.rgsynt]
|
||||||
|
return synt
|
||||||
|
|
||||||
|
def ShallowClone(self):
|
||||||
|
# assumes constructor takes named arguments and assigns them to attributes with the same name
|
||||||
|
# if a more complex case comes up the subclass should override ShallowClone to allow cut/paste
|
||||||
|
# to work
|
||||||
|
rgarg = []
|
||||||
|
for arg in inspect.getargspec(self.InitPersistent).args[1:]:
|
||||||
|
rgarg.append(getattr(self, arg))
|
||||||
|
return self.__class__(*rgarg)
|
||||||
|
|
||||||
def ProjectTypein(self, pcur):
|
def ProjectTypein(self, pcur):
|
||||||
return self.syntParent.ProjectTypeinForChild(pcur, self, self.StForTypein())
|
return self.syntParent.ProjectTypeinForChild(pcur, self, self.StForTypein())
|
||||||
|
|
||||||
|
@ -317,9 +332,9 @@ class SyntDesc(Synt):
|
||||||
isynt += 1
|
isynt += 1
|
||||||
|
|
||||||
class SyntText(Synt):
|
class SyntText(Synt):
|
||||||
def InitPersistent(self):
|
def InitPersistent(self, st=""):
|
||||||
Synt.InitPersistent(self)
|
Synt.InitPersistent(self)
|
||||||
self.st = ""
|
self.st = st
|
||||||
def InitTransient(self):
|
def InitTransient(self):
|
||||||
Synt.InitTransient(self)
|
Synt.InitTransient(self)
|
||||||
self.SetStTypein(self.st)
|
self.SetStTypein(self.st)
|
||||||
|
@ -377,10 +392,10 @@ class SyntBlock(Synt):
|
||||||
elif (key == ansi.K_DEL or key == ansi.K_CTRL('x')) and pwKey.pwChild.RgpwChild()[0] == psel.PwSelected(pwKey):
|
elif (key == ansi.K_DEL or key == ansi.K_CTRL('x')) and pwKey.pwChild.RgpwChild()[0] == psel.PwSelected(pwKey):
|
||||||
self.RemoveLine(synt, psel)
|
self.RemoveLine(synt, psel)
|
||||||
elif key == ansi.K_CTRL('c') and pwKey.pwChild.RgpwChild()[0] == psel.PwSelected(pwKey):
|
elif key == ansi.K_CTRL('c') and pwKey.pwChild.RgpwChild()[0] == psel.PwSelected(pwKey):
|
||||||
psel.syntClipboard = synt.DeepClone().WithParent(None)
|
psel.syntClipboard = synt.Clone().WithParent(None)
|
||||||
elif key == ansi.K_CTRL('v') and psel.syntClipboard:
|
elif key == ansi.K_CTRL('v') and psel.syntClipboard:
|
||||||
isyntInsert = self.rgsynt.index(synt)
|
isyntInsert = self.rgsynt.index(synt)
|
||||||
self.InsertLineAt(isyntInsert, psel.syntClipboard.DeepClone())
|
self.InsertLineAt(isyntInsert, psel.syntClipboard.Clone())
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
13
tpers.py
13
tpers.py
|
@ -84,9 +84,6 @@ class TPrs(object):
|
||||||
def UpgradeFrom(self, versionOld):
|
def UpgradeFrom(self, versionOld):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def DeepClone(self):
|
|
||||||
return Odb.DeepClone(self)
|
|
||||||
|
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
stPersistent = "no persistent yet"
|
stPersistent = "no persistent yet"
|
||||||
if key != "_persistent":
|
if key != "_persistent":
|
||||||
|
@ -166,16 +163,6 @@ class Odb(object):
|
||||||
cls.rgtprsToInit = None
|
cls.rgtprsToInit = None
|
||||||
return tprs
|
return tprs
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def DeepClone(cls, tprs):
|
|
||||||
cls.rgtprsToInit = []
|
|
||||||
clone = cPickle.loads(cPickle.dumps(tprs))
|
|
||||||
for tprsToInit in cls.rgtprsToInit:
|
|
||||||
with tprsToInit.SetTransiently():
|
|
||||||
tprsToInit.InitTransient()
|
|
||||||
cls.rgtprsToInit = None
|
|
||||||
return clone
|
|
||||||
|
|
||||||
clsList = list
|
clsList = list
|
||||||
clsDict = dict
|
clsDict = dict
|
||||||
clsSet = set
|
clsSet = set
|
||||||
|
|
Loading…
Reference in a new issue