Skip to content

Commit

Permalink
#1 Mapped Custom Talk entries to ENPCResidents for additional shop en…
Browse files Browse the repository at this point in the history
…tries.
  • Loading branch information
JamesDonnelly committed Jun 21, 2019
1 parent bc59c1b commit 9a2b3c0
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 53 deletions.
2 changes: 1 addition & 1 deletion data/methods/shops.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/de/barding.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/de/minions.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/de/mounts.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/de/orchestrion.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/en/barding.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/en/minions.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/en/mounts.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/en/orchestrion.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/fr/barding.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/fr/minions.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/fr/mounts.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/fr/orchestrion.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/ja/barding.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/ja/minions.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/ja/mounts.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/ja/orchestrion.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129
148
12 changes: 8 additions & 4 deletions src/APICrawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module.exports = class APICrawler {

const {
columns,
filter
filter,
silent
} = this.config;

// Used to handle API timeouts gracefully.
Expand All @@ -67,7 +68,7 @@ module.exports = class APICrawler {
const limit = pageIn === -1 ? 1 : limitValues[limitValueOffset];
const page = pageIn === -1 ? 1 : (this.recordsProcessed / limit) + 1;

if (pageIn !== -1 && page === 1 && limitValueOffset === 0) {
if (pageIn !== -1 && page === 1 && limitValueOffset === 0 && !silent) {
console.time(log);
console.info(`Starting ${isPaginated ? '' : 'un'}paginated fetch of ${log}.`);
}
Expand Down Expand Up @@ -130,8 +131,11 @@ module.exports = class APICrawler {

// If the resource is not paginated, return the data.
if (!isPaginated || !data.Pagination) {
console.info(`Finished unpaginated fetch of ${log}.`);
console.timeEnd(log);
if (!silent) {
console.info(`Finished unpaginated fetch of ${log}.`);
console.timeEnd(log);
}

return data;
}

Expand Down
14 changes: 5 additions & 9 deletions src/config/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const itemActionTypesQuery = (prefix) => [
];

const customTalkScriptArgs = 30;
const eNPCBaseDataRefs = 32;

const fishingSpotItemIDFields = [
'Item0TargetID',
Expand Down Expand Up @@ -366,6 +367,8 @@ module.exports = {
cacheAs: 'npc-shops',
/**
* For ENPCResidents we need to extract the following fields:
* `Base` - The ENPCBase data's...
* `ENpcData{0...n}` - External references used for mapping to Custom Talk entries;
* `GilShop.*` - An array of gil shops attached to the NPC's...
* `Name_{lang}` - Localised name;
* `ID` - Shop identifier;
Expand All @@ -375,22 +378,15 @@ module.exports = {
* `SpecialShop` - An array of special shops attached to the NPC.
*/
columns: [
...new Array(eNPCBaseDataRefs).fill(1).map((_, index) => `Base.ENpcData${index}`),
...helper.localisedColumnProperty(`GilShop.*.Name`),
'GilShop.*.ID',
'GilShop.*.Items',
'ID',
...helper.localisedColumnProperty(`Name`),
'SpecialShop'
],
/**
* Filter out any data sets which:
* 1. Have no GilShops.
*/
filter: (data) => {
return data.filter(
eNPCResident => eNPCResident.GilShop.length || eNPCResident.SpecialShop.length
);
},
eNPCBaseDataRefs,
isPaginated: true,
log: 'ENPCResidents (for Shops)',
method: 'fetch',
Expand Down
70 changes: 56 additions & 14 deletions src/parsers/customTalk.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const APICrawler = require('../APICrawler');
const fs = require('fs');
const Progress = require('cli-progress');

/**
* Parse custom talk data from XIVAPI.
Expand All @@ -17,6 +18,9 @@ module.exports = async (data) => {
specialShops: []
};

const gilShops = [];
const specialShops = [];

for (const entry of data) {
for (let i = 0; i < customTalkScriptArgs; i++) {
const reference = entry[`ScriptArg${i}`];
Expand All @@ -26,35 +30,73 @@ module.exports = async (data) => {
args: [reference],
isPaginated: false,
log: `Gil Shop #${reference}`,
name: 'gilShop'
name: 'gilShop',
silent: true
});

const data = await crawler.fetch();

// Gil shops.
parsed.gilShops.push({
gilShops.push({
customTalk: entry.ID,
data
reference
});
} else if (reference >= 1760000 && reference < 1770000) {
const crawler = await new APICrawler({
args: [reference],
isPaginated: false,
log: `Special Shop #${reference}`,
name: 'specialShop'
});

const data = await crawler.fetch();

// Special shops.
parsed.specialShops.push({
specialShops.push({
customTalk: entry.ID,
data
reference
});
}
}
};

const progressBar = new Progress.Bar({}, Progress.Presets.shades_grey);
progressBar.start(gilShops.length + specialShops.length, 0);
let parsedCount = 0;

// Parse Gil Shops.
for (const entry of gilShops) {
const crawler = new APICrawler({
args: [entry.reference],
isPaginated: false,
log: `Gil Shop #${entry.reference}`,
name: 'gilShop',
silent: true
});

const data = await crawler.fetch();

parsed.gilShops.push({
customTalk: entry.customTalk,
data
});

progressBar.update(++parsedCount);
}

// Parse Special Shops.
for (const entry of specialShops) {
const crawler = await new APICrawler({
args: [entry.reference],
isPaginated: false,
log: `Special Shop #${entry.reference}`,
name: 'specialShop',
silent: true
});

const data = await crawler.fetch();

parsed.specialShops.push({
customTalk: entry.customTalk,
data
});

progressBar.update(++parsedCount);
}

progressBar.stop();

fs.writeFileSync(
'./data/customTalk.json',
JSON.stringify(parsed),
Expand Down
54 changes: 48 additions & 6 deletions src/parsers/shops.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const currencies = require('../../data/currencies.json');
const customTalk = require('../../data/customTalk.json');
const currencyParser = require('../parsers/currencies');
const items = require('../../data/items.json');

Expand All @@ -11,6 +12,12 @@ module.exports = (
gcScripShopItems
) => {
const config = require('../config/data').shops;

const {
eNPCBaseDataRefs,
specialShopItemIndexes
} = config.eNPCResident;

let currenciesAddedCount = 0;
const parsed = {};

Expand All @@ -21,9 +28,48 @@ module.exports = (

const gil = currencies.find(currency => currency.id === 1);

// Extend data set to include Custom Talk Gil Shops and Special Shops.
eNPCResidents.filter(eNPCResident => {
const {
Base
} = eNPCResident;

if (!Base) {
return;
}

for (let i = 0; i < eNPCBaseDataRefs; i++) {
const v = Base[`ENpcData${i}`];

if (v >= 720000 && v < 730000) {
return true;
}
}
}).forEach(eNPCResident => {
for (let i = 0; i < eNPCBaseDataRefs; i++) {
const v = eNPCResident.Base[`ENpcData${i}`];

if (v >= 720000 && v < 730000) {
// Gil shops.
const customTalkGilShopMatches = customTalk.gilShops.filter(entry => entry.customTalk === v);

for (const customTalkGilShop of customTalkGilShopMatches) {
eNPCResident.GilShop.push(customTalkGilShop.data);
}

// Special shops.
const customTalkSpecialShopMatches = customTalk.specialShops.filter(entry => entry.customTalk === v);

for (const customTalkSpecialShop of customTalkSpecialShopMatches) {
eNPCResident.SpecialShop.push(customTalkSpecialShop.data);
}
}
}
});

// Gil shops...
eNPCResidents.filter(
eNPCResident => eNPCResident.GilShop.length
eNPCResident => Array.isArray(eNPCResident.GilShop) && eNPCResident.GilShop.length
).reduce((arr, eNPCResident) => ([
...arr,
...eNPCResident.GilShop.reduce((arr2, entry) => ([
Expand Down Expand Up @@ -70,13 +116,9 @@ module.exports = (
})
});

const {
specialShopItemIndexes
} = config.eNPCResident;

// Special shops...
eNPCResidents.filter(
eNPCResident => eNPCResident.SpecialShop.length
eNPCResident => Array.isArray(eNPCResident.SpecialShop) && eNPCResident.SpecialShop.length
).reduce((arr, eNPCResident) => ([
...arr,
...eNPCResident.SpecialShop.reduce((arr2, specialShop) => ([
Expand Down
4 changes: 2 additions & 2 deletions src/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ class API {
);

// Custom Talk entries.
const customTalk = await this.crawl(config.customTalk);
await require('./parsers/customTalk')(customTalk);
// const customTalk = await this.crawl(config.customTalk);
// await require('./parsers/customTalk')(customTalk);

// // Shops.
const eNPCResidents = await this.crawl(config.shops.eNPCResident);
Expand Down

0 comments on commit 9a2b3c0

Please sign in to comment.