Skip to content

Commit

Permalink
General minor optimizations
Browse files Browse the repository at this point in the history
- Batch DOM reads and writes in hot paths
- Use in-syntax, replaceAll where possible
- Load badge images in badge listing on demand
- Create player nametag tooltips on demand and per player
  • Loading branch information
Desdaemon committed Nov 24, 2024
1 parent 80184f7 commit c208bb4
Show file tree
Hide file tree
Showing 19 changed files with 928 additions and 412 deletions.
22 changes: 8 additions & 14 deletions 2kki.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@ function queryAndSet2kkiLocation(mapId, prevMapId, prevLocations, setLocationFun
}

function set2kkiClientLocation(mapId, prevMapId, locations, prevLocations, cacheLocation, saveLocation) {
document.getElementById('locationText').innerHTML = getLocalized2kkiLocationsHtml(locations, '<br>');
document.documentElement.style.setProperty('--location-width', `${document.querySelector('#locationText > *').offsetWidth}px`);
const localizedLocationsHtml = getLocalized2kkiLocationsHtml(locations, '<br>');
fastdom.mutate(() => document.getElementById('locationText').innerHTML = localizedLocationsHtml);

fastdom.measure(() => {
const width = `${document.querySelector('#locationText > *').offsetWidth}px`;
fastdom.mutate(() => document.getElementById('nextLocationContainer').style.setProperty('--location-width', width));
});

onUpdateChatboxInfo();
preloadFilesFromMapId(mapId);
if (cacheLocation) {
Expand Down Expand Up @@ -545,18 +551,6 @@ function getDepthRgba(depth, maxDepth) {
return depthColors[Math.min(depth, maxDepth)];
}

function init2kkiFileVersionAppend() {
if (!gameVersion)
return;
const ca = wasmImports.ca;
wasmImports.ca = function (url, file, request, param, arg, onload, onerror, onprogress) {
let _url = UTF8ToString(url);
if (_url)
url = stringToNewUTF8(`${_url}${_url.indexOf('?') > -1 ? '&' : '?'}v=${gameVersion}`);
ca(url, file, request, param, arg, onload, onerror, onprogress);
};
}

function checkShow2kkiVersionUpdate() {
return new Promise(resolve => {
const chatboxContainer = document.getElementById('chatboxContainer');
Expand Down
Loading

0 comments on commit c208bb4

Please sign in to comment.