diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51348ff --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +*.swp +build/ diff --git a/dist/DarkSoulsItemRandomizer.exe b/dist/DarkSoulsItemRandomizer.exe index c11fdb1..89727f9 100644 Binary files a/dist/DarkSoulsItemRandomizer.exe and b/dist/DarkSoulsItemRandomizer.exe differ diff --git a/dist/randomizer.ini b/dist/randomizer.ini new file mode 100644 index 0000000..4b036e6 --- /dev/null +++ b/dist/randomizer.ini @@ -0,0 +1,12 @@ +[DEFAULT] +difficulty = 0 +fashion_souls = True +key_placement = 2 +use_lordvessel = True +use_lord_souls = True +soul_items_diff = 2 +start_items_diff = 2 +game_version = DARK SOULS: Prepare To Die Edition +randomize_npc_armor = True +ascend_weapons = True + diff --git a/ini_parser.py b/ini_parser.py new file mode 100644 index 0000000..ba0f9f2 --- /dev/null +++ b/ini_parser.py @@ -0,0 +1,37 @@ +import configparser + +def get_values_from_ini(ini_file, section="DEFAULT"): + config = configparser.ConfigParser() + config.read(ini_file) + + if section in config: #check if section in ini + return config[section] + else: + return config["DEFAULT"] + +def save_ini(ini_file, options): + config = configparser.ConfigParser() + for k,v in vars(options).items(): + config["DEFAULT"][k] = str(v) #values must be strings to write + + with open(ini_file, 'w') as configfile: + config.write(configfile) + +def get_option_value(config, k): + """ + The following parses the values in the ini to produce the option list in the correct format + While I could create a separate list/dict to specify the typing of the data coming in + or by creating a section in the inifile for the typing + This would add extra work to the developer who adds new features which I think is far more annoying + So instead we get this ugly mess of try/excepts to get the typing we actually care about: int -> bool -> string + TODO: Allow type to be specified when calling (not really important at all) + """ + try: + option = config.getint(k, 0) + except ValueError: + try: + option = config.getboolean(k, False) + except ValueError: + option = config.get(k, "No Default Value") + + return option diff --git a/randomizer.ini b/randomizer.ini new file mode 100644 index 0000000..4b036e6 --- /dev/null +++ b/randomizer.ini @@ -0,0 +1,12 @@ +[DEFAULT] +difficulty = 0 +fashion_souls = True +key_placement = 2 +use_lordvessel = True +use_lord_souls = True +soul_items_diff = 2 +start_items_diff = 2 +game_version = DARK SOULS: Prepare To Die Edition +randomize_npc_armor = True +ascend_weapons = True + diff --git a/randomizer_gui.py b/randomizer_gui.py index 5f99aa9..d5bd35d 100644 --- a/randomizer_gui.py +++ b/randomizer_gui.py @@ -19,6 +19,9 @@ import logging log = logging.getLogger(__name__) +import ini_parser +INI_FILE = "randomizer.ini" + MAX_SEED_LENGTH = 64 VERSION_NUM = "0.3" @@ -102,6 +105,7 @@ def write_state_to_area(self): class MainGUI: def __init__(self): + init_options = ini_parser.get_values_from_ini(INI_FILE, section="DEFAULT") #load ini file self.seed_rng = random.Random() self.has_hovered_desc = False self.root = tk.Tk() @@ -147,10 +151,17 @@ def __init__(self): self.desc_area = tk.Text(self.root, width=76, height=19, state="disabled", background=self.root.cget('background'), wrap="word") self.desc_area.grid(row=2, column=0, columnspan=3, rowspan=9, padx=2, pady=2) + self.save_options = tk.BooleanVar() + self.save_options.set(False) + self.save_options_check = tk.Checkbutton(self.root, text="Save Settings as Default", + variable=self.save_options, onvalue=True, offvalue=False, padx=2, + width=20, anchor=tk.W) + self.save_options_check.grid(row=1, column=3, columnspan=2) + self.diff_frame = tk.LabelFrame(text="Difficulty:") self.diff_frame.grid(row=2, column=3, rowspan=1, sticky='NS', padx=2) self.diff = tk.IntVar() - self.diff.set(rngopts.RandOptDifficulty.EASY) + self.diff.set(ini_parser.get_option_value(init_options, "difficulty")) self.diff.trace('w', lambda name, index, mode: self.update()) self.diff_rbutton1 = tk.Radiobutton(self.diff_frame, text=rngopts.RandOptDifficulty.as_string(rngopts.RandOptDifficulty.EASY), @@ -171,7 +182,7 @@ def __init__(self): self.key_diff_frame = tk.LabelFrame(text="Key Placement:") self.key_diff_frame.grid(row=3, column=3, rowspan=4, sticky='NS', padx=2) self.key_diff = tk.IntVar() - self.key_diff.set(rngopts.RandOptKeyDifficulty.RANDOMIZE) + self.key_diff.set(ini_parser.get_option_value(init_options, "key_placement")) self.key_diff.trace('w', lambda name, index, mode: self.update()) self.key_diff_rbutton1 = tk.Radiobutton(self.key_diff_frame, text=rngopts.RandOptKeyDifficulty.as_string(rngopts.RandOptKeyDifficulty.LEAVE_ALONE), @@ -197,7 +208,7 @@ def __init__(self): self.soul_frame = tk.LabelFrame(text="Soul Items:") self.soul_frame.grid(row=7, column=3, rowspan=5, sticky='NS', padx=2, pady=2) self.soul_diff = tk.IntVar() - self.soul_diff.set(rngopts.RandOptSoulItemsDifficulty.SHUFFLE) + self.soul_diff.set(ini_parser.get_option_value(init_options, "soul_items_diff")) self.soul_diff.trace('w', lambda name, index, mode: self.update()) self.soul_diff_rbutton1 = tk.Radiobutton(self.soul_frame, text=rngopts.RandOptSoulItemsDifficulty.as_string(rngopts.RandOptSoulItemsDifficulty.SHUFFLE), @@ -218,7 +229,7 @@ def __init__(self): self.start_items_frame = tk.LabelFrame(text="Starting Items:") self.start_items_frame.grid(row=2, column=4, sticky='NS', padx=2) self.start_items_diff = tk.IntVar() - self.start_items_diff.set(rngopts.RandOptStartItemsDifficulty.SHIELD_AND_2H) + self.start_items_diff.set(ini_parser.get_option_value(init_options, "start_items_diff")) self.start_items_diff.trace('w', lambda name, index, mode: self.update()) self.start_items_rbutton1 = tk.Radiobutton(self.start_items_frame, text=rngopts.RandOptStartItemsDifficulty.as_string(rngopts.RandOptStartItemsDifficulty.SHIELD_AND_1H), @@ -237,7 +248,7 @@ def __init__(self): self.setup_hover_events(self.start_items_rbutton3, {"start_items": rngopts.RandOptStartItemsDifficulty.COMBINED_POOL_AND_2H}) self.fashion_bool = tk.BooleanVar() - self.fashion_bool.set(True) + self.fashion_bool.set(ini_parser.get_option_value(init_options, "fashion_souls")) self.fashion_bool.trace('w', lambda name, index, mode: self.update()) self.fashion_check = tk.Checkbutton(self.root, text="Fashion Souls", variable=self.fashion_bool, onvalue=True, offvalue=False, padx=2, @@ -246,7 +257,7 @@ def __init__(self): self.setup_hover_events(self.fashion_check, {"fashion": None}, no_emph = True) self.npc_armor_bool = tk.BooleanVar() - self.npc_armor_bool.set(False) + self.npc_armor_bool.set(ini_parser.get_option_value(init_options, "randomize_npc_armor")) self.npc_armor_bool.trace('w', lambda name, index, mode: self.update()) self.npc_armor_check = tk.Checkbutton(self.root, text="Laundromat Mixup", variable=self.npc_armor_bool, onvalue=True, offvalue=False, padx=2, @@ -255,7 +266,7 @@ def __init__(self): self.setup_hover_events(self.npc_armor_check, {"npc_armor": None}, no_emph = True) self.use_lordvessel = tk.BooleanVar() - self.use_lordvessel.set(False) + self.use_lordvessel.set(ini_parser.get_option_value(init_options, "use_lordvessel")) self.use_lordvessel.trace('w', lambda name, index, mode: self.update()) self.lv_check = tk.Checkbutton(self.root, text="Senile Gwynevere", variable=self.use_lordvessel, onvalue=True, offvalue=False, padx=2, @@ -264,7 +275,7 @@ def __init__(self): self.setup_hover_events(self.lv_check, {"use_lv": None}, no_emph = True) self.use_lord_souls = tk.BooleanVar() - self.use_lord_souls.set(False) + self.use_lord_souls.set(ini_parser.get_option_value(init_options, "use_lord_souls")) self.use_lordvessel.trace('w', lambda name, index, mode: self.update()) self.lord_soul_check = tk.Checkbutton(self.root, text="Senile Primordial Serpents", variable=self.use_lord_souls, onvalue=True, offvalue=False, padx=2, @@ -273,7 +284,7 @@ def __init__(self): self.setup_hover_events(self.lord_soul_check, {"use_lord_souls": None}, no_emph = True) self.ascend_weapons_bool = tk.BooleanVar() - self.ascend_weapons_bool.set(False) + self.ascend_weapons_bool.set(ini_parser.get_option_value(init_options, "ascend_weapons")) self.ascend_weapons_bool.trace('w', lambda name, index, mode: self.update()) self.ascend_weapons_check = tk.Checkbutton(self.root, text="Eager Smiths", variable=self.ascend_weapons_bool, onvalue=True, offvalue=False, padx=2, @@ -436,6 +447,9 @@ def randomize_data(self, chr_init_data): self.soul_diff.get(), self.start_items_diff.get(), self.game_version.get(), self.npc_armor_bool.get(), self.ascend_weapons_bool.get()) + if self.save_options.get(): + ini_parser.save_ini(INI_FILE, options) #save options right before creating seed + rng = random.Random() rng.seed(int(hashlib.sha256(self.seed_string.get().encode('utf-8')).hexdigest(), 16)) return (options, randomize_item_table.build_table(options, rng, chr_init_data), rng) diff --git a/randomizer_gui.spec b/randomizer_gui.spec new file mode 100644 index 0000000..0ec48ee --- /dev/null +++ b/randomizer_gui.spec @@ -0,0 +1,35 @@ +# -*- mode: python -*- + +block_cipher = None + + +a = Analysis(['randomizer_gui.py'], + pathex=['C:\\Users\\ekrechmer\\DarkSoulsItemRandomizer'], + binaries=[], + datas=[('favicon.ico', '.'), ('favicon.gif', '.')], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='DarkSoulsItemRandomizer', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + runtime_tmpdir=None, + console=False , icon='favicon.ico') + +import shutil +shutil.copyfile('randomizer.ini', '{0}/randomizer.ini'.format(DISTPATH))