Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
Also made some parts of the templates a little clearer
  • Loading branch information
Mode8fx committed Jan 4, 2021
1 parent 3686d12 commit 2a47228
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
4 changes: 3 additions & 1 deletion Readme (Tutorial).md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Welcome to the Simple Randomizer Maker tutorial!

I recommend you read this file using [GitHub's reader](https://github.com/GateGuy/SimpleRandomizerMaker/blob/master/Readme%20%28Tutorial%29.md).

This will explain what you can create for your randomizer and how to do it, through both written documentation and code snippets. Or if you'd rather learn by example, there are two templates included that feature everything explained here.

If you want to edit one of the templates, keep in mind that you need to rename it to `randomizer.py`.
Expand Down Expand Up @@ -295,7 +297,7 @@ Rule(
- Optimization algorithms are used to speed up seed generation. But if your randomizer is going too slow, see if you have any "count" rules and consider reworking them into something else; "count" doesn't work as well with optimization. If it's still too slow, see if increasing your Timeout by a few seconds solves it.

##### Turning Your Randomizer Into An Executable
- When distributing your newly-created randomizer, all you need to do is package your `randomizer.py` file with a copy of the Simple Randomizer Maker executable. But if you want to combine them into one file instead, you can use a program like PyInstaller to package `srm.py` (the main Simple Randomizer Maker script that the EXE runs) with your randomizer file to make a single executable. If you use PyInstaller, just make sure `srm.py`, `gatelib.py`, `classes.py`, and your `randomizer.py` are all in the same directory, make sure you have SRM's dependencies (and PyInstaller) installed, then open a command window in that directory and run `pyinstaller srm.py --onefile --windowed --hidden-import classes`. Your executable will be saved as `YOUR DIRECTORY/dist/srm.exe`, which you can rename to whatever you want.
- When distributing your newly-created randomizer, all you need to do is package your `randomizer.py` file with a copy of the Simple Randomizer Maker executable. But if you want to combine them into one file instead, you can use a program like PyInstaller to package `srm.py` (the main Simple Randomizer Maker script that the EXE runs) with your randomizer file to make a single executable. If you use PyInstaller, just make sure `srm.py`, `gatelib.py`, `classes.py`, and your `randomizer.py` are all in the same directory, make sure you have SRM's dependencies (and PyInstaller) installed, then open a command window in that directory and run `pyinstaller srm.py --onefile --windowed --name "NAME"`, where NAME is the name of your randomizer. Your executable will be saved as `YOUR DIRECTORY/dist/NAME.exe`.

##### No Solution?
- In case you run into a situation where your randomizer gives an error that no possible combination of values was found: Look through your Attributes and Rules again and make sure they can actually generate a solution. That includes making sure two enabled optional rulesets don't conflict with each other. You can also try running the randomizer a few more times; maybe you just got a bad seed. Otherwise, read on.
Expand Down
11 changes: 10 additions & 1 deletion Template (Amazing Mirror).py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def value(name):
right_side=("==", 0, "==", 0),
),
],
must_be_enabled=None,
must_be_disabled=None,
),
Ruleset(
name="All Unique",
Expand All @@ -115,6 +117,7 @@ def value(name):
right_side=None,
),
],
must_be_enabled=None,
must_be_disabled=["All Master", "Smashing!"],
),
Ruleset(
Expand All @@ -134,6 +137,7 @@ def value(name):
right_side=None,
),
],
must_be_enabled=None,
must_be_disabled=["All Unique", "At Least 1 UFO", "Smashing!"],
),
Ruleset(
Expand All @@ -147,6 +151,7 @@ def value(name):
right_side=("==", 0x0E, ">=", 1),
),
],
must_be_enabled=None,
must_be_disabled=["All Master", "Smashing!"],
),
Ruleset(
Expand Down Expand Up @@ -196,6 +201,8 @@ def value(name):
right_side=0x13,
),
],
must_be_enabled=None,
must_be_disabled=None,
),
Ruleset(
name="Smashing!",
Expand Down Expand Up @@ -244,10 +251,11 @@ def value(name):
right_side=[0x16, 0x14, 0x8, 0x6, 0x11],
),
],
must_be_enabled=None,
must_be_disabled=["All Master", "At Least 1 UFO", "All Unique"],
),
Ruleset(
name="XOR Statement",
name="XOR Statement (move mouse over this)",
description="Either Waddle Dee gives Cutter (ability #6), or Droppy gives Throw (ability #10), but not both/neither.",
rules=[
Rule(
Expand All @@ -257,6 +265,7 @@ def value(name):
right_side=("==", True, "==", 1),
),
],
must_be_enabled=None,
must_be_disabled=["All Master"]
),
]
2 changes: 1 addition & 1 deletion Template (Empty).py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def value(name):

Program_Name = "My Randomizer"
Rom_Name = "Rom Name"
Rom_File_Format = "gba" # Rom file format (nes, gba, etc.)
Rom_File_Format = "gba" # File format (nes, gba, etc.)
About_Page_Text = "This is the text that will show on the About page."
Timeout = 10
Slow_Mode = False
Expand Down
2 changes: 2 additions & 0 deletions Template (Tutorial).py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def value(name):
right_side=("<", 70, "<=", 2),
),
],
must_be_enabled=None,
must_be_disabled=None,
),
Ruleset(
name="Special Ruleset",
Expand Down
51 changes: 27 additions & 24 deletions srm.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ def optimizeAttributes(ruleset):
numAllCombinationsNew = 1
for att in Attributes:
numAllCombinationsNew *= len(att.possible_values)
print(str(round((1-(numAllCombinationsNew/numAllCombinations))*100, 3))+"% reduction in seed generation time.")
try:
print(str(round((1-(numAllCombinationsNew/numAllCombinations))*100, 3))+"% reduction in seed generation time.")
except:
print("Something broke. Close the program, reopen, and try again.") # This shouldn't happen
return False
return True

# Attempt 50 completely random combinations before attempting a normal approach.
Expand Down Expand Up @@ -453,7 +457,7 @@ def __init__(self, top=None):
## Menu Bar
menubar = tk.Menu(self.top, bg=_bgcolor, fg=_fgcolor, tearoff=0)
fileMenu = tk.Menu(menubar, tearoff=0)
fileMenu.add_command(label="Load ROM...", command=self.setSourceRom)
fileMenu.add_command(label="Load File...", command=self.setSourceRom)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=fileMenu)
Expand Down Expand Up @@ -517,7 +521,7 @@ def __init__(self, top=None):
self.Button_RomInput.place(relx=.845, rely=.0365*vMult, relheight=.057*vMult, relwidth=.12)
self.Button_RomInput.configure(command=self.setSourceRom)
self.Button_RomInput.configure(takefocus="")
self.Button_RomInput.configure(text='Load ROM')
self.Button_RomInput.configure(text='Load File')

# Use Settings Radio Button
self.RadioButton_UseSettings = ttk.Radiobutton(self.top)
Expand Down Expand Up @@ -664,32 +668,18 @@ def prepareSettingsFromDependencies(self):
currCheckButton.configure(state="disabled")
break

def decrementAndSetRomInput(self):
global currRomIndex
currRomIndex -= 1
if currRomIndex < 0:
currRomIndex += len(Rom_Name)
self.setRomInput()

def incrementAndSetRomInput(self):
global currRomIndex
currRomIndex += 1
if currRomIndex >= len(Rom_Name):
currRomIndex -= len(Rom_Name)
self.setRomInput()

def decrementAndSetDisplayedRulesets(self):
global currRulesetPage
currRulesetPage -= 1
if currRulesetPage < 0:
currRulesetPage += len(Optional_Rulesets) // 15
currRulesetPage = len(Optional_Rulesets) // 15
self.setDisplayedRulesets()

def incrementAndSetDisplayedRulesets(self):
global currRulesetPage
currRulesetPage += 1
if currRulesetPage >= len(Optional_Rulesets) // 15:
currRulesetPage -= len(Optional_Rulesets) // 15
if currRulesetPage > len(Optional_Rulesets) // 15:
currRulesetPage = 0
self.setDisplayedRulesets()

def setDisplayedRulesets(self):
Expand All @@ -703,12 +693,12 @@ def setDisplayedRulesets(self):
optRulesetNum = 0
for i in range(len(Optional_Rulesets)):
if firstIndex <= i < lastIndex:
self.CheckButtons[optRulesetNum].place(relx=.475-self.getMaxColumnWidth(optRulesetNum)/2+xShiftArray[optRulesetNum//5], rely=(.40+yShiftArray[optRulesetNum%5])*vMult, relheight=.05*vMult, relwidth=self.getTextLength(Optional_Rulesets[i].name)+.03)
self.CheckButtons[i].place(relx=.475-self.getMaxColumnWidth(optRulesetNum)/2+xShiftArray[optRulesetNum//5], rely=(.40+yShiftArray[optRulesetNum%5])*vMult, relheight=.05*vMult, relwidth=self.getTextLength(Optional_Rulesets[i].name)+.03)
optRulesetNum += 1
else:
self.CheckButtons[optRulesetNum].place(relx=10, rely=10, relheight=.05*vMult, relwidth=self.getTextLength(Optional_Rulesets[i].name)+.03)
self.CheckButtons[i].place(relx=10, rely=10, relheight=.05*vMult, relwidth=self.getTextLength(Optional_Rulesets[i].name)+.03)

if optRulesetNum <= 15:
if optRulesetNum < 15:
# Number of Seeds Label
seedX = .475-self.getMaxColumnWidth(optRulesetNum)/2+xShiftArray[optRulesetNum//5]
self.Label_NumSeeds.place(relx=seedX, rely=(.40+yShiftArray[optRulesetNum%5])*vMult, relheight=.05*vMult, relwidth=.11)
Expand All @@ -719,6 +709,20 @@ def setDisplayedRulesets(self):
self.ComboBox_NumSeeds.place(relx=10, rely=10, relheight=.05*vMult, relwidth=.088)
self.prepareSettingsAndSeed()

def decrementAndSetRomInput(self):
global currRomIndex
currRomIndex -= 1
if currRomIndex < 0:
currRomIndex = len(Rom_Name) - 1
self.setRomInput()

def incrementAndSetRomInput(self):
global currRomIndex
currRomIndex += 1
if currRomIndex >= len(Rom_Name):
currRomIndex = 0
self.setRomInput()

def setRomInput(self):
romTextLength = self.getTextLength(Rom_Name[currRomIndex])
self.Label_RomInput.place(relx=.035+changeRomVal, rely=.04*vMult, relheight=.05*vMult, relwidth=romTextLength)
Expand All @@ -728,7 +732,6 @@ def setRomInput(self):

def setSourceRom(self):
global sourceRoms
print(Rom_File_Format)
currRFF = Rom_File_Format[currRomIndex % len(Rom_File_Format)]
if currRFF is None or currRFF == "":
sourceRoms[currRomIndex].set(askopenfilename())
Expand Down

0 comments on commit 2a47228

Please sign in to comment.