Jump to content

Item_proto and item_names checker


Recommended Posts

 

 

Hi 🙂  Maybe not many of you need this, but since I made it, it may help someone.
It's a simple script made in python, which checks both files (item_names.txt and item_proto.txt) for missing VNUM differences in one of the files.

For example: I used it because I rebuilt both files, deleted items I will never use and restructured some data. In the end, I realized that I have quite a few missing lines from the item_proto.txt file but have them present in item_names.txt. So I made this script, which checked every VNUM present in item_names.txt but missing from item_proto.txt. This made it much easier for me to solve this problem. 

Atention: For the GUI one, you will need to install PyQt5 via PIP

There is a version of just code, so u gonna modify in the code the file names, then run it via terminal

spacer.png

Spoiler
def read_vnums_from_file(filename):
	vnums = set()
	with open(filename, 'r', encoding='utf-8', errors='replace') as file:
		next(file)
		for line_number, line in enumerate(file, start=1):
			line = line.strip()
			if not line:
				continue
			parts = line.split()
			if len(parts) >= 1:
				vnum = parts[0]
				vnums.add(vnum)
			else:
				print(f"Warning: Invalid data at line {line_number} in file {filename}")
	return vnums

item_proto_file = "item_proto.txt"
item_names_file = "item_names.txt"

try:
	item_proto_vnums = read_vnums_from_file(item_proto_file)
	item_names_vnums = read_vnums_from_file(item_names_file)

	missing_vnums = item_proto_vnums - item_names_vnums

	print("Vnums present in item_proto.txt but not in item_names.txt:")
	print(missing_vnums)
except FileNotFoundError as e:
	print(f"Error: {e}")
except Exception as e:
	print(f"Error: An unexpected error occurred - {e}")

 

And there is a GUI version, when u run it into a terminal, it will open a GUI and u can chose the files from anywhere, check vnums and also lines
spacer.png

Spoiler
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QFileDialog, QTextEdit, QVBoxLayout, QWidget, QTableWidget, QTableWidgetItem, QLabel
from PyQt5.QtGui import QTextCursor, QColor
from PyQt5.QtCore import Qt

def read_vnums_from_file(filename):
	vnums = {}
	with open(filename, 'r', encoding='utf-8', errors='replace') as file:
		next(file)
		for line_number, line in enumerate(file, start=1):
			line = line.strip()
			if not line:
				continue
			parts = line.split()
			if len(parts) >= 1:
				vnum = parts[0]
				vnums[vnum] = line_number
	return vnums

class VnumsCheckerApp(QMainWindow):
	def __init__(self):
		super().__init__()

		self.initUI()

	def initUI(self):
		self.setWindowTitle("Vnums Checker Metin2Dev")
		self.setGeometry(100, 100, 200, 500)
		self.setStyleSheet("background-color: #282a36; color: #f8f8f2;")

		self.central_widget = QWidget(self)
		self.setCentralWidget(self.central_widget)

		self.layout = QVBoxLayout(self.central_widget)

		self.choose_item_proto_btn = QPushButton("Choose item_proto.txt", self.central_widget)
		self.choose_item_proto_btn.setStyleSheet("background-color: #6272a4; color: #f8f8f2;")
		self.choose_item_proto_btn.clicked.connect(self.choose_item_proto_file)
		self.layout.addWidget(self.choose_item_proto_btn)

		self.choose_item_names_btn = QPushButton("Choose item_names.txt", self.central_widget)
		self.choose_item_names_btn.setStyleSheet("background-color: #6272a4; color: #f8f8f2;")
		self.choose_item_names_btn.clicked.connect(self.choose_item_names_file)
		self.layout.addWidget(self.choose_item_names_btn)

		self.check_btn = QPushButton("Check Missing Vnums", self.central_widget)
		self.check_btn.setStyleSheet("background-color: #6272a4; color: #f8f8f2;")
		self.check_btn.clicked.connect(self.check_missing_vnums)
		self.layout.addWidget(self.check_btn)

		self.vnums_label = QLabel("Missing Vnums and Line Numbers in item_proto.txt:", self.central_widget)
		self.vnums_label.setStyleSheet("color: #ff79c6;")
		self.layout.addWidget(self.vnums_label)

		self.table = QTableWidget(self.central_widget)
		self.table.setStyleSheet("background-color: #44475a; color: #f8f8f2;")
		self.table.setColumnCount(2)
		self.table.setHorizontalHeaderLabels(["Vnum", "Line Number"])
		self.table.setEditTriggers(QTableWidget.NoEditTriggers)  # Prevent editing cells
		
		header = self.table.horizontalHeader()
		header.setStyleSheet("background-color: #44475a; color: #f8f8f2;")
		header.setDefaultAlignment(Qt.AlignLeft | Qt.AlignVCenter)  # Adjust alignment

		# Set color for header labels
		header_item = QTableWidgetItem("Vnum")
		header_item.setForeground(QColor("#ff79c6"))  # Set the desired color
		self.table.setHorizontalHeaderItem(0, header_item)

		header_item = QTableWidgetItem("Line Number")
		header_item.setForeground(QColor("#ff79c6"))  # Set the desired color
		self.table.setHorizontalHeaderItem(1, header_item)
		
		self.layout.addWidget(self.table)

		self.layout.setContentsMargins(20, 20, 20, 20)
		self.layout.setSpacing(10)

		self.selected_item_proto = ""
		self.selected_item_names = ""


	def choose_item_proto_file(self):
		file_dialog = QFileDialog()
		file_dialog.setNameFilter("Text Files (*.txt)")
		item_proto_file, _ = file_dialog.getOpenFileName(self, "Choose item_proto.txt")
		if item_proto_file:
			self.selected_item_proto = item_proto_file
			self.choose_item_proto_btn.setText(item_proto_file.split('/')[-1])

	def choose_item_names_file(self):
		file_dialog = QFileDialog()
		file_dialog.setNameFilter("Text Files (*.txt)")
		item_names_file, _ = file_dialog.getOpenFileName(self, "Choose item_names.txt")
		if item_names_file:
			self.selected_item_names = item_names_file
			self.choose_item_names_btn.setText(item_names_file.split('/')[-1])

	def check_missing_vnums(self):
		if not self.selected_item_proto or not self.selected_item_names:
			self.table.clearContents()
			self.table.setRowCount(0)
			return
		table_width = self.table.viewport().width()
		self.table.setColumnWidth(0, table_width // 2 - 9)
		self.table.setColumnWidth(1, table_width // 2 - 9)
		try:
			item_proto_vnums = read_vnums_from_file(self.selected_item_proto)
			item_names_vnums = read_vnums_from_file(self.selected_item_names)

			missing_vnums = [(vnum, str(line_number)) for vnum, line_number in item_proto_vnums.items() if vnum not in item_names_vnums]

			self.table.setRowCount(len(missing_vnums))
			for row, (vnum, line_number) in enumerate(missing_vnums):
				vnum_item = QTableWidgetItem(vnum)
				line_number_item = QTableWidgetItem(line_number)
				self.table.setItem(row, 0, vnum_item)
				self.table.setItem(row, 1, line_number_item)
		except Exception as e:
			self.table.clearContents()
			self.table.setRowCount(0)

def main():
	app = QApplication(sys.argv)
	window = VnumsCheckerApp()
	window.show()
	sys.exit(app.exec_())

if __name__ == "__main__":
	main()

 

 

Edited by Bughy
Adding Infos about requirements
  • Metin2 Dev 2
  • Good 3
Link to comment
Share on other sites

  • Forum Moderator

Thanks for the release, but if you do a quick search in the forum, you'll find that I released something similar to this 4 years ago.

 

.png

  • Lmao 1
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.