Skip to content

Commit

Permalink
Separate projected fits from list of affectors. Also, show when affec…
Browse files Browse the repository at this point in the history
…ted module is projected. Still need to clean up affector tree stuff
  • Loading branch information
blitzmann committed Jul 17, 2015
1 parent 3ad5aaa commit d6199a5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
9 changes: 6 additions & 3 deletions eos/modifiedAttributeDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,16 @@ def __afflict(self, attributeName, operation, bonus, used=True):
if attributeName not in self.__affectedBy:
self.__affectedBy[attributeName] = {}
affs = self.__affectedBy[attributeName]
origin = self.fit.getOrigin()
fit = origin if origin and origin != self.fit else self.fit
# If there's no set for current fit in dictionary, create it
if self.fit not in affs:
affs[self.fit] = []
if fit not in affs:
affs[fit] = []
# Reassign alias to list
affs = affs[self.fit]
affs = affs[fit]
# Get modifier which helps to compose 'Affected by' map
modifier = self.fit.getModifier()

# Add current affliction to list
affs.append((modifier, operation, bonus, used))

Expand Down
5 changes: 5 additions & 0 deletions eos/saveddata/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,10 @@ def __deepcopy__(self, memo):
copy = Skill(self.item, self.level, self.__ro)
return copy

def __repr__(self):
return "Skill(ID={}, name={}) at {}".format(
self.item.ID, self.item.name, hex(id(self))
)

class ReadOnlyException(Exception):
pass
8 changes: 6 additions & 2 deletions eos/saveddata/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,9 @@ def clear(self, projected=False):

#Methods to register and get the thing currently affecting the fit,
#so we can correctly map "Affected By"
def register(self, currModifier):
def register(self, currModifier, origin=None):
self.__modifier = currModifier
self.__origin = origin
if hasattr(currModifier, "itemModifiedAttributes"):
currModifier.itemModifiedAttributes.fit = self
if hasattr(currModifier, "chargeModifiedAttributes"):
Expand All @@ -391,6 +392,9 @@ def register(self, currModifier):
def getModifier(self):
return self.__modifier

def getOrigin(self):
return self.__origin

def __calculateGangBoosts(self, runTime):
logger.debug("Applying gang boosts in `%s` runtime for %s", runTime, self)
for name, info in self.gangBoosts.iteritems():
Expand Down Expand Up @@ -506,7 +510,7 @@ def calculateModifiedAttributes(self, targetFit=None, withBoosters=False, dirtyS
item.calculateModifiedAttributes(self, runTime, False)
if projected is True:
for _ in xrange(projectionInfo.amount):
targetFit.register(item)
targetFit.register(item, origin=self)
item.calculateModifiedAttributes(targetFit, runTime, True)

timer.checkpoint('Done with runtime: %s'%runTime)
Expand Down
8 changes: 8 additions & 0 deletions eos/saveddata/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,14 @@ def __deepcopy__(self, memo):
copy.state = self.state
return copy

def __repr__(self):
if self.item:
return "Module(ID={}, name={}) at {}".format(
self.item.ID, self.item.name, hex(id(self))
)
else:
return "EmptyModule() at {}".format(hex(id(self)))

class Rack(Module):
'''
This is simply the Module class named something else to differentiate
Expand Down
47 changes: 32 additions & 15 deletions gui/itemStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import sys
import wx.lib.mixins.listctrl as listmix
import wx.html
from eos.types import Ship, Module, Skill, Booster, Implant, Drone, Mode
from eos.types import Fit, Ship, Module, Skill, Booster, Implant, Drone, Mode
from gui.utils.numberFormatter import formatAmount
import service
import config
Expand Down Expand Up @@ -549,9 +549,9 @@ def OnClick(self, event):


class ItemAffectedBy (wx.Panel):
ORDER = [Ship, Mode, Module, Drone, Implant, Booster, Skill]
ORDER = [Fit, Ship, Mode, Module, Drone, Implant, Booster, Skill]
def __init__(self, parent, stuff, item):
wx.Panel.__init__ (self, parent)
wx.Panel.__init__(self, parent)
self.stuff = stuff
self.item = item

Expand Down Expand Up @@ -640,26 +640,37 @@ def ToggleViewMode(self, event):
def PopulateTree(self):
root = self.affectedBy.AddRoot("WINPWNZ0R")
self.affectedBy.SetPyData(root, None)

activeFit = gui.mainFrame.MainFrame.getInstance().getActiveFit()
print activeFit
self.imageList = wx.ImageList(16, 16)
self.affectedBy.SetImageList(self.imageList)

cont = self.stuff.itemModifiedAttributes if self.item == self.stuff.item else self.stuff.chargeModifiedAttributes
things = {}
holding = {}

for attrName in cont.iterAfflictions():
# if value is 0 or there has been no change from original to modified, return
if cont[attrName] == (cont.getOriginal(attrName) or 0):
continue

for fit, afflictors in cont.getAfflictions(attrName).iteritems():
for afflictor, modifier, amount, used in afflictors:
container = things
#print "\t", afflictor, modifier, amount, used,

if not used or afflictor.item is None:
continue

if afflictor.item.name not in things:
things[afflictor.item.name] = [type(afflictor), set(), []]
if fit.ID != activeFit:
if fit not in holding:
holding[fit] = {}
container = holding[fit]

info = things[afflictor.item.name]
if afflictor.item.name not in container:
container[afflictor.item.name] = [type(afflictor), set(), [], getattr(afflictor, "projected", False)]

info = container[afflictor.item.name]
info[1].add(afflictor)
# If info[1] > 1, there are two separate modules working.
# Check to make sure we only include the modifier once
Expand All @@ -668,15 +679,20 @@ def PopulateTree(self):
continue
info[2].append((attrName, modifier, amount))

for fit, items in holding.iteritems():
child = self.affectedBy.AppendItem(root, fit.name, self.imageList.Add(bitmapLoader.getBitmap("ship_small", "icons")))
self.test(child, holding[fit])
self.test(root, things)
self.ExpandCollapseTree()

def test(self, parent, things):
order = things.keys()
order.sort(key=lambda x: (self.ORDER.index(things[x][0]), x))

for itemName in order:
info = things[itemName]

afflictorType, afflictors, attrData = info
afflictorType, afflictors, attrData, projected = info
counter = len(afflictors)

baseAfflictor = afflictors.pop()
if afflictorType == Ship:
itemIcon = self.imageList.Add(bitmapLoader.getBitmap("ship_small", "icons"))
Expand All @@ -686,7 +702,12 @@ def PopulateTree(self):
else:
itemIcon = -1

child = self.affectedBy.AppendItem(root, "%s" % itemName if counter == 1 else "%s x %d" % (itemName,counter), itemIcon)
displayStr = "%s" % itemName if counter == 1 else "%s x %d" % (itemName,counter)

if projected:
displayStr += " (projected)"

child = self.affectedBy.AppendItem(parent, displayStr, itemIcon)

if counter > 0:
attributes = []
Expand Down Expand Up @@ -716,7 +737,6 @@ def PopulateTree(self):
attributes.append((attrName, (displayName if displayName != "" else attrName), attrModifier, attrAmount, penalized, attrIcon))

attrSorted = sorted(attributes, key = lambda attribName: attribName[0])

for attr in attrSorted:
attrName, displayName, attrModifier, attrAmount, penalized, attrIcon = attr
if self.toggleView == 1:
Expand All @@ -725,6 +745,3 @@ def PopulateTree(self):
else:
treeitem = self.affectedBy.AppendItem(child, "%s %s %.2f %s" % (attrName, attrModifier, attrAmount, penalized), attrIcon)
self.affectedBy.SetPyData(treeitem,"%s %s %.2f %s" % ((displayName if displayName != "" else attrName), attrModifier, attrAmount, penalized))

self.ExpandCollapseTree()

0 comments on commit d6199a5

Please sign in to comment.