more python3 compat

This commit is contained in:
Open Toontown 2022-01-16 22:47:39 -05:00
parent 635ea1d3d1
commit a2e37e3389
2 changed files with 18 additions and 26 deletions

View file

@ -2,6 +2,7 @@ from . import CatalogItem
from pandac.PandaModules import * from pandac.PandaModules import *
from direct.distributed.PyDatagram import PyDatagram from direct.distributed.PyDatagram import PyDatagram
from direct.distributed.PyDatagramIterator import PyDatagramIterator from direct.distributed.PyDatagramIterator import PyDatagramIterator
import functools
class CatalogItemList: class CatalogItemList:
@ -9,7 +10,7 @@ class CatalogItemList:
self.store = store self.store = store
self.__blob = None self.__blob = None
self.__list = None self.__list = None
if isinstance(source, str): if isinstance(source, bytes):
self.__blob = source self.__blob = source
elif isinstance(source, list): elif isinstance(source, list):
self.__list = source[:] self.__list = source[:]
@ -156,7 +157,7 @@ class CatalogItemList:
if cmpfunc == None: if cmpfunc == None:
self.__list.sort() self.__list.sort()
else: else:
self.__list.sort(cmpfunc) self.__list.sort(key=functools.cmp_to_key(cmpfunc))
self.__blob = None self.__blob = None
return return
@ -166,6 +167,10 @@ class CatalogItemList:
return len(self.__list) return len(self.__list)
def __getitem__(self, index): def __getitem__(self, index):
if isinstance(index, slice):
if self.__list == None:
self.__decodeList()
return CatalogItemList(self.__list[index.start:index.stop], store=self.store)
if self.__list == None: if self.__list == None:
self.__decodeList() self.__decodeList()
return self.__list[index] return self.__list[index]
@ -173,6 +178,12 @@ class CatalogItemList:
def __setitem__(self, index, item): def __setitem__(self, index, item):
if self.__list == None: if self.__list == None:
self.__decodeList() self.__decodeList()
if isinstance(index, slice):
if isinstance(item, CatalogItemList):
self.__list[index.start:index.stop] = item.__list
else:
self.__list[index.start:index.stop] = item
else:
self.__list[index] = item self.__list[index] = item
self.__blob = None self.__blob = None
return return
@ -180,29 +191,10 @@ class CatalogItemList:
def __delitem__(self, index): def __delitem__(self, index):
if self.__list == None: if self.__list == None:
self.__decodeList() self.__decodeList()
del self.__list[index] if isinstance(index, slice):
self.__blob = None del self.__list[index.start:index.stop]
return
def __getslice__(self, i, j):
if self.__list == None:
self.__decodeList()
return CatalogItemList(self.__list[i:j], store=self.store)
def __setslice__(self, i, j, s):
if self.__list == None:
self.__decodeList()
if isinstance(s, CatalogItemList):
self.__list[i:j] = s.__list
else: else:
self.__list[i:j] = s del self.__list[index]
self.__blob = None
return
def __delslice__(self, i, j):
if self.__list == None:
self.__decodeList()
del self.__list[i:j]
self.__blob = None self.__blob = None
return return

View file

@ -99,7 +99,7 @@ class DistributedHouseInterior(DistributedObject.DistributedObject):
return return
numSurfaceTypes = CatalogSurfaceItem.NUM_ST_TYPES numSurfaceTypes = CatalogSurfaceItem.NUM_ST_TYPES
numRooms = min(len(self.wallpaper) / numSurfaceTypes, len(RoomNames)) numRooms = min(len(self.wallpaper) // numSurfaceTypes, len(RoomNames))
for room in range(numRooms): for room in range(numRooms):
roomName = RoomNames[room] roomName = RoomNames[room]
roomNode = self.interior.find(roomName) roomNode = self.interior.find(roomName)