Skip to content

Commit

Permalink
Merge pull request #2984 from zku/glyph-export-addon
Browse files Browse the repository at this point in the history
Addon Glyph Export: Do not rely on localized names
  • Loading branch information
zku authored Apr 21, 2023
2 parents 6d8eb7b + b34c911 commit 9512d30
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
30 changes: 8 additions & 22 deletions tools/wowsimsexporter/WowSimsExporter/WowSimsExporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,18 @@ end
function WowSimsExporter:CreateGlyphEntry()
local minor = {}
local major = {}

for t = 1, 6 do

local enabled, glyphType, glyphTooltipIndex, glyphSpellID, icon = GetGlyphSocketInfo(t);
local link = GetGlyphLink(t);

if(enabled) then

local name, _ = string.match(link,"Glyph of .+]")
if(name) then
local formattedName = name:gsub('%]', '')

if(glyphType == 1 ) then-- major
table.insert(major, formattedName)
else if(glyphType == 2 ) then -- minor
table.insert(minor, formattedName)
end
for t = 1, 6 do
local enabled, glyphType, glyphSpellID = GetGlyphSocketInfo(t)
if enabled and glyphSpellID then
local localizedName = GetSpellInfo(glyphSpellID)
if localizedName then
local t = glyphType == 1 and major or minor
table.insert(t, {["name"] = localizedName, ["spellID"] = glyphSpellID})
end

end
self.Character.glyphs.major = major
self.Character.glyphs.minor = minor

end

end
end
end

function WowSimsExporter:CreateProfessionEntry()
Expand Down
20 changes: 16 additions & 4 deletions ui/core/components/importers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { classGlyphsConfig, talentSpellIdsToTalentString } from '../talents/fact
import { GlyphConfig } from '../talents/glyphs_picker';
import { BaseModal } from './base_modal';
import { buf2hex } from '../utils';
import { JsonObject } from '@protobuf-ts/runtime';

export abstract class Importer extends BaseModal {
protected readonly textElem: HTMLTextAreaElement;
Expand Down Expand Up @@ -409,7 +410,7 @@ export class IndividualAddonImporter<SpecType extends Spec> extends Importer {
`;
}

onImport(data: string) {
async onImport(data: string) {
const importJson = JSON.parse(data);

// Parse all the settings.
Expand All @@ -431,10 +432,12 @@ export class IndividualAddonImporter<SpecType extends Spec> extends Importer {
});

const talentsStr = (importJson['talents'] as string) || '';

const glyphsConfig = classGlyphsConfig[charClass];
const majorGlyphIDs = (importJson['glyphs']['major'] as Array<string>).map(glyphName => glyphNameToID(glyphName, glyphsConfig.majorGlyphs));
const minorGlyphIDs = (importJson['glyphs']['minor'] as Array<string>).map(glyphName => glyphNameToID(glyphName, glyphsConfig.minorGlyphs));

const db = await Database.get();
const majorGlyphIDs = (importJson['glyphs']['major'] as Array<string|JsonObject>).map(g => glyphToID(g, db, glyphsConfig.majorGlyphs));
const minorGlyphIDs = (importJson['glyphs']['minor'] as Array<string|JsonObject>).map(g => glyphToID(g, db, glyphsConfig.minorGlyphs));

const glyphs = Glyphs.create({
major1: majorGlyphIDs[0] || 0,
major2: majorGlyphIDs[1] || 0,
Expand Down Expand Up @@ -469,3 +472,12 @@ function glyphNameToID(glyphName: string, glyphsConfig: Record<number, GlyphConf
}
throw new Error(`Unknown glyph name '${glyphName}'`);
}

function glyphToID(glyph: string|JsonObject, db: Database, glyphsConfig: Record<number, GlyphConfig>): number {
if (typeof glyph === 'string') {
// Legacy version: AddOn exports Glyphs by name (string) only. Names must be in English.
return glyphNameToID(glyph, glyphsConfig);
}
// New version exports glyph information in a table that includes the name and the glyph spell ID.
return db.glyphSpellToItemId(glyph['spellID'] as number);
}

0 comments on commit 9512d30

Please sign in to comment.