Rework code to use handle and unit to access various definitions

This commit is contained in:
DarkPhoenix
2019-06-25 11:40:10 +03:00
parent 022f0c06ee
commit 4b960af9ab
3 changed files with 50 additions and 79 deletions

View File

@@ -47,7 +47,7 @@ class Graph(metaclass=ABCMeta):
@property
def yDefMap(self):
return OrderedDict((y.handle, y) for y in self.yDefs)
return OrderedDict(((y.handle, y.unit), y) for y in self.yDefs)
@property
@abstractmethod
@@ -56,7 +56,7 @@ class Graph(metaclass=ABCMeta):
@property
def xDefMap(self):
return OrderedDict((x.handle, x) for x in self.xDefs)
return OrderedDict(((x.handle, x.unit), x) for x in self.xDefs)
@property
def inputs(self):
@@ -64,36 +64,20 @@ class Graph(metaclass=ABCMeta):
@property
def inputMap(self):
return OrderedDict((i.handle, i) for i in self.inputs)
return OrderedDict(((i.handle, i.unit), i) for i in self.inputs)
@property
def srcVectorDef(self):
return None
@property
def tgtVectorDef(self):
return None
@property
def hasTargets(self):
return False
@property
def hasSrcVector(self):
return False
@property
def srcVectorLengthHandle(self):
return None
@property
def srcVectorAngleHandle(self):
return None
@property
def hasTgtVector(self):
return False
@property
def tgtVectorLengthHandle(self):
return None
@property
def tgtVectorAngleHandle(self):
return None
@property
def redrawOnEffectiveChange(self):
return False
@@ -130,9 +114,10 @@ class Graph(metaclass=ABCMeta):
getattr(self, yDef.eosGraph).clearCache(key=key)
XDef = namedtuple('XDef', ('handle', 'label', 'unit', 'mainInputHandle'))
YDef = namedtuple('YDef', ('handle', 'label', 'unit', 'eosGraph'))
Input = namedtuple('Input', ('handle', 'label', 'unit', 'iconID', 'defaultValue', 'defaultRange', 'mainOnly'))
XDef = namedtuple('XDef', ('handle', 'unit', 'label', 'mainInput'))
YDef = namedtuple('YDef', ('handle', 'unit', 'label', 'eosGraph'))
Input = namedtuple('Input', ('handle', 'unit', 'label', 'iconID', 'defaultValue', 'defaultRange', 'mainOnly'))
VectorDef = namedtuple('VectorDef', ('lengthHandle', 'lengthUnit', 'angleHandle', 'angleUnit'))
# noinspection PyUnresolvedReferences

View File

@@ -19,7 +19,7 @@
from eos.graph.fitDpsVsRange import FitDpsVsRangeGraph as EosGraph
from .base import Graph, XDef, YDef, Input
from .base import Graph, XDef, YDef, Input, VectorDef
class FitDamageStatsGraph(Graph):
@@ -33,55 +33,39 @@ class FitDamageStatsGraph(Graph):
@property
def xDefs(self):
return [
XDef(handle='distance', label='Distance', unit='km', mainInputHandle='distance'),
XDef(handle='time', label='Time', unit='s', mainInputHandle='time'),
XDef(handle='tgtSpeedAbs', label='Target speed', unit='m/s', mainInputHandle='tgtSpeed'),
XDef(handle='tgtSpeedRel', label='Target speed', unit='%', mainInputHandle='tgtSpeed'),
XDef(handle='tgtSigRadAbs', label='Target signature radius', unit='m', mainInputHandle='tgtSigRad'),
XDef(handle='tgtSigRadRel', label='Target signature radius', unit='%', mainInputHandle='tgtSigRad')]
XDef(handle='distance', unit='km', label='Distance', mainInput=('distance', 'km')),
XDef(handle='time', unit='s', label='Time', mainInput=('time', 's')),
XDef(handle='tgtSpeed', unit='m/s', label='Target speed', mainInput=('tgtSpeed', '%')),
XDef(handle='tgtSpeed', unit='%', label='Target speed', mainInput=('tgtSpeed', '%')),
XDef(handle='tgtSigRad', unit='m', label='Target signature radius', mainInput=('tgtSigRad', '%')),
XDef(handle='tgtSigRad', unit='%', label='Target signature radius', mainInput=('tgtSigRad', '%'))]
@property
def yDefs(self):
return [
YDef(handle='dps', label='DPS', unit=None, eosGraph='eosGraph'),
YDef(handle='volley', label='Volley', unit=None, eosGraph='eosGraph'),
YDef(handle='damage', label='Damage inflicted', unit=None, eosGraph='eosGraph')]
YDef(handle='dps', unit=None, label='DPS', eosGraph='eosGraph'),
YDef(handle='volley', unit=None, label='Volley', eosGraph='eosGraph'),
YDef(handle='damage', unit=None, label='Damage inflicted', eosGraph='eosGraph')]
@property
def inputs(self):
return [
Input(handle='time', label='Time', unit='s', iconID=1392, defaultValue=None, defaultRange=(0, 80), mainOnly=False),
Input(handle='distance', label='Distance', unit='km', iconID=1391, defaultValue=50, defaultRange=(0, 100), mainOnly=False),
Input(handle='tgtSpeed', label='Target speed', unit='%', iconID=1389, defaultValue=100, defaultRange=(0, 100), mainOnly=False),
Input(handle='tgtSigRad', label='Target signature radius', unit='%', iconID=1390, defaultValue=100, defaultRange=(100, 200), mainOnly=True)]
Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=None, defaultRange=(0, 80), mainOnly=False),
Input(handle='distance', unit='km', label='Distance', iconID=1391, defaultValue=50, defaultRange=(0, 100), mainOnly=False),
Input(handle='tgtSpeed', unit='%', label='Target speed', iconID=1389, defaultValue=100, defaultRange=(0, 100), mainOnly=False),
Input(handle='tgtSigRad', unit='%', label='Target signature radius', iconID=1390, defaultValue=100, defaultRange=(100, 200), mainOnly=True)]
@property
def srcVectorDef(self):
return VectorDef(lengthHandle='atkSpeed', lengthUnit='%', angleHandle='atkAngle', angleUnit='degrees')
@property
def tgtVectorDef(self):
return VectorDef(lengthHandle='tgtSpeed', lengthUnit='%', angleHandle='tgtAngle', angleUnit='degrees')
@property
def hasTargets(self):
return True
@property
def hasSrcVector(self):
return True
@property
def srcVectorLengthHandle(self):
return 'atkSpeed'
@property
def srcVectorAngleHandle(self):
return 'atkAngle'
@property
def hasTgtVector(self):
return True
@property
def tgtVectorLengthHandle(self):
return 'tgtSpeed'
@property
def tgtVectorAngleHandle(self):
return 'tgtAngle'
FitDamageStatsGraph.register()

View File

@@ -123,19 +123,21 @@ class GraphControlPanel(wx.Panel):
self.xSubSelection.SetSelection(0)
# Setup inputs
shownHandles = set()
if view.hasSrcVector:
shownHandles.add(view.srcVectorLengthHandle)
shownHandles.add(view.srcVectorAngleHandle)
if view.hasTgtVector:
shownHandles.add(view.tgtVectorLengthHandle)
shownHandles.add(view.tgtVectorAngleHandle)
for inputDef in (view.inputMap[view.xDefs[0].mainInputHandle], *(i for i in view.inputs)):
if inputDef.handle != view.xDefs[0].mainInputHandle and inputDef.mainOnly:
shownFields = set()
srcVectorDef = view.srcVectorDef
if srcVectorDef is not None:
shownFields.add((srcVectorDef.lengthHandle, srcVectorDef.lengthUnit))
shownFields.add((srcVectorDef.angleHandle, srcVectorDef.angleUnit))
tgtVectorDef = view.tgtVectorDef
if tgtVectorDef is not None:
shownFields.add((tgtVectorDef.lengthHandle, tgtVectorDef.lengthUnit))
shownFields.add((tgtVectorDef.angleHandle, tgtVectorDef.angleUnit))
for inputDef in (view.inputMap[view.xDefs[0].mainInput], *(i for i in view.inputs)):
if (inputDef.handle, inputDef.unit) != view.xDefs[0].mainInput and inputDef.mainOnly:
continue
if inputDef.handle in shownHandles:
if (inputDef.handle, inputDef.unit) in shownFields:
continue
shownHandles.add(inputDef.handle)
shownFields.add((inputDef.handle, inputDef.unit))
textBox = wx.TextCtrl(self, wx.ID_ANY, style=0)
textBox.Bind(wx.EVT_TEXT, self.OnFieldChanged)
self.inputsSizer.Add(textBox, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)