Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split info into handbook kv #354

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions datasources/handbook.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import WorkerKV from '../utils/worker-kv.mjs';

class HandbookAPI extends WorkerKV {
constructor(dataSource) {
super('handbook_data', dataSource);
//this.gameModes.push('pve');
}

async getCategory(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.ItemCategory[id] || cache.HandbookCategory[id];
}

async getTopCategory(context, info, id) {
const cat = await this.getCategory(context, info, id);
if (cat && cat.parent_id) return this.getTopCategory(context, info, cat.parent_id);
return cat;
}

async getCategories(context, info) {
const { cache } = await this.getCache(context, info);
if (!cache) {
return Promise.reject(new Error('Item cache is empty'));
}
const categories = [];
for (const id in cache.ItemCategory) {
categories.push(cache.ItemCategory[id]);
}
return categories;
}

async getCategoriesEnum(context, info) {
const cats = await this.getCategories(context, info);
const map = {};
for (const id in cats) {
map[cats[id].enumName] = cats[id];
}
return map;
}

async getHandbookCategory(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.HandbookCategory[id];
}

async getHandbookCategories(context, info) {
const { cache } = await this.getCache(context, info);
if (!cache) {
return Promise.reject(new Error('Item cache is empty'));
}
return Object.values(cache.HandbookCategory);
}

async getArmorMaterials(context, info) {
const { cache } = await this.getCache(context, info);
return Object.values(cache.ArmorMaterial).sort();
}

async getArmorMaterial(context, info, matKey) {
const { cache } = await this.getCache(context, info);
return cache.ArmorMaterial[matKey];
}

async getMasterings(context, info) {
const { cache } = await this.getCache(context, info);
return cache.Mastering;
}

async getMastering(context, info, mastId) {
const { cache } = await this.getCache(context, info);
return cache.Mastering.find(m => m.id === mastId);
}

async getSkills(context, info) {
const { cache } = await this.getCache(context, info);
return cache.Skill;
}

async getSkill(context, info, skillId) {
const { cache } = await this.getCache(context, info);
return cache.Skill.find(s => s.id === skillId);
}

async getPlayerLevels(context, info) {
const { cache } = await this.getCache(context, info);
return cache.PlayerLevel;
}

async getAllItemProperties(context, info) {
const { cache } = await this.getCache(context, info);
return cache.ItemProperties;
}

async getItemProperties(context, info, itemId) {
const { cache } = await this.getCache(context, info);
return cache.ItemProperties[itemId];
}
}

export default HandbookAPI;
2 changes: 2 additions & 0 deletions datasources/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BartersAPI from './barters.mjs';
import CraftsAPI from './crafts.mjs';
import HandbookAPI from './handbook.mjs';
import HideoutAPI from './hideout.mjs';
import HistoricalPricesAPI from './historical-prices.mjs';
import ArchivedPricesAPI from './archived-prices.mjs';
Expand All @@ -23,6 +24,7 @@ class DataSource {
this.worker = {
barter: new BartersAPI(this),
craft: new CraftsAPI(this),
handbook: new HandbookAPI(this),
hideout: new HideoutAPI(this),
historicalPrice: new HistoricalPricesAPI(this),
archivedPrice: new ArchivedPricesAPI(this),
Expand Down
92 changes: 4 additions & 88 deletions datasources/items.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ItemsAPI extends WorkerKV {
if (!items) {
items = Object.values(cache.Item);
}
const categories = (await this.getCategories(context, info)).filter(cat => names.includes(cat.enumName));
const categories = (await context.data.worker.handbook.getCategories(context, info)).filter(cat => names.includes(cat.enumName));
return items.filter((item) => {
return item.categories.some(catId => categories.some(cat => cat.id === catId));
});
Expand All @@ -181,7 +181,7 @@ class ItemsAPI extends WorkerKV {
if (!items) {
items = Object.values(cache.Item);
}
const categories = (await this.getHandbookCategories(context, info)).filter(cat => names.includes(cat.enumName));
const categories = (await context.data.worker.handbook.getHandbookCategories(context, info)).filter(cat => names.includes(cat.enumName));
return items.filter((item) => {
return item.handbookCategories.some(catId => categories.some(cat => cat.id === catId));
});
Expand Down Expand Up @@ -216,108 +216,24 @@ class ItemsAPI extends WorkerKV {
});
}

async getCategory(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.ItemCategory[id] || cache.HandbookCategory[id];
}

async getTopCategory(context, info, id) {
const cat = await this.getCategory(context, info, id);
if (cat && cat.parent_id) return this.getTopCategory(context, info, cat.parent_id);
return cat;
}

async getCategories(context, info) {
const { cache } = await this.getCache(context, info);
if (!cache) {
return Promise.reject(new Error('Item cache is empty'));
}
const categories = [];
for (const id in cache.ItemCategory) {
categories.push(cache.ItemCategory[id]);
}
return categories;
}

async getCategoriesEnum(context, info) {
const cats = await this.getCategories(context, info);
const map = {};
for (const id in cats) {
map[cats[id].enumName] = cats[id];
}
return map;
}

async getHandbookCategory(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.HandbookCategory[id];
}

async getHandbookCategories(context, info) {
const { cache } = await this.getCache(context, info);
if (!cache) {
return Promise.reject(new Error('Item cache is empty'));
}
return Object.values(cache.HandbookCategory);
}

async getFleaMarket(context, info) {
const { cache } = await this.getCache(context, info);
return cache.FleaMarket;
}

async getArmorMaterials(context, info) {
const { cache } = await this.getCache(context, info);
return Object.values(cache.ArmorMaterial).sort();
}

async getArmorMaterial(context, info, matKey) {
const { cache } = await this.getCache(context, info);
return cache.ArmorMaterial[matKey];
}

async getMasterings(context, info) {
const { cache } = await this.getCache(context, info);
return cache.Mastering;
}

async getMastering(context, info, mastId) {
const { cache } = await this.getCache(context, info);
return cache.Mastering.find(m => m.id === mastId);
}

async getSkills(context, info) {
const { cache } = await this.getCache(context, info);
return cache.Skill;
}

async getSkill(context, info, skillId) {
const { cache } = await this.getCache(context, info);
return cache.Skill.find(s => s.id === skillId);
}

async getAmmoList(context, info) {
const allAmmo = await this.getItemsByBsgCategoryId(context, info, '5485a8684bdc2da71d8b4567').then(ammoItems => {
// ignore bb
return ammoItems.filter(item => item.id !== '6241c316234b593b5676b637');
});
const itemProperties = await context.data.worker.handbook.getAllItemProperties(context, info);
return allAmmo.map(item => {
return {
...item,
...item.properties
...itemProperties[item.id],
};
});
}

async getPlayerLevels(context, info) {
const { cache } = await this.getCache(context, info);
return cache.PlayerLevel;
}

async getTypes(context, info) {
const { cache } = await this.getCache(context, info);
return cache.ItemType;
}
}

export default ItemsAPI;
2 changes: 1 addition & 1 deletion resolvers/hideoutResolver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
return context.data.worker.hideout.getLocale(data.name, context, info);
},
skill(data, args, context, info) {
return context.data.worker.item.getSkill(context, info, data.name);
return context.data.worker.handbook.getSkill(context, info, data.name);
},
},
HideoutModule: {
Expand Down
Loading
Loading