Create new flags!
This commit is contained in:
parent
0d83da70ae
commit
96f9475b7f
39
scripting.py
39
scripting.py
|
@ -39,7 +39,7 @@ class Botdef(TPrs):
|
|||
class Flagdef(TPrs):
|
||||
def InitPersistent(self, stName, value = True):
|
||||
self.stName = stName
|
||||
self.value = True
|
||||
self.value = value
|
||||
|
||||
class Rbot(TPrs):
|
||||
def InitPersistent(self, botdef):
|
||||
|
@ -74,7 +74,7 @@ class Vm(TPrs):
|
|||
self.mpflagdef[flagdef] = fValue
|
||||
|
||||
def FFlagSet(self, flagdef):
|
||||
return self.mpflagdef[flagdef]
|
||||
return self.mpflagdef[flagdef] if flagdef in self.mpflagdef else flagdef.value
|
||||
|
||||
def AddPlayer(self):
|
||||
rgbotdefPlayer = [botdef for botdef in self.defs.rgbotdef if botdef.fPlayer]
|
||||
|
@ -116,6 +116,15 @@ class StypeEnum(Stype):
|
|||
class StypeStmt(StypeEnum):
|
||||
rgclsSynt = []
|
||||
|
||||
class StypeNewFlag(Stype):
|
||||
def RgsyntFromSt(self, defs, st):
|
||||
if len(st) > 0:
|
||||
for flagdef in defs.rgflagdef:
|
||||
if flagdef.stName == st:
|
||||
return
|
||||
yield SyntMakeFlagDef(defs, st, False)
|
||||
yield SyntMakeFlagDef(defs, st, True)
|
||||
|
||||
class Rtype(Stype):
|
||||
"Runtime type"
|
||||
def StForSobj(self, sobj):
|
||||
|
@ -179,6 +188,11 @@ class Synt(Typeable):
|
|||
def SyntDefault(cls):
|
||||
return cls()
|
||||
|
||||
def WithParent(self, syntParent):
|
||||
assert self.syntParent == None
|
||||
self.syntParent = syntParent
|
||||
return self
|
||||
|
||||
def Populate(self):
|
||||
"Populate rgsynt with useful default values."
|
||||
pass
|
||||
|
@ -220,9 +234,7 @@ class Synt(Typeable):
|
|||
pcur.pwTooltip.AddTip(pwTypein, Tooltip)
|
||||
|
||||
def Replace(self, syntOld, syntNew):
|
||||
assert syntNew.syntParent == None
|
||||
syntNew.syntParent = self
|
||||
self.rgsynt[self.Isynt(syntOld)] = syntNew
|
||||
self.rgsynt[self.Isynt(syntOld)] = syntNew.WithParent(self)
|
||||
|
||||
def Append(self, syntNew):
|
||||
assert syntNew.syntParent == None
|
||||
|
@ -404,6 +416,21 @@ class SyntFlagRef(Synt):
|
|||
except:
|
||||
return env.vm.Fail("No such flag", self)
|
||||
|
||||
class SyntMakeFlagDef(Synt):
|
||||
def InitPersistent(self, defs, stName, fInit):
|
||||
Synt.InitPersistent(self)
|
||||
self.defs = defs
|
||||
self.stName = stName
|
||||
self.fInit = fInit
|
||||
|
||||
def StForTypein(self):
|
||||
return "New flag: " + self.stName + " (initially " + str(self.fInit) + ")"
|
||||
|
||||
def WithParent(self, syntParent):
|
||||
flagdef = Flagdef(self.stName, self.fInit)
|
||||
self.defs.rgflagdef.append(flagdef)
|
||||
return SyntFlagRef(flagdef).WithParent(syntParent)
|
||||
|
||||
class SyntIsFlagSet(SyntDesc):
|
||||
desc = [["set"]]
|
||||
def Eval(self, env, val):
|
||||
|
@ -441,7 +468,7 @@ class SyntIf(SyntDesc):
|
|||
|
||||
@RegStmt
|
||||
class SyntSet(SyntDesc):
|
||||
desc = [["Set flag"], " ", RtypeFlag(), " to ", RtypeUnion(RtypeBool(), RtypeFlag())]
|
||||
desc = [["Set flag"], " ", RtypeUnion(RtypeFlag(), StypeNewFlag()), " to ", RtypeUnion(RtypeBool(), RtypeFlag())]
|
||||
lvalue = SyntDesc.DefProp(0)
|
||||
expr = SyntDesc.DefProp(1)
|
||||
def Eval(self, env):
|
||||
|
|
Loading…
Reference in a new issue