edit username/entId ranges moved to EditorGlobals
This commit is contained in:
parent
ba426a409a
commit
fbc3a2c4c3
|
|
@ -1,44 +1,22 @@
|
|||
"""EditMgrAI module: contains the EditMgrAI class"""
|
||||
|
||||
import EditMgrBase
|
||||
from PythonUtil import list2dict, uniqueElements
|
||||
|
||||
if __debug__:
|
||||
EntIdRange = 5000
|
||||
username2entIdBase = {
|
||||
'darren': 1*EntIdRange,
|
||||
'samir': 2*EntIdRange,
|
||||
'skyler': 3*EntIdRange,
|
||||
'joe': 4*EntIdRange,
|
||||
'mark': 5*EntIdRange,
|
||||
}
|
||||
assert uniqueElements(username2entIdBase.values())
|
||||
|
||||
UndefinedUsername = 'UNDEFINED_USERNAME'
|
||||
UsernameConfigVar = 'factory-edit-username'
|
||||
username = config.GetString(UsernameConfigVar, UndefinedUsername)
|
||||
|
||||
class EditMgrAI(EditMgrBase.EditMgrBase):
|
||||
"""This class handles AI-side editor-specific functionality"""
|
||||
if __debug__:
|
||||
from PythonUtil import list2dict
|
||||
import EditorGlobals
|
||||
|
||||
def setRequestNewEntity(self, data):
|
||||
# pick an unused entId
|
||||
spec = self.level.levelSpec
|
||||
entIds = spec.getAllEntIds()
|
||||
entIdDict = list2dict(entIds)
|
||||
|
||||
# Feel free to add your name to the table if it's not in there yet
|
||||
if username == UndefinedUsername:
|
||||
self.setRequestSave(None)
|
||||
self.notify.error("you must config '%s'" % UsernameConfigVar)
|
||||
if username not in username2entIdBase:
|
||||
self.notify.error("unknown editor username '%s'" % username)
|
||||
|
||||
# dumb linear search for now
|
||||
# make this smarter (cache last-allocated id)
|
||||
baseId = username2entIdBase[username]
|
||||
id = baseId
|
||||
for id in xrange(baseId, baseId + EntIdRange):
|
||||
for id in xrange(*EditorGlobals.getEntIdAllocRange()):
|
||||
if not id in entIdDict:
|
||||
break
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
"""EditorGlobals module: contains global editor data"""
|
||||
|
||||
from PythonUtil import uniqueElements
|
||||
|
||||
EntIdRange = 10000
|
||||
username2entIdBase = {
|
||||
'darren': 1*EntIdRange,
|
||||
'samir': 2*EntIdRange,
|
||||
'skyler': 3*EntIdRange,
|
||||
'joe': 4*EntIdRange,
|
||||
'mark': 5*EntIdRange,
|
||||
}
|
||||
assert uniqueElements(username2entIdBase.values())
|
||||
|
||||
usernameConfigVar = 'level-edit-username'
|
||||
undefinedUsername = 'UNDEFINED_USERNAME'
|
||||
editUsername = config.GetString(usernameConfigVar, undefinedUsername)
|
||||
|
||||
# call this to make sure things have been set up correctly
|
||||
def assertReadyToEdit():
|
||||
assert editUsername != undefinedUsername, (
|
||||
"you must config '%s'" % usernameConfigVar)
|
||||
# Feel free to add your name to the table if it's not in there
|
||||
assert editUsername in username2entIdBase, (
|
||||
"unknown editor username '%s'" % username)
|
||||
|
||||
def getEntIdAllocRange():
|
||||
"""range of valid entId values for this user.
|
||||
returns [min, max+1] (values taken by range() and xrange())"""
|
||||
baseId = username2entIdBase[editUsername]
|
||||
return [baseId, baseId+EntIdRange]
|
||||
Loading…
Reference in New Issue