project support

This commit is contained in:
Jeremy Penner 2011-09-14 18:30:44 -04:00
parent 3dc0752a5d
commit d8b3317fcf
3 changed files with 112 additions and 31 deletions

View file

@ -122,9 +122,14 @@ class Ownable(TPrs):
if self.owner != None and not self.owner.FPersist(): if self.owner != None and not self.owner.FPersist():
return False return False
return TPrs.FPersist(self) return TPrs.FPersist(self)
def TransferToOwner(self, ownerNew):
self.owner.rgtokOwn.remove(self)
ownerNew.rgtokOwn.append(self)
self.owner = ownerNew
def die(self): def die(self):
if self.owner != None: if self.owner != None:
self.owner.rgtokOwn.remove(self) self.owner.rgtokOwn.remove(self)
self.owner = None
for tok in [x for x in self.rgtokOwn]: for tok in [x for x in self.rgtokOwn]:
tok.die() tok.die()
self.DontPersist() self.DontPersist()

View file

@ -99,9 +99,8 @@ class TPrs(object):
def __delattr__(self, key): def __delattr__(self, key):
try: try:
del self._persistent[key] del self._persistent[key]
return except Exception:
except Exception: pass self.__obj_delattr(key)
self.__obj_delattr(key)
def __reduce__(self): def __reduce__(self):
if self.FPersist(): if self.FPersist():

View file

@ -24,6 +24,31 @@ class Layer(TPrs):
def FSelectable(self): def FSelectable(self):
return True return True
class Project(Ownable):
def InitPersistent(self, owner, stName, user):
Ownable.InitPersistent(self, owner)
self.stName = stName
self.user = user
self.rgboard = []
self.rgscript = []
def NewBoard(self, user):
self.rgboard.append(Board(self, "Board " + len(self.rgboard), user))
def BoardTouched(self, board):
if board != self.rgboard[0]:
self.rgboard.remove(board)
self.rgboard.insert(0, board)
self.owner.BoardTouched(board)
def StName(self):
return self.owner.StNameProject(self)
def StLastModified(self):
boardLast = None
for board in self.rgboard:
if boardLast == None or board.dtLastModified > boardLast.dtLastModified:
board = boardLast
if boardLast != None:
return boardLast.StLastModified()
return "never"
@Version(3) @Version(3)
class Board(Ownable): class Board(Ownable):
def InitPersistent(self, owner, stName, user, rglayer=None, dtLastModified=None): def InitPersistent(self, owner, stName, user, rglayer=None, dtLastModified=None):
@ -40,7 +65,7 @@ class Board(Ownable):
self.dtLastModified = dtLastModified self.dtLastModified = dtLastModified
def StName(self): def StName(self):
return self.owner.StNameBoard(self) return self.owner.owner.StNameBoard(self)
def StLastModified(self): def StLastModified(self):
return self.dtLastModified.strftime("%b %d, %Y at %I:%M%p") return self.dtLastModified.strftime("%b %d, %Y at %I:%M%p")
@ -121,9 +146,6 @@ class Whiteboard(Token):
if versionOld < 5: if versionOld < 5:
self.board = Board(self.game.gameLobby, self.game.stName, self.game.user, rglayer, dt) self.board = Board(self.game.gameLobby, self.game.stName, self.game.user, rglayer, dt)
class Chl(object): class Chl(object):
def __init__(self, client, st): def __init__(self, client, st):
self.user = client.cld.user self.user = client.cld.user
@ -540,23 +562,72 @@ class Joiner(Token):
class Lobby(TokenClient): class Lobby(TokenClient):
def InitPersistent(self, owner, client): def InitPersistent(self, owner, client):
TokenClient.InitPersistent(self, owner, client) TokenClient.InitPersistent(self, owner, client)
self.miDrawings = MiMenu(RgmiProjected(self.game.rgboard, DgProjectMiButton(self.Goto))) self.lobbyCurrent = LobbyProject(self, client)
self.miCmds = MiMenu([None, None, MiTypein(self.New, "DrawingName"), MiButton("New Drawing", self.NewBtn),
None, None, None, None, None, None, None, None, MiStatic("Last modified:"), MiDgText(self.StLastModified)]) def SwitchToLobby(self, lobbyNew):
self.lobbyCurrent.die()
self.lobbyCurrent = lobbyNew
class LobbyI(TokenClient):
def InitPersistent(self, owner, client):
TokenClient.InitPersistent(self, owner, client)
self.miDrawings = MiMenu(RgmiProjected(self.RgObj(), DgProjectMiButton(self.OnObjSelected)))
self.miCmds = MiMenu([None, None, MiTypein(self.NewI, "ObjectName"), MiButton(self.StNewObj(), self.NewI),
None, None, None, None, None, None, None, None, MiStatic("Last modified:"), MiDgText(self.StLastModifiedI)])
OvMenu(self, client, MiMenuHoriz([self.miDrawings, self.miCmds], [65, 35]), OvMenu.FILL) OvMenu(self, client, MiMenuHoriz([self.miDrawings, self.miCmds], [65, 35]), OvMenu.FILL)
def StNewObj(self):
"Text for the 'New X' text field"
raise "not implemented"
def RgObj(self):
"Return the list of objects we are selecting from"
raise "not implemented"
def OnObjSelected(self, obj):
"Called when an object is selected by the user"
raise "not implemented"
def New(self, stName): def New(self, stName):
"Create a new object with the given name"
raise "not implemented"
def StLastModified(self, obj):
"Return a string stating when the object was last modified"
raise "not implemented"
def StLastModifiedI(self):
return self.StLastModified(self.miDrawings.Value())
def NewI(self, stName = None):
if stName == None:
stName = self.miCmds.Value("ObjectName")
if stName != "": if stName != "":
self.game.NewBoard(stName, self.client.cld.user) self.New(stName)
def NewBtn(self): class LobbyBoard(LobbyI):
self.New(self.miCmds.Value("DrawingName")) def InitPersistent(self, owner, client, project):
self.project = project
LobbyI.InitPersistent(self, owner, client)
def StLastModified(self): def StNewObj(self):
return self.miDrawings.Value().StLastModified() return "New Board"
def RgObj(self):
def Goto(self, board): return self.project.rgboard
def OnObjSelected(self, board):
self.client.leaveGame(board) self.client.leaveGame(board)
def New(self, stName):
self.project.NewBoard(stName, self.client.cld.user)
def StLastModified(self, board):
return board.StLastModified()
class LobbyProject(LobbyI):
def StNewObj(self):
return "New Project"
def RgObj(self):
return self.game.rgproject
def OnObjSelected(self, project):
self.owner.SwitchToLobby(LobbyBoard(self.owner, self.client, project))
def New(self, stName):
project = self.game.NewProject(stName, self.client.cld.user)
self.OnObjSelected(project)
def StLastModified(self, project):
return project.StLastModified()
class RunnerWB(Runner): class RunnerWB(Runner):
def InitPersistent(self): def InitPersistent(self):
@ -573,10 +644,10 @@ class GameLogin(Game):
def GetRgclsTokTrans(self): def GetRgclsTokTrans(self):
return [[AutoJoiner, login.LoginTerm]] return [[AutoJoiner, login.LoginTerm]]
@Version(5) @Version(6)
class GameLobby(Game): class GameLobby(Game):
def InitPersistent(self): def InitPersistent(self):
self.rgboard = [] self.rgproject = []
Game.InitPersistent(self) Game.InitPersistent(self)
def InitTransient(self): def InitTransient(self):
@ -596,20 +667,19 @@ class GameLobby(Game):
return gameWB return gameWB
return self.mpboard_gameWB[board] return self.mpboard_gameWB[board]
def NewBoard(self, stName, user): def CclientBoard(self, board):
self.rgboard.insert(0, Board(self, stName, user)) if board in self.mpboard_gameWB:
return len(self.mpboard_gameWB[board].rgclient)
return 0
def StNameProject(self, project):
return project.stName + " (by " + project.user + ") [" + str(sum([self.CclientBoard(board) for board in project.rgboard])) + "]"
def StNameBoard(self, board): def StNameBoard(self, board):
cclient = 0 return board.stName + " (by " + board.user + ") [" + str(self.CclientBoard(board)) + "]"
if board in self.mpboard_gameWB:
cclient = len(self.mpboard_gameWB[board].rgclient)
return board.stName + " (by " + board.user + ") [" + str(cclient) + "]"
def BoardTouched(self, board): def BoardTouched(self, board):
#haaaack #haaaack
if board != self.rgboard[0]:
self.rgboard.remove(board)
self.rgboard.insert(0, board)
self.ensureRun() # redraw self.ensureRun() # redraw
def UpgradeFrom(self, versionOld): def UpgradeFrom(self, versionOld):
@ -622,6 +692,13 @@ class GameLobby(Game):
gameWB.finish() gameWB.finish()
if versionOld < 5: if versionOld < 5:
del self.rggameWB del self.rggameWB
if versionOld < 6:
project = Project(self, "Drawings", "Willy Marmot")
for board in self.rgboard:
board.TransferToOwner(project)
project.rgboard.append(board)
del self.rgboard
self.rgproject = [project]
class GameWB(Game): class GameWB(Game):
def InitPersistent(self, gameLobby, board): def InitPersistent(self, gameLobby, board):