project support
This commit is contained in:
parent
3dc0752a5d
commit
d8b3317fcf
|
@ -122,9 +122,14 @@ class Ownable(TPrs):
|
|||
if self.owner != None and not self.owner.FPersist():
|
||||
return False
|
||||
return TPrs.FPersist(self)
|
||||
def TransferToOwner(self, ownerNew):
|
||||
self.owner.rgtokOwn.remove(self)
|
||||
ownerNew.rgtokOwn.append(self)
|
||||
self.owner = ownerNew
|
||||
def die(self):
|
||||
if self.owner != None:
|
||||
self.owner.rgtokOwn.remove(self)
|
||||
self.owner = None
|
||||
for tok in [x for x in self.rgtokOwn]:
|
||||
tok.die()
|
||||
self.DontPersist()
|
||||
|
|
5
tpers.py
5
tpers.py
|
@ -99,9 +99,8 @@ class TPrs(object):
|
|||
def __delattr__(self, key):
|
||||
try:
|
||||
del self._persistent[key]
|
||||
return
|
||||
except Exception: pass
|
||||
self.__obj_delattr(key)
|
||||
except Exception:
|
||||
self.__obj_delattr(key)
|
||||
|
||||
def __reduce__(self):
|
||||
if self.FPersist():
|
||||
|
|
133
whiteboard.py
133
whiteboard.py
|
@ -24,6 +24,31 @@ class Layer(TPrs):
|
|||
def FSelectable(self):
|
||||
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)
|
||||
class Board(Ownable):
|
||||
def InitPersistent(self, owner, stName, user, rglayer=None, dtLastModified=None):
|
||||
|
@ -40,7 +65,7 @@ class Board(Ownable):
|
|||
self.dtLastModified = dtLastModified
|
||||
|
||||
def StName(self):
|
||||
return self.owner.StNameBoard(self)
|
||||
return self.owner.owner.StNameBoard(self)
|
||||
def StLastModified(self):
|
||||
return self.dtLastModified.strftime("%b %d, %Y at %I:%M%p")
|
||||
|
||||
|
@ -120,10 +145,7 @@ class Whiteboard(Token):
|
|||
del self.rglayer
|
||||
if versionOld < 5:
|
||||
self.board = Board(self.game.gameLobby, self.game.stName, self.game.user, rglayer, dt)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Chl(object):
|
||||
def __init__(self, client, st):
|
||||
self.user = client.cld.user
|
||||
|
@ -540,24 +562,73 @@ class Joiner(Token):
|
|||
class Lobby(TokenClient):
|
||||
def InitPersistent(self, owner, client):
|
||||
TokenClient.InitPersistent(self, owner, client)
|
||||
self.miDrawings = MiMenu(RgmiProjected(self.game.rgboard, DgProjectMiButton(self.Goto)))
|
||||
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)])
|
||||
self.lobbyCurrent = LobbyProject(self, client)
|
||||
|
||||
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)
|
||||
|
||||
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):
|
||||
"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 != "":
|
||||
self.game.NewBoard(stName, self.client.cld.user)
|
||||
|
||||
def NewBtn(self):
|
||||
self.New(self.miCmds.Value("DrawingName"))
|
||||
|
||||
def StLastModified(self):
|
||||
return self.miDrawings.Value().StLastModified()
|
||||
|
||||
def Goto(self, board):
|
||||
self.New(stName)
|
||||
|
||||
class LobbyBoard(LobbyI):
|
||||
def InitPersistent(self, owner, client, project):
|
||||
self.project = project
|
||||
LobbyI.InitPersistent(self, owner, client)
|
||||
|
||||
def StNewObj(self):
|
||||
return "New Board"
|
||||
def RgObj(self):
|
||||
return self.project.rgboard
|
||||
def OnObjSelected(self, 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):
|
||||
def InitPersistent(self):
|
||||
self.gameLobby = GameLobby()
|
||||
|
@ -573,10 +644,10 @@ class GameLogin(Game):
|
|||
def GetRgclsTokTrans(self):
|
||||
return [[AutoJoiner, login.LoginTerm]]
|
||||
|
||||
@Version(5)
|
||||
@Version(6)
|
||||
class GameLobby(Game):
|
||||
def InitPersistent(self):
|
||||
self.rgboard = []
|
||||
self.rgproject = []
|
||||
Game.InitPersistent(self)
|
||||
|
||||
def InitTransient(self):
|
||||
|
@ -595,21 +666,20 @@ class GameLobby(Game):
|
|||
self.mpboard_gameWB[board] = gameWB
|
||||
return gameWB
|
||||
return self.mpboard_gameWB[board]
|
||||
|
||||
def CclientBoard(self, board):
|
||||
if board in self.mpboard_gameWB:
|
||||
return len(self.mpboard_gameWB[board].rgclient)
|
||||
return 0
|
||||
|
||||
def NewBoard(self, stName, user):
|
||||
self.rgboard.insert(0, Board(self, stName, user))
|
||||
def StNameProject(self, project):
|
||||
return project.stName + " (by " + project.user + ") [" + str(sum([self.CclientBoard(board) for board in project.rgboard])) + "]"
|
||||
|
||||
def StNameBoard(self, board):
|
||||
cclient = 0
|
||||
if board in self.mpboard_gameWB:
|
||||
cclient = len(self.mpboard_gameWB[board].rgclient)
|
||||
return board.stName + " (by " + board.user + ") [" + str(cclient) + "]"
|
||||
return board.stName + " (by " + board.user + ") [" + str(self.CclientBoard(board)) + "]"
|
||||
|
||||
def BoardTouched(self, board):
|
||||
#haaaack
|
||||
if board != self.rgboard[0]:
|
||||
self.rgboard.remove(board)
|
||||
self.rgboard.insert(0, board)
|
||||
self.ensureRun() # redraw
|
||||
|
||||
def UpgradeFrom(self, versionOld):
|
||||
|
@ -622,6 +692,13 @@ class GameLobby(Game):
|
|||
gameWB.finish()
|
||||
if versionOld < 5:
|
||||
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):
|
||||
def InitPersistent(self, gameLobby, board):
|
||||
|
|
Loading…
Reference in a new issue