Skip to content

Commit

Permalink
Collecting Items for the Market files and ensuring uniqueness (still …
Browse files Browse the repository at this point in the history
…work to do)
  • Loading branch information
idarthjedi committed Mar 1, 2023
1 parent 9802bd6 commit 4036102
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 12 deletions.
15 changes: 6 additions & 9 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from types_loader import load_profiles
from PyQt6.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton
from dayz_admin_tools.utilities.economy.Types import Types
from dayz_admin_tools.utilities.economy.Type import Type
from config import config

import mainConfig
import sys
Expand All @@ -13,6 +13,8 @@
_profiles_directory = ""
_json_directory = ""
_xml_directory = ""
_market_dir = ""
_trader_dir = ""

_debug = True

Expand Down Expand Up @@ -50,6 +52,8 @@ def readconfig():
global _profiles_directory
global _json_directory
global _xml_directory
global _market_dir
global _trader_dir

if not os.path.exists('config/app-config.json'):
# view in GUI
Expand All @@ -62,14 +66,7 @@ def readconfig():
MainWindow.show()
ret = app.exec()

with open('config/app-config.json') as config_file:
try:
config = json.load(config_file)
_profiles_directory = config["properties"]["dayz-profile-dir"]
_json_directory = config["properties"]["other_dirs"]["json"]
_xml_directory = config["properties"]["other_dirs"]["xml"]
except json.JSONDecodeError as error:
print(Fore.RED + f"Cannot validate app-config.json")
_profiles_directory, _market_dir, _trader_dir, _json_directory, _xml_directory = config.loadConfig()

return

Expand Down
33 changes: 31 additions & 2 deletions dayz_admin_tools/utilities/traders/expansion/Items.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import json

import jsonschema.exceptions

from dayz_admin_tools.config import ROOT_DIR
from jsonschema import validate as json_validate
from dayz_admin_tools.utilities.files.fManager import FileManager
from jsonpath_ng import jsonpath
from jsonpath_ng.ext import parser as json_parser

from dayz_admin_tools.utilities.economy.Type import Type
from dayz_admin_tools.utilities.traders.expansion.Item import Item
from colorama import Fore, Back, Style


Expand Down Expand Up @@ -53,6 +54,34 @@ def load_items(self, file: str) -> tuple[bool, list]:
# The document failed Schema Validation, move onto the next document
return False, errors

classname_search = json_parser.parse('$..Items..ClassName')

items_list = classname_search.find(json_doc)
if len(items_list) <= 0:
errors.append(f"{Fore.RED}{file} contains no Items!")
return

for market_item in items_list:
if market_item.value in self:
errors.append(f"Object {market_item.value} duplications:{os.linesep}"\
f"\t{Fore.GREEN}Winner: {self[market_item.value].filesource}{os.linesep}"\
f"\t{Fore.RED}Loser: {file}.")
else:
parent = self[market_item.value] = Item(market_item.value, file)
# check for Variants
variants_search = json_parser.parse(
f"$.Items[?(@.ClassName=='{market_item.value}')].Variants")
variants_list = variants_search.find(json_doc)
if len(variants_list[0].value) > 0:
# no variants
for variant in variants_list[0].value:
if variant in self:
errors.append(f"Object {variant} variant listed with duplications:{os.linesep}" \
f"\t{Fore.GREEN}Winner: {self[variant].filesource}{os.linesep}" \
f"\t{Fore.RED}Loser: {file}.")
else:
self[variant] = Item(variant, file, parent)

# JSON turned out to be valid per schema, loop through each of the Items and create an Item object

# # xml turned out to be valid per schema, loop through each of the type in types and create an type object
Expand Down
56 changes: 55 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ colorama = "^0.4.6"
lxml = "^4.9.2"
pyqt6 = "^6.4.2"
jsonschema = "^4.17.3"
jsonpath-ng = "^1.5.3"


[build-system]
Expand Down

0 comments on commit 4036102

Please sign in to comment.