makeatoon: pattern names work now

This commit is contained in:
Open Toontown 2019-11-15 22:28:30 -05:00
parent 651de8ddd8
commit e3b96e2cfd
4 changed files with 167 additions and 33 deletions

View file

@ -536,4 +536,6 @@ dclass AstronLoginManager : DistributedObject {
avatarListResponse(PotentialAvatar[]); avatarListResponse(PotentialAvatar[]);
createAvatar(blob, uint8) clsend; createAvatar(blob, uint8) clsend;
createAvatarResponse(uint32); createAvatarResponse(uint32);
setNamePattern(uint32, int16, uint8, int16, uint8, int16, uint8, int16, uint8) clsend;
namePatternAnswer(uint32, uint8);
}; };

View file

@ -13,6 +13,7 @@ class AstronLoginManager(DistributedObjectGlobal):
def __init__(self, cr): def __init__(self, cr):
DistributedObjectGlobal.__init__(self, cr) DistributedObjectGlobal.__init__(self, cr)
self.doneEvent = None self.doneEvent = None
self._callback = None
def handleRequestLogin(self, doneEvent): def handleRequestLogin(self, doneEvent):
self.doneEvent = doneEvent self.doneEvent = doneEvent
@ -127,3 +128,10 @@ class AstronLoginManager(DistributedObjectGlobal):
def createAvatarResponse(self, avId): def createAvatarResponse(self, avId):
messenger.send('nameShopCreateAvatarDone', [avId]) messenger.send('nameShopCreateAvatarDone', [avId])
def sendSetNamePattern(self, avId, p1, f1, p2, f2, p3, f3, p4, f4, callback):
self._callback = callback
self.sendUpdate('setNamePattern', [avId, p1, f1, p2, f2, p3, f3, p4, f4])
def namePatternAnswer(self, avId, status):
self._callback(avId, status)

View file

@ -10,6 +10,7 @@ from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobal
from direct.distributed.PyDatagram import * from direct.distributed.PyDatagram import *
from toontown.toon.ToonDNA import ToonDNA from toontown.toon.ToonDNA import ToonDNA
from toontown.toonbase import TTLocalizer from toontown.toonbase import TTLocalizer
from toontown.makeatoon.NameGenerator import NameGenerator
class AccountDB: class AccountDB:
""" """
@ -345,11 +346,87 @@ class CreateAvatarOperation:
del self.loginManager.account2operation[self.sender] del self.loginManager.account2operation[self.sender]
class SetNamePatternOperation:
notify = DirectNotifyGlobal.directNotify.newCategory('SetNamePatternOperation')
def __init__(self, loginManager, sender):
self.loginManager = loginManager
self.sender = sender
self.avId = None
self.pattern = None
def start(self, avId, pattern):
self.avId = avId
self.pattern = pattern
self.__handleRetrieveAccount()
def __handleRetrieveAccount(self):
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.sender, self.__handleAccountRetrieved)
def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu
return
self.account = fields
self.avList = self.account['ACCOUNT_AV_SET']
self.avList = self.avList[:6]
self.avList += [0] * (6 - len(self.avList))
self.__handleRetrieveAvatar()
def __handleRetrieveAvatar(self):
if self.avId and self.avId not in self.avList:
# Main screen turn on.
# It's you!
return
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId, self.__handleAvatarRetrieved)
def __handleAvatarRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']:
# How are you gentlemen?
# All your base are belong to us
return
if fields['WishNameState'][0] != 'OPEN':
# You are on your way to destruction
# What you say?
return
self.__handleSetName()
def __handleSetName(self):
parts = []
for p, f in self.pattern:
part = self.loginManager.nameGenerator.nameDictionary.get(p, ('', ''))[1]
if f:
part = part[:1].upper() + part[1:]
else:
part = part.lower()
parts.append(part)
parts[2] += parts.pop(3)
while '' in parts:
parts.remove('')
name = ' '.join(parts)
self.loginManager.air.dbInterface.updateObject(self.loginManager.air.dbId, self.avId, self.loginManager.air.dclassesByName['DistributedToonUD'],
{'WishNameState': ('LOCKED',),
'WishName': ('',),
'setName': (name,)})
self.loginManager.sendUpdateToAccountId(self.sender, 'namePatternAnswer', [self.avId, 1])
del self.loginManager.account2operation[self.sender]
class AstronLoginManagerUD(DistributedObjectGlobalUD): class AstronLoginManagerUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManagerUD') notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManagerUD')
def __init__(self, air): def __init__(self, air):
DistributedObjectGlobalUD.__init__(self, air) DistributedObjectGlobalUD.__init__(self, air)
self.nameGenerator = None
self.accountDb = None self.accountDb = None
self.sender2loginOperation = {} self.sender2loginOperation = {}
self.account2operation = {} self.account2operation = {}
@ -357,6 +434,9 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD):
def announceGenerate(self): def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self) DistributedObjectGlobalUD.announceGenerate(self)
# This is for processing name patterns.
self.nameGenerator = NameGenerator()
# Instantiate the account database backend. # Instantiate the account database backend.
# TODO: In the future, add more database interfaces & make this configurable. # TODO: In the future, add more database interfaces & make this configurable.
self.accountDb = DeveloperAccountDB(self) self.accountDb = DeveloperAccountDB(self)
@ -402,3 +482,18 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD):
newOperation = CreateAvatarOperation(self, sender) newOperation = CreateAvatarOperation(self, sender)
self.account2operation[sender] = newOperation self.account2operation[sender] = newOperation
newOperation.start(avDNA, avPosition) newOperation.start(avDNA, avPosition)
def setNamePattern(self, avId, p1, f1, p2, f2, p3, f3, p4, f4):
sender = self.air.getAccountIdFromSender()
if not sender:
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = SetNamePatternOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start(avId, [(p1, f1), (p2, f2),
(p3, f3), (p4, f4)])

View file

@ -866,6 +866,14 @@ class NameShop(StateData.StateData):
def checkNamePattern(self): def checkNamePattern(self):
self.notify.debug('checkNamePattern') self.notify.debug('checkNamePattern')
if base.cr.astronSupport:
base.cr.astronLoginManager.sendSetNamePattern(self.avId,
self.nameIndices[0], self.nameFlags[0],
self.nameIndices[1], self.nameFlags[1],
self.nameIndices[2], self.nameFlags[2],
self.nameIndices[3], self.nameFlags[3],
self.handleSetNamePatternAnswerMsg)
else:
datagram = PyDatagram() datagram = PyDatagram()
datagram.addUint16(CLIENT_SET_NAME_PATTERN) datagram.addUint16(CLIENT_SET_NAME_PATTERN)
datagram.addUint32(self.avId) datagram.addUint32(self.avId)
@ -880,6 +888,7 @@ class NameShop(StateData.StateData):
messenger.send('nameShopPost', [datagram]) messenger.send('nameShopPost', [datagram])
self.waitForServer() self.waitForServer()
if not config.GetBool('astron-support', True):
def handleSetNamePatternAnswerMsg(self, di): def handleSetNamePatternAnswerMsg(self, di):
self.notify.debug('handleSetNamePatternAnswerMsg') self.notify.debug('handleSetNamePatternAnswerMsg')
self.cleanupWaitForServer() self.cleanupWaitForServer()
@ -901,6 +910,26 @@ class NameShop(StateData.StateData):
self.notify.debug('name pattern rejected') self.notify.debug('name pattern rejected')
self.rejectName(TTLocalizer.NameError) self.rejectName(TTLocalizer.NameError)
return None return None
else:
def handleSetNamePatternAnswerMsg(self, newavId, returnCode):
self.notify.debug('handleSetNamePatternAnswerMsg')
self.cleanupWaitForServer()
if newavId != self.avId:
self.notify.debug("doid's don't match up!")
self.rejectName(TTLocalizer.NameError)
if returnCode == 1:
style = self.toon.getStyle()
avDNA = style.makeNetString()
self.notify.debug('pattern name accepted')
newPotAv = PotentialAvatar.PotentialAvatar(newavId, self.names, avDNA, self.index, 0)
self.avList.append(newPotAv)
self.doneStatus = 'done'
self.storeSkipTutorialRequest()
messenger.send(self.doneEvent)
else:
self.notify.debug('name pattern rejected')
self.rejectName(TTLocalizer.NameError)
return None
def _submitTypeANameAsPickAName(self): def _submitTypeANameAsPickAName(self):
pnp = TTPickANamePattern(self.nameEntry.get(), self.toon.style.gender) pnp = TTPickANamePattern(self.nameEntry.get(), self.toon.style.gender)