Skip to content

Commit

Permalink
Optimise Dungeon Token page loading
Browse files Browse the repository at this point in the history
  • Loading branch information
wormania committed Jan 21, 2024
1 parent ca811e7 commit 999b833
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
11 changes: 9 additions & 2 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -78544,14 +78544,19 @@ const checkExist = setInterval(function() {
}
}, 100);

const highestRouteCache = {};

const highestRoute = (region, weather) => {
const cacheKey = `${region}-${weather}`;
const cachedResult = highestRouteCache[cacheKey];
if (cachedResult) return cachedResult;

region = region;
weather = weather;

var routeArr = [];

Routes.getRoutesByRegion(region).map(route => {
const routes = Routes.getRoutesByRegion(region).map(r => MapHelper.normalizeRoute(r.number, region, false));
var pkmon1 = [];
pkmon1.push(Object.values(route.pokemon).flat());
route.pokemon.special.forEach((element) => {
Expand Down Expand Up @@ -78607,7 +78612,9 @@ const highestRoute = (region, weather) => {
return dt[7] > max[7] ? dt : max;
});

return( [[highestPB[0], highestPBMB[0], highestGB[0], highestGBMB[0], highestUB[0], highestUBMB[0]],routeArr] );
const result = [[highestPB[0], highestPBMB[0], highestGB[0], highestGBMB[0], highestUB[0], highestUBMB[0]], routeArr];
highestRouteCache[cacheKey] = result;
return result;
}

const setWeather = (evt, weather) => {
Expand Down
44 changes: 12 additions & 32 deletions pages/Dungeon Tokens/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ <h4>By Region</h4>
<tbody data-bind="foreach: GameHelper.enumNumbers(GameConstants.Region).filter((r) => r <= GameConstants.MAX_AVAILABLE_REGION && r != GameConstants.Region.none)">
<tr>
<td data-bind="text: GameConstants.camelCaseToString(GameConstants.Region[$data])"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute($data, 0)[0][0]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute($data, 0)[0][1]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute($data, 0)[0][2]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute($data, 0)[0][3]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute($data, 0)[0][4]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute($data, 0)[0][5]"></td>
<!-- ko foreach: Wiki.dungeonTokens.highestRoute($data, 0)[0] -->
<td data-bind="text: $data"></td>
<!-- /ko -->
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -50,12 +47,9 @@ <h4>Galar's Optimal Routes by Weather</h4>
<img width="18" class="me-1" data-bind="attr: { src: `./images/weather/${GameConstants.camelCaseToString(WeatherType[$data])}.png` }" />
<ko data-bind="text: GameConstants.camelCaseToString(WeatherType[$data])"></ko>
</td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute(7, $data)[0][0]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute(7, $data)[0][1]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute(7, $data)[0][2]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute(7, $data)[0][3]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute(7, $data)[0][4]"></td>
<td data-bind="html: Wiki.dungeonTokens.highestRoute(7, $data)[0][5]"></td>
<!-- ko foreach: Wiki.dungeonTokens.highestRoute(7, $data)[0] -->
<td data-bind="text: $data"></td>
<!-- /ko -->
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -83,16 +77,9 @@ <h4><a data-bind="text: GameConstants.camelCaseToString(GameConstants.Region[$da
</tr>
</thead>
<tbody data-bind="foreach: Wiki.dungeonTokens.highestRoute($data, 0)[1]">
<tr>
<td data-bind="text: $data[0]"></td>
<td data-bind="text: $data[1]"></td>
<td data-bind="text: $data[2]"></td>
<td data-bind="text: $data[3]"></td>
<td data-bind="text: $data[4]"></td>
<td data-bind="text: $data[5]"></td>
<td data-bind="text: $data[6]"></td>
<td data-bind="text: $data[7]"></td>
</tr>
<tr data-bind="foreach: $data">
<td data-bind="text: $data"></td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -120,16 +107,9 @@ <h4><a data-bind="text: GameConstants.camelCaseToString(GameConstants.Region[$da
</tr>
</thead>
<tbody id="weatherTable" data-bind="foreach: Wiki.dungeonTokens.highestRoute($parent, $data)[1]">
<tr>
<td data-bind="text: $data[0]"></td>
<td data-bind="text: $data[1]"></td>
<td data-bind="text: $data[2]"></td>
<td data-bind="text: $data[3]"></td>
<td data-bind="text: $data[4]"></td>
<td data-bind="text: $data[5]"></td>
<td data-bind="text: $data[6]"></td>
<td data-bind="text: $data[7]"></td>
</tr>
<tr data-bind="foreach: $data">
<td data-bind="text: $data"></td>
</tr>
</tbody>
</table>
</div>
Expand Down
11 changes: 9 additions & 2 deletions scripts/pages/dungeonTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ const checkExist = setInterval(function() {
}
}, 100);

const highestRouteCache = {};

const highestRoute = (region, weather) => {
const cacheKey = `${region}-${weather}`;
const cachedResult = highestRouteCache[cacheKey];
if (cachedResult) return cachedResult;

region = region;
weather = weather;

var routeArr = [];

Routes.getRoutesByRegion(region).map(route => {
const routes = Routes.getRoutesByRegion(region).map(r => MapHelper.normalizeRoute(r.number, region, false));
var pkmon1 = [];
pkmon1.push(Object.values(route.pokemon).flat());
route.pokemon.special.forEach((element) => {
Expand Down Expand Up @@ -68,7 +73,9 @@ const highestRoute = (region, weather) => {
return dt[7] > max[7] ? dt : max;
});

return( [[highestPB[0], highestPBMB[0], highestGB[0], highestGBMB[0], highestUB[0], highestUBMB[0]],routeArr] );
const result = [[highestPB[0], highestPBMB[0], highestGB[0], highestGBMB[0], highestUB[0], highestUBMB[0]], routeArr];
highestRouteCache[cacheKey] = result;
return result;
}

const setWeather = (evt, weather) => {
Expand Down

0 comments on commit 999b833

Please sign in to comment.