Skip to content
This repository was archived by the owner on Apr 5, 2022. It is now read-only.

Commit 50098e0

Browse files
Properly map AP items and locations by id
1 parent f042d57 commit 50098e0

File tree

5 files changed

+21
-29
lines changed

5 files changed

+21
-29
lines changed

assets/console.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const appendFormattedConsoleMessage = (messageParts) => {
130130
break;
131131
case 'location_id':
132132
span.style.color = '#5ea2c1';
133-
span.innerText = locationMap[Number(part.text)];
133+
span.innerText = locationsById[Number(part.text)];
134134
break;
135135
default:
136136
span.innerText = part.text;

assets/globals.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const DEFAULT_SERVER_PORT = 38281;
1818
let serverSocket = null;
1919
let serverAuthError = false;
2020

21-
// Local client connection
21+
// Local client connection state
2222
let n64Connected = false;
2323

2424
// Players in the current game, received from Connected server packet
@@ -28,10 +28,8 @@ let players = [];
2828
let hintCost = null;
2929

3030
// Location and item maps, populated from localStorage
31-
let itemsById = {};
32-
33-
// Object matting locationId to locationName
34-
let locationMap = {};
31+
let apItemsById = {};
32+
let apLocationsById = {};
3533

3634
// Data shared between main and renderer processes
3735
let sharedData = {};

assets/n64Interface.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ const isItemReceivable = () => new Promise((resolve) => {
2929

3030
const receiveItem = (itemId) => new Promise((resolve) => {
3131
currentResolve = resolve;
32-
window.oot.receiveItem(parseInt(itemId, 10));
32+
window.oot.receiveItem(romItemsByName[apItemsById[itemId]]);
3333
});
3434

assets/romData.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const items = {
1+
const romItemsByName = {
22
'Bombs (5)': 0x01,
33
'Deku Nuts (5)': 0x02,
44
'Bombchus (10)': 0x03,

assets/serverSocket.js

+15-21
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,12 @@ const connectToServer = async (address) => {
7676
document.getElementById('points-per-check').innerText = command.location_check_points.toString();
7777

7878
// Update the local cache of location and item maps if necessary
79-
if (!localStorage.getItem('dataPackageVersion') || !localStorage.getItem('locationMap') ||
80-
!localStorage.getItem('itemMap') ||
79+
if (!localStorage.getItem('dataPackageVersion') || !localStorage.getItem('dataPackage') ||
8180
command.datapackage_version !== localStorage.getItem('dataPackageVersion')) {
82-
updateLocationCache();
81+
requestDataPackage();
8382
} else {
8483
// Load the location and item maps into memory
85-
buildLocationData(JSON.parse(localStorage.getItem('locationMap')));
86-
itemsById = JSON.parse(localStorage.getItem('itemMap'));
84+
buildItemAndLocationData(JSON.parse(localStorage.getItem('dataPackage')));
8785
}
8886

8987
const romName = await getRomName();
@@ -206,13 +204,9 @@ const connectToServer = async (address) => {
206204
// Save updated location and item maps into localStorage
207205
if (command.data.version !== 0) { // Unless this is a custom package, denoted by version zero
208206
localStorage.setItem('dataPackageVersion', command.data.version);
209-
localStorage.setItem('locationMap', JSON.stringify(command.data.lookup_any_location_id_to_name));
210-
localStorage.setItem('itemMap', JSON.stringify(command.data.lookup_any_item_id_to_name));
207+
localStorage.setItem('dataPackage', JSON.stringify(command.data));
211208
}
212-
213-
buildLocationData(command.data.lookup_any_location_id_to_name);
214-
itemsById = command.data.lookup_any_item_id_to_name;
215-
209+
buildItemAndLocationData(command.data);
216210
break;
217211

218212
default:
@@ -289,7 +283,7 @@ const serverSync = () => {
289283
}
290284
};
291285

292-
const updateLocationCache = () => {
286+
const requestDataPackage = () => {
293287
if (!serverSocket || serverSocket.readyState !== WebSocket.OPEN) { return; }
294288
serverSocket.send(JSON.stringify([{
295289
cmd: 'GetDataPackage',
@@ -304,14 +298,14 @@ const sendLocationChecks = (locationIds) => {
304298
}]));
305299
};
306300

307-
/**
308-
* Build two global objects which are used to reference location data
309-
* @param locations An object of { locationId: locationName, ... }
310-
*/
311-
const buildLocationData = (locations) => {
312-
locationMap = locations;
313-
const locationIds = Object.keys(locations);
314-
const locationNames = Object.values(locations);
315-
301+
const buildItemAndLocationData = (dataPackage) => {
302+
Object.values(dataPackage.games).forEach((game) => {
303+
Object.keys(game.item_name_to_id).forEach((item) => {
304+
apItemsById[game.item_name_to_id[item]] = item;
305+
});
316306

307+
Object.keys(game.location_name_to_id).forEach((location) => {
308+
apLocationsById[game.location_name_to_id[location]] = location;
309+
});
310+
});
317311
};

0 commit comments

Comments
 (0)