1
0
mirror of synced 2025-02-13 00:44:33 +01:00

reduced db access with new chuni webui customizations

This commit is contained in:
daydensteve 2024-11-07 20:28:28 -05:00
parent 3a44b18d91
commit 954bd565d3

View File

@ -3,6 +3,7 @@ from starlette.routing import Route, Mount
from starlette.requests import Request
from starlette.responses import Response, RedirectResponse
from starlette.staticfiles import StaticFiles
from sqlalchemy.engine import Row
from os import path
import yaml
import jinja2
@ -134,13 +135,8 @@ class ChuniFrontend(FE_Base):
# While map icons and system voices weren't present prior to AMAZON, we don't need to bother checking
# version here - it'll just end up being empty sets and the jinja will ignore the variables anyway.
user_map_icons = await self.data.item.get_items(user_id, ItemKind.MAP_ICON.value)
user_map_icons = [icon["itemId"] for icon in user_map_icons] + [profile.mapIconId]
user_system_voices = await self.data.item.get_items(user_id, ItemKind.SYSTEM_VOICE.value)
user_system_voices = [icon["itemId"] for icon in user_system_voices] + [profile.voiceId]
map_icons, total_map_icons = await self.get_available_map_icons(version, user_map_icons)
system_voices, total_system_voices = await self.get_available_system_voices(version, user_system_voices)
map_icons, total_map_icons = await self.get_available_map_icons(version, profile)
system_voices, total_system_voices = await self.get_available_system_voices(version, profile)
resp = Response(template.render(
title=f"{self.core_config.server.name} | {self.nav_name}",
@ -354,15 +350,19 @@ class ChuniFrontend(FE_Base):
else:
return RedirectResponse("/gate/", 303)
async def get_available_map_icons(self, version: int, user_unlocked_items: List[int]) -> (List[dict], int):
async def get_available_map_icons(self, version: int, profile: Row) -> (List[dict], int):
items = dict()
rows = await self.data.static.get_map_icons(version)
if rows:
force_unlocked = self.game_cfg.mods.forced_item_unlocks("map_icons")
user_map_icons = []
if not force_unlocked:
user_map_icons = await self.data.item.get_items(profile.user, ItemKind.MAP_ICON.value)
user_map_icons = [icon["itemId"] for icon in user_map_icons] + [profile.mapIconId]
for row in rows:
# Only include items that are either available by default or in the user unlocked list
if row["defaultHave"] or \
row["mapIconId"] in user_unlocked_items or \
self.game_cfg.mods.forced_item_unlocks("map_icons"):
if force_unlocked or row["defaultHave"] or row["mapIconId"] in user_map_icons:
item = dict()
item["id"] = row["mapIconId"]
item["name"] = row["name"]
@ -371,15 +371,19 @@ class ChuniFrontend(FE_Base):
return (items, len(rows))
async def get_available_system_voices(self, version: int, user_unlocked_items: List[int]) -> (List[dict], int):
async def get_available_system_voices(self, version: int, profile: Row) -> (List[dict], int):
items = dict()
rows = await self.data.static.get_system_voices(version)
if rows:
force_unlocked = self.game_cfg.mods.forced_item_unlocks("system_voices")
user_system_voices = []
if not force_unlocked:
user_system_voices = await self.data.item.get_items(profile.user, ItemKind.SYSTEM_VOICE.value)
user_system_voices = [icon["itemId"] for icon in user_system_voices] + [profile.voiceId]
for row in rows:
# Only include items that are either available by default or in the user unlocked list
if row["defaultHave"] or \
row["voiceId"] in user_unlocked_items or \
self.game_cfg.mods.forced_item_unlocks("system_voices"):
if force_unlocked or row["defaultHave"] or row["voiceId"] in user_system_voices:
item = dict()
item["id"] = row["voiceId"]
item["name"] = row["name"]
@ -388,15 +392,19 @@ class ChuniFrontend(FE_Base):
return (items, len(rows))
async def get_available_nameplates(self, version: int, user_unlocked_items: List[int]) -> (List[dict], int):
async def get_available_nameplates(self, version: int, profile: Row) -> (List[dict], int):
items = dict()
rows = await self.data.static.get_nameplates(version)
if rows:
force_unlocked = self.game_cfg.mods.forced_item_unlocks("nameplates")
user_nameplates = []
if not force_unlocked:
user_nameplates = await self.data.item.get_items(profile.user, ItemKind.NAMEPLATE.value)
user_nameplates = [item["itemId"] for item in user_nameplates] + [profile.nameplateId]
for row in rows:
# Only include items that are either available by default or in the user unlocked list
if row["defaultHave"] or \
row["nameplateId"] in user_unlocked_items or \
self.game_cfg.mods.forced_item_unlocks("nameplates"):
if force_unlocked or row["defaultHave"] or row["nameplateId"] in user_nameplates:
item = dict()
item["id"] = row["nameplateId"]
item["name"] = row["name"]
@ -405,15 +413,19 @@ class ChuniFrontend(FE_Base):
return (items, len(rows))
async def get_available_trophies(self, version: int, user_unlocked_items: List[int]) -> (List[dict], int):
async def get_available_trophies(self, version: int, profile: Row) -> (List[dict], int):
items = dict()
rows = await self.data.static.get_trophies(version)
if rows:
force_unlocked = self.game_cfg.mods.forced_item_unlocks("trophies")
user_trophies = []
if not force_unlocked:
user_trophies = await self.data.item.get_items(profile.user, ItemKind.TROPHY.value)
user_trophies = [item["itemId"] for item in user_trophies] + [profile.trophyId]
for row in rows:
# Only include items that are either available by default or in the user unlocked list
if row["defaultHave"] or \
row["trophyId"] in user_unlocked_items or \
self.game_cfg.mods.forced_item_unlocks("trophies"):
if force_unlocked or row["defaultHave"] or row["trophyId"] in user_trophies:
item = dict()
item["id"] = row["trophyId"]
item["name"] = row["name"]
@ -422,15 +434,19 @@ class ChuniFrontend(FE_Base):
return (items, len(rows))
async def get_available_characters(self, version: int, user_unlocked_items: List[int]) -> (List[dict], int):
async def get_available_characters(self, version: int, profile: Row) -> (List[dict], int):
items = dict()
rows = await self.data.static.get_characters(version)
if rows:
force_unlocked = self.game_cfg.mods.forced_item_unlocks("character_icons")
user_characters = []
if not force_unlocked:
user_characters = await self.data.item.get_characters(profile.user)
user_characters = [chara["characterId"] for chara in user_characters] + [profile.characterId, profile.charaIllustId]
for row in rows:
# Only include items that are either available by default or in the user unlocked list
if row["defaultHave"] or \
row["characterId"] in user_unlocked_items or \
self.game_cfg.mods.forced_item_unlocks("character_icons"):
if force_unlocked or row["defaultHave"] or row["characterId"] in user_characters:
item = dict()
item["id"] = row["characterId"]
item["name"] = row["name"]
@ -443,11 +459,10 @@ class ChuniFrontend(FE_Base):
items = dict()
rows = await self.data.static.get_avatar_items(version, category.value)
if rows:
force_unlocked = self.game_cfg.mods.forced_item_unlocks("avatar_accessories")
for row in rows:
# Only include items that are either available by default or in the user unlocked list
if row["defaultHave"] or \
row["avatarAccessoryId"] in user_unlocked_items or \
self.game_cfg.mods.forced_item_unlocks("avatar_accessories"):
if force_unlocked or row["defaultHave"] or row["avatarAccessoryId"] in user_unlocked_items:
item = dict()
item["id"] = row["avatarAccessoryId"]
item["name"] = row["name"]
@ -474,18 +489,11 @@ class ChuniFrontend(FE_Base):
# Get the user profile so we know how the userbox is currently configured
profile = await self.data.profile.get_profile_data(user_id, version)
# Get all the user unlocked components so we know what to populate as options
user_nameplates = await self.data.item.get_items(user_id, ItemKind.NAMEPLATE.value)
user_nameplates = [item["itemId"] for item in user_nameplates] + [profile.nameplateId]
user_trophies = await self.data.item.get_items(user_id, ItemKind.TROPHY.value)
user_trophies = [item["itemId"] for item in user_trophies] + [profile.trophyId]
user_characters = await self.data.item.get_characters(user_id)
user_characters = [chara["characterId"] for chara in user_characters] + [profile.charaIllustId]
# Build up available list of components
nameplates, total_nameplates = await self.get_available_nameplates(version, user_nameplates)
trophies, total_trophies = await self.get_available_trophies(version, user_trophies)
characters, total_characters = await self.get_available_characters(version, user_characters)
# Build up lists of available userbox components
nameplates, total_nameplates = await self.get_available_nameplates(version, profile)
trophies, total_trophies = await self.get_available_trophies(version, profile)
characters, total_characters = await self.get_available_characters(version, profile)
# Get the user's team
team_name = "ARTEMiS"