示例#1
0
 def restoreFromCache(self):
     if self.__storageCache:
         return
     from gui.shared.utils import getPlayerDatabaseID, getPlayerName
     self.__storageCache = StorageLocalCache((getPlayerDatabaseID(), getPlayerName(), 'storage'))
     self.__storageCache.onRead += self.__onRead
     self.__storageCache.read()
示例#2
0
 def restoreFromCache(self):
     if self.__storageCache:
         return
     from messenger.ext.player_helpers import getPlayerDatabaseID, getPlayerName
     self.__storageCache = StorageLocalCache((getPlayerDatabaseID(), getPlayerName(), 'storage'))
     self.__storageCache.onRead += self.__onRead
     self.__storageCache.read()
示例#3
0
 def restoreFromCache(self):
     if self.__storageCache:
         return
     from gui.shared.utils import getPlayerDatabaseID, getPlayerName
     self.__storageCache = StorageLocalCache((getPlayerDatabaseID(), getPlayerName(), 'storage'))
     self.__storageCache.onRead += self.__onRead
     self.__storageCache.read()
示例#4
0
class StorageDecorator(object):
    __metaclass__ = ROPropertyMeta
    __readonly__ = _STORAGE

    def __repr__(self):
        return 'StorageDecorator(id=0x{0:08X}, ro={1!r:s})'.format(
            id(self), self.__readonly__.keys())

    def __init__(self):
        super(StorageDecorator, self).__init__()
        self.__storageCache = None
        return

    def restoreFromCache(self):
        if self.__storageCache:
            return
        from gui.shared.utils import getPlayerDatabaseID, getPlayerName
        self.__storageCache = StorageLocalCache(
            (getPlayerDatabaseID(), getPlayerName(), 'storage'))
        self.__storageCache.onRead += self.__onRead
        self.__storageCache.read()

    def init(self):
        for name, storage in self.__readonly__.iteritems():
            storage.init()

    def switch(self, scope):
        for name, storage in self.__readonly__.iteritems():
            storage.switch(scope)

    def clear(self):
        if self.__storageCache:
            for name, storage in self.__readonly__.iteritems():
                record = storage.makeRecordInCache()
                if record:
                    self.__storageCache.addRecord(name, record)

            self.__storageCache.write()
            self.__storageCache.clear()
            self.__storageCache = None
        for storage in self.__readonly__.itervalues():
            storage.clear()

        return

    def __onRead(self):
        if not self.__storageCache:
            return
        for name, storage in self.__readonly__.iteritems():
            storage.restoreFromCache(self.__storageCache.popRecord(name))
示例#5
0
class StorageDecorator(object):
    __metaclass__ = ROPropertyMeta
    __readonly__ = _STORAGE

    def __repr__(self):
        return 'StorageDecorator(id=0x{0:08X}, ro={1!r:s})'.format(id(self), self.__readonly__.keys())

    def __init__(self):
        super(StorageDecorator, self).__init__()
        self.__storageCache = None
        return

    def restoreFromCache(self):
        if self.__storageCache:
            return
        from gui.shared.utils import getPlayerDatabaseID, getPlayerName
        self.__storageCache = StorageLocalCache((getPlayerDatabaseID(), getPlayerName(), 'storage'))
        self.__storageCache.onRead += self.__onRead
        self.__storageCache.read()

    def init(self):
        for name, storage in self.__readonly__.iteritems():
            storage.init()

    def switch(self, scope):
        for name, storage in self.__readonly__.iteritems():
            storage.switch(scope)

    def clear(self):
        if self.__storageCache:
            for name, storage in self.__readonly__.iteritems():
                record = storage.makeRecordInCache()
                if record:
                    self.__storageCache.addRecord(name, record)

            self.__storageCache.write()
            self.__storageCache.clear()
            self.__storageCache = None
        for storage in self.__readonly__.itervalues():
            storage.clear()

        return

    def __onRead(self):
        if not self.__storageCache:
            return
        for name, storage in self.__readonly__.iteritems():
            storage.restoreFromCache(self.__storageCache.popRecord(name))