Skip to content

Commit

Permalink
Alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
syntaxaire committed Jul 7, 2019
1 parent df3a402 commit 3d1f696
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
2 changes: 0 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
xmlpath: /Users/rlb77/Library/Application Support/Steam/SteamApps/common/Caves of Qud/CoQ.app/Contents/Resources/Data/StreamingAssets/Base

Image overrides:
Asphodel: Earl_asphodel.png
32 changes: 18 additions & 14 deletions qud_explorer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import pprint
import sys

from PySide2.QtCore import QModelIndex
from PySide2.QtGui import QStandardItemModel, QStandardItem, QIcon
from PySide2.QtWidgets import QMainWindow, QApplication, QTreeView, QSizePolicy, QAbstractItemView
from PySide2.QtWidgets import QMainWindow, QApplication, QTreeView, QSizePolicy, QAbstractItemView, \
QFileDialog

from item import wikify_item, get_item_stats
import qud_object_tree
from qud_explorer_window import Ui_MainWindow
from qud_object import QudObject
from qud_object_tree import qud_object_root

# most interesting targets to have expanded in the tree to start
INITIAL_EXPANSION_TARGETS = ['Food', 'MeleeWeapon', 'MissileWeapon', 'Armor', 'Shield', 'Token',
Expand Down Expand Up @@ -60,15 +58,12 @@ def __init__(self, app: QApplication, *args, **kwargs):

def open_xml(self):
"""Browse for and open ObjectBluePrints.xml."""
pass
filename = QFileDialog.getOpenFileName()[0]
if filename.endswith('ObjectBlueprints.xml'):
self.qud_object_root = qud_object_tree.load(filename)
self.init_qud_tree_model()

def init_qud_tree_view(self):
self.qud_object_model = QStandardItemModel()
self.qud_object_model.setHorizontalHeaderLabels(['Name', 'Display Name'])
self.items_to_expand = [] # filled out during recursion of the Qud object tree
# We only need to add Object to the model, since all other Objects are loaded as children:
self.qud_object_model.appendRow(
self.init_qud_object(self.qud_object_model, qud_object_root))
size_policy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
size_policy.setHorizontalStretch(1)
size_policy.setVerticalStretch(0)
Expand All @@ -78,10 +73,18 @@ def init_qud_tree_view(self):
self.treeView.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.treeView.setObjectName("treeView")
self.verticalLayout_2.addWidget(self.treeView)
self.treeView.setModel(self.qud_object_model)
self.treeView.setIndentation(10)

def init_qud_tree_model(self):
self.qud_object_model = QStandardItemModel()
# self.qud_object_model.setHorizontalHeaderLabels(['Name', 'Display Name'])
self.items_to_expand = [] # filled out during recursion of the Qud object tree
# We only need to add Object to the model, since all other Objects are loaded as children:
self.qud_object_model.appendRow(
self.init_qud_object(self.qud_object_model, self.qud_object_root))
for item in self.items_to_expand:
recursive_expand(item, self.treeView, self.qud_object_model)
self.treeView.setIndentation(10)
self.treeView.setModel(self.qud_object_model)

def init_qud_object(self, model: QStandardItemModel, qud_object: QudObject):
"""Recursive function to translate hierarchy from the Qud object AnyTree model to the
Expand Down Expand Up @@ -111,6 +114,7 @@ def tree_selection_handler(self, indices):
def search_changed(self):
pass


app = QApplication(sys.argv)
app.setApplicationName("Qud Blueprint Explorer")
main_window = MainWindow(app)
Expand Down
39 changes: 20 additions & 19 deletions qud_object_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
import re

from xml.etree import ElementTree as et
from pathlib import Path

from config import config
from qud_object import QudObject, qindex

# Do some repair of invalid XML
pattern = re.compile("()|()")
xmlpath = Path(config['xmlpath'])
repaired = []
with open(xmlpath/'ObjectBlueprints.xml', 'r', encoding='utf-8') as f:
for line in f:
repaired.append(pattern.sub('', line))
raw = et.fromstringlist(repaired)

# Build the Qud object hierarchy from the XML data
for element in raw:
if element.tag != 'object':
continue
newobj = QudObject(element, qindex)

# import into other modules for access to the root of the Qud object hierarchy
qud_object_root = qindex['Object']

def load(path):
"""Load ObjectBlueprints.xml from the specified filepath and return a reference to the root."""
# Do some repair of invalid XML
pattern = re.compile("()|()")
repaired = []
with open(path, 'r', encoding='utf-8') as f:
for line in f:
repaired.append(pattern.sub('', line))
raw = et.fromstringlist(repaired)

# Build the Qud object hierarchy from the XML data
for element in raw:
if element.tag != 'object':
continue
newobj = QudObject(element, qindex)

# import into other modules for access to the root of the Qud object hierarchy
qud_object_root = qindex['Object']
return qud_object_root

0 comments on commit 3d1f696

Please sign in to comment.