Skip to content

Commit

Permalink
Merge pull request #179 from DestinyItemManager/enums-2
Browse files Browse the repository at this point in the history
Enums 2
  • Loading branch information
delphiactual committed Sep 12, 2020
2 parents 4dcf0ed + 187dfc9 commit 181124d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
"blackarmory",
"bungie",
"calus",
"caluseum",
"crimsondays",
"crownofsorrow",
"cryptarch",
"datalattice",
"delphiactual",
"dusklight",
"equippable",
"eriana's",
"eververse",
"fotl",
Expand All @@ -36,12 +38,15 @@
"holliday",
"hset",
"ikora",
"intrinsics",
"ironbanner",
"itemhash",
"jalaal",
"jötunn",
"lastwish",
"legendaryengram",
"machinegun",
"masterworked",
"meyrin",
"modslot",
"modslot's",
Expand All @@ -62,9 +67,13 @@
"shaxx",
"shortname",
"sourcehash",
"spawnfx",
"submachinegun",
"submatch",
"superset",
"swordflight",
"transmat",
"unlockable",
"volundr",
"warmind",
"wavesplitter",
Expand Down
46 changes: 46 additions & 0 deletions output/generated-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,49 @@ export const enum SocketCategoryHashes {
WeaponMods = 2685412949,
WeaponPerks = 4241085061,
}

export const enum BucketHashes {
Auras = 1269569095,
BrightDust = 2689798311,
ChestArmor = 14239492,
ClanBanners = 4292445962,
ClassArmor = 1585787867,
Consumables = 1469714392,
Emblems = 4274335291,
Emotes_Equippable = 3054419239,
Emotes_Invisible = 1107761855,
EnergyWeapons = 2465295065,
Engrams = 375726501,
Finishers = 3683254069,
Gauntlets = 3551918588,
General = 138197802,
Ghost = 4023194814,
Glimmer = 2689798308,
Helmet = 3448274439,
KineticWeapons = 1498876634,
LegArmor = 20886954,
LegendaryShards = 2689798309,
LostItems = 215593132,
Materials = 3865314626,
Messages = 3161908920,
Modifications = 3313201758,
PowerWeapons = 953998645,
Quests = 1345459588,
SeasonalArtifact = 1506418338,
Shaders_Equippable = 2973005342,
Shaders_Invisible = 18606351,
Ships = 284967655,
Silver = 2689798310,
SpecialOrders = 1367666825,
StrangeCoin = 2689798305,
Subclass = 3284755031,
UpgradePoint = 2689798304,
Vehicle = 2025709351,
WrappedItems = 3350918817,
}

export const enum BreakerTypeHashes {
Disruption = 2611060930,
ShieldPiercing = 485622768,
Stagger = 3178805705,
}
12 changes: 12 additions & 0 deletions src/flipped-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ const DestinyItemSubType = {
ClassArmor: 30,
Bow: 31,
};
const BucketCategory = {
Invisible: 0,
Item: 1,
Currency: 2,
Equippable: 3,
Ignored: 4,
};

export const DestinySocketCategoryStyleLookup: Record<number, string> = {};
Object.entries(DestinySocketCategoryStyle).forEach(([name, num]) => {
Expand All @@ -83,3 +90,8 @@ export const DestinyItemSubTypeLookup: Record<number, string> = {};
Object.entries(DestinyItemSubType).forEach(([name, num]) => {
DestinyItemSubTypeLookup[num] = name;
});

export const BucketCategoryLookup: Record<number, string> = {};
Object.entries(BucketCategory).forEach(([name, num]) => {
BucketCategoryLookup[num] = name;
});
35 changes: 23 additions & 12 deletions src/generate-enums.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getAll, loadLocal } from 'destiny2-manifest/node';
import {
BucketCategoryLookup,
DestinyItemSubTypeLookup,
DestinyItemTypeLookup,
DestinySocketCategoryStyleLookup,
Expand Down Expand Up @@ -28,11 +29,15 @@ inventoryItems.forEach((item) => {
const allStats = getAll('DestinyStatDefinition');
const allItemCategories = getAll('DestinyItemCategoryDefinition');
const allSocketCategories = getAll('DestinySocketCategoryDefinition');
const allBuckets = getAll('DestinyInventoryBucketDefinition');
const allBreakers = getAll('DestinyBreakerTypeDefinition');

const enumSources = [
{ name: 'StatHashes', data: allStats },
{ name: 'ItemCategoryHashes', data: allItemCategories },
{ name: 'SocketCategoryHashes', data: allSocketCategories },
{ name: 'BucketHashes', data: allBuckets },
{ name: 'BreakerTypeHashes', data: allBreakers },
];
type Data = typeof enumSources[number]['data'][number];

Expand All @@ -57,7 +62,7 @@ enumSources.forEach(({ name, data }) => {
foundNames.add(identifier);
});

// store dupenamed items here for tiebreaking
// store duplicate named items here for tie-breaking
const dupeNamedItems: Data[] = [];

// this loop is to build output enums
Expand All @@ -72,7 +77,7 @@ enumSources.forEach(({ name, data }) => {
return;
}

// process later if it's a preidentified dupe name
// process later if it's a pre-identified dupe name
if (dupeNames.has(identifier)) {
dupeNamedItems.push(thing);
return;
Expand Down Expand Up @@ -132,23 +137,23 @@ function convertMixedStringToLeadingCapCamelCase(input: string) {
// this looks for additional information about an item, to include when its displayProperties.name isn't unique enough
// i've tried to involve enums a bunch so they are unlikely to change
function tryToGetAdditionalStringContent(thing: Data) {
const strs: string[] = [];
const labels: string[] = [];

// for item categories, try using its granted types as labels
const thingAsItemCategory = thing as typeof allItemCategories[number];
if (thingAsItemCategory.grantDestinyItemType !== undefined) {
if (thingAsItemCategory.grantDestinyItemType) {
strs.push(DestinyItemTypeLookup[thingAsItemCategory.grantDestinyItemType]);
labels.push(DestinyItemTypeLookup[thingAsItemCategory.grantDestinyItemType]);
}
if (thingAsItemCategory.grantDestinySubType) {
strs.push(DestinyItemSubTypeLookup[thingAsItemCategory.grantDestinySubType]);
labels.push(DestinyItemSubTypeLookup[thingAsItemCategory.grantDestinySubType]);
}
}
// for socket categories, try using its granted types as labels
const thingAsSocketCategory = thing as typeof allSocketCategories[number];
if (thingAsSocketCategory.categoryStyle !== undefined) {
if (thingAsSocketCategory.categoryStyle) {
strs.push(DestinySocketCategoryStyleLookup[thingAsSocketCategory.categoryStyle]);
labels.push(DestinySocketCategoryStyleLookup[thingAsSocketCategory.categoryStyle]);
}

// or try to go find an example item with this socket type, to show more info about where this socket ends up
Expand All @@ -158,20 +163,26 @@ function tryToGetAdditionalStringContent(thing: Data) {
);
if (!exampleItems.length) {
// no item actually has a socket with this socket category
strs.push('UNUSED');
labels.push('UNUSED');
} else {
const itemTypes = [
...new Set(exampleItems.map((i) => i.itemTypeDisplayName).filter(Boolean)),
];
// only use this label if all found items have the same item type
if (itemTypes.length === 1) {
strs.push(convertMixedStringToLeadingCapCamelCase(itemTypes[0]));
labels.push(convertMixedStringToLeadingCapCamelCase(itemTypes[0]));
}
}
}
if (!strs.length) {
strs.push(`${thing.hash}`);
// for buckets, try using its category as labels
const thingAsBucket = thing as typeof allBuckets[number];
if (thingAsBucket.category !== undefined) {
labels.push(BucketCategoryLookup[thingAsBucket.category]);
}
strs.unshift('');
return strs.join('_');

if (!labels.length) {
labels.push(`${thing.hash}`);
}
labels.unshift('');
return labels.join('_');
}

0 comments on commit 181124d

Please sign in to comment.