Spaces:
Running
Running
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() | |