Skip to content

Commit

Permalink
Expose webpack ids to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Sep 15, 2024
1 parent 036ba39 commit a2a3f9a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
40 changes: 40 additions & 0 deletions css_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,46 @@ def __get_target_steam_version(data : dict) -> str|None:

return target_steam_version

def generate_webpack_id_name_list_from_local_file() -> dict[str, dict]:
name_list = {}
path = os.path.join(get_theme_path(), "css_translations.json")

try:
with open(path, 'r', encoding="utf-8") as fp:
data = json.load(fp)
except Exception as e:
Log(f"Error while loading translations: {str(e)}.")
return name_list

target_steam_version = __get_target_steam_version(data)
same_branch_versions = __get_same_branch_versions(data)
if target_steam_version == None:
return name_list

for _, (module_id, module_data) in enumerate(data['module_mappings'].items()):
if target_steam_version in module_data['ids']:
new_module_id = module_data['ids'][target_steam_version]
else:
prev = "9999999999999"
new_module_id = None
for _, (steam_version, module_id_of_steam_version) in list(enumerate(module_data['ids'].items()))[::-1]:
if target_steam_version not in same_branch_versions:
continue

if int(prev) > int(target_steam_version) and int(steam_version) < int(target_steam_version):
new_module_id = module_id_of_steam_version
break

prev = steam_version

if new_module_id == None:
# Assuming module doesn't exist in this steam version
continue

name_list[new_module_id] = {"name": str(module_id) if module_data['name'] is None else module_data['name'], "ignore": module_data['ignore_webpack_keys']}

return name_list

def generate_translations_from_local_file() -> dict[str, str]:
translations = {}
timer = time.time()
Expand Down
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from css_server import start_server
from css_browserhook import initialize
from css_loader import Loader
from css_mappings import force_fetch_translations, start_fetch_translations, load_global_translations
from css_mappings import force_fetch_translations, start_fetch_translations, load_global_translations, generate_webpack_id_name_list_from_local_file


ALWAYS_RUN_SERVER = False
Expand Down Expand Up @@ -138,6 +138,9 @@ async def store_write(self, key : str, val : str) -> dict:
async def save_mappings(self, val: str, version: str) -> dict:
util_save_mappings(val, version)
return Result(True).to_dict()

async def get_webpack_mappigns(self) -> dict:
return generate_webpack_id_name_list_from_local_file()

async def exit(self):
try:
Expand Down

0 comments on commit a2a3f9a

Please sign in to comment.