File size: 3,961 Bytes
1adce1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c4d06c
1adce1c
 
6c4d06c
1adce1c
 
 
 
 
 
 
 
 
 
 
 
6c4d06c
 
 
 
1adce1c
6c4d06c
 
1adce1c
6c4d06c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1adce1c
6c4d06c
 
 
1adce1c
6c4d06c
1adce1c
 
6c4d06c
 
1adce1c
6c4d06c
 
0029495
6c4d06c
 
1adce1c
 
6c4d06c
 
 
 
 
 
 
1adce1c
6c4d06c
 
1adce1c
6c4d06c
 
 
 
1adce1c
 
6c4d06c
1adce1c
6c4d06c
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import streamlit as st
import asyncio
import websockets
import uuid
from datetime import datetime
import os
import random
import hashlib
import base64
import edge_tts
import nest_asyncio
import re
import threading
import time
import json
import streamlit.components.v1 as components
from gradio_client import Client
from streamlit_marquee import streamlit_marquee
import folium
from streamlit_folium import folium_static
import glob
import pytz
from collections import defaultdict
import pandas as pd

# ๐Ÿ› ๏ธ (1) Allow nested asyncio loops for compatibility
nest_asyncio.apply()

# ๐ŸŽจ (2) Page Configuration for Streamlit UI
st.set_page_config(
    layout="wide",
    page_title="Rocky Mountain Quest 3D ๐Ÿ”๏ธ๐ŸŽฎ",
    page_icon="๐ŸฆŒ",
    initial_sidebar_state="auto",
    menu_items={
        'Get Help': 'https://huggingface.co/awacke1',
        'Report a bug': 'https://huggingface.co/spaces/awacke1',
        'About': "Rocky Mountain Quest 3D ๐Ÿ”๏ธ๐ŸŽฎ"
    }
)

# ๐ŸŒŸ (3) Prominent Player Join Notifications
async def broadcast_player_join(username):
    message = json.dumps({"type": "player_joined", "username": username})
    await broadcast_message(message, "quest")

# ๐Ÿ”„ (4) Real-Time Game State Synchronization
async def broadcast_game_state():
    while True:
        game_state = load_game_state(time.time())
        await broadcast_message(json.dumps({"type": "sync", "state": game_state}), "quest")
        await asyncio.sleep(1)

# ๐ŸŒŒ (5) Fractal and Emergent Data Generation for 3D Visualization
FRAC_SEEDS = [random.uniform(-40, 40) for _ in range(100)]

# ๐ŸŽฒ (6) Three.js Shape Primitives and Fractal Data Structures
shape_primitives = ['sphere', 'cube', 'cylinder', 'cone', 'torus', 'dodecahedron', 'octahedron', 'tetrahedron', 'icosahedron']
fractals = [{
    "type": random.choice(shape_primitives),
    "position": [random.uniform(-40,40), random.uniform(0,20), random.uniform(-40,40)],
    "color": random.randint(0, 0xFFFFFF)
} for _ in range(100)]

# ๐Ÿ–ฅ๏ธ (7) Initialize WebSocket Server for Multiplayer Connectivity
if not st.session_state.get('server_running', False):
    threading.Thread(target=start_websocket_server, daemon=True).start()
    st.session_state['server_running'] = True

# ๐Ÿ’ฐ (8) Increment Scores and Automatically Save at Milestones
async def increment_and_save_scores():
    while True:
        game_state = load_game_state(time.time())
        for player in game_state["players"].values():
            player["score"] += 1
            if player["score"] % 100 == 0:
                filename = f"cache_{player['username']}_score_{player['score']}.json"
                with open(filename, 'w') as f:
                    json.dump(player, f)
        update_game_state(game_state)
        await asyncio.sleep(1)

# ๐Ÿš€ (9) Start Background Async Tasks for Game Operations
asyncio.run(increment_and_save_scores())
asyncio.run(broadcast_game_state())

# ๐ŸŒ (10) Main Streamlit UI Function

def main():
    # ๐Ÿ”๏ธ Game Title Display
    st.title("Rocky Mountain Quest 3D ๐Ÿ”๏ธ๐ŸŽฎ")

    # ๐Ÿ“ UI Layout with Columns
    col1, col2 = st.columns([3, 1])

    # ๐ŸŽฎ Left Column - Three.js Game Canvas
    with col1:
        components.html(rocky_map_html, width=800, height=600)

    # ๐Ÿ“‹ Right Column - Player Information and Maps
    with col2:
        st.subheader("Active Players ๐Ÿง™โ€โ™‚๏ธ")
        current_state = load_game_state(time.time())
        for player in current_state["players"].values():
            st.write(f"๐Ÿ‘ค {player['username']} - ๐ŸŒŸ {player['score']} points")

        st.subheader("๐ŸŒพ Prairie Map")
        prairie_map = folium.Map(location=[44.0, -103.0], zoom_start=8)
        folium_static(prairie_map)

    # ๐ŸŽฏ Sidebar Game Controls
    st.sidebar.markdown("### ๐ŸŽฏ Game Controls")
    if st.sidebar.button("Reset World ๐ŸŒ"):
        reset_game_state()
        st.rerun()

# โœ… Run the application
if __name__ == "__main__":
    main()