Try a different approach to temp skill levels

This commit is contained in:
blitzmann
2015-09-13 16:51:36 -04:00
parent 1402ceec63
commit 1584586fd2
3 changed files with 17 additions and 41 deletions

View File

@@ -144,13 +144,13 @@ def getUser(lookfor, eager=None):
def getCharacter(lookfor, eager=None):
if isinstance(lookfor, int):
if eager is None:
character = character_session.query(Character).get(lookfor)
character = saveddata_session.query(Character).get(lookfor)
else:
eager = processEager(eager)
character = character_session.query(Character).options(*eager).filter(Character.ID == lookfor).first()
character = saveddata_session.query(Character).options(*eager).filter(Character.ID == lookfor).first()
elif isinstance(lookfor, basestring):
eager = processEager(eager)
character = character_session.query(Character).options(*eager).filter(Character.name == lookfor).first()
character = saveddata_session.query(Character).options(*eager).filter(Character.name == lookfor).first()
else:
raise TypeError("Need integer or string as argument")
return character
@@ -158,14 +158,14 @@ def getCharacter(lookfor, eager=None):
def getCharacterList(eager=None):
eager = processEager(eager)
with sd_lock:
characters = character_session.query(Character).options(*eager).all()
characters = saveddata_session.query(Character).options(*eager).all()
return characters
def getCharactersForUser(lookfor, eager=None):
if isinstance(lookfor, int):
eager = processEager(eager)
with sd_lock:
characters = character_session.query(Character).options(*eager).filter(Character.ownerID == lookfor).all()
characters = saveddata_session.query(Character).options(*eager).filter(Character.ownerID == lookfor).all()
else:
raise TypeError("Need integer as argument")
return characters

View File

@@ -154,6 +154,12 @@ class Character(object):
def isDirty(self):
return getattr(self, "dirty", False)
def saveLevels(self):
for skill in self.skills:
skill.__level = skill.level
self.dirty = False
eos.db.commit()
def filteredSkillIncrease(self, filter, *args, **kwargs):
for element in self.skills:
if filter(element):
@@ -204,6 +210,7 @@ class Skill(HandledItem):
self.__item = item if not isinstance(item, int) else None
self.itemID = item.ID if not isinstance(item, int) else item
self.__level = level if learned else None
self.activeLevel = self.__level
self.commandBonus = 0
self.build(ro)
@@ -222,7 +229,7 @@ class Skill(HandledItem):
@property
def level(self):
return self.__level or 0
return self.activeLevel or 0
@level.setter
def level(self, level):
@@ -232,7 +239,8 @@ class Skill(HandledItem):
if hasattr(self, "_Skill__ro") and self.__ro == True:
raise ReadOnlyException()
self.__level = level
self.activeLevel = level
self.character.dirty = True
@property
def item(self):

View File

@@ -186,13 +186,6 @@ class Character(object):
baseChars = [eos.types.Character.getAll0(), eos.types.Character.getAll5()]
sFit = service.Fit.getInstance()
for thing in eos.db.character_session.dirty:
if isinstance(thing, eos.types.Skill):
if not thing.character.isDirty:
thing.character.dirty = True
elif thing in eos.db.character_session.dirty:
thing.dirty = True
return map(lambda c: (c.ID, c.name if not c.isDirty else "{} *".format(c.name), c == sFit.character), eos.db.getCharacterList())
def getCharacter(self, charID):
@@ -200,30 +193,8 @@ class Character(object):
return char
def saveCharacter(self, charID):
"""
Saves the edited character.
I feel like there should be a better way to specifically tell
SQLAlchemy to only flush and commit a specific object. But this magic
function doesn't seem to exist, so instead we basically gather a list
of our characters, expunge the entire session, and then add the
edited character all by themself. After committing, we simply add our
characters back to the session.
Without doing this, this would save all edited characters, which is
not something that should happen.
"""
char = eos.db.getCharacter(charID)
charList = eos.db.getCharacterList()
eos.db.character_session.expunge_all()
eos.db.character_session.add(char)
eos.db.character_session.commit()
char.dirty = False
for char in charList:
eos.db.character_session.add(char)
char.saveLevels()
def getSkillGroups(self):
cat = eos.db.getCategory(16)
@@ -256,10 +227,7 @@ class Character(object):
def new(self):
char = eos.types.Character("New Character")
eos.db.character_session.add(char)
# We can flush this single character to the DB to get an ID. It will be
# committed with the rename function
eos.db.character_session.flush([char])
eos.db.save(char)
return char.ID
def rename(self, charID, newName):