Added character saving.
Deleting characters is broken for now due to using wrong session, but I believe creating character works. Further tests needed
This commit is contained in:
@@ -5,7 +5,7 @@ debug = False
|
||||
gamedataCache = True
|
||||
saveddataCache = True
|
||||
gamedata_connectionstring = 'sqlite:///' + unicode(realpath(join(dirname(abspath(__file__)), "..", "staticdata", "eve.db")), sys.getfilesystemencoding())
|
||||
saveddata_connectionstring = 'sqlite:///:memory:'
|
||||
saveddata_connectionstring = 'sqlite:///' + unicode(realpath(join(dirname(abspath(__file__)), "..", "saveddata", "saveddata.db")), sys.getfilesystemencoding())
|
||||
|
||||
#Autodetect path, only change if the autodetection bugs out.
|
||||
path = dirname(unicode(__file__, sys.getfilesystemencoding()))
|
||||
|
||||
@@ -148,7 +148,6 @@ def getCharacter(lookfor, eager=None):
|
||||
else:
|
||||
eager = processEager(eager)
|
||||
character = character_session.query(Character).options(*eager).filter(Character.ID == lookfor).first()
|
||||
print character
|
||||
elif isinstance(lookfor, basestring):
|
||||
eager = processEager(eager)
|
||||
character = character_session.query(Character).options(*eager).filter(Character.name == lookfor).first()
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
from sqlalchemy.orm import validates, reconstructor
|
||||
|
||||
from eos.effectHandlerHelpers import HandledItem
|
||||
import eos.db
|
||||
import eos
|
||||
|
||||
class Character(object):
|
||||
@@ -33,7 +34,6 @@ class Character(object):
|
||||
@classmethod
|
||||
def getSkillList(cls):
|
||||
if cls.__itemList is None:
|
||||
import eos.db
|
||||
cls.__itemList = eos.db.getItemsByCategory("Skill")
|
||||
|
||||
return cls.__itemList
|
||||
@@ -150,6 +150,10 @@ class Character(object):
|
||||
def implants(self):
|
||||
return self.__implants
|
||||
|
||||
@property
|
||||
def isDirty(self):
|
||||
return getattr(self, "dirty", False)
|
||||
|
||||
def iterSkills(self):
|
||||
for item in self.getSkillList():
|
||||
yield self.getSkill(item)
|
||||
|
||||
@@ -94,6 +94,7 @@ class ChangeAffectingSkills(ContextMenu):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
self.sFit.changeChar(fitID, self.charID)
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.CharListUpdated())
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
ChangeAffectingSkills.register()
|
||||
|
||||
@@ -418,6 +418,8 @@ class MainFrame(wx.Frame):
|
||||
self.Bind(wx.EVT_MENU, self.goWiki, id = menuBar.wikiId)
|
||||
# EVE Forums
|
||||
self.Bind(wx.EVT_MENU, self.goForums, id = menuBar.forumId)
|
||||
# Save current character
|
||||
self.Bind(wx.EVT_MENU, self.saveChar, id = menuBar.saveCharId)
|
||||
|
||||
#Clipboard exports
|
||||
self.Bind(wx.EVT_MENU, self.exportToClipboard, id=wx.ID_COPY)
|
||||
@@ -482,6 +484,12 @@ class MainFrame(wx.Frame):
|
||||
atable = wx.AcceleratorTable(actb)
|
||||
self.SetAcceleratorTable(atable)
|
||||
|
||||
def saveChar(self, event):
|
||||
sChr = service.Character.getInstance()
|
||||
charID = self.charSelection.getActiveCharacter()
|
||||
sChr.saveCharacter(charID)
|
||||
wx.PostEvent(self, GE.CharListUpdated())
|
||||
|
||||
def AdditionsTabSelect(self, event):
|
||||
selTab = self.additionsSelect.index(event.GetId())
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ class MainMenuBar(wx.MenuBar):
|
||||
self.exportHtmlId = wx.NewId()
|
||||
self.wikiId = wx.NewId()
|
||||
self.forumId = wx.NewId()
|
||||
self.saveCharId = wx.NewId()
|
||||
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
@@ -70,6 +71,8 @@ class MainMenuBar(wx.MenuBar):
|
||||
pasteText = "&From Clipboard" + ("\tCTRL+V" if 'wxMSW' in wx.PlatformInfo else "")
|
||||
editMenu.Append(wx.ID_COPY, copyText, "Export a fit to the clipboard")
|
||||
editMenu.Append(wx.ID_PASTE, pasteText, "Import a fit from the clipboard")
|
||||
editMenu.AppendSeparator()
|
||||
editMenu.Append(self.saveCharId, "Save Character")
|
||||
|
||||
# Character menu
|
||||
windowMenu = wx.Menu()
|
||||
|
||||
@@ -191,12 +191,46 @@ class Character(object):
|
||||
# Flush incase all0 & all5 weren't in the db yet
|
||||
eos.db.commit()
|
||||
sFit = service.Fit.getInstance()
|
||||
return map(lambda c: (c.ID, c.name, c == sFit.character), eos.db.getCharacterList())
|
||||
|
||||
for thing in eos.db.character_session.dirty:
|
||||
if isinstance(thing, eos.types.Skill):
|
||||
if not thing.character.isDirty:
|
||||
thing.character.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):
|
||||
char = eos.db.getCharacter(charID)
|
||||
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)
|
||||
if not char.isDirty:
|
||||
return
|
||||
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)
|
||||
|
||||
def getSkillGroups(self):
|
||||
cat = eos.db.getCategory(16)
|
||||
groups = []
|
||||
|
||||
Reference in New Issue
Block a user