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():
|
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()
|
||||||
|
|
5
tpers.py
5
tpers.py
|
@ -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():
|
||||||
|
|
133
whiteboard.py
133
whiteboard.py
|
@ -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")
|
||||||
|
|
||||||
|
@ -120,10 +145,7 @@ class Whiteboard(Token):
|
||||||
del self.rglayer
|
del self.rglayer
|
||||||
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,24 +562,73 @@ 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
|
||||||
def StLastModified(self):
|
LobbyI.InitPersistent(self, owner, client)
|
||||||
return self.miDrawings.Value().StLastModified()
|
|
||||||
|
def StNewObj(self):
|
||||||
def Goto(self, board):
|
return "New Board"
|
||||||
|
def RgObj(self):
|
||||||
|
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):
|
||||||
self.gameLobby = GameLobby()
|
self.gameLobby = GameLobby()
|
||||||
|
@ -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):
|
||||||
|
@ -595,21 +666,20 @@ class GameLobby(Game):
|
||||||
self.mpboard_gameWB[board] = gameWB
|
self.mpboard_gameWB[board] = gameWB
|
||||||
return gameWB
|
return gameWB
|
||||||
return self.mpboard_gameWB[board]
|
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):
|
def StNameProject(self, project):
|
||||||
self.rgboard.insert(0, Board(self, stName, user))
|
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):
|
||||||
|
|
Loading…
Reference in a new issue