Skip to content

Commit

Permalink
- reworking custom prices for itemstore
Browse files Browse the repository at this point in the history
  • Loading branch information
Graveflo committed May 20, 2021
1 parent 92c3ab1 commit 37437c9
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 45 deletions.
6 changes: 3 additions & 3 deletions src/BDO_Enhancement_Tool/Core/ItemStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def clear(self):

def check_out_item(self, item_id):
if item_id is None:
raise ItemStoreException('Item is none')
return None
if type(item_id) is int:
item_id = STR_FMT_ITM_ID.format(item_id)
return item_id
Expand Down Expand Up @@ -164,8 +164,8 @@ def get_state_json(self) -> dict:
for key, item in self.store_items.items():
items[key] = item.get_state_json()
return {
'items': items,
'custom_prices': self.custom_prices
'items': items.copy(),
'custom_prices': self.custom_prices.copy()
}

def set_state_json(self, state):
Expand Down
29 changes: 12 additions & 17 deletions src/BDO_Enhancement_Tool/EnhanceModelSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class EnhanceModelSettings(EnhanceSettings):
VERSION = '0.0.1.8'
VERSION = '0.0.1.9'

P_FAIL_STACKERS = 'fail_stackers'
P_FAIL_STACKER_SECONDARY = 'fail_stackers_2'
Expand Down Expand Up @@ -89,14 +89,12 @@ def get_state_json(self):
})
item_store = super_state[self.P_ITEM_STORE]
customs = item_store['custom_prices']
new_customs = {}
for k,v in customs.items():
if isinstance(k, Gear):
v['gear'] = 'gear'
new_customs[id(k)] = v
else:
new_customs[k] = v
item_store['custom_prices'] = new_customs
gear_customs = {}
gear_entries = [k for k in customs.keys() if isinstance(k, Gear)]
for ge in gear_entries:
vm = customs.pop(ge)
gear_customs[id(ge)] = vm
super_state['gear_customs'] = gear_customs
return super_state

def unwrap_gear_list(self, gl):
Expand Down Expand Up @@ -153,15 +151,12 @@ def set_state_json(self, state):

item_store = state[self.P_ITEM_STORE]
customs = item_store['custom_prices']
new_customs = {}
for k, v in customs.items():
gear_customs = state.pop('gear_customs')

for k, v in gear_customs.items():
gid = int(k)
if 'gear' in v and gid in self.gear_reg:
v.pop('gear')
new_customs[self.gear_reg[gid]] = {int(x):y for x,y in v.items()}
else:
new_customs[k] = v
item_store['custom_prices'] = new_customs
if gid in self.gear_reg:
customs[self.gear_reg[gid]] = {int(x):y for x,y in v.items()}

super(EnhanceModelSettings, self).set_state_json(state) # load settings base settings first
update_r = {
Expand Down
10 changes: 5 additions & 5 deletions src/BDO_Enhancement_Tool/WidgetTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ def __init__(self, text):
self.setText(text)

def setData(self, role, p_str):
p_str = remove_numeric_modifiers(p_str)
if p_str is None or p_str == '':
super(comma_seperated_twi, self).setData(role, p_str)
else:
super(comma_seperated_twi, self).setData(role, MONNIES_FORMAT.format(int(float(p_str))))
if role == Qt.DisplayRole:
p_str = remove_numeric_modifiers(p_str)
if p_str is None or p_str == '':
return super(comma_seperated_twi, self).setData(role, MONNIES_FORMAT.format(int(float(p_str))))
return super(comma_seperated_twi, self).setData(role, p_str)

# def setText(self, p_str):

Expand Down
24 changes: 17 additions & 7 deletions src/BDO_Enhancement_Tool/Widgets/Abstract_FS_Table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from BDO_Enhancement_Tool.model import SettingsException
from BDO_Enhancement_Tool.WidgetTools import QBlockSig, MONNIES_FORMAT, MPThread, \
GearWidget, set_cell_color_compare, set_cell_lvl_compare, monnies_twi_factory
from BDO_Enhancement_Tool.qt_UI_Common import STR_LENS_PATH
from BDO_Enhancement_Tool.qt_UI_Common import STR_LENS_PATH, COLOR_CUSTOM_PRICE
from BDO_Enhancement_Tool.Core.Gear import Gear, generate_gear_obj, gear_types
from BDO_Enhancement_Tool.Core.ItemStore import ItemStore
from BDO_Enhancement_Tool.Qt_common import SpeedUpTable, clear_table
Expand Down Expand Up @@ -44,20 +44,24 @@ def mouseReleaseEvent(self, a0) -> None:

def cellChanged_callback(self, row, col):
idx_NAME = self.HEADERS.index(HEADER_NAME)
t_item = self.cellWidget(row, idx_NAME)
gw = self.cellWidget(row, idx_NAME)

this_gear = t_item.gear
this_gear = gw.gear
idx_BASE_ITEM_COST = self.get_header_index(HEADER_BASE_ITEM_COST)

if col == 2:
if col == idx_BASE_ITEM_COST:
t_cost = self.item(row, col)
str_this_item = t_cost.text()
if str_this_item == '':
str_this_item = '0'
try:
try:
this_gear.excl = True

this_gear.set_base_item_cost(float(str_this_item))
this_cost_set = float(str_this_item)
item_store = self.enh_model.item_store()
item_store.override_gear_price(this_gear, -1, this_cost_set)
t_item = self.item(row, idx_BASE_ITEM_COST)
t_item.setForeground(COLOR_CUSTOM_PRICE)
this_gear.set_base_item_cost(this_cost_set)
except ValueError:
self.frmMain.sig_show_message.emit(self.frmMain.REGULAR, 'Invalid number: {}'.format(str_this_item))
except ValueError:
Expand Down Expand Up @@ -143,6 +147,8 @@ def table_FS_add_gear(self, this_gear:Gear, check_state=Qt.Checked):
settings = model.settings
rc = self.rowCount()

idx_BASE_ITEM_COST = self.get_header_index(HEADER_BASE_ITEM_COST)

with SpeedUpTable(self):
self.insertRow(rc)
with QBlockSig(self):
Expand All @@ -165,11 +171,15 @@ def table_FS_add_gear(self, this_gear:Gear, check_state=Qt.Checked):
cmb_gt.currentTextChanged.connect(lambda x: set_cell_color_compare(twi_gt, x))
cmb_enh.currentTextChanged.connect(lambda x: set_cell_lvl_compare(twi_lvl, x, this_gear.gear_type))

item_store = model.item_store()

with QBlockSig(self):
f_two.add_to_table(self, rc, col=0)
self.setCellWidget(rc, 1, cmb_gt)
twi = monnies_twi_factory(this_gear.base_item_cost)
self.setItem(rc, 2, twi)
if item_store.price_is_overridden(this_gear, -1):
twi.setForeground(COLOR_CUSTOM_PRICE)
self.setCellWidget(rc, 3, cmb_enh)
self.setItem(rc, 1, twi_gt)
self.setItem(rc, 3, twi_lvl)
Expand Down
6 changes: 3 additions & 3 deletions src/BDO_Enhancement_Tool/Widgets/Abstract_Gear_Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from BDO_Enhancement_Tool.Core.Gear import Gear, generate_gear_obj, gear_types
from BDO_Enhancement_Tool.Core.ItemStore import ItemStore
from BDO_Enhancement_Tool.model import SettingsException
from BDO_Enhancement_Tool.qt_UI_Common import pix, STR_MINUS_PIC, STR_PLUS_PIC, STR_GOLD_PIC, STR_LENS_PATH
from BDO_Enhancement_Tool.qt_UI_Common import pix, STR_MINUS_PIC, STR_PLUS_PIC, STR_GOLD_PIC, STR_LENS_PATH, COLOR_CUSTOM_PRICE
from BDO_Enhancement_Tool.mp_login import CentralMarketPriceUpdator

from .Abstract_Table import AbstractTable
Expand Down Expand Up @@ -140,7 +140,7 @@ def table_itemChanged(self, t_item: QTreeWidgetItem, col):
str_val='0'
this_cost_set = float(str_val)
item_store.override_gear_price(this_gear, -1, this_cost_set)
t_item.setForeground(idx_BASE_ITEM_COST, QColor(Qt.red).lighter())
t_item.setForeground(idx_BASE_ITEM_COST, COLOR_CUSTOM_PRICE)
this_gear.set_base_item_cost(this_cost_set)
self.sig_sec_gear_changed.emit(this_gear)
except ValueError:
Expand Down Expand Up @@ -199,7 +199,7 @@ def set_item_data(self, top_lvl):
top_lvl.setText(idx_BASE_ITEM_COST, MONNIES_FORMAT.format(int(round(this_gear.base_item_cost))))
item_store = self.enh_model.item_store()
if item_store.price_is_overridden(this_gear, -1):
top_lvl.setForeground(idx_BASE_ITEM_COST, QColor(Qt.red).lighter())
top_lvl.setForeground(idx_BASE_ITEM_COST, COLOR_CUSTOM_PRICE)
top_lvl.setText(idx_GEAR_TYPE, gt_name)
top_lvl.setText(idx_TARGET, this_gear.enhance_lvl)
top_lvl.setForeground(idx_GEAR_TYPE, Qt.black)
Expand Down
53 changes: 45 additions & 8 deletions src/BDO_Enhancement_Tool/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def relative_path_convert(x):
:return: str: a path to the file object relative to this file
"""
return os.path.abspath(os.path.join(os.path.split(__file__)[0], x))
from typing import Dict, List
from typing import Dict, List, Union
from .bdo_database.gear_database import GEAR_DB, CachedGearDataBase, GearData
from .Core.CronStones import initialize_cronstone_manager
DB_FOLDER = relative_path_convert('bdo_database') # Could be error if this is a file for some reason
Expand Down Expand Up @@ -151,16 +151,41 @@ class GearItemStore(ItemStore):

def __init__(self, gear_db=None):
if gear_db is None:
gear_db = CachedGearDataBase()
gear_db = GearGTDataBase()
self.gear_db = gear_db
super(GearItemStore, self).__init__()

def override_gear_price(self, gear: Union[Gear, int], grade: int, price: float):
if isinstance(gear, Gear):
if grade == -1:
gear.base_item_cost = price
bn_mp = gear.gear_type.bin_mp(grade)
item_id = gear.item_id
super(GearItemStore, self).override_gear_price(gear, bn_mp, price)
if (item_id is not None) and (gear not in self):
super(GearItemStore, self).override_gear_price(item_id, bn_mp, price)
else: # gear parameter is an item id
gd = self.gear_db.lookup_id(gear)
gt = gd.get_gear_type()
bn_mp = gt.bin_mp(grade)
super(GearItemStore, self).override_gear_price(gear, bn_mp, price)

def price_is_overridden(self, gear, grade):
if isinstance(gear, Gear):
bn_mp = gear.gear_type.bin_mp(grade)
item_id = gear.item_id
return super(GearItemStore, self).price_is_overridden(gear, bn_mp) or \
super(GearItemStore, self).price_is_overridden(item_id, bn_mp)
else: # gear parameter is an item id
gd = self.gear_db.lookup_id(gear)
gt = gd.get_gear_type()
bn_mp = gt.bin_mp(grade)
return super(GearItemStore, self).price_is_overridden(gear, bn_mp)

def check_out_item(self, item):
if isinstance(item, Gear):
item_id = item.item_id
if item_id is None:
raise ItemStoreException('Item ID is None for gear: {}, {}'.format(item, item))
return STR_FMT_ITM_ID.format(item.item_id)
return super(GearItemStore, self).check_out_item(item_id)
else:
return super(GearItemStore, self).check_out_item(item)

Expand All @@ -187,17 +212,25 @@ def get_cost(self, priceable, grade=None):

if priceable in self.custom_prices:
price_reg = self.custom_prices[priceable]
if grade in price_reg:
if bn_mp in price_reg:
return price_reg[bn_mp]
else:
item_id = priceable
bn_mp = grade
if item_id in self.gear_db:
gd = self.gear_db.lookup_id(item_id)
gt = gd.get_gear_type()
if grade is None:
bn_mp = 0
else:
bn_mp = gt.bin_mp(grade)
else:
bn_mp = grade

try:
return super(GearItemStore, self).get_cost(item_id, bn_mp=bn_mp)
except ItemStoreException as e:
if is_gear and bn_mp == 0:
return item_id.base_item_cost
return priceable.base_item_cost
else:
raise e

Expand All @@ -223,4 +256,8 @@ def process_rows(self, rows) -> List[GtGearData]:
def lookup_id(self, item_id) -> GtGearData:
return super(GearGTDataBase, self).lookup_id(item_id)

def __contains__(self, item):
return int(item) in self.id_cache


GEAR_DB_MANAGER = GearGTDataBase()
9 changes: 8 additions & 1 deletion src/BDO_Enhancement_Tool/old_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ def convert_0017(state_obj):
item_store['custom_prices']= {}
return state_obj

def convert_0018(state_obj):
item_store = state_obj['item_store']
item_store['custom_prices'] ={}
state_obj['gear_customs'] = {}
return state_obj


class ConversionError(Exception):
pass
Expand All @@ -225,7 +231,8 @@ def __init__(self, state_obj):
'0.0.1.4': (convert_0014, '0.0.1.5'),
'0.0.1.5': (convert_0015, '0.0.1.6'),
'0.0.1.6': (convert_0016, '0.0.1.7'),
'0.0.1.7': (convert_0017, '0.0.1.8')
'0.0.1.7': (convert_0017, '0.0.1.8'),
'0.0.1.8': (convert_0018, '0.0.1.9')
}

def add_converter(self, target_ver, conversion_func, out_ver):
Expand Down
5 changes: 4 additions & 1 deletion src/BDO_Enhancement_Tool/qt_UI_Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"""
import os

from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPixmap, QColor

from .common import relative_path_convert

Expand Down Expand Up @@ -44,6 +45,8 @@
STR_LENS_PATH = relative_path_convert('Images/lens2.png')


COLOR_CUSTOM_PRICE = QColor(Qt.red).lighter()

class PictureStorage(object):
def __init__(self):
self.pixmap_cache = {}
Expand Down

0 comments on commit 37437c9

Please sign in to comment.