File size: 5,662 Bytes
88bab31
 
6fc412e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39bd597
 
88bab31
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import pandas as pd
import streamlit as st

# Set page title and icon
st.set_page_config(page_title="Dice Roller", page_icon="๐ŸŽฒ")

# Set page title
st.title("๐ŸŽฒ Dice Roller")

# Check if username is already set, if not, create a text input to set it
if 'username' not in st.session_state:
    st.session_state.username = st.text_input("๐Ÿ‘ค Username", max_chars=50)

# Define the dice types
dice_types = {
    "๐ŸŽฒ Six-sided dice": {"sides": 6, "name": "d6", "emoji": "๐ŸŽฒ"},
    "๐ŸŽฒ Thirty-sided dice": {"sides": 30, "name": "d30", "emoji": "๐ŸŽฒ"},
    "๐ŸŽฒ Twenty-sided dice": {"sides": 20, "name": "d20", "emoji": "๐ŸŽฒ"},
    "๐ŸŽฒ One hundred-sided dice": {"sides": 100, "name": "d100", "emoji": "๐Ÿ’ฏ"},
}

# Create a selectbox to choose the dice type
dice_type = st.selectbox("๐ŸŽฒ Select a dice type", options=list(dice_types.keys()), format_func=lambda x: x.split(' ')[-2])

# Create a slider to choose the number of rolls
num_rolls = st.slider("๐ŸŽฒ How many times do you want to roll the dice?", 1, 1000000, 100)

# Create a string with the rolls for the selected dice type
rolls = [str(pd.Series([dice_types[dice_type]["sides"]] * num_rolls).apply(pd.Series.sample, replace=True))]
rolls = rolls[0].strip('[]').split('\n')

# Create a button to roll the dice
if st.button("๐ŸŽฒ Roll Dice"):
    # Display the rolls
    display_roll = [int(i) for i in rolls]
    st.write(f"{dice_types[dice_type]['emoji']} You rolled {len(display_roll)} {dice_types[dice_type]['name']} dice: {', '.join(map(str, display_roll))}.")

    # Check if the count is a multiple of the dice sides to see if there's a bonus match
    bonus_match = None
    count = sum(display_roll)
    if count % dice_types[dice_type]['sides'] == 0:
        bonus_match = dice_types[dice_type]['name']
        bonus_emoji = dice_types[dice_type]['emoji']
        st.write(f"๐ŸŽ‰ Bonus match! You rolled a multiple of {dice_types[dice_type]['sides']}.")

    # Create a DataFrame with the rolls, count, and dice number of sides
    df = pd.DataFrame({'Roll': rolls, 'Count': count, 'DiceNumberOfSides': dice_types[dice_type]['sides']})

    # Check if the file exists
    file_exists = os.path.exists("SharedState.csv")

    # Append the new rolls to the file
    if file_exists:
        df.to_csv("SharedState.csv", mode='a', header=False, index=False)
    # If the file doesn't exist, create it and write the headers
    else:
        df.to_csv("SharedState.csv", mode='w', header=True, index=False)

# Create a checkbox to download the roll history
download_roll_history = st.checkbox("๐Ÿ“ฅ Download Roll History", value=True)

# Check if the file exists and display it as a download link
if os.path.exists("SharedState.csv"):
    # Read the file into a DataFrame
    data = pd.read_csv("SharedState.csv")

    # Check if the user wants to include their name in the output
    if st.checkbox("๐Ÿ’ป Include Username in Output", value=True):
        # Add the username to the DataFrame
        data["DiceRollerName"] = st.session_state.username
        # Check if there is a bonus match and add the bonus match column to the DataFrame
        if bonus_match:
            data["BonusMatchToDiceName"] = bonus_match
            data["BonusMatchToDiceEmoji"] = bonus_emoji
        # Check if the user wants to download the file
        if download_roll_history:
            st.download_button("๐Ÿ“ฅ Download Roll History", data.to_csv(index=False), f"shared_state_{st.session_state.username}.csv", "text/csv")
    else:
        # Remove the username from the DataFrame
        data = data.drop(columns=["DiceRollerName"])
        # Check if there is a bonus match and add the bonus match column to the DataFrame
        if bonus_match:
            data["BonusMatchToDiceName"] = bonus_match
            data["BonusMatchToDiceEmoji"] = bonus_emoji
        # Check if the user wants to download the file
        if download_roll_history:
            st.download_button("๐Ÿ“ฅ Download Roll History", data.to_csv(index=False), "shared_state.csv", "text/csv")
else:
    st.write("๐Ÿ“œ No roll history available.")


st.write("""

๐Ÿž Bread, ๐Ÿฅ Croissant, ๐Ÿฅ– Baguette Bread, ๐Ÿซ“ Flatbread, ๐Ÿฅจ Pretzel, ๐Ÿฅฏ Bagel, ๐Ÿฅž Pancakes, ๐Ÿง‡ Waffle, ๐Ÿง€ Cheese Wedge, ๐Ÿ– Meat on Bone, ๐Ÿ— Poultry Leg, ๐Ÿฅฉ Cut of Meat, ๐Ÿฅ“ Bacon, ๐Ÿ” Hamburger, ๐ŸŸ French Fries, ๐Ÿ• Pizza, ๐ŸŒญ Hot Dog, ๐Ÿฅช Sandwich, ๐ŸŒฎ Taco, ๐ŸŒฏ Burrito, ๐Ÿซ” Tamale, ๐Ÿฅ™ Stuffed Flatbread, ๐Ÿง† Falafel, ๐Ÿฅš Egg, ๐Ÿณ Cooking, ๐Ÿฅ˜ Shallow Pan of Food, ๐Ÿฒ Pot of Food, ๐Ÿซ• Fondue, ๐Ÿฅฃ Bowl with Spoon, ๐Ÿฅ— Green Salad, ๐Ÿฟ Popcorn, ๐Ÿงˆ Butter, ๐Ÿง‚ Salt, ๐Ÿฅซ Canned Food, ๐Ÿฑ Bento Box, ๐Ÿ˜ Rice Cracker, ๐Ÿ™ Rice Ball, ๐Ÿš Cooked Rice, ๐Ÿ› Curry Rice, ๐Ÿœ Steaming Bowl, ๐Ÿ Spaghetti, ๐Ÿ  Roasted Sweet Potato, ๐Ÿข Oden, ๐Ÿฃ Sushi, ๐Ÿค Fried Shrimp, ๐Ÿฅ Fish Cake with Swirl, ๐Ÿฅฎ Moon Cake, ๐Ÿก Dango, ๐ŸฅŸ Dumpling, ๐Ÿฅ  Fortune Cookie, ๐Ÿฅก Takeout Box, ๐Ÿฆช Oyster, ๐Ÿฆ Soft Ice Cream, ๐Ÿง Shaved Ice, ๐Ÿจ Ice Cream, ๐Ÿฉ Doughnut, ๐Ÿช Cookie, ๐ŸŽ‚ Birthday Cake, ๐Ÿฐ Shortcake, ๐Ÿง Cupcake, ๐Ÿฅง Pie, ๐Ÿซ Chocolate Bar, ๐Ÿฌ Candy, ๐Ÿญ Lollipop, ๐Ÿฎ Custard, ๐Ÿฏ Honey Pot, ๐Ÿผ Baby Bottle, ๐Ÿฅ› Glass of Milk, โ˜• Hot Beverage, ๐Ÿซ– Teapot, ๐Ÿต Teacup Without Handle, ๐Ÿถ Sake, ๐Ÿพ Bottle with Popping Cork, ๐Ÿท Wine Glass, ๐Ÿธ Cocktail Glass, ๐Ÿน Tropical Drink, ๐Ÿบ Beer Mug, ๐Ÿป Clinking Beer Mugs, ๐Ÿฅ‚ Clinking Glasses, ๐Ÿฅƒ Tumbler Glass, ๐Ÿซ— Pouring Liquid, ๐Ÿฅค Cup with Straw, ๐Ÿง‹ Bubble Tea, ๐Ÿงƒ Beverage Box, ๐Ÿง‰ Mate, ๐ŸงŠ Ice, ๐Ÿฅข Chopsticks, ๐Ÿฝ๏ธ Fork and Knife with Plate, ๐Ÿด Fork and Knife, ๐Ÿฅ„ Spoon, ๐Ÿซ™ Jar")
""")