Skip to content

Commit

Permalink
(v3.1.12b) Sounds shop and battle
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumitti committed Jun 27, 2024
1 parent 1932835 commit 67c21c6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
8 changes: 7 additions & 1 deletion panel/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import streamlit as st

from starwalkers import sql
from starwalkers import sql, sound_effects
from starwalkers.func import roll, get_d_sym, get_cost, upgrade_fleet, upgrade


Expand Down Expand Up @@ -51,9 +51,15 @@ def shop(username, df, value_list):
min_value=0, max_value=int(min(fleet_size - len(df), money / ((10 + 10 * grade) * commerce_bonus)) if min(fleet_size - len(df), money / ((10 + 10 * grade) * commerce_bonus)) >= 1 else 1),
disabled=True if money < ((10 + 10 * grade) * commerce_bonus) or len(df) >= fleet_size else False)

if "buy_shuttles" not in st.session_state:
st.session_state.buy_shuttles = False
if st.session_state.buy_shuttles is True:
sound_effects.shuttles()
st.session_state.buy_shuttles = False
colopencase2.markdown("")
if colopencase2.button(f"Open {open_case} case(s) for {open_case * ((10 + 10 * grade) * commerce_bonus)}$",
disabled=True if money < ((10 + 10 * grade) * commerce_bonus) or len(df) >= fleet_size else False):
st.session_state.buy_shuttles = True
for i in range(0, open_case):
ship = roll(proba_letter=p_letter, proba_number=p_number)
sql.add_ship(username, ship, price=10, add_to="player")
Expand Down
Binary file removed sounds/ambient/space-adventure-29296.mp3
Binary file not shown.
Binary file removed sounds/space-adventure-29296.mp3
Binary file not shown.
34 changes: 12 additions & 22 deletions starwalkers/sound_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import streamlit as st


def shuttles():
audio_files = [os.path.join('./sounds/effect/shuttles/', f) for f in os.listdir('./sounds/effect/shuttles/') if
f.endswith('.mp3')]
effect(audio_files)


def battle():
audio_files = [os.path.join('./sounds/effect/battle/', f) for f in os.listdir('./sounds/effect/battle/') if f.endswith('.mp3')]
effect(audio_files)


def effect(audio_files):
st.markdown(f"""
<audio id="audio" autoplay>
<source src="data:audio/mp3;base64,{base64.b64encode(open(random.choice(audio_files), 'rb').read()).decode()}" type="audio/mp3">
</audio>
<script>
var audio = document.getElementById('audio');
audio.volume = 1.0;
document.addEventListener('DOMContentLoaded', function() {{
audio.play().catch(function(error) {{
console.log('Playback prevented: ' + error);
}});
}});
</script>
""", unsafe_allow_html=True)
</audio>""", unsafe_allow_html=True)


def ambient():
Expand All @@ -38,14 +38,4 @@ def ambient():
<audio id="audio" autoplay loop>
<source src="data:audio/mp3;base64,{audio_data}" type="audio/mp3">
Your browser does not support the audio element.
</audio>
<script>
var audio = document.getElementById('audio');
audio.volume = 1.0;
document.addEventListener('DOMContentLoaded', function() {{
audio.play().catch(function(error) {{
console.log('Playback prevented: ' + error);
}});
}});
</script>
""", unsafe_allow_html=True)
</audio>""", unsafe_allow_html=True)

0 comments on commit 67c21c6

Please sign in to comment.