add variations for drones, fighters, boosters, and implants

This commit is contained in:
Ebag333
2017-01-12 01:24:26 -08:00
parent d489fdd700
commit 3774e3bca0
4 changed files with 77 additions and 9 deletions

View File

@@ -23,6 +23,7 @@ from sqlalchemy.sql import and_, or_, select
import eos.config
from eos.db import gamedata_session
from eos.db.gamedata.metaGroup import metatypes_table, items_table
from eos.db.gamedata.group import groups_table
from eos.db.util import processEager, processWhere
from eos.types import Item, Category, Group, MarketGroup, AttributeInfo, MetaData, MetaGroup
@@ -231,7 +232,7 @@ def searchItems(nameLike, where=None, join=None, eager=None):
@cachedQuery(2, "where", "itemids")
def getVariations(itemids, where=None, eager=None):
def getVariations(itemids, groupIDs=None, where=None, eager=None):
for itemid in itemids:
if not isinstance(itemid, int):
raise TypeError("All passed item IDs must be integers")
@@ -244,7 +245,18 @@ def getVariations(itemids, where=None, eager=None):
joinon = items_table.c.typeID == metatypes_table.c.typeID
vars = gamedata_session.query(Item).options(*processEager(eager)).join((metatypes_table, joinon)).filter(
filter).all()
return vars
if vars:
return vars
elif groupIDs:
itemfilter = or_(*(groups_table.c.groupID == groupID for groupID in groupIDs))
filter = processWhere(itemfilter, where)
joinon = items_table.c.groupID == groups_table.c.groupID
vars = gamedata_session.query(Item).options(*processEager(eager)).join((groups_table, joinon)).filter(
filter).all()
return vars
@cachedQuery(1, "attr")

View File

@@ -12,7 +12,13 @@ class MetaSwap(ContextMenu):
def display(self, srcContext, selection):
if self.mainFrame.getActiveFit() is None or srcContext not in ("fittingModule",):
if self.mainFrame.getActiveFit() is None or srcContext not in (
"fittingModule",
"droneItem",
"fighterItem",
"boosterItem",
"implantItem",
):
return False
# Check if list of variations is same for all of selection
@@ -92,9 +98,58 @@ class MetaSwap(ContextMenu):
fitID = self.mainFrame.getActiveFit()
fit = sFit.getFit(fitID)
for mod in self.selection:
pos = fit.modules.index(mod)
sFit.changeModule(fitID, pos, item.ID)
for selected_item in self.selection:
if type(selected_item).__name__== 'Module':
pos = fit.modules.index(selected_item)
sFit.changeModule(fitID, pos, item.ID)
elif type(selected_item).__name__== 'Drone':
drone_count = None
drone_index = None
for idx, drone_stack in enumerate(fit.drones):
if drone_stack is selected_item:
drone_count = drone_stack.amount
sFit.removeDrone(fitID, idx, drone_count)
break
if drone_count:
sFit.addDrone(fitID, item.ID, drone_count)
elif type(selected_item).__name__== 'Fighter':
fighter_count = None
fighter_index = None
for idx, fighter_stack in enumerate(fit.fighters):
# Right now fighters always will have max stack size.
# Including this for future improvement, so if adjustable
# fighter stacks get added we're ready for it.
if fighter_stack is selected_item:
if fighter_stack.amount > 0:
fighter_count = fighter_stack.amount
elif fighter_stack.amount == -1:
fighter_count = fighter_stack.amountActive
else:
fighter_count.amount = 0
sFit.removeFighter(fitID, idx)
break
sFit.addFighter(fitID, item.ID)
elif type(selected_item).__name__== 'Booster':
for idx, booster_stack in enumerate(fit.boosters):
if booster_stack is selected_item:
sFit.removeBooster(fitID, idx)
sFit.addBooster(fitID, item.ID)
break
elif type(selected_item).__name__== 'Implant':
for idx, implant_stack in enumerate(fit.implants):
if implant_stack is selected_item:
sFit.removeImplant(fitID, idx)
sFit.addImplant(fitID, item.ID, False)
break
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))

View File

@@ -722,7 +722,7 @@ class Fit(object):
self.recalc(fit)
return True
def addDrone(self, fitID, itemID):
def addDrone(self, fitID, itemID, numDronesToAdd=1):
if fitID is None:
return False
@@ -741,7 +741,7 @@ class Fit(object):
fit.drones.append(drone)
else:
return False
drone.amount += 1
drone.amount += numDronesToAdd
eos.db.commit()
self.recalc(fit)
return True

View File

@@ -537,7 +537,8 @@ class Market():
variations.update(parents)
# Add all variations of parents to the set
parentids = tuple(item.ID for item in parents)
variations.update(eos.db.getVariations(parentids))
groupids = tuple(item.group.ID for item in parents)
variations.update(eos.db.getVariations(parentids, groupids))
return variations
def getGroupsByCategory(self, cat):