Go to the documentation of this file.00001 '''
00002 Anoria (c) Gsk 2010
00003 '''
00004
00005
00006 import BigWorld
00007 import ResMgr
00008
00009 ''' As far as I can tell this code (which is based on code right at the very end of FD Avatar.py)
00010 is probably deprecated and not used in FD anymore. Instead the set_AvatarModel() stuff starting around
00011 l.714 seems to be the current code.
00012 We use this for now anyway since its simple and seems to work well. Probably going to have to replace it
00013 once we go into customizable Avatar Models though '''
00014
00015 class AvatarModelManager():
00016 ''' This is the AvatarModelManager Singleton
00017 it reads and parses the master model definition .xml files from scripts/client/data
00018 and makes functionality related to those available
00019 '''
00020
00021 __instance = None
00022
00023 def __init__(self):
00024 if AvatarModelManager.__instance: return
00025 AvatarModelManager.__instance=self;
00026
00027 self.modelPresets = None
00028 self.AvatarModels = None
00029 self.buildAvatarModels()
00030
00031
00032
00033
00034 def buildAvatarModels(self, cclass = None ):
00035 self.AvatarModels = ResMgr.openSection( "scripts/client/data/AvatarModels.xml" )
00036
00037 good = 0
00038 try:
00039 amp = ResMgr.openSection( "scripts/client/data/AvatarModelPresets.xml" )
00040 if not cclass or not amp.has_key( cclass ): cclass = "presets"
00041 self.modelPresets = eval( amp.readString( cclass ) )
00042 good = (type(self.modelPresets) == type([]))
00043 except:
00044 pass
00045 if not good: self.modelPresets = []
00046
00047
00048
00049 def makeModel(self, num, oldModel ):
00050
00051
00052 mnames = []
00053 dspecs = {}
00054
00055
00056
00057 skelsec = self.AvatarModels
00058 skelcount = len(skelsec)
00059 skelid = num % skelcount
00060 num = (num-skelid) / skelcount
00061 skel = self.AvatarModels.values()[ skelid ]
00062
00063
00064
00065
00066 for partsec in skel.values():
00067
00068
00069 partcount = len(partsec)
00070 partid = num % partcount
00071 num = (num-partid) / partcount
00072 part = partsec.values()[ partid ]
00073 mnames.append( part.asString )
00074
00075
00076
00077
00078 for tintsec in part.values():
00079
00080
00081 tintcount = len(tintsec) + 1
00082 tintid = num % tintcount
00083 num = (num-tintid) / tintcount
00084 if tintid > 0:
00085 tint = tintsec.keys()[ tintid-1 ]
00086 else:
00087 tint = ""
00088 dspecs[ tintsec.name ] = tint
00089
00090
00091
00092
00093
00094 if oldModel != None and oldModel.sources == tuple(mnames):
00095 m = oldModel
00096 else:
00097 m = BigWorld.Model( *mnames )
00098
00099
00100
00101 for dye in dspecs.items():
00102 setattr( m, dye[0], dye[1] )
00103
00104
00105 return m
00106
00107
00108
00109
00110
00111
00112 def treeModelNumbers(self):
00113
00114 tr = []
00115 for skel in self.AvatarModels.values():
00116 ts = []
00117 for partsec in skel.values():
00118 tps = []
00119 for part in partsec.values():
00120 tp = []
00121 for tintsec in part.values():
00122 tt = len(tintsec)+1
00123 tp.append( tt )
00124 tps.append( tp )
00125 ts.append( tuple(tps) )
00126 tr.append( ts )
00127 return [tuple(tr)]
00128
00129
00130
00131 def listModelNumbers(self):
00132 return self.listModelNode(self.treeModelNumbers())
00133
00134
00135 def listModelNode(self, node ):
00136 if node == []: return [0]
00137
00138 b = []
00139
00140
00141 for elt in node:
00142 l = []
00143
00144
00145 if type(elt) == type((0,)):
00146 lenelt = len(elt)
00147 for ei in range(lenelt):
00148 for i in self.listModelNode( elt[ei] ):
00149 l.append( ei + lenelt * i )
00150
00151 else:
00152 l = range(elt)
00153
00154 b.append( l )
00155
00156
00157 nums = [0]
00158 for i in range( len(b)-1, -1, -1 ):
00159 nn = []
00160 for j in b[i]:
00161 for val in nums:
00162 nn.append( j + len(b[i]) * val )
00163 nums = nn
00164
00165 return nums
00166
00167 AvatarModelManager=AvatarModelManager()
00168
00169