def updateFromPlayerProfile(self): try: self.profileName = self.profileNames[self.profileIndex] character = self.profiles[self.profileName].get('character', 'Spaz') if character not in self.characterNames and character in bsSpaz.appearances: self.characterNames.append(character) self.characterIndex = self.characterNames.index(character) marker = self.profileName.encode('utf-8')[0] if self.profileName.encode('utf-8')[0] in self.markers else None if marker is not None: glow = self.glowDict.get(marker, [1, 1, 0, 0]) cM, hM, stabilizeC, stabilizeH = glow[0], glow[1], glow[2], glow[3] self._color, self._highlight = bsUtils.getPlayerProfileColors(self.profileName, profiles=self.profiles) if not stabilizeC: self._color = (self._color[0]*cM, self._color[1]*cM, self._color[2]*cM) else: m = max(self._color) self._color = tuple([i*cM if i == m else i for i in list(self._color)]) if not stabilizeH: self._highlight = (self._highlight[0]*hM, self._highlight[1]*hM, self._highlight[2]*hM) else: m = max(self._highlight) self._highlight = tuple([i*hM if i == m else i for i in list(self._highlight)]) else: self._color, self._highlight = bsUtils.getPlayerProfileColors(self.profileName, profiles=self.profiles) except Exception as E: self.characterIndex = self._randomCharacterIndex self._color = self._randomColor self._highlight = self._randomHighlight print(str(E)) self._updateIcon() self._updateText()
def updateFromPlayerProfile(self): # set character based on profile; otherwise default to # our pre-picked random try: # store the name even though we usually use index (in case # the profile list changes) self.profileName = self.profileNames[self.profileIndex] character = self.profiles[self.profileName]['character'] # hmmm; at the moment we're not properly pulling the list # of available characters from clients, so profiles might use a # character not in their list. for now, just go ahead and add # the character name to their list as long as we're aware of it if (character not in self.characterNames and character in bsSpaz.appearances): self.characterNames.append(character) self.characterIndex = self.characterNames.index(character) self._color, self._highlight = \ bsUtils.getPlayerProfileColors(self.profileName, profiles=self.profiles) except Exception as e: self.characterIndex = self._randomCharacterIndex self._color = self._randomColor self._highlight = self._randomHighlight self._updateIcon() self._updateText()
def __init__(self, vPos, player, lobby): import bsInternal self._deekSound = bs.getSound('deek') self._clickSound = bs.getSound('click01') self._punchSound = bs.getSound('punch01') self._swishSound = bs.getSound('punchSwish') self._errorSound = bs.getSound('error') self._maskTexture = bs.getTexture('characterIconMask') self._vPos = vPos self._lobby = weakref.ref(lobby) self._player = player self._inited = False self._dead = False # load available profiles either from the local config or from the # remote device.. self.reloadProfiles() # note: this is just our local index out of available teams; *not* # the team ID! self._selectedTeamIndex = self.getLobby().nextAddTeam # store a persistent random character index; we'll use this for the # '_random' profile. Let's use their inputDevice id to seed it.. this # will give a persistent character for them between games and will # distribute characters nicely if everyone is random try: inputDeviceID = self._player.getInputDevice().getID() except Exception as e: print 'ERROR: exc getting inputDeviceID for chooser creation:', e inputDeviceID = 0 import traceback traceback.print_stack() # we want the first device that asks for a chooser to always get # spaz as a random character.. global gRandomCharIndexOffset if gRandomCharIndexOffset is None: # scratch that.. we now kinda accomplish the same thing with # account profiles so lets just be fully random here.. gRandomCharIndexOffset = random.randrange(1000) # to calc our random index we pick a random character out of our # unlocked list and then locate that character's index in the full list self._randomCharacterIndex = ( (inputDeviceID + gRandomCharIndexOffset) % len(self.characterNames)) self._randomColor, self._randomHighlight = \ bsUtils.getPlayerProfileColors(None) global gAccountProfileDeviceID # attempt to pick an initial profile based on what's been stored # for this input device try: inputDevice = self._player.getInputDevice() name = inputDevice.getName() uniqueID = inputDevice.getUniqueIdentifier() self.profileName = ( bs.getConfig()['Default Player Profiles'][name + ' ' + uniqueID]) self.profileIndex = self.profileNames.index(self.profileName) # if this one is __account__ and is local and we havn't marked # anyone as the account-profile device yet, mark this guy as it. # (prevents the next joiner from getting the account profile too) if (self.profileName == '__account__' and not inputDevice.isRemoteClient() and gAccountProfileDeviceID is None): gAccountProfileDeviceID = inputDeviceID # well hmm that didn't work.. pick __account__, _random, or some # other random profile.. except Exception: profileNames = self.profileNames # we want the first local input-device in the game to latch on to # the account profile if (not inputDevice.isRemoteClient() and not inputDevice.isControllerApp()): if (gAccountProfileDeviceID is None and '__account__' in profileNames): gAccountProfileDeviceID = inputDeviceID # if this is the designated account-profile-device, try to default # to the account profile if (inputDeviceID == gAccountProfileDeviceID and '__account__' in profileNames): self.profileIndex = profileNames.index('__account__') else: # if this is the controller app, it defaults to using a random # profile (since we can pull the random name from the app) if inputDevice.isControllerApp(): self.profileIndex = profileNames.index('_random') else: # if its a client connection, for now just force the account # profile if possible.. (need to provide a way for clients # to specify/remember their default profile) if (inputDevice.isRemoteClient() and '__account__' in profileNames): self.profileIndex = profileNames.index('__account__') else: global gRandProfileIndex # cycle through our non-random profiles once; after # that, everyone gets random. while (gRandProfileIndex < len(profileNames) and profileNames[gRandProfileIndex] in ('_random', '__account__', '_edit')): gRandProfileIndex += 1 if gRandProfileIndex < len(profileNames): self.profileIndex = gRandProfileIndex gRandProfileIndex += 1 else: self.profileIndex = profileNames.index('_random') self.profileName = profileNames[self.profileIndex] self.characterIndex = self._randomCharacterIndex self._color = self._randomColor self._highlight = self._randomHighlight self.ready = False self._textNode = bs.newNode('text', delegate=self, attrs={ 'position': (-100, self._vPos), 'maxWidth': 160, 'shadow': 0.5, 'vrDepth': -20, 'hAlign': 'left', 'vAlign': 'center', 'vAttach': 'top' }) bsUtils.animate(self._textNode, 'scale', {0: 0, 100: 1.0}) self.icon = bs.newNode('image', owner=self._textNode, attrs={ 'position': (-130, self._vPos + 20), 'maskTexture': self._maskTexture, 'vrDepth': -10, 'attach': 'topCenter' }) bsUtils.animateArray(self.icon, 'scale', 2, {0: (0, 0), 100: (45, 45)}) self._setReady(False) # set our initial name to '<choosing player>' in case anyone asks.. self._player.setName(bs.Lstr(resource='choosingPlayerText').evaluate(), real=False) self.updateFromPlayerProfile() self.updatePosition() self._inited = True
def updateFromPlayerProfile(self): # set character based on profile; otherwise default to # our pre-picked random try: # store the name even though we usually use index (in case # the profile list changes) self.profileName = self.profileNames[self.profileIndex] character = self.profiles[self.profileName]['character'] # hmmm; at the moment we're not properly pulling the list # of available characters from clients, so profiles might use a # character not in their list. for now, just go ahead and add # the character name to their list as long as we're aware of it if (character not in self.characterNames and character in bsSpaz.appearances): self.characterNames.append(character) self.characterIndex = self.characterNames.index(character) # well, actually the glowing profiles if self.profileName.encode('utf-8')[0] in self.glowDict: cM = self.glowDict[self.profileName.encode('utf-8')[0]][0] if cM >= 25.0: cM = 25.0 hM = float( self.glowDict[self.profileName.encode('utf-8')[0]][1]) if hM >= 25.0: hM = 25.0 stabilizeC = int( self.glowDict[self.profileName.encode('utf-8')[0]][2]) > 0 stabilizeH = int( self.glowDict[self.profileName.encode('utf-8')[0]][3]) > 0 self._color, self._highlight = bsUtils.getPlayerProfileColors( self.profileName, profiles=self.profiles) if not stabilizeC: self._color = (self._color[0] * cM, self._color[1] * cM, self._color[2] * cM) else: m = max(self._color) self._color = list(self._color) if self._color[0] == m: self._color[0] = self._color[0] * cM if self._color[1] == m: self._color[1] = self._color[1] * cM if self._color[2] == m: self._color[2] = self._color[2] * cM self._color = tuple(self._color) if not stabilizeH: self._highlight = (self._highlight[0] * hM, self._highlight[1] * hM, self._highlight[2] * hM) else: m = max(self._highlight) self._highlight = list(self._highlight) if self._highlight[0] == m: self._highlight[0] = self._highlight[0] * hM if self._highlight[1] == m: self._highlight[1] = self._highlight[1] * hM if self._highlight[2] == m: self._highlight[2] = self._highlight[2] * hM self._highlight = tuple(self._highlight) else: self._color, self._highlight = \ bsUtils.getPlayerProfileColors(self.profileName, profiles=self.profiles) except: self.characterIndex = self._randomCharacterIndex self._color = self._randomColor self._highlight = self._randomHighlight self._updateIcon() self._updateText()