awacke1 commited on
Commit
ab455b5
·
verified ·
1 Parent(s): 642d274

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -34
app.py CHANGED
@@ -254,7 +254,7 @@ async def periodic_update():
254
  await broadcast_message(f"System|{message}", "quest")
255
  await broadcast_message(f"MAP_UPDATE:{player_data}", "quest")
256
 
257
- prairie_list = ", ".join([f"{p['username']} ({p['animal']})" for p in st.session_state.prairie_players.values()]) or "No animals yet!"
258
  prairie_message = f"🌾 Prairie Update: {prairie_list}"
259
  prairie_data = json.dumps(list(st.session_state.prairie_players.values()))
260
  await broadcast_message(f"System|{prairie_message}", "quest")
@@ -437,65 +437,65 @@ prairie_simulator_html = """
437
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
438
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
439
  <script>
440
- const playerName = "{username}";
441
  let ws = new WebSocket('ws://localhost:8765/prairie');
442
  const map = L.map('map').setView([44.0, -103.0], 7);
443
- L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png', {{
444
  attribution: '© OpenStreetMap contributors'
445
- }}).addTo(map);
446
 
447
- const locations = {{
448
  "Deadwood, SD": [44.3769, -103.7298],
449
  "Wind Cave National Park": [43.6047, -103.4798],
450
  "Wyoming Spring Creek": [41.6666, -106.6666]
451
- }};
452
- for (let loc in locations) {{
453
  L.marker(locations[loc]).addTo(map).bindPopup(loc);
454
- }}
455
 
456
- let players = {{}};
457
- const markers = {{}};
458
 
459
- function updatePlayers(playerData) {{
460
- playerData.forEach(player => {{
461
- if (!markers[player.username]) {{
462
- markers[player.username] = L.circleMarker(player.location, {{
463
- color: `#${{player.color.toString(16).padStart(6, '0')}}`,
464
  radius: 5
465
- }}).addTo(map).bindPopup(`${{player.username}} (${{player.animal}})`);
466
- }} else {{
467
  markers[player.username].setLatLng(player.location);
468
- }}
469
- }});
470
- document.getElementById('status').textContent = `Players: ${{Object.keys(markers).length}}`;
471
- }}
472
 
473
- function updateAnimal() {{
474
  const animal = document.getElementById('animal').value;
475
- ws.send(`${{playerName}}|PRAIRIE:ANIMAL:${{animal}}`);
476
- }}
477
 
478
- function move() {{
479
  const location = document.getElementById('location').value;
480
- ws.send(`${{playerName}}|PRAIRIE:MOVE:${{location}}`);
481
- }}
482
 
483
- ws.onmessage = function(event) {{
484
  const data = event.data;
485
- if (data.startsWith('PRAIRIE_UPDATE:')) {{
486
  const playerData = JSON.parse(data.split('PRAIRIE_UPDATE:')[1]);
487
  updatePlayers(playerData);
488
- }} else if (!data.startsWith('MAP_UPDATE:')) {{
489
  const [sender, message] = data.split('|');
490
  const chatBox = document.getElementById('chatBox');
491
- chatBox.innerHTML += `<p>${{sender}}: ${{message}}</p>`;
492
  chatBox.scrollTop = chatBox.scrollHeight;
493
- }}
494
- }};
495
  </script>
496
  </body>
497
  </html>
498
- """.format(username=st.session_state.username)
499
 
500
  # Main Game Loop
501
  def main():
 
254
  await broadcast_message(f"System|{message}", "quest")
255
  await broadcast_message(f"MAP_UPDATE:{player_data}", "quest")
256
 
257
+ prairie_list = ", ".join([F"{p['username']} ({p['animal']})" for p in st.session_state.prairie_players.values()]) or "No animals yet!"
258
  prairie_message = f"🌾 Prairie Update: {prairie_list}"
259
  prairie_data = json.dumps(list(st.session_state.prairie_players.values()))
260
  await broadcast_message(f"System|{prairie_message}", "quest")
 
437
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
438
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
439
  <script>
440
+ const playerName = "%s";
441
  let ws = new WebSocket('ws://localhost:8765/prairie');
442
  const map = L.map('map').setView([44.0, -103.0], 7);
443
+ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
444
  attribution: '© OpenStreetMap contributors'
445
+ }).addTo(map);
446
 
447
+ const locations = {
448
  "Deadwood, SD": [44.3769, -103.7298],
449
  "Wind Cave National Park": [43.6047, -103.4798],
450
  "Wyoming Spring Creek": [41.6666, -106.6666]
451
+ };
452
+ for (let loc in locations) {
453
  L.marker(locations[loc]).addTo(map).bindPopup(loc);
454
+ }
455
 
456
+ let players = {};
457
+ const markers = {};
458
 
459
+ function updatePlayers(playerData) {
460
+ playerData.forEach(player => {
461
+ if (!markers[player.username]) {
462
+ markers[player.username] = L.circleMarker(player.location, {
463
+ color: `#${player.color.toString(16).padStart(6, '0')}`,
464
  radius: 5
465
+ }).addTo(map).bindPopup(`${player.username} (${player.animal})`);
466
+ } else {
467
  markers[player.username].setLatLng(player.location);
468
+ }
469
+ });
470
+ document.getElementById('status').textContent = `Players: ${Object.keys(markers).length}`;
471
+ }
472
 
473
+ function updateAnimal() {
474
  const animal = document.getElementById('animal').value;
475
+ ws.send(`${playerName}|PRAIRIE:ANIMAL:${animal}`);
476
+ }
477
 
478
+ function move() {
479
  const location = document.getElementById('location').value;
480
+ ws.send(`${playerName}|PRAIRIE:MOVE:${location}`);
481
+ }
482
 
483
+ ws.onmessage = function(event) {
484
  const data = event.data;
485
+ if (data.startsWith('PRAIRIE_UPDATE:')) {
486
  const playerData = JSON.parse(data.split('PRAIRIE_UPDATE:')[1]);
487
  updatePlayers(playerData);
488
+ } else if (!data.startsWith('MAP_UPDATE:')) {
489
  const [sender, message] = data.split('|');
490
  const chatBox = document.getElementById('chatBox');
491
+ chatBox.innerHTML += `<p>${sender}: ${message}</p>`;
492
  chatBox.scrollTop = chatBox.scrollHeight;
493
+ }
494
+ };
495
  </script>
496
  </body>
497
  </html>
498
+ """ % st.session_state.username
499
 
500
  # Main Game Loop
501
  def main():