Skip to content

Commit

Permalink
add interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
magicbear committed Feb 21, 2024
1 parent 9134d51 commit 10075e9
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Changelog
Note that they these tags will not actually close the issue/PR until they
are merged into the "default" branch.

0.8.1
-------

Feature:

- Startup Inteactive Mode in GUI

0.8.0
-------

Expand Down
77 changes: 54 additions & 23 deletions palworld_server_toolkit/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,35 @@ def load_skipped_decode(_worldSaveData, skip_paths, recursive=True):

def gui_thread():
global gui
try:
gui = GUI()
gui.load()
gui.mainloop()
except tk.TclError:
log.error("Failed to create GUI", exc_info=True)
gui = None
gui.mainloop()

class InteractThread(threading.Thread):
_instance = None

def __init__(self):
super().__init__(daemon=True)

@staticmethod
def load():
if InteractThread._instance is None:
InteractThread._instance = InteractThread()
InteractThread._instance.start()
return InteractThread._instance

def interact_readfunc(self, prompt):
print(prompt, end="", flush=True)
line = sys.stdin.readline()
if line.strip() == "quit()":
return None
return line

def run(self):
import code
try:
code.interact(readfunc=self.interact_readfunc, local=globals())
except Exception as e:
traceback.print_exception(e)
InteractThread._instance = None

def main():
global output_file, output_path, args, gui, playerMapping
Expand Down Expand Up @@ -307,17 +328,6 @@ def main():
messagebox.showerror("Error Save File", "Corrupted Save File, be sure you are open the right Level.sav")
sys.exit(0)

if args.gui and sys.platform == 'darwin':
if sys.flags.interactive:
log.warning("Mac OS python not support interactive with GUI")
gui = GUI()
gui.load()
gui.gui.update()
# gui_thread()
# sys.exit(0)
elif args.gui and sys.flags.interactive:
threading.Thread(target=gui_thread, daemon=True).start()

if args.statistics:
Statistics()

Expand Down Expand Up @@ -381,12 +391,28 @@ def main():
print(" search_key(wsd, '<value>') - Locate the key in the structure")
print(" search_values(wsd, '<value>') - Locate the value in the structure")
print(" PrettyPrint(value) - Use XML format to show the value")
return
elif args.gui:
gui_thread()
elif modify_to_file:
Save()

if args.gui:
global gui
try:
gui = GUI()
gui.load()

if sys.flags.interactive:
if sys.platform == 'darwin':
# log.warning("Mac OS python not support interactive with GUI")
InteractThread.load()
gui.gui.mainloop()
else:
threading.Thread(target=gui_thread, daemon=True).start()
else:
gui.mainloop()
except tk.TclError:
log.error("Failed to create GUI", exc_info=True)
gui = None


try:
class AutocompleteCombobox(ttk.Combobox):
Expand Down Expand Up @@ -1910,13 +1936,13 @@ def cleanup_character(self):

def set_progress(self, val):
try:
self.progressbar['value'] = val
self.lbl_status.config(text="%s %d%%" % (self.lang_data['status_loading'], val))
self.progressbar['value'] = val
self.gui.update()
except AttributeError as e:
traceback.print_exception(e)
except RuntimeError as e:
traceback.print_exception(e)
pass

def update_progress(self, x, y):
try:
Expand Down Expand Up @@ -2251,6 +2277,11 @@ def build_gui(self):
self.i18n['repair_all_user'] = g_repair_all
g_repair_all.pack(side=tk.LEFT)

if not sys.flags.interactive:
self.i18n['interactive'] = ttk.Button(master=g_wholefile, text="Interactive", style="custom.TButton",
command=InteractThread.load)
self.i18n['interactive'].pack(side=tk.LEFT)

g_save = ttk.Button(text="Save & Exit", style="custom.TButton", command=self.save)
self.i18n['save'] = g_save
g_save.pack()
Expand Down
1 change: 1 addition & 0 deletions palworld_server_toolkit/resources/gui_en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"migrate_to_nosteam": "Migrate To No Steam",
"copy_player": "⬆️ Copy Player ⬇️",
"op_for_all": "Operate for File",
"interactive": "Interactive",
"del_unreference_item": "\uD83D\uDDD1️ Cleanup Item",
"cleanup_character": "\uD83D\uDDD1️ Cleanup Character",
"del_damage_obj": "\uD83C\uDD98 Del Damage Instance",
Expand Down
1 change: 1 addition & 0 deletions palworld_server_toolkit/resources/gui_ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"migrate_player": "キャラクターを移行する",
"copy_player": "キャラクターをコピー",
"op_for_all": "ファイルの操作",
"interactive": "インタプリタ",
"del_unreference_item": "\uD83D\uDDD1️ 部品格納庫削除",
"cleanup_character": "\uD83D\uDDD1️ パル格納庫削除",
"del_damage_obj": "\uD83C\uDD98 破損を削除",
Expand Down
1 change: 1 addition & 0 deletions palworld_server_toolkit/resources/gui_zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"migrate_to_nosteam": "有Steam转无Steam",
"copy_player": "复制玩家",
"op_for_all": "对文件进行操作",
"interactive": "交互模式",
"del_unreference_item": "\uD83D\uDDD1️ 清理无用物品库",
"cleanup_character": "\uD83D\uDDD1️ 清理无用角色库",
"del_damage_obj": "\uD83C\uDD98 删除损坏对象",
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = palworld-server-toolkit
version = 0.8.0
version = 0.8.1
author = MagicBear
author_email = [email protected]
description = A toolset for PalWorld Server
Expand Down

0 comments on commit 10075e9

Please sign in to comment.