Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Picker done
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hegedus committed Jan 22, 2023
1 parent 48932d0 commit a9a8724
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 301 deletions.
35 changes: 35 additions & 0 deletions mod-downloader/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

UNDERLINE = "(!u!)"
BOLD = "(!b!)"
RESET_ALL ="(!reset_all!)"
RESET_STYLE ="(!reset_s!)"
RESET_COLOR ="(!reset_c!)"

BLACK = "(!black!)"
RED = "(!red!)"
GREEN = "(!green!)"
YELLOW = "(!yellow!)"
GRAY = "(!gray!)"
PINK = "(!pink!)"

ansi_dict = {
RESET_ALL: "\033[0m",
RESET_COLOR: "\033[39m",
BLACK : "\033[30m",
RED : "\033[31m",
GREEN : "\033[32m",
YELLOW : "\033[33m",
"(!blue!)": "\033[34m",
"(!purple!)": "\033[35m",
"(!cyan!)": "\033[36m",
"(!white!)": "\033[37m",
PINK: "\033[38;5;213m",
GRAY: "\033[90m",
BOLD: "\033[1m",
UNDERLINE: "\033[4m" }

def colorize(text: str, opstional_style=''):
full_str = f'{opstional_style}{text}' + RESET_ALL
for code in ansi_dict:
full_str = full_str.replace(code, ansi_dict[code])
return full_str
8 changes: 4 additions & 4 deletions mod-downloader/config/packs.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
{
"name": "j-c",
"display_name": "Joshua + Csenge",
"description": "This modpack is being used by one of, if not the cutest couple.",
"display_name": "(!red!)Joshua + Csenge(!reset_all!)",
"description": "This modpack is being used by one of, if not the (!b!)(!pink!)cutest couple(!reset_all!).",
"pack_content": [
"3553332",
"3553317",
Expand Down Expand Up @@ -110,8 +110,8 @@
},
{
"name": "logi-win-2023",
"display_name": "Logiscool T\u00e9li T\u00e1bor 2023",
"description": "Ezt a modpack-ot haszn\u00e1ltuk, a t\u00e1borban, van benne kaland, izgalom \u00e9s kih\u00edv\u00e1s is!",
"display_name": "(!purple!)Logi(!yellow!)s(!cyan!)cool(!reset_c!) (!purple!)T\u00e9li (!yellow!)T\u00e1bor (!cyan!)2023(!reset_all!)",
"description": "(!green!)Ezt a modpack-ot haszn\u00e1ltuk, a t\u00e1borban, van benne kaland, izgalom \u00e9s kih\u00edv\u00e1s is!(!reset_all!)",
"pack_content": [
"3607198",
"3520927",
Expand Down
10 changes: 5 additions & 5 deletions mod-downloader/mod-downloader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from mod import ModManager
from baselib import clear_dir, minecraft_path
from baselib import minecraft_path
from modoperations import copy_to_target

manager = ModManager()
pack, i = manager.select_mod_packs()
pack = manager.select_mod_packs()
if pack is not None:
copy_to_target(manager, pack.pack_content, minecraft_path())
input("Press Enter to exit...")

copy_to_target(manager, pack.pack_content, minecraft_path())

input("Press Enter to exit...")
134 changes: 1 addition & 133 deletions mod-downloader/mod-manager.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,8 @@
from pick import pick
from mod import Mod, ModPack, ModManager, pack_mods, unpack_mods
from typing import Any, List, Optional, Sequence, Callable


menu = (['Add/Remove Mod', 'Edit Mod dependency', 'Pack the mods', 'Unpack the mods', 'Manage packs'],
'Choose an operation: ',
False, True)
menu_1 = (['Add Dependency', 'Remove Dependency', 'Edit All'],
'Choose an operation: ', True, True)
menu_2 = ['Add/Remove Mod', 'Edit Mod dependency',
'Pack the mods', 'Unpack the mods', 'Manage packs']


def confirm(message: str) -> int:
return pick((['Yes', 'No', 'Quit'], message, False, True))


mods = ModManager(True)


class MenuItem():
def __init__(self, content, callback: Callable = None):
self.content = content
self.callback = callback

def __str__(self):
return self.content

def _exit():
exit(0)

@classmethod
def exit(cls):
return cls("Exit", callback=cls._exit)

@classmethod
def back(cls):
return cls("Back")


class Menu:
def __init__(self, options: list[MenuItem], title="Menu:"):
self.options = options
self.options.append(MenuItem.exit())
self.title = title

def pick(self) -> tuple[MenuItem, int]:
return pick(self.options, self.title)

def show(self):
selected, i = self.pick()
if selected.callback is not None:
selected.callback()
return selected.content



class SubMenu(Menu):
def __init__(self, options: list[MenuItem], title="Menu:"):
self.options.append(MenuItem.back())
super().__init__(options, title)

def show(self, parent: Menu):
selected, i = self.pick()
if selected.callback is not None:
selected.callback()
if selected.content == "Back":
parent.show()

def select_one_mod():
result_count = 0
while result_count != 1:
Expand All @@ -78,71 +13,4 @@ def select_one_mod():
print("Please narrow your seach:")
for i in mod_res:
print(f"\t{i.name}")
return mod_res[0]


def add_mods_to_pack():
pack, i = mods.select_mod_packs()
diff = set(mods.mod_list) - set(pack.pack_content)
selected_mods = pick(list(diff), 'Choose a mod: ', indicator='=>', multiselect=True)
for mod, i in selected_mods:
if mod.state == "install":
pack.pack_content.append(mod)
mods.packs_to_json()


def edit_mods_in_pack():
pack, i = mods.select_mod_packs()
selected_mods = pick(mods.mod_list, 'Choose a mod: ', indicator='=>', multiselect=True)
for mod, i in selected_mods:
if mod.state == "install":
pack.pack_content.append(mod)
mods.packs_to_json()


def remove_mods_from_pack():
pack, i = mods.select_mod_packs()
selected_mods = pick(pack.pack_content, 'Choose a mod: ', indicator='=>', multiselect=True)
for mod, i in selected_mods:
pack.pack_content.remove(mod)
mods.packs_to_json()


def create_pack():
pack = ModPack.create_pack()
selected_mods = pick(mods.mod_list, 'Choose a mod: ', indicator='=>', multiselect=True)
for mod, i in selected_mods:
if mod.state == "install":
pack.pack_content.append(mod)
mods.mod_packs.append(pack)
mods.packs_to_json()


pack_content_menu = SubMenu(
[
MenuItem("Add", add_mods_to_pack),
MenuItem("Edit", edit_mods_in_pack),
MenuItem("Remove", remove_mods_from_pack)
], "Select a content operation"
)


pack_detail_menu = SubMenu(
[
MenuItem("Name"),
MenuItem("Display Name"),
MenuItem("Description"),
MenuItem("Content"),
], 'What do you want to modify?'
)


pack_menu = Menu(
[
MenuItem('Create Pack', create_pack),
MenuItem('Edit Pack', pack_detail_menu.show(pack_menu)),
MenuItem('Remove Pack'),
], "Select a pack operation"
)

pack_menu.show()
return mod_res[0]
Loading

0 comments on commit a9a8724

Please sign in to comment.