File size: 82,486 Bytes
29b445b |
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 |
"""
Redesigned Library System with Instant Discovery and Cooldown for Tag Collector Game
"""
import streamlit as st
import random
import time
import math
import pandas as pd
import datetime
from game_constants import (
TAG_CURRENCY_NAME,
RARITY_LEVELS,
ENKEPHALIN_CURRENCY_NAME,
ENKEPHALIN_ICON,
TAG_POWER_BONUSES
)
from essence_generator import display_essence_generator
from tag_categories import (
TAG_CATEGORIES,
get_collection_power_level
)
import tag_storage
# Define library properties
LIBRARY_INFO = {
"name": "The Library",
"description": "A vast repository of knowledge where tags are discovered through patient exploration and research.",
"color": "#4A148C", # Deep purple
"rarities_available": ["Canard", "Urban Myth", "Urban Legend", "Urban Plague", "Urban Nightmare", "Star of the City", "Impuritas Civitas"],
"odds_multiplier": 2.0
}
# Define library floors with their unlocking requirements and rarity boosts
LIBRARY_FLOORS = [
{
"name": "Floor of General Works",
"description": "The foundation of knowledge. Contains basic tags with limited rarity.",
"required_tags": 0, # Available from the start
"rarity_boost": 0.0,
"color": "#8D99AE", # Light blue-gray
"unlocked": True, # Always unlocked
"rarities": ["Canard", "Urban Myth", "Urban Legend"],
"odds_multiplier": 1.0 # Base odds multiplier
},
{
"name": "Floor of History",
"description": "Archives of past knowledge. Offers more access to uncommon tags.",
"required_tags": 25, # Unlocked after collecting 25 tags
"rarity_boost": 0.2,
"color": "#457B9D", # Moderate blue
"rarities": ["Canard", "Urban Myth", "Urban Legend", "Urban Plague"],
"odds_multiplier": 1.2
},
{
"name": "Floor of Technological Sciences",
"description": "Repository of technical knowledge. Access to rare tags begins here.",
"required_tags": 75, # Unlocked after collecting 75 tags
"rarity_boost": 0.4,
"color": "#2B9348", # Green
"rarities": ["Canard", "Urban Myth", "Urban Legend", "Urban Plague"],
"odds_multiplier": 1.5
},
{
"name": "Floor of Literature",
"description": "A vast collection of narrative concepts. Higher chance of rare discoveries.",
"required_tags": 150, # Unlocked after collecting 150 tags
"rarity_boost": 0.6,
"color": "#6A0572", # Purple
"rarities": ["Canard", "Urban Myth", "Urban Legend", "Urban Plague", "Urban Nightmare"],
"odds_multiplier": 1.8
},
{
"name": "Floor of Art",
"description": "The realm of aesthetic concepts. First access to Urban Nightmare tags.",
"required_tags": 250, # Unlocked after collecting 250 tags
"rarity_boost": 0.8,
"color": "#D90429", # Red
"rarities": ["Canard", "Urban Myth", "Urban Legend", "Urban Plague", "Urban Nightmare"],
"odds_multiplier": 2.2
},
{
"name": "Floor of Natural Sciences",
"description": "Where empirical knowledge is cataloged. Significant chance of very rare tags.",
"required_tags": 500, # Unlocked after collecting 400 tags
"rarity_boost": 1.0,
"color": "#1A759F", # Deep blue
"rarities": ["Urban Myth", "Urban Legend", "Urban Plague", "Urban Nightmare", "Star of the City"],
"odds_multiplier": 2.5
},
{
"name": "Floor of Language",
"description": "The domain of linguistic concepts. First glimpse of Star of the City tags.",
"required_tags": 1000, # Unlocked after collecting 600 tags
"rarity_boost": 1.2,
"color": "#FF8C00", # Orange
"rarities": ["Urban Myth", "Urban Legend", "Urban Plague", "Urban Nightmare", "Star of the City"],
"odds_multiplier": 3.0
},
{
"name": "Floor of Social Sciences",
"description": "Complex social patterns and abstractions. Notable chance of exceptional rarities.",
"required_tags": 2000, # Unlocked after collecting 1000 tags
"rarity_boost": 1.4,
"color": "#76B041", # Brighter green
"rarities": ["Urban Legend", "Urban Plague", "Urban Nightmare", "Star of the City"],
"odds_multiplier": 3.5
},
{
"name": "Floor of Philosophy",
"description": "The realm of profound thought. First access to the rarest 'Impuritas Civitas' tags.",
"required_tags": 5000, # Unlocked after collecting 1500 tags
"rarity_boost": 1.6,
"color": "#7209B7", # Deep purple
"rarities": ["Urban Legend", "Urban Plague", "Urban Nightmare", "Star of the City", "Impuritas Civitas"],
"odds_multiplier": 5.0
},
{
"name": "Floor of Religion",
"description": "The ultimate repository of the most profound conceptual territories.",
"required_tags": 10000,
"rarity_boost": 2.0,
"color": "#FFBD00", # Gold
"rarities": ["Urban Plague", "Urban Nightmare", "Star of the City", "Impuritas Civitas"],
"odds_multiplier": 10.0
}
]
def start_instant_expedition():
"""
Start an instant expedition with a cooldown before next expedition.
Returns:
List of discoveries or None if on cooldown
"""
# Check if we're on cooldown
current_time = time.time()
if hasattr(st.session_state, 'last_expedition_time'):
elapsed_time = current_time - st.session_state.last_expedition_time
cooldown_duration = calculate_expedition_duration()
if elapsed_time < cooldown_duration:
# Still on cooldown
time_remaining = cooldown_duration - elapsed_time
minutes, seconds = divmod(int(time_remaining), 60)
st.error(f"Expedition on cooldown. {minutes:02d}:{seconds:02d} remaining.")
return None
# Generate instant discoveries
discoveries = generate_expedition_discoveries()
# Set the cooldown timer
st.session_state.last_expedition_time = current_time
# Save state
tag_storage.save_game(st.session_state)
# Preserve the current tab
if 'library_tab_index' not in st.session_state:
st.session_state.library_tab_index = 0
return discoveries
def generate_expedition_discoveries():
"""
Generate expedition discoveries instantly.
Returns:
List of discovered tags and their info
"""
# Get current library floor
current_floor = None
collection_size = len(st.session_state.collected_tags) if hasattr(st.session_state, 'collected_tags') else 0
if hasattr(st.session_state, 'library_floors'):
# Find the highest unlocked floor
for floor in reversed(st.session_state.library_floors):
if collection_size >= floor["required_tags"]:
current_floor = floor
break
# Default to first floor if we couldn't find one
if not current_floor:
current_floor = st.session_state.library_floors[0] if hasattr(st.session_state, 'library_floors') else {
"name": "Archival Records",
"rarities": ["Canard", "Urban Myth"],
"rarity_boost": 0.0
}
# Calculate rarity odds for discoveries
rarity_odds = calculate_rarity_odds()
# Calculate capacity from upgrades
tags_capacity = calculate_expedition_capacity()
# Generate discoveries
discoveries = []
for _ in range(tags_capacity):
# Select a rarity based on calculated odds
rarities = list(rarity_odds.keys())
weights = list(rarity_odds.values())
selected_rarity = random.choices(rarities, weights=weights, k=1)[0]
# Now select a random tag with this rarity that hasn't been discovered yet
possible_tags = []
# Check if we have tag metadata with rarity info
if hasattr(st.session_state, 'tag_rarity_metadata') and st.session_state.tag_rarity_metadata:
# Find all tags of the selected rarity
for tag, tag_info in st.session_state.tag_rarity_metadata.items():
# Skip if already discovered
if tag in st.session_state.discovered_tags:
continue
# Handle both formats - new (dict with rarity) and old (just rarity string)
if isinstance(tag_info, dict) and "rarity" in tag_info:
if tag_info["rarity"] == selected_rarity:
possible_tags.append(tag)
elif tag_info == selected_rarity:
possible_tags.append(tag)
# If no undiscovered tags found in the selected rarity, fallback to already discovered tags
if not possible_tags:
if hasattr(st.session_state, 'tag_rarity_metadata') and st.session_state.tag_rarity_metadata:
for tag, tag_info in st.session_state.tag_rarity_metadata.items():
# Skip if in different rarity
tag_rarity = tag_info.get("rarity", tag_info) if isinstance(tag_info, dict) else tag_info
if tag_rarity != selected_rarity:
continue
possible_tags.append(tag)
# If still no tags found (or no metadata), create a fallback
if not possible_tags:
# If we have the model's full tag list, use it
if hasattr(st.session_state, 'metadata') and 'idx_to_tag' in st.session_state.metadata:
all_tags = list(st.session_state.metadata['idx_to_tag'].values())
# Just pick a random tag and assign the selected rarity
possible_tags = random.sample(all_tags, min(20, len(all_tags)))
else:
# Complete fallback - use some generic tags
possible_tags = ["portrait", "landscape", "digital_art", "anime", "realistic",
"fantasy", "sci-fi", "city", "nature", "character"]
# If we found possible tags, select one randomly
if possible_tags:
selected_tag = random.choice(possible_tags)
# Get category from metadata if available
category = "unknown"
if hasattr(st.session_state, 'metadata') and 'tag_to_category' in st.session_state.metadata:
if selected_tag in st.session_state.metadata['tag_to_category']:
category = st.session_state.metadata['tag_to_category'][selected_tag]
# Use the enhanced tag storage function to add the discovered tag
is_new = tag_storage.add_discovered_tag(
tag=selected_tag,
rarity=selected_rarity,
session_state=st.session_state,
library_floor=current_floor["name"],
category=category # Pass the category we found
)
# Record for library growth
st.session_state.library_growth["total_discoveries"] += 1
st.session_state.library_growth["last_discovery_time"] = time.time()
# Create timestamp for display
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
# Add to results
discoveries.append({
"tag": selected_tag,
"rarity": selected_rarity,
"is_new": is_new,
"timestamp": timestamp,
"library": current_floor["name"]
})
# Save the game state after discoveries
tag_storage.save_library_state(session_state=st.session_state)
tag_storage.save_game(st.session_state)
return discoveries
def update_discovered_tag_categories():
"""Update categories of discovered tags from metadata if they're unknown"""
if not hasattr(st.session_state, 'discovered_tags') or not st.session_state.discovered_tags:
return 0
updated_count = 0
# First try from metadata.tag_to_category
if hasattr(st.session_state, 'metadata') and 'tag_to_category' in st.session_state.metadata:
tag_to_category = st.session_state.metadata['tag_to_category']
for tag, info in st.session_state.discovered_tags.items():
if info.get('category', 'unknown') == 'unknown' and tag in tag_to_category:
info['category'] = tag_to_category[tag]
updated_count += 1
# Then try from tag_rarity_metadata
if hasattr(st.session_state, 'tag_rarity_metadata') and st.session_state.tag_rarity_metadata:
for tag, info in st.session_state.discovered_tags.items():
if info.get('category', 'unknown') == 'unknown' and tag in st.session_state.tag_rarity_metadata:
tag_metadata = st.session_state.tag_rarity_metadata[tag]
if isinstance(tag_metadata, dict) and "category" in tag_metadata:
info['category'] = tag_metadata["category"]
updated_count += 1
if updated_count > 0:
print(f"Updated categories for {updated_count} discovered tags")
tag_storage.save_library_state(session_state=st.session_state)
return updated_count
def calculate_expedition_duration():
"""
Calculate the duration of cooldown after an expedition based on upgrades.
Returns:
Duration in seconds for the cooldown
"""
base_duration = 10 # Default to 10 seconds
# Apply speed upgrades if they exist
speed_level = 1
if hasattr(st.session_state, 'library_upgrades'):
speed_level = st.session_state.library_upgrades.get("speed", 1)
# Each speed level reduces duration by 10% (multiplicative)
duration_multiplier = 0.9 ** (speed_level - 1)
# Calculate final duration (minimum 1 second)
duration = max(1, base_duration * duration_multiplier)
return duration
def calculate_expedition_capacity():
"""
Calculate how many tags can be discovered in one expedition.
Returns:
Number of tags that can be discovered
"""
base_capacity = 1 # Default to 1 discovery per expedition
# Apply capacity upgrades if they exist
capacity_level = 1
if hasattr(st.session_state, 'library_upgrades'):
capacity_level = st.session_state.library_upgrades.get("capacity", 1)
# Each capacity level increases discoveries by 1
capacity = base_capacity + (capacity_level - 1)
return capacity
def calculate_rarity_odds():
"""
Calculate rarity odds based on library floor level and upgrades.
Returns:
Dictionary of {rarity: probability} for available rarities
"""
# Get current library floor
current_floor = None
if hasattr(st.session_state, 'library_floors'):
collection_size = len(st.session_state.collected_tags) if hasattr(st.session_state, 'collected_tags') else 0
# Find the highest unlocked floor
for floor in reversed(st.session_state.library_floors):
if collection_size >= floor["required_tags"]:
current_floor = floor
break
# Default to first floor if we couldn't find one
if not current_floor:
current_floor = st.session_state.library_floors[0] if hasattr(st.session_state, 'library_floors') else {
"rarities": ["Canard", "Urban Myth"],
"rarity_boost": 0.0,
"odds_multiplier": 1.0
}
# Get available rarities from current floor
available_rarities = current_floor.get("rarities", ["Canard", "Urban Myth"])
odds_multiplier = current_floor.get("odds_multiplier", 1.0)
# Base weights for each rarity
base_weights = {
"Canard": 70,
"Urban Myth": 20,
"Urban Legend": 7,
"Urban Plague": 2,
"Urban Nightmare": 1,
"Star of the City": 0.1,
"Impuritas Civitas": 0.01
}
# Apply floor's rarity boost
floor_rarity_boost = current_floor.get("rarity_boost", 0.0)
# Apply rarity upgrades if they exist
rarity_level = 1
if hasattr(st.session_state, 'library_upgrades'):
rarity_level = st.session_state.library_upgrades.get("rarity", 1)
# Calculate boost based on rarity level
upgrade_rarity_boost = (rarity_level - 1) * 0.2 # Each level gives 20% more chance for rare tags
# Combine boosts
total_boost = floor_rarity_boost + upgrade_rarity_boost
# Adjust weights based on rarity boost
adjusted_weights = {}
for rarity in available_rarities:
if rarity == "Canard":
# Reduce common tag odds as rarity level increases
adjusted_weights[rarity] = base_weights[rarity] * (1.0 - total_boost * 0.7)
elif rarity == "Urban Myth":
# Slight reduction for uncommon as rarity level increases
adjusted_weights[rarity] = base_weights[rarity] * (1.0 - total_boost * 0.3)
else:
# Increase rare tag odds as rarity level increases
rarity_index = list(RARITY_LEVELS.keys()).index(rarity)
# Higher rarities get larger boosts
boost_factor = 1.0 + (total_boost * odds_multiplier * (rarity_index + 1))
adjusted_weights[rarity] = base_weights[rarity] * boost_factor
# Normalize weights
total = sum(adjusted_weights.values())
normalized_weights = {r: w/total for r, w in adjusted_weights.items()}
return normalized_weights
def format_time_remaining(seconds):
"""
Format seconds into a human-readable time remaining format.
Args:
seconds: Seconds remaining
Returns:
String with formatted time
"""
if seconds < 60:
return f"{int(seconds)} seconds"
elif seconds < 3600:
minutes = seconds / 60
return f"{int(minutes)} minutes"
else:
hours = seconds / 3600
minutes = (seconds % 3600) / 60
if minutes > 0:
return f"{int(hours)} hours, {int(minutes)} minutes"
else:
return f"{int(hours)} hours"
def display_cooldown_timer():
"""Display a countdown timer until the next expedition is available"""
# Check if on cooldown
current_time = time.time()
cooldown_remaining = 0
cooldown_duration = calculate_expedition_duration()
if hasattr(st.session_state, 'last_expedition_time'):
elapsed_time = current_time - st.session_state.last_expedition_time
if elapsed_time < cooldown_duration:
cooldown_remaining = cooldown_duration - elapsed_time
# If on cooldown, show timer
if cooldown_remaining > 0:
minutes, seconds = divmod(int(cooldown_remaining), 60)
# Create a timer display with dark-mode styling
st.markdown("""
<div style="background-color: rgba(255, 152, 0, 0.15);
border: 1px solid #FF9800;
border-radius: 5px;
padding: 10px;
text-align: center;
margin-bottom: 15px;
color: #ffffff;">
<p style="margin: 0; font-weight: bold;">β±οΈ Next expedition available in:</p>
<p style="font-size: 1.2em; margin: 5px 0;">{:02d}:{:02d}</p>
</div>
""".format(minutes, seconds), unsafe_allow_html=True)
# Add refresh button for the timer
if st.button("π Refresh Timer", key="refresh_timer"):
st.rerun()
return True # Still on cooldown
return False # Not on cooldown
def display_library_exploration_interface():
"""Display the unified interface for library exploration using Streamlit elements."""
# Tag collection progress
tag_count = len(st.session_state.collected_tags) if hasattr(st.session_state, 'collected_tags') else 0
# Check if we have tags to start exploring
if not hasattr(st.session_state, 'collected_tags') or not st.session_state.collected_tags:
st.warning("Start scanning images to collect tags first. The library will grow as you collect more tags!")
return
# Get current library floor
current_floor = None
if hasattr(st.session_state, 'library_floors'):
# Find the highest unlocked floor
for floor in reversed(st.session_state.library_floors):
if tag_count >= floor["required_tags"]:
current_floor = floor
break
# Default to first floor if we couldn't find one
if not current_floor:
current_floor = st.session_state.library_floors[0] if hasattr(st.session_state, 'library_floors') else {
"name": "Floor of General Works",
"description": "The foundational level of knowledge.",
"color": "#607D8B",
"rarities": ["Canard", "Urban Myth"]
}
# Library growth progress
total_discoveries = st.session_state.library_growth["total_discoveries"]
# Create container with colored border for current floor
floor_container = st.container()
with floor_container:
# Use a stylized container with dark mode theme
st.markdown(f"""
<div style="border-left: 5px solid {current_floor['color']};
border-radius: 5px;
background-color: rgba({int(current_floor['color'][1:3], 16)},
{int(current_floor['color'][3:5], 16)},
{int(current_floor['color'][5:7], 16)}, 0.15);
padding: 15px 10px 10px 15px;
margin-bottom: 15px;
color: #ffffff;">
<h3 style="margin-top: 0; color: {current_floor['color']};">{current_floor['name']}</h3>
<p>{current_floor['description']}</p>
<p>Total Discoveries: <strong>{total_discoveries}</strong></p>
</div>
""", unsafe_allow_html=True)
# Create a nice divider for dark theme
st.markdown("<hr style='margin: 20px 0; border: 0; height: 1px; background-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0));'>", unsafe_allow_html=True)
# Display expedition details
st.subheader("Expedition Details")
# Calculate capacity
capacity = calculate_expedition_capacity()
# Two columns for expedition stats
col1, col2 = st.columns(2)
with col1:
# Expedition duration/timer
cooldown_duration = calculate_expedition_duration()
st.write(f"π Cooldown: {format_time_remaining(cooldown_duration)}")
st.write(f"π Tag Discoveries: {capacity} per expedition")
with col2:
# Calculate and display rarity odds with Streamlit elements
rarity_odds = calculate_rarity_odds()
available_rarities = current_floor.get("rarities", ["Canard", "Urban Myth"])
# Display rarity chances with dark theme styling
for rarity in available_rarities:
if rarity in rarity_odds:
color = RARITY_LEVELS[rarity]["color"]
percentage = rarity_odds[rarity]*100
# Custom styling based on rarity
if rarity == "Impuritas Civitas":
st.markdown(f"""
<div style="display: flex; align-items: center; margin-bottom: 5px;">
<span style="animation: rainbow-text 4s linear infinite; font-weight: bold; width: 140px;">{rarity}:</span>
<div style="flex-grow: 1; background-color: #2c2c2c; border-radius: 5px; height: 10px;">
<div style="width: {min(percentage*5, 100)}%; background: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet); height: 10px; border-radius: 5px;"></div>
</div>
<span style="margin-left: 10px;">{percentage:.1f}%</span>
</div>
""", unsafe_allow_html=True)
elif rarity == "Star of the City":
st.markdown(f"""
<div style="display: flex; align-items: center; margin-bottom: 5px;">
<span style="color:{color}; text-shadow: 0 0 3px gold; font-weight: bold; width: 140px;">{rarity}:</span>
<div style="flex-grow: 1; background-color: #2c2c2c; border-radius: 5px; height: 10px;">
<div style="width: {min(percentage*5, 100)}%; background-color: {color}; box-shadow: 0 0 5px gold; height: 10px; border-radius: 5px;"></div>
</div>
<span style="margin-left: 10px;">{percentage:.1f}%</span>
</div>
""", unsafe_allow_html=True)
elif rarity == "Urban Nightmare":
st.markdown(f"""
<div style="display: flex; align-items: center; margin-bottom: 5px;">
<span style="color:{color}; text-shadow: 0 0 1px #FF5722; font-weight: bold; width: 140px;">{rarity}:</span>
<div style="flex-grow: 1; background-color: #2c2c2c; border-radius: 5px; height: 10px;">
<div style="width: {min(percentage*5, 100)}%; background-color: {color}; animation: pulse-bar 3s infinite; height: 10px; border-radius: 5px;"></div>
</div>
<span style="margin-left: 10px;">{percentage:.1f}%</span>
</div>
""", unsafe_allow_html=True)
else:
st.markdown(f"""
<div style="display: flex; align-items: center; margin-bottom: 5px;">
<span style="color:{color}; font-weight: bold; width: 140px;">{rarity}:</span>
<div style="flex-grow: 1; background-color: #2c2c2c; border-radius: 5px; height: 10px;">
<div style="width: {min(percentage*5, 100)}%; background-color: {color}; height: 10px; border-radius: 5px;"></div>
</div>
<span style="margin-left: 10px;">{percentage:.1f}%</span>
</div>
""", unsafe_allow_html=True)
# Check for cooldown and display timer if needed
on_cooldown = display_cooldown_timer()
# Add button to start expedition regardless of cooldown status
# The button will always be displayed, but if on cooldown, expedition won't start
if st.button("π Start Expedition", key="start_expedition", use_container_width=True, disabled=on_cooldown):
if not on_cooldown:
discoveries = start_instant_expedition()
if discoveries:
# Store discovery results for display
st.session_state.expedition_results = discoveries
# Show success message
st.success(f"Expedition completed! Discovered {len(discoveries)} new tags!")
# Show balloons for celebration
st.balloons()
# Display the results
display_expedition_results(discoveries)
# Save state
tag_storage.save_game(st.session_state)
else:
# This should not be reached due to disabled button, but just in case
st.error("Expedition on cooldown. Please wait until the timer expires.")
# Display library upgrades
display_library_upgrades()
def display_expedition_results(results):
"""Display results from completed expeditions using Streamlit elements with enhanced dark-mode visuals."""
st.subheader("Expedition Discoveries")
# Add animations CSS for dark theme
st.markdown("""
<style>
@keyframes rainbow-text {
0% { color: red; }
14% { color: orange; }
28% { color: yellow; }
42% { color: green; }
57% { color: blue; }
71% { color: indigo; }
85% { color: violet; }
100% { color: red; }
}
@keyframes rainbow-border {
0% { border-color: red; }
14% { border-color: orange; }
28% { border-color: yellow; }
42% { border-color: green; }
57% { border-color: blue; }
71% { border-color: indigo; }
85% { border-color: violet; }
100% { border-color: red; }
}
@keyframes star-glow {
0% { box-shadow: 0 0 5px #FFD700; }
50% { box-shadow: 0 0 15px #FFD700; }
100% { box-shadow: 0 0 5px #FFD700; }
}
@keyframes nightmare-pulse {
0% { border-color: #FF9800; }
50% { border-color: #FF5722; }
100% { border-color: #FF9800; }
}
@keyframes pulse-bar {
0% { opacity: 0.8; }
50% { opacity: 1; }
100% { opacity: 0.8; }
}
.expedition-tag-impuritas {
animation: rainbow-text 4s linear infinite;
font-weight: bold;
}
.expedition-card-impuritas {
background-color: rgba(255, 0, 0, 0.15);
border-radius: 8px;
border: 3px solid red;
padding: 12px;
animation: rainbow-border 4s linear infinite;
color: #ffffff;
}
.expedition-card-star {
background-color: rgba(255, 215, 0, 0.15);
border-radius: 8px;
border: 2px solid gold;
padding: 12px;
animation: star-glow 2s infinite;
color: #ffffff;
}
.expedition-card-nightmare {
background-color: rgba(255, 152, 0, 0.15);
border-radius: 8px;
border: 2px solid #FF9800;
padding: 12px;
animation: nightmare-pulse 3s infinite;
color: #ffffff;
}
.expedition-card-plague {
background-color: rgba(156, 39, 176, 0.12);
border-radius: 8px;
border: 1px solid #9C27B0;
padding: 12px;
box-shadow: 0 0 3px #9C27B0;
color: #ffffff;
}
.expedition-card-legend {
background-color: rgba(33, 150, 243, 0.15);
border-radius: 8px;
border: 1px solid #2196F3;
padding: 12px;
color: #ffffff;
}
.expedition-card-myth {
background-color: rgba(76, 175, 80, 0.15);
border-radius: 8px;
border: 1px solid #4CAF50;
padding: 12px;
color: #ffffff;
}
.expedition-card-canard {
background-color: rgba(170, 170, 170, 0.15);
border-radius: 8px;
border: 1px solid #AAAAAA;
padding: 12px;
color: #ffffff;
}
</style>
""", unsafe_allow_html=True)
# Group by rarity first for better organization
results_by_rarity = {}
for result in results:
rarity = result["rarity"]
if rarity not in results_by_rarity:
results_by_rarity[rarity] = []
results_by_rarity[rarity].append(result)
# Get ordered rarities (rarest first)
ordered_rarities = list(RARITY_LEVELS.keys())
ordered_rarities.reverse() # Reverse to display rarest first
# Display rare discoveries first
for rarity in ordered_rarities:
if rarity not in results_by_rarity:
continue
rarity_results = results_by_rarity[rarity]
if not rarity_results:
continue
color = RARITY_LEVELS[rarity]["color"]
# Special styling for rare discoveries
if rarity == "Impuritas Civitas":
st.markdown(f"""
<div style="background-color: rgba(255, 0, 0, 0.15); border-radius: 10px; padding: 15px; margin-bottom: 20px; border: 2px solid red; animation: rainbow-border 4s linear infinite; color: #ffffff;">
<h3 style="margin-top: 0; animation: rainbow-text 4s linear infinite;">β¨ EXTRAORDINARY DISCOVERY!</h3>
<p>You found {len(rarity_results)} Impuritas Civitas tag(s)!</p>
</div>
""", unsafe_allow_html=True)
st.balloons() # Add celebration effect
elif rarity == "Star of the City":
st.markdown(f"""
<div style="background-color: rgba(255, 215, 0, 0.15); border-radius: 10px; padding: 15px; margin-bottom: 20px; border: 2px solid gold; animation: star-glow 2s infinite; color: #ffffff;">
<h3 style="margin-top: 0; color: {color}; text-shadow: 0 0 3px gold;">π EXCEPTIONAL DISCOVERY!</h3>
<p>You found {len(rarity_results)} Star of the City tag(s)!</p>
</div>
""", unsafe_allow_html=True)
elif rarity == "Urban Nightmare":
st.markdown(f"""
<div style="background-color: rgba(255, 152, 0, 0.15); border-radius: 10px; padding: 15px; margin-bottom: 20px; border: 2px solid #FF9800; animation: nightmare-pulse 3s infinite; color: #ffffff;">
<h3 style="margin-top: 0; color: {color}; text-shadow: 0 0 1px #FF5722;">π RARE DISCOVERY!</h3>
<p>You found {len(rarity_results)} Urban Nightmare tag(s)!</p>
</div>
""", unsafe_allow_html=True)
elif rarity == "Urban Plague":
st.markdown(f"""
<div style="background-color: rgba(156, 39, 176, 0.12); border-radius: 10px; padding: 15px; margin-bottom: 20px; border: 1px solid #9C27B0; box-shadow: 0 0 3px #9C27B0; color: #ffffff;">
<h3 style="margin-top: 0; color: {color}; text-shadow: 0 0 1px #9C27B0;">βοΈ UNCOMMON DISCOVERY!</h3>
<p>You found {len(rarity_results)} Urban Plague tag(s)!</p>
</div>
""", unsafe_allow_html=True)
else:
st.markdown(f"### {rarity} ({len(rarity_results)} discoveries)")
# Display tags in this rarity
cols = st.columns(3)
for i, result in enumerate(rarity_results):
col_idx = i % 3
with cols[col_idx]:
tag = result["tag"]
floor_name = result.get("library", "Library")
# Get the appropriate card class based on rarity
rarity_class = rarity.lower().replace(' ', '-')
card_class = f"expedition-card-{rarity_class}"
# Create styled card for each tag
tag_html = f"""<div class="{card_class}">"""
# Special styling for the tag name based on rarity
if rarity == "Impuritas Civitas":
tag_html += f"""<p style="font-size: 1.1em; margin-bottom: 5px;"><span class="expedition-tag-impuritas">β¨ {tag}</span></p>"""
elif rarity == "Star of the City":
tag_html += f"""<p style="font-size: 1.1em; margin-bottom: 5px;"><span style="color: {color}; text-shadow: 0 0 3px gold; font-weight: bold;">π {tag}</span></p>"""
elif rarity == "Urban Nightmare":
tag_html += f"""<p style="font-size: 1.1em; margin-bottom: 5px;"><span style="color: {color}; text-shadow: 0 0 1px #FF5722; font-weight: bold;">π {tag}</span></p>"""
elif rarity == "Urban Plague":
tag_html += f"""<p style="font-size: 1.1em; margin-bottom: 5px;"><span style="color: {color}; text-shadow: 0 0 1px #9C27B0; font-weight: bold;">βοΈ {tag}</span></p>"""
else:
tag_html += f"""<p style="font-size: 1.1em; margin-bottom: 5px;"><span style="color: {color}; font-weight: bold;">{tag}</span></p>"""
# Mark as new if it is
is_new = result.get("is_new", False)
new_badge = """<span style="background-color: #4CAF50; color: white; padding: 2px 6px; border-radius: 10px; font-size: 0.7em; margin-left: 5px;">NEW</span>""" if is_new else ""
# Add other tag details
tag_html += f"""
<p style="margin: 0; font-size: 0.9em;">Found in: {floor_name} {new_badge}</p>
<p style="margin: 5px 0 0 0; font-size: 0.9em;">Rarity: <span style="color: {color};">{rarity}</span></p>
</div>
"""
st.markdown(tag_html, unsafe_allow_html=True)
# Add separator between rarity groups
st.markdown("<hr style='margin: 20px 0; border: 0; height: 1px; background-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0));'>", unsafe_allow_html=True)
def display_library_building():
"""Display a visual representation of the library building with all floors."""
st.subheader("The Great Library Building")
# Get collection size
collection_size = len(st.session_state.collected_tags) if hasattr(st.session_state, 'collected_tags') else 0
# Determine current floor
current_floor_index = 0
for i, floor in enumerate(st.session_state.library_floors):
if collection_size >= floor["required_tags"]:
current_floor_index = i
# Create a visual representation of the library building
total_floors = len(st.session_state.library_floors)
# Enhanced CSS for the library building with dark theme
st.markdown("""
<style>
@keyframes floor-glow {
0% { box-shadow: 0 0 5px rgba(13, 110, 253, 0.5); }
50% { box-shadow: 0 0 15px rgba(13, 110, 253, 0.8); }
100% { box-shadow: 0 0 5px rgba(13, 110, 253, 0.5); }
}
.library-roof {
background: linear-gradient(90deg, #8D6E63, #A1887F);
height: 35px;
width: 90%;
margin: 0 auto;
border-radius: 8px 8px 0 0;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
box-shadow: 0 -2px 10px rgba(0,0,0,0.4);
}
.library-floor {
height: 65px;
width: 80%;
margin: 0 auto;
border: 1px solid #444;
display: flex;
align-items: center;
padding: 0 20px;
position: relative;
transition: all 0.3s ease;
color: #ffffff;
background-color: #2c2c2c;
}
.library-floor:hover {
transform: translateX(10px);
}
.library-floor.current {
box-shadow: 0 0 10px rgba(13, 110, 253, 0.5);
z-index: 2;
animation: floor-glow 2s infinite;
border-left: 5px solid #0d6efd;
}
.library-floor.locked {
background-color: #1e1e1e;
color: #777;
filter: grayscale(50%);
}
.library-floor-number {
position: absolute;
left: -30px;
width: 25px;
height: 25px;
background-color: #0d6efd;
color: white;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-weight: bold;
}
.library-floor.locked .library-floor-number {
background-color: #555;
}
.library-entrance {
background: linear-gradient(90deg, #5D4037, #795548);
height: 45px;
width: 35%;
margin: 0 auto;
border-radius: 10px 10px 0 0;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
box-shadow: 0 -2px 10px rgba(0,0,0,0.4);
}
.library-floor-details {
flex: 1;
}
.library-floor-name {
font-weight: bold;
margin: 0;
}
.library-floor-description {
font-size: 0.85em;
margin: 3px 0 0 0;
opacity: 0.9;
}
.library-floor-status {
display: flex;
align-items: center;
font-weight: bold;
}
.library-floor-rarities {
font-size: 0.8em;
margin-top: 4px;
}
.rarity-dot {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
margin-right: 3px;
}
/* Special animations for rarer floors */
.library-floor.star {
background-color: rgba(255, 215, 0, 0.15);
}
.library-floor.impuritas {
background-color: rgba(255, 0, 0, 0.15);
}
@keyframes rainbow-border {
0% { border-color: red; }
14% { border-color: orange; }
28% { border-color: yellow; }
42% { border-color: green; }
57% { border-color: blue; }
71% { border-color: indigo; }
85% { border-color: violet; }
100% { border-color: red; }
}
.rainbow-border {
animation: rainbow-border 4s linear infinite;
}
</style>
""", unsafe_allow_html=True)
# Roof
st.markdown('<div class="library-roof">ποΈ The Great Library</div>', unsafe_allow_html=True)
# Display floors from top (highest) to bottom
for i in reversed(range(total_floors)):
floor = st.session_state.library_floors[i]
is_current = i == current_floor_index
is_unlocked = collection_size >= floor["required_tags"]
# Style based on floor status
floor_class = "library-floor"
if is_current:
floor_class += " current"
if not is_unlocked:
floor_class += " locked"
# Add special classes for highest floors
if i >= 8 and is_unlocked: # Impuritas Civitas level floors
floor_class += " impuritas"
elif i >= 6 and is_unlocked: # Star of the City level floors
floor_class += " star"
# Determine rarity dots HTML
rarity_dots = ""
for rarity in floor.get("rarities", []):
color = RARITY_LEVELS[rarity]["color"]
rarity_dots += f'<span class="rarity-dot" style="background-color:{color};"></span>'
# Floor style based on color
if is_unlocked:
floor_style = f"background-color: rgba({int(floor['color'][1:3], 16)}, {int(floor['color'][3:5], 16)}, {int(floor['color'][5:7], 16)}, 0.25);"
else:
floor_style = ""
# Special border animation for highest floor
border_class = ""
if i == 9 and is_unlocked: # Top floor
border_class = "rainbow-border"
# Display the floor
floor_content = f"""
<div class="{floor_class} {border_class}" style="{floor_style}">
<span class="library-floor-number">{i+1}</span>
<div class="library-floor-details">
<p class="library-floor-name">{floor['name']}</p>
<p class="library-floor-description">{floor['description'] if is_unlocked else 'Locked'}</p>
<div class="library-floor-rarities">{rarity_dots}</div>
</div>
<div class="library-floor-status">
{"π" if is_unlocked else "π"} {floor['required_tags']} tags
</div>
</div>
"""
st.markdown(floor_content, unsafe_allow_html=True)
# Entrance
st.markdown('<div class="library-entrance">π Entrance</div>', unsafe_allow_html=True)
# Floor details expander
with st.expander("Floor Details", expanded=False):
# Create a table with styled rarities for dark theme
st.markdown("""
<style>
.floor-details-table {
width: 100%;
border-collapse: collapse;
color: #ffffff;
}
.floor-details-table th {
background-color: #333;
padding: 8px;
text-align: left;
border: 1px solid #444;
}
.floor-details-table td {
padding: 8px;
border: 1px solid #444;
}
.floor-details-table tr:nth-child(even) {
background-color: rgba(255,255,255,0.03);
}
.floor-details-table tr:nth-child(odd) {
background-color: rgba(0,0,0,0.2);
}
.floor-details-table tr:hover {
background-color: rgba(13, 110, 253, 0.1);
}
.current-floor {
background-color: rgba(13, 110, 253, 0.15) !important;
}
</style>
<table class="floor-details-table">
<tr>
<th>Floor</th>
<th>Name</th>
<th>Status</th>
<th>Req. Tags</th>
<th>Rarities</th>
<th>Rarity Boost</th>
</tr>
""", unsafe_allow_html=True)
# Add each floor to the table
for i, floor in enumerate(st.session_state.library_floors):
is_unlocked = collection_size >= floor["required_tags"]
is_current = i == current_floor_index
# Format rarities with colors
rarity_text = ""
for rarity in floor.get("rarities", []):
color = RARITY_LEVELS[rarity]["color"]
# Special styling based on rarity
if rarity == "Impuritas Civitas":
rarity_text += f"<span style='animation: rainbow-text 4s linear infinite;'>{rarity}</span>, "
elif rarity == "Star of the City":
rarity_text += f"<span style='color:{color}; text-shadow: 0 0 3px gold;'>{rarity}</span>, "
elif rarity == "Urban Nightmare":
rarity_text += f"<span style='color:{color}; text-shadow: 0 0 1px #FF5722;'>{rarity}</span>, "
elif rarity == "Urban Plague":
rarity_text += f"<span style='color:{color}; text-shadow: 0 0 1px #9C27B0;'>{rarity}</span>, "
else:
rarity_text += f"<span style='color:{color};'>{rarity}</span>, "
# Current floor class
row_class = "current-floor" if is_current else ""
# Add the floor row
st.markdown(f"""
<tr class="{row_class}">
<td>{i+1}</td>
<td>{floor["name"]}</td>
<td>{"π Unlocked" if is_unlocked else "π Locked"}</td>
<td>{floor["required_tags"]}</td>
<td>{rarity_text[:-2] if rarity_text else ""}</td>
<td>+{int(floor.get('rarity_boost', 0) * 100)}%</td>
</tr>
""", unsafe_allow_html=True)
# Close the table
st.markdown("</table>", unsafe_allow_html=True)
def add_discovered_tag(tag, rarity, library_floor=None):
"""
Add a tag to the discovered tags with enriched metadata
Args:
tag: The tag name
rarity: The tag rarity level
library_floor: The library floor where it was discovered (optional)
Returns:
bool: True if it's a new discovery, False if already discovered
"""
is_new = tag not in st.session_state.discovered_tags
# Get current time
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
# Get tag category if metadata is available
category = "unknown"
if hasattr(st.session_state, 'tag_rarity_metadata') and st.session_state.tag_rarity_metadata:
if tag in st.session_state.tag_rarity_metadata:
tag_info = st.session_state.tag_rarity_metadata[tag]
if isinstance(tag_info, dict) and "category" in tag_info:
category = tag_info["category"]
# Get or update tag info
if is_new:
tag_info = {
"rarity": rarity,
"discovery_time": timestamp,
"category": category,
"discovery_count": 1,
"last_seen": timestamp
}
if library_floor:
tag_info["library_floor"] = library_floor
st.session_state.discovered_tags[tag] = tag_info
# Track exploration of library tiers
if 'explored_library_tiers' not in st.session_state:
st.session_state.explored_library_tiers = set()
if library_floor:
st.session_state.explored_library_tiers.add(library_floor)
else:
# Update existing tag
tag_info = st.session_state.discovered_tags[tag]
tag_info["discovery_count"] = tag_info.get("discovery_count", 1) + 1
tag_info["last_seen"] = timestamp
# Only update library floor if provided
if library_floor:
tag_info["library_floor"] = library_floor
# Track exploration
if 'explored_library_tiers' not in st.session_state:
st.session_state.explored_library_tiers = set()
st.session_state.explored_library_tiers.add(library_floor)
# Save state after updating
tag_storage.save_library_state(session_state=st.session_state)
return is_new
def calculate_upgrade_cost(upgrade_type, current_level):
base_cost = {
"speed": 50,
"capacity": 100,
"rarity": 150
}
# Cost increases with each level
return int(base_cost[upgrade_type] * (current_level * 1.5))
def purchase_library_upgrade(upgrade_type):
"""
Purchase a library upgrade
Args:
upgrade_type: The type of upgrade ("speed", "capacity", or "rarity")
Returns:
bool: True if purchased successfully, False otherwise
"""
# Get current level and calculate cost
current_level = st.session_state.library_upgrades.get(upgrade_type, 1)
cost = calculate_upgrade_cost(upgrade_type, current_level)
# Check if player can afford it
if st.session_state.tag_currency < cost:
return False
# Apply purchase
st.session_state.tag_currency -= cost
st.session_state.library_upgrades[upgrade_type] = current_level + 1
# Update stats
if hasattr(st.session_state, 'game_stats'):
if "currency_spent" not in st.session_state.game_stats:
st.session_state.game_stats["currency_spent"] = 0
st.session_state.game_stats["currency_spent"] += cost
# Save state
tag_storage.save_library_state(session_state=st.session_state)
tag_storage.save_game(st.session_state)
return True
def display_library_upgrades():
"""Display and manage upgrades for the library using Streamlit elements with enhanced visuals."""
st.subheader("Library Upgrades")
# Add styling for upgrade cards with dark theme
st.markdown("""
<style>
.upgrade-card {
border: 1px solid #444;
border-radius: 10px;
padding: 15px;
margin-bottom: 20px;
background-color: #222;
color: #ffffff;
transition: transform 0.2s, box-shadow 0.2s;
}
.upgrade-card:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
.upgrade-title {
font-size: 1.2em;
font-weight: bold;
margin-bottom: 10px;
color: #ffffff;
}
.upgrade-level {
display: inline-block;
background-color: #0d6efd;
color: white;
padding: 3px 8px;
border-radius: 10px;
font-size: 0.8em;
margin-bottom: 10px;
}
.upgrade-stat {
display: flex;
align-items: center;
margin-bottom: 5px;
}
.upgrade-stat-label {
width: 100px;
font-size: 0.9em;
color: #adb5bd;
}
.upgrade-stat-value {
font-weight: bold;
}
.upgrade-cost {
margin-top: 10px;
font-weight: bold;
color: #6610f2;
}
.level-bar {
height: 6px;
background-color: #333;
border-radius: 3px;
margin-bottom: 10px;
overflow: hidden;
}
.level-progress {
height: 100%;
background-color: #0d6efd;
border-radius: 3px;
}
@keyframes pulse-button {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.pulse-button {
animation: pulse-button 2s infinite;
}
</style>
""", unsafe_allow_html=True)
st.write("Improve your expeditions with these upgrades:")
# Create columns for each upgrade type
col1, col2, col3 = st.columns(3)
# Get current upgrade levels
upgrades = st.session_state.library_upgrades
# Speed upgrade
with col1:
speed_level = upgrades.get("speed", 1)
speed_cost = calculate_upgrade_cost("speed", speed_level)
# Calculate max level for progress bar
max_level = 10
progress_percentage = min(100, (speed_level / max_level) * 100)
# Create an upgrade card with progress bar in dark theme
st.markdown(f"""
<div class="upgrade-card">
<div class="upgrade-title">β±οΈ Speed Upgrade</div>
<div class="upgrade-level">Level {speed_level}</div>
<div class="level-bar">
<div class="level-progress" style="width: {progress_percentage}%;"></div>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Effect:</span>
<span class="upgrade-stat-value">Reduces cooldown time</span>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Current:</span>
<span class="upgrade-stat-value">{format_time_remaining(calculate_expedition_duration())}</span>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Next Level:</span>
<span class="upgrade-stat-value">{format_time_remaining(calculate_expedition_duration() * 0.9)}</span>
</div>
<div class="upgrade-cost" style="color: #9D4EDD;">Cost: {speed_cost} {TAG_CURRENCY_NAME}</div>
</div>
""", unsafe_allow_html=True)
# Upgrade button
can_afford = st.session_state.tag_currency >= speed_cost
button_class = "pulse-button" if can_afford else ""
if st.button(f"Upgrade Speed", key=f"upgrade_speed", disabled=not can_afford, use_container_width=True):
if purchase_library_upgrade("speed"):
st.success(f"Speed upgraded to level {speed_level + 1}!")
st.rerun()
else:
st.error(f"Not enough {TAG_CURRENCY_NAME}. Need {speed_cost}.")
# Capacity upgrade
with col2:
capacity_level = upgrades.get("capacity", 1)
capacity_cost = calculate_upgrade_cost("capacity", capacity_level)
# Calculate max level for progress bar
max_level = 10
progress_percentage = min(100, (capacity_level / max_level) * 100)
# Create an upgrade card with progress bar in dark theme
st.markdown(f"""
<div class="upgrade-card">
<div class="upgrade-title">π Capacity Upgrade</div>
<div class="upgrade-level">Level {capacity_level}</div>
<div class="level-bar">
<div class="level-progress" style="width: {progress_percentage}%;"></div>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Effect:</span>
<span class="upgrade-stat-value">Increases tags discovered</span>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Current:</span>
<span class="upgrade-stat-value">{calculate_expedition_capacity()} tags</span>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Next Level:</span>
<span class="upgrade-stat-value">{calculate_expedition_capacity() + 1} tags</span>
</div>
<div class="upgrade-cost" style="color: #9D4EDD;">Cost: {capacity_cost} {TAG_CURRENCY_NAME}</div>
</div>
""", unsafe_allow_html=True)
# Upgrade button
can_afford = st.session_state.tag_currency >= capacity_cost
button_class = "pulse-button" if can_afford else ""
if st.button(f"Upgrade Capacity", key=f"upgrade_capacity", disabled=not can_afford, use_container_width=True):
if purchase_library_upgrade("capacity"):
st.success(f"Capacity upgraded to level {capacity_level + 1}!")
st.rerun()
else:
st.error(f"Not enough {TAG_CURRENCY_NAME}. Need {capacity_cost}.")
# Rarity upgrade
with col3:
rarity_level = upgrades.get("rarity", 1)
rarity_cost = calculate_upgrade_cost("rarity", rarity_level)
# Calculate max level for progress bar
max_level = 10
progress_percentage = min(100, (rarity_level / max_level) * 100)
# Create an upgrade card with progress bar in dark theme
st.markdown(f"""
<div class="upgrade-card">
<div class="upgrade-title">π Rarity Upgrade</div>
<div class="upgrade-level">Level {rarity_level}</div>
<div class="level-bar">
<div class="level-progress" style="width: {progress_percentage}%;"></div>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Effect:</span>
<span class="upgrade-stat-value">Improves rare tag chance</span>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Current:</span>
<span class="upgrade-stat-value">+{(rarity_level - 1) * 20}% boost</span>
</div>
<div class="upgrade-stat">
<span class="upgrade-stat-label">Next Level:</span>
<span class="upgrade-stat-value">+{rarity_level * 20}% boost</span>
</div>
<div class="upgrade-cost" style="color: #9D4EDD;">Cost: {rarity_cost} {TAG_CURRENCY_NAME}</div>
</div>
""", unsafe_allow_html=True)
# Upgrade button
can_afford = st.session_state.tag_currency >= rarity_cost
button_class = "pulse-button" if can_afford else ""
if st.button(f"Upgrade Rarity", key=f"upgrade_rarity", disabled=not can_afford, use_container_width=True):
if purchase_library_upgrade("rarity"):
st.success(f"Rapacity upgraded to level {rarity_level + 1}!")
st.rerun()
else:
st.error(f"Not enough {TAG_CURRENCY_NAME}. Need {rarity_cost}.")
# Add a styled info box about library growth with dark theme
st.markdown("""
<div style="background-color: rgba(13, 110, 253, 0.15);
border-left: 4px solid #0d6efd;
border-radius: 4px;
padding: 15px;
margin-top: 20px;
color: #ffffff;">
<h4 style="margin-top: 0; color: #6495ED;">π Library Growth</h4>
<p style="margin-bottom: 0;">
Your library will grow as you collect more tags. Each floor of the library unlocks new rarities and
improves your chances of finding rare tags. Continue collecting tags to unlock deeper levels of the library!
</p>
</div>
""", unsafe_allow_html=True)
def initialize_library_system():
"""Initialize the library system state in session state if not already present."""
if 'library_system_initialized' not in st.session_state:
st.session_state.library_system_initialized = True
# Try to load from storage first
library_state = tag_storage.load_library_state(st.session_state)
if library_state:
# We already have the state loaded into session_state by the load function
print("Library system loaded from storage.")
else:
# Initialize with defaults
st.session_state.discovered_tags = {} # {tag_name: {"rarity": str, "discovery_time": timestamp, "category": str}}
st.session_state.library_exploration_history = [] # List of recent library explorations
# Initialize enkephalin if not present
if 'enkephalin' not in st.session_state:
st.session_state.enkephalin = 0
# For the library interface
st.session_state.expedition_results = [] # Results from completed expeditions
# Library growth system
st.session_state.library_growth = {
"total_discoveries": 0,
"last_discovery_time": time.time()
}
# Upgrade system for library
st.session_state.library_upgrades = {
"speed": 1, # Expedition speed (reduces cooldown time)
"capacity": 1, # Tags discovered per expedition
"rarity": 1 # Rare tag chance
}
# Set of explored library tiers
st.session_state.explored_library_tiers = set()
print("Library system initialized with defaults.")
# Store library floors in session state if not already there
if 'library_floors' not in st.session_state:
st.session_state.library_floors = LIBRARY_FLOORS
# Update categories for any "unknown" category tags
update_discovered_tag_categories()
# Add CSS animations for styling
st.markdown("""
<style>
/* Star of the City animation */
@keyframes star-glow {
0% { text-shadow: 0 0 5px #FFD700; }
50% { text-shadow: 0 0 15px #FFD700; }
100% { text-shadow: 0 0 5px #FFD700; }
}
/* Impuritas Civitas animation */
@keyframes rainbow-text {
0% { color: red; }
14% { color: orange; }
28% { color: yellow; }
42% { color: green; }
57% { color: blue; }
71% { color: indigo; }
85% { color: violet; }
100% { color: red; }
}
@keyframes rainbow-border {
0% { border-color: red; }
14% { border-color: orange; }
28% { border-color: yellow; }
42% { border-color: green; }
57% { border-color: blue; }
71% { border-color: indigo; }
85% { border-color: violet; }
100% { border-color: red; }
}
/* Urban Nightmare animation */
@keyframes nightmare-pulse {
0% { border-color: #FF9800; }
50% { border-color: #FF5722; }
100% { border-color: #FF9800; }
}
/* Urban Plague subtle effect */
.glow-purple {
text-shadow: 0 0 3px #9C27B0;
}
/* Apply the animations to specific rarity classes */
.star-of-city {
animation: star-glow 2s infinite;
font-weight: bold;
}
.impuritas-civitas {
animation: rainbow-text 4s linear infinite;
font-weight: bold;
}
.urban-nightmare {
animation: nightmare-pulse 3s infinite;
font-weight: bold;
}
.urban-plague {
text-shadow: 0 0 3px #9C27B0;
font-weight: bold;
}
</style>
""", unsafe_allow_html=True)
def display_library_extraction():
"""Display the library exploration interface."""
initialize_library_system()
st.title(f"Welcome to {LIBRARY_INFO['name']}")
st.markdown(f"""
<div style="background-color: rgba(74, 20, 140, 0.15);
border-radius: 10px;
padding: 15px;
margin-bottom: 20px;
border-left: 5px solid {LIBRARY_INFO['color']};
color: #ffffff;">
<p style="margin: 0;">{LIBRARY_INFO['description']}</p>
</div>
""", unsafe_allow_html=True)
# Create tabs with enhanced styling for dark theme
st.markdown("""
<style>
/* Custom styling for tabs */
.stTabs [data-baseweb="tab-list"] {
gap: 2px;
}
.stTabs [data-baseweb="tab"] {
border-radius: 5px 5px 0 0;
padding: 10px 16px;
font-weight: 600;
}
</style>
""", unsafe_allow_html=True)
# Store current tab index in session state if not present
if 'library_tab_index' not in st.session_state:
st.session_state.library_tab_index = 0
# Create expanded tabs - removed the essence tab
explore_tab, discovered_tab, building_tab = st.tabs([
"π Library Exploration",
"π Discovered Tags",
"ποΈ Library Building"
])
with explore_tab:
st.session_state.library_tab_index = 0
display_library_exploration_interface()
with discovered_tab:
st.session_state.library_tab_index = 1
st.subheader("Your Discovered Tags")
st.write("These are tags you've discovered through the library system. They differ from your collected tags, which are obtained from scanning images.")
# Display discovered tags using our new function
display_discovered_tags()
with building_tab:
st.session_state.library_tab_index = 2
display_library_building()
def display_discovered_tags():
"""Display the user's discovered tags with the same visual style as the tag collection"""
# Show total unique discovered tags
if not hasattr(st.session_state, 'discovered_tags') or not st.session_state.discovered_tags:
st.info("Explore the library to discover new tags!")
return
unique_tags = len(st.session_state.discovered_tags)
st.write(f"You have discovered {unique_tags} unique tags.")
# Count tags by rarity
rarity_counts = {}
for tag_info in st.session_state.discovered_tags.values():
rarity = tag_info.get("rarity", "Unknown")
if rarity not in rarity_counts:
rarity_counts[rarity] = 0
rarity_counts[rarity] += 1
# Only display rarity categories that have tags
active_rarities = {r: c for r, c in rarity_counts.items() if c > 0}
# If there are active rarities to display
if active_rarities:
display_discovered_rarity_distribution(active_rarities)
# Add a sorting option
sort_options = ["Category (rarest first)", "Rarity", "Discovery Time"]
selected_sort = st.selectbox("Sort tags by:", sort_options, key="discovered_tags_sort")
# Group tags by the selected method
if selected_sort == "Category (rarest first)":
# Group tags by category
categories = {}
for tag, info in st.session_state.discovered_tags.items():
category = info.get("category", "unknown")
if category not in categories:
categories[category] = []
categories[category].append((tag, info))
# Display tags by category in expanders
for category, tags in sorted(categories.items()):
# Get rarity order for sorting
rarity_order = list(RARITY_LEVELS.keys())
# Sort tags by rarity (rarest first)
def get_rarity_index(tag_tuple):
tag, info = tag_tuple
rarity = info.get("rarity", "Unknown")
if rarity in rarity_order:
return len(rarity_order) - rarity_order.index(rarity)
return 0
sorted_tags = sorted(tags, key=get_rarity_index, reverse=True)
# Check if category has any rare tags
has_rare_tags = any(info.get("rarity") in ["Impuritas Civitas", "Star of the City"]
for _, info in sorted_tags)
# Get category info if available
category_display = category.capitalize()
if category in TAG_CATEGORIES:
category_info = TAG_CATEGORIES[category]
category_icon = category_info.get("icon", "")
category_color = category_info.get("color", "#888888")
category_display = f"<span style='color:{category_color};'>{category_icon} {category.capitalize()}</span>"
# Create header with information about rare tags if present
header = f"{category_display} ({len(tags)} tags)"
if has_rare_tags:
header += " β¨ Contains rare tags!"
# Display the header and expander
st.markdown(header, unsafe_allow_html=True)
with st.expander("Show/Hide", expanded=has_rare_tags):
# Group by rarity within category
rarity_groups = {}
for tag, info in sorted_tags:
rarity = info.get("rarity", "Unknown")
if rarity not in rarity_groups:
rarity_groups[rarity] = []
rarity_groups[rarity].append((tag, info))
# Display each rarity group in order (rarest first)
for rarity in reversed(rarity_order):
if rarity in rarity_groups:
tags_in_rarity = rarity_groups[rarity]
if tags_in_rarity:
color = RARITY_LEVELS[rarity]["color"]
# Special styling for rare rarities
if rarity == "Impuritas Civitas":
rarity_style = f"animation:rainbow-text 4s linear infinite;font-weight:bold;"
elif rarity == "Star of the City":
rarity_style = f"color:{color};text-shadow:0 0 3px gold;font-weight:bold;"
elif rarity == "Urban Nightmare":
rarity_style = f"color:{color};text-shadow:0 0 1px #FF5722;font-weight:bold;"
else:
rarity_style = f"color:{color};font-weight:bold;"
st.markdown(f"<span style='{rarity_style}'>{rarity.capitalize()}</span> ({len(tags_in_rarity)} tags)", unsafe_allow_html=True)
display_discovered_tag_grid(tags_in_rarity)
st.markdown("---")
elif selected_sort == "Rarity":
# Group tags by rarity level
rarity_groups = {}
for tag, info in st.session_state.discovered_tags.items():
rarity = info.get("rarity", "Unknown")
if rarity not in rarity_groups:
rarity_groups[rarity] = []
rarity_groups[rarity].append((tag, info))
# Get ordered rarities (rarest first)
ordered_rarities = list(RARITY_LEVELS.keys())
ordered_rarities.reverse() # Reverse to show rarest first
# Display tags by rarity
for rarity in ordered_rarities:
if rarity in rarity_groups:
tags = rarity_groups[rarity]
color = RARITY_LEVELS[rarity]["color"]
# Add special styling for rare rarities
rarity_html = f"<span style='color:{color};font-weight:bold;'>{rarity.capitalize()}</span>"
if rarity == "Impuritas Civitas":
rarity_html = f"<span style='animation:rainbow-text 4s linear infinite;font-weight:bold;'>{rarity.capitalize()}</span>"
elif rarity == "Star of the City":
rarity_html = f"<span style='color:{color};text-shadow:0 0 3px gold;font-weight:bold;'>{rarity.capitalize()}</span>"
elif rarity == "Urban Nightmare":
rarity_html = f"<span style='color:{color};text-shadow:0 0 1px #FF5722;font-weight:bold;'>{rarity.capitalize()}</span>"
# First create the title with HTML, then use it in the expander
st.markdown(f"### {rarity_html} ({len(tags)} tags)", unsafe_allow_html=True)
with st.expander("Show/Hide", expanded=rarity in ["Impuritas Civitas", "Star of the City"]):
# Group by category within rarity
category_groups = {}
for tag, info in tags:
category = info.get("category", "unknown")
if category not in category_groups:
category_groups[category] = []
category_groups[category].append((tag, info))
# Display each category within this rarity level
for category, category_tags in sorted(category_groups.items()):
# Get category info if available
category_display = category.capitalize()
if category in TAG_CATEGORIES:
category_info = TAG_CATEGORIES[category]
category_icon = category_info.get("icon", "")
category_color = category_info.get("color", "#888888")
category_display = f"<span style='color:{category_color};'>{category_icon} {category.capitalize()}</span>"
st.markdown(f"#### {category_display} ({len(category_tags)} tags)", unsafe_allow_html=True)
display_discovered_tag_grid(category_tags)
st.markdown("---")
elif selected_sort == "Discovery Time":
# Sort all tags by discovery time (newest first)
sorted_tags = []
for tag, info in st.session_state.discovered_tags.items():
discovery_time = info.get("discovery_time", "")
sorted_tags.append((tag, info, discovery_time))
sorted_tags.sort(key=lambda x: x[2], reverse=True) # Sort by time, newest first
# Group by date
date_groups = {}
for tag, info, time_str in sorted_tags:
# Extract just the date part if timestamp has date and time
date = time_str.split()[0] if " " in time_str else time_str
if date not in date_groups:
date_groups[date] = []
date_groups[date].append((tag, info))
# Display tags grouped by discovery date
for date, tags in date_groups.items():
date_display = date if date else "Unknown date"
st.markdown(f"### Discovered on {date_display} ({len(tags)} tags)")
with st.expander("Show/Hide", expanded=date == list(date_groups.keys())[0]): # Expand most recent by default
display_discovered_tag_grid(tags)
st.markdown("---")
def display_discovered_rarity_distribution(active_rarities):
"""Display distribution of discovered tags by rarity with themed animations"""
# Add the necessary CSS for animations
st.markdown("""
<style>
@keyframes grid-glow {
0% { text-shadow: 0 0 2px gold; }
50% { text-shadow: 0 0 6px gold; }
100% { text-shadow: 0 0 2px gold; }
}
@keyframes grid-rainbow {
0% { color: red; }
14% { color: orange; }
28% { color: yellow; }
42% { color: green; }
57% { color: blue; }
71% { color: indigo; }
85% { color: violet; }
100% { color: red; }
}
@keyframes grid-pulse {
0% { opacity: 0.8; }
50% { opacity: 1; }
100% { opacity: 0.8; }
}
.grid-star {
text-shadow: 0 0 3px gold;
animation: grid-glow 2s infinite;
}
.grid-impuritas {
animation: grid-rainbow 4s linear infinite;
}
.grid-nightmare {
text-shadow: 0 0 1px #FF5722;
animation: grid-pulse 3s infinite;
}
.grid-plague {
text-shadow: 0 0 1px #9C27B0;
}
</style>
""", unsafe_allow_html=True)
rarity_cols = st.columns(len(active_rarities))
for i, (rarity, count) in enumerate(active_rarities.items()):
with rarity_cols[i]:
# Get color with fallback
color = RARITY_LEVELS.get(rarity, {}).get("color", "#888888")
# Apply special styling based on rarity
style = f"color:{color};font-weight:bold;"
class_name = ""
if rarity == "Impuritas Civitas":
class_name = "grid-impuritas"
elif rarity == "Star of the City":
class_name = "grid-star"
elif rarity == "Urban Nightmare":
class_name = "grid-nightmare"
elif rarity == "Urban Plague":
class_name = "grid-plague"
if class_name:
st.markdown(
f"<div style='text-align:center;'><span class='{class_name}' style='font-weight:bold;'>{rarity.capitalize()}</span><br>{count}</div>",
unsafe_allow_html=True
)
else:
st.markdown(
f"<div style='text-align:center;'><span style='{style}'>{rarity.capitalize()}</span><br>{count}</div>",
unsafe_allow_html=True
)
def display_discovered_tag_grid(tags):
"""Display discovered tags in a grid layout with discovery information"""
# Create a grid layout for tags
cols = st.columns(3)
for i, (tag, info) in enumerate(sorted(tags)):
col_idx = i % 3
with cols[col_idx]:
rarity = info.get("rarity", "Unknown")
discovery_time = info.get("discovery_time", "")
library_floor = info.get("library_floor", "")
discovery_count = info.get("discovery_count", 1)
color = RARITY_LEVELS.get(rarity, {}).get("color", "#888888")
# Get sample count if available
sample_count = None
if hasattr(st.session_state, 'tag_rarity_metadata') and st.session_state.tag_rarity_metadata:
if tag in st.session_state.tag_rarity_metadata:
tag_info = st.session_state.tag_rarity_metadata[tag]
if isinstance(tag_info, dict) and "sample_count" in tag_info:
sample_count = tag_info["sample_count"]
# Format sample count
sample_display = ""
if sample_count is not None:
if sample_count >= 1000000:
sample_display = f"<span style='font-size:0.8em;color:#666;'>({sample_count/1000000:.1f}M)</span>"
elif sample_count >= 1000:
sample_display = f"<span style='font-size:0.8em;color:#666;'>({sample_count/1000:.1f}K)</span>"
else:
sample_display = f"<span style='font-size:0.8em;color:#666;'>({sample_count})</span>"
# Apply special styling for rare tags
tag_html = tag
if rarity == "Impuritas Civitas":
tag_html = f"<span style='animation: rainbow-text 4s linear infinite;'>{tag}</span>"
elif rarity == "Star of the City":
tag_html = f"<span style='text-shadow: 0 0 3px gold;'>{tag}</span>"
elif rarity == "Urban Nightmare":
tag_html = f"<span style='text-shadow: 0 0 1px #FF9800;'>{tag}</span>"
# Display tag with rarity badge and discovery info
st.markdown(
f"{tag_html} <span style='background-color:{color};color:white;padding:2px 6px;border-radius:10px;font-size:0.8em;'>{rarity.capitalize()}</span> {sample_display}",
unsafe_allow_html=True
)
# Show discovery details
if library_floor:
st.markdown(f"<span style='font-size:0.85em;'>Found in: {library_floor}</span>", unsafe_allow_html=True)
if discovery_count > 1:
st.markdown(f"<span style='font-size:0.85em;'>Seen {discovery_count} times</span>", unsafe_allow_html=True) |