Skip to content

Commit

Permalink
0.2 version: Added parse cheats function
Browse files Browse the repository at this point in the history
  • Loading branch information
nsilveri committed Aug 22, 2023
1 parent 0094e1b commit fd2d32e
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 32 deletions.
116 changes: 88 additions & 28 deletions CHT_Manager.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import tkinter as tk
from tkinter import filedialog, messagebox, ttk
import re

DESCRIPTION = 0
CODE = 1
ENABLE = 2
SELECTED_ITEM = None

VERSION = "0.2"
DATE = "22/08/2023"

cheats = None

def load_file():
global cheats
filepath = filedialog.askopenfilename(filetypes=[("CHT File", "*.cht")])
if filepath:
with open(filepath, "r") as file:
Expand All @@ -27,23 +34,24 @@ def extract_value(input_string):
return extracted_text

def parse_file_content(content):
global cheats
cheats = []
lines = content.split("\n")
current_cheat = None

cheat_number = None
cheat_number = None
for line in lines:
line = line.strip()
if line.startswith("cheats = "):
cheat_number = 0
elif line.startswith("cheat" + str(cheat_number)):
if line.startswith("cheat" + str(cheat_number) + "_desc"):
current_cheat = (extract_value(line),)
current_cheat = (extract_value(line),)
elif line.startswith("cheat" + str(cheat_number) + "_code"):
current_cheat += (extract_value(line),)
current_cheat += (extract_value(line),)
elif line.startswith("cheat" + str(cheat_number) + "_enable"):
current_cheat += ("false",)
cheats.append(current_cheat)
current_cheat += ("false",)
cheats.append(current_cheat)
cheat_number += 1
return cheats

Expand All @@ -58,6 +66,7 @@ def update_cheat_list(cheats):

def show_cheat_details(event):
global SELECTED_ITEM
global cheats

if cheat_list.curselection():
selected = cheat_list.get(cheat_list.curselection()[0])
Expand All @@ -74,7 +83,7 @@ def show_cheat_details(event):

cheat = selected
description_entry.delete(0, tk.END)
description_entry.insert(0, cheat[DESCRIPTION])
description_entry.insert(0, cheat[DESCRIPTION])
code_entry.delete(0, tk.END)
code_entry.insert(0, cheat[CODE])
else:
Expand All @@ -88,42 +97,46 @@ def show_cheat_details(event):

def save_changes():
global SELECTED_ITEM
list_len = cheat_list.size()
print(list_len)
print(SELECTED_ITEM)

if SELECTED_ITEM != None: #cheat_list.curselection():
#selected_index = cheat_list.curselection()[0]
selected = cheat_list.get(SELECTED_ITEM)#(selected_index)
if SELECTED_ITEM is not None and 0 <= SELECTED_ITEM < list_len: #len(cheats):
selected = cheat_list.get(SELECTED_ITEM)
cheat = selected

new_description = description_entry.get()
new_code = code_entry.get()
modified_cheat = (new_description, new_code, "false")
cheats[SELECTED_ITEM] = modified_cheat
cheat_list.delete(SELECTED_ITEM)#(selected_index)
cheat_list.insert(SELECTED_ITEM, modified_cheat)#(selected_index, modified_cheat)
print(cheats[SELECTED_ITEM])
modified_cheat = (new_description, new_code, "false")
print("cheat: " + str(cheat_list))
#cheats[SELECTED_ITEM] = modified_cheat
cheat_list.delete(SELECTED_ITEM)
cheat_list.insert(SELECTED_ITEM, modified_cheat)
#print(cheats[SELECTED_ITEM])
print(cheat_list)
SELECTED_ITEM = None
messagebox.showinfo("Save", "Changes have been successfully saved.")
else:
messagebox.showerror("Error", "Make sure you have selected an item.")
messagebox.showerror("Error", "Make sure you have selected a valid item.")


def delete_cheat():
if cheat_list.curselection():
selected_index = cheat_list.curselection()[0]
cheat_list.delete(selected_index)
cheat_list.delete(selected_index)

def create_new_cheat():
new_description = new_description_entry.get()
new_code = new_code_entry.get()
if new_description and new_code:
new_cheat = (new_description, new_code, "false")
new_cheat = (new_description, new_code, "false")
list_length = cheat_list.size()
cheat_list.insert(list_length, new_cheat)
new_description_entry.delete(0, tk.END)
new_code_entry.delete(0, tk.END)
messagebox.showinfo("New Cheat", "New cheat have been successfully created and added to list.")
messagebox.showinfo("New Cheat", "New cheat has been successfully created and added to the list.")
else:
messagebox.showerror("New Cheat", "Error while creating new cheat.\nPlease insert values")
messagebox.showerror("New Cheat", "Error while creating a new cheat.\nPlease insert values")

def save_content_to_file():
content = []
Expand All @@ -137,15 +150,61 @@ def save_content_to_file():
content.append(f"cheat{i}_code = \"{cheat[CODE]}\"")
content.append(f"cheat{i}_enable = {cheat[ENABLE]}")
content.append("")

filepath = filedialog.asksaveasfilename(defaultextension=".cht", filetypes=[("CHT File", "*.cht")])

if filepath:
with open(filepath, "w") as file:
file.write("\n".join(content))

def info_window():
messagebox.showinfo("Info", "Version: 0.1.1 \n21/08/2023\n\nCredits: Nicola Silveri\nGithub: https://github.com/nsilveri/CHT_Manager")
messagebox.showinfo("Info", "Version: " + VERSION + " \n" + DATE + "\n\nCredits: Nicola Silveri\nGithub: https://github.com/nsilveri/CHT_Manager")

def open_parse_window():
# Crea una nuova finestra per il parsing del testo
parse_window = tk.Toplevel(root)
parse_window.title("Parse Cheat")

# Aggiungi una casella di testo multilinea per incollare il testo
text_widget = tk.Text(parse_window, wrap=tk.WORD, width=40, height=10)
text_widget.pack()


def parse_text():
# Ottieni il testo dalla casella di testo
text = text_widget.get("1.0", "end-1c")

# Utilizza espressioni regolari per trovare tutti i trucchi nel testo
cheats = []
cheat_pattern = r"([A-Za-z0-9\s]+?)(?:\s+(\d+))?\s+([A-Fa-f0-9\sX+]+)"

for line in text.split("\n"):
match = re.match(cheat_pattern, line)
if match:
name = match.group(1).strip()
if(match.group(2)):
name_number = " " + match.group(2)
else:
name_number = ""
code = match.group(3).strip()
cheats.append((name + str(name_number), code, "false"))

# Aggiorna la lista dei trucchi
#update_cheat_list(cheats)
#new_cheat = (new_description, new_code, "false")

for cheat in cheats:
list_length = cheat_list.size()
print("list_length: " + str(list_length))
cheat_list.insert(list_length, cheat)


# Chiudi la finestra di parsing
parse_window.destroy()

# Aggiungi un pulsante "Parse" per avviare l'analisi del testo
parse_button = tk.Button(parse_window, text="Parse", command=parse_text)
parse_button.pack()

root = tk.Tk()
root.title("Cheat Code Management")
Expand Down Expand Up @@ -177,7 +236,7 @@ def info_window():
separator_save_file_h = ttk.Separator(root, orient="horizontal")
separator_save_file_v = ttk.Separator(root, orient="vertical")

credits_label = tk.Label(root, text="Credits: Nicola Silveri")
#credits_label = tk.Label(root, text="Credits: Nicola Silveri")

cheat_list.bind("<Double-Button-1>", show_cheat_details)

Expand All @@ -204,9 +263,10 @@ def info_window():

separator_mod_new_code.grid(row=5, column=1, columnspan=3, sticky="ew")

#separator_save_file_h.grid(row=11, column=3, columnspan=1, sticky="ew")
#separator_save_file_v.grid(row=12, column=3, rowspan=1, sticky="ns")
# Aggiungi un pulsante "Parse cheat"
parse_button = tk.Button(root, text="Parse cheat", command=open_parse_window)
parse_button.grid(row=0, column=1)

cheats = {}
#credits_label.grid(row=13, column=0, columnspan=6)

root.mainloop()
root.mainloop()
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Advertisement:
<img width="55%" height="55%" src="images/Making_new_cheat_item.jpg">
</p>

Adding new itam cheat:
Adding new item cheat:
<p align="center">
<img width="55%" height="55%" src="images/adding_new_cheat_item.jpg">
</p>
Expand All @@ -64,13 +64,41 @@ Advertisement:
<img width="55%" height="55%" src="images/selected_new_item.jpg">
</p>

Parse cheat function:

you can add new cheats simply pasting a list of cheats like this:
<p align="center">
<img width="55%" height="55%" src="images/list_cheat_notepad.jpg">
</p>
Sintax:

CHEAT_NAME(you can add a final numeber) CHEAT_CODE_1 CHEAT_CODE_2 ...

<p align="center">
<img width="55%" height="55%" src="images/parse_cheat_paste_window.jpg">
</p>

<p align="center">
<img width="55%" height="55%" src="images/parse_cheat_created_items.jpg">
</p>

Saving edited list in a cht file:
<p align="center">
<img width="55%" height="55%" src="images/saving_new_cht_file.jpg">
</p>

NEXT FEATURES:
RELEASES:

- Ability to extract an item cheat by copying and pasting one or more lines of cheats, for example, from a web page.
The release is made with "pyinstaller"

- Enable state select
CHANGELOG:

0.1:
Initial release
----
0.1.1:
Some GUI changes
----
0.2:
Added parse cheats function
Binary file added images/list_cheat_notepad.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/main_screen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/parse_cheat_created_items.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/parse_cheat_paste_window.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fd2d32e

Please sign in to comment.