Skip to content

Commit

Permalink
Merge pull request #238 from the-hideout/more-location-info
Browse files Browse the repository at this point in the history
add location information for lots of things
  • Loading branch information
Razzmatazzz authored Oct 30, 2023
2 parents 1424b9a + 3ec82b0 commit 372555f
Show file tree
Hide file tree
Showing 12 changed files with 1,494 additions and 1,792 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist/
.env
.vscode/
tmp/
kv/
42 changes: 42 additions & 0 deletions datasources/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,48 @@ class MapAPI extends WorkerKV {
return false;
});
}

async getLootContainer(context, id) {
await this.init(context);
return this.cache.LootContainer[id];
}

async getAllLootContainers(context) {
await this.init(context);
return Object.values(this.cache.LootContainer);
}

async getExtract(context, id) {
await this.init(context);
return this.cache.Map.reduce((found, current) => {
if (found) {
return found;
}
found = current.extracts.find(e => e.id === id);
return found;
}, false);
}

async getSwitch(context, id) {
await this.init(context);
return this.cache.Map.reduce((found, current) => {
if (found) {
return found;
}
found = current.switches.find(e => e.id === id);
return found;
}, false);
}

async getStationaryWeapon(context, id) {
await this.init(context);
return this.cache.StationaryWeapon[id];
}

async getAllStationaryWeapons(context) {
await this.init(context);
return Object.values(this.cache.StationaryWeapon);
}
}

module.exports = MapAPI;
16 changes: 8 additions & 8 deletions datasources/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ class SchemaAPI extends WorkerKV {
super('schema_data', dataSource);
}

async getCategories(requestId) {
await this.init(requestId);
async getCategories(context) {
await this.init(context);
if (!this.cache) {
return Promise.reject(new Error('Schema cache is empty'));
}
return this.cache.ItemCategory;
}

async getHandbookCategories(requestId) {
await this.init(requestId);
async getHandbookCategories(context) {
await this.init(context);
if (!this.cache) {
return Promise.reject(new Error('Schema cache is empty'));
}
return this.cache.HandbookCategory;
}

async getItemTypes(requestId) {
await this.init(requestId);
async getItemTypes(context) {
await this.init(context);
if (!this.cache) {
return Promise.reject(new Error('Schema cache is empty'));
}
return this.cache.ItemType;
}

async getLanguageCodes(requestId) {
await this.init(requestId);
async getLanguageCodes(context) {
await this.init(context);
if (!this.cache) {
return Promise.reject(new Error('Schema cache is empty'));
}
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const schemaRefreshInterval = 1000 * 60 * 10;
const skipCache = false; //ENVIRONMENT !== 'production' || false;

// Example of how router can be used in an application
async function getSchema(data, requestId) {
async function getSchema(data, context) {
if (schema && new Date() - lastSchemaRefresh < schemaRefreshInterval) {
return schema;
}
Expand All @@ -46,13 +46,13 @@ async function getSchema(data, requestId) {
console.log(`Schema loading timed out; forcing load`);
clearInterval(loadingInterval);
loadingSchema = false;
return resolve(getSchema(data, requestId));
return resolve(getSchema(data, context));
}
}, 100);
});
}
loadingSchema = true;
return dynamicTypeDefs(data, requestId).catch(error => {
return dynamicTypeDefs(data, context).catch(error => {
loadingSchema = false;
console.error('Error loading dynamic type definitions', error);
return Promise.reject(error);
Expand Down Expand Up @@ -162,7 +162,7 @@ async function graphqlHandler(event, graphQLOptions) {
}

const context = { data: dataAPI, util: graphqlUtil, requestId, lang: {}, warnings: [], errors: [] };
let result = await graphql(await getSchema(dataAPI, requestId), query, {}, context, variables);
let result = await graphql(await getSchema(dataAPI, context), query, {}, context, variables);
if (context.errors.length > 0) {
if (!result.errors) {
result = Object.assign({errors: []}, result); // this puts the errors at the start of the result
Expand Down
Loading

0 comments on commit 372555f

Please sign in to comment.