Refactor Run class

This commit is contained in:
Em (Ethan) Ruszanowski 2024-02-09 18:00:04 -05:00
parent 31730b8406
commit 4a5b994ef0
Signed by: em
GPG key ID: C725D6E571252B96

16
app.py
View file

@ -22,8 +22,8 @@ class Creature:
class Run: class Run:
def __init__(self, moon): def __init__(self, moon):
self.moon = moon self.moon = moon
self.inside_power_level = moon.inside_max_power self.inside_power = moon.inside_max_power
self.outside_power_level = moon.outside_max_power self.outside_power = moon.outside_max_power
def main(): def main():
@ -81,7 +81,6 @@ def main():
for creature in chain(outside_creatures, inside_creatures): for creature in chain(outside_creatures, inside_creatures):
st.session_state[creature.name] = 0 st.session_state[creature.name] = 0
st.markdown(f"## {run.moon.name} (Tier {run.moon.tier})") st.markdown(f"## {run.moon.name} (Tier {run.moon.tier})")
column_1, column_2 = st.columns(2) column_1, column_2 = st.columns(2)
@ -91,29 +90,26 @@ def main():
for creature in outside_creatures: for creature in outside_creatures:
hold = st.session_state[creature.name] hold = st.session_state[creature.name]
moon_max = min(creature.max_spawns, run.outside_power_level // creature.power) moon_max = min(creature.max_spawns, run.outside_power // creature.power)
if moon_max > 0: if moon_max > 0:
st.slider(creature.name, 0, moon_max, key=creature.name, help=creature.nickname) st.slider(creature.name, 0, moon_max, key=creature.name, help=creature.nickname)
else: else:
st.slider(creature.name, 0, 1, key=creature.name, help=creature.nickname, disabled=True) st.slider(creature.name, 0, 1, key=creature.name, help=creature.nickname, disabled=True)
run.outside_power_level = run.outside_power_level - st.session_state[creature.name] run.outside_power = run.outside_power - st.session_state[creature.name]
with column_2: with column_2:
st.markdown('### Inside') st.markdown('### Inside')
st.info(f"Maximum power: {run.moon.inside_max_power}") st.info(f"Maximum power: {run.moon.inside_max_power}")
for creature in inside_creatures: for creature in inside_creatures:
moon_max = min(creature.max_spawns, run.inside_power_level // creature.power) moon_max = min(creature.max_spawns, run.inside_power // creature.power)
if moon_max > 0: if moon_max > 0:
st.slider(creature.name, 0, moon_max, key=creature.name, help=creature.nickname) st.slider(creature.name, 0, moon_max, key=creature.name, help=creature.nickname)
else: else:
st.slider(creature.name, 0, 1, key=creature.name, help=creature.nickname, disabled=True) st.slider(creature.name, 0, 1, key=creature.name, help=creature.nickname, disabled=True)
run.inside_power_level = run.inside_power_level - st.session_state[creature.name] run.inside_power = run.inside_power - st.session_state[creature.name]
# https://docs.streamlit.io/library/api-reference/session-state # https://docs.streamlit.io/library/api-reference/session-state