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

Fix broken BG abilities in Russian #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

piedpiper358
Copy link
Contributor

Is there any point in manually changing the text of broken BG abilities (or, for example, untranslated mercs bounty names) or will it be overwritten the next time you upload data from the Heartstone client?

@sebastientromp
Copy link
Contributor

It will be overwritten

@piedpiper358
Copy link
Contributor Author

If you look at the broken abilities, you can see that the collectionText field is a continuation of the text field. Perhaps the error is in the data scraper.
If this can't be fixed, then I suggest don't display the Hero Power text, but instead enlarge the Hero Power card.

@sebastientromp
Copy link
Contributor

Yes, the data scraper needs to be improved. It is currently in a private repo (because there are other things in there that contain some sensitive information), and the bits that parse the collectionText field are thus:

// See GameStrings.ParseLanguageRules in decompiled DLL
const cleanCardDescription = (record: any, localeId: number): [string, string] => {
	const localizedValue: string = getLocValue(record, 'm_textInHand', localeId);
	if (!localizedValue) {
		return [null, null];
	}

	let text = localizedValue.replace(/_/g, ' ');
	const count = text.match(/@/g)?.length ?? 0;
	if (!count) {
		return [text, ''];
	}

	const cardId: string = record['m_noteMiniGuid'];
	if (SPELLSTONES.includes(cardId)) {
		return [text.replace(/@/g, ''), text.replace(/@/g, '')];
	}

	if (SCHEMES.includes(cardId) || cardId.startsWith('BAR_763t')) {
		return [text.replace(/@/g, '###'), text.replace(/@/g, '###')];
	}

	const parts = text.split('@');
	let collectionText = '';
	if (parts.length === 2) {
		[text, collectionText] = parts;
		const collectionTextForCheck = collectionText.trim().toLowerCase();

		// TODO: localization
		if (
			collectionTextForCheck.startsWith('damage') ||
			collectionTextForCheck.startsWith('turn') ||
			collectionTextForCheck.startsWith('time') ||
			collectionTextForCheck.startsWith('left') ||
			collectionTextForCheck.includes('left!') ||
			collectionTextForCheck.includes('turns)') ||
			collectionTextForCheck.includes('improves') ||
			collectionTextForCheck.includes('upgrades after each use') ||
			text.endsWith('$') ||
			text.endsWith('(') ||
			text.endsWith('+')
		) {
			const tmp = text + '###' + collectionText;
			collectionText = text + '###' + collectionText;
			text = tmp;
		} else {
			text = text.trim();
		}
	} else if (parts.length > 2) {
		collectionText = parts[0];
		if (collectionText.trim().endsWith('+')) {
			return [text.replace(/@/g, '###'), text.replace(/@/g, '###')];
		}
	}

	return [text, collectionText];
};


const cleanUpText = (text: string, tags?: readonly InternalTag[]): string => {
	if (!text || text.length === 0) {
		return null;
	}

	const replaced = text
		.replace(/\u00A0/gm, ' ')
		.replace(/\n \n/gm, '\n') // Remove line jumps?
		.replace(/\n{2,}/gm, '\n') // Remove line jumps?
		.replace('@', '')
		.replace(/[ ]{2,}/g, ' ')
		.trim();
	const placeholders = (tags ?? [])
		.filter((tag) =>
			[
				GameTag.TAG_SCRIPT_DATA_NUM_1,
				GameTag.TAG_SCRIPT_DATA_NUM_2,
				GameTag.SCORE_VALUE_1,
				GameTag.SCORE_VALUE_2,
				GameTag.SCORE_VALUE_3,
			].includes(tag.tagId),
		)
		.sort((a, b) => a.tagId - b.tagId)
		.map((tag) => tag.tagValue)
		// ULDA_804t has both tags set, with the first being 0 and the second being the real value (3)
		.filter((tagValue) => tagValue > 0);
	let finalText = replaced;
	if (placeholders.length === 1) {
		finalText = finalText.replace(/###/g, '' + placeholders[0]);
		if (placeholders[0] <= 1) {
			finalText = finalText.replace(/\|\d\((.*?),.*?\)/gm, '$1');
		}
	} else {
		for (const placeholder of placeholders) {
			finalText = finalText.replace('###', '' + placeholder);
			// Handling singular
			if (placeholder <= 1) {
				finalText = finalText.replace(/\|\d\((.*?),.*?\)/gm, '$1');
			}
		}
	}
	finalText = finalText.replace(/###/gm, '0').replace(/\|\d\(.*,(.*?)\)/gm, '$1');
	return !!finalText?.length ? finalText : null;
};

It's an old piece of code that should be reworked when I have the time (and/or should be extracted to a public repo).

@piedpiper358
Copy link
Contributor Author

Thanks for the code! Can I also get sample data from the client to understand why errors occur?

@sebastientromp
Copy link
Contributor

The game data for TB_BaconShop_HP_056 is

{
            "m_ID": 60448,
            "m_noteMiniGuid": "TB_BaconShop_HP_056",
            "m_longGuid": "00000011-0a56-4f6e-a00f-792399a1569d",
            "m_textInHand": {
                "m_locValues": [
                    "[x]<b>Passive.</b> After you sell\n2 minions, add a random\nMurloc to Bob's Tavern.\n<i>(@ left.)</i>",
                    "[x]<b>Passiv</b>\nFügt Bobs Gasthaus einen\nzufälligen Murloc hinzu,\nnachdem Ihr 2 Diener verkauft\nhabt. <i>(Noch @)</i>",
                    "[x]<b>Pasivo</b>\nTras vender dos esbirros,\nañade un múrloc aleatorio\na la taberna de Bob.\n<i>(¡@ más!).</i>",
                    "<b>Pasivo</b>\nDespués de vender 2 esbirros, agrega un Múrloc aleatorio a_la_Taberna de Bob. <i>(|4(Falta, Faltan) @).</i>",
                    "<b>Effet passif</b>\nUne fois que vous avez vendu 2_serviteurs, ajoute un Murloc aléatoire_dans_la_taverne de Bob. <i>(Encore_@.)</i>",
                    "[x]<b>Passivo</b>. Dopo che hai venduto\n2 servitori, aggiunge un Murloc\ncasuale alla Locanda di Bob.\n<i>(Ancora @)</i>",
                    "[x]<b>常時発動</b>\n自分がミニオンを2体\n売った後、ボブの酒場に\nランダムなマーロック\n1体を追加する。\n<i>(あと@体)</i>",
                    "<b>지속 능력</b>\n내가 하수인을 둘 판 후에,\n밥의 선술집에 무작위 멀록을 추가합니다. <i>(@ 남음!)</i>",
                    "<b>Działanie pasywne:</b>\nGdy sprzedasz 2_stronników, dodaj losowego Murloka do Karczmy Boba. <i>(Jeszcze @).</i>",
                    "<b>Passivo:</b> Depois que você vender 2 lacaios, adicione um Murloc aleatório à Taverna do Bob. <i>(Resta: @.)</i>",
                    "<b>Пассивный эффект:</b>\nпосле того как вы продаете 2 существ, добавляет случайного мурлока в таверну Боба. <i>(Еще @.)</i>",
                    "<b>ติดตัว</b> หลังจากคุณขาย[b]มินเนี่ยน_2_ตัว_สุ่มเพิ่ม[b]เมอร์ล็อคหนึ่งตัวในโรงเตี๊ยม[b]ของบ็อบ <i>(อีก_@_ตัว)</i>",
                    "<b>被动</b>\n在你出售2个随从后,随机在鲍勃的酒馆中添加一个鱼人。<i>(还剩@个。)</i>",
                    "<b>被動</b>\n在你出售2個手下後,放一個隨機魚人到鮑伯的旅店<i>(還剩@個)</i>"
                ],
                "m_locId": 2721384
            },
            "m_gameplayEvent": "always",
            "m_craftingEvent": "always",
            "m_goldenCraftingEvent": "",
            "m_suggestionWeight": 0,
            "m_changeVersion": 0,
            "m_name": {
                "m_locValues": [
                    "Gone Fishing",
                    "Angelausflug",
                    "Escamando",
                    "De pesca",
                    "À la pêche",
                    "Fuori a Pesca",
                    "魚夫の利",
                    "월척",
                    "Na ryby",
                    "Conversa de Pescador",
                    "Рыбалка",
                    "ตกปลากันเถอะ",
                    "愿者上钩",
                    "魚人上鉤"
                ],
                "m_locId": 2721383
            },
            "m_flavorText": {
                "m_locValues": [
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    ""
                ],
                "m_locId": 0
            },
            "m_howToGetCard": {
                "m_locValues": [
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    ""
                ],
                "m_locId": 0
            },
            "m_howToGetGoldCard": {
                "m_locValues": [
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    ""
                ],
                "m_locId": 0
            },
            "m_howToGetDiamondCard": {
                "m_locValues": [
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    ""
                ],
                "m_locId": 0
            },
            "m_targetArrowText": {
                "m_locValues": [
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    ""
                ],
                "m_locId": 0
            },
            "m_artistName": "",
            "m_shortName": {
                "m_locValues": [
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    ""
                ],
                "m_locId": 0
            },
            "m_creditsCardName": "",
            "m_featuredCardsEvent": "",
            "m_battlegroundsActiveEvent": "always",
            "m_battlegroundsEarlyAccessEvent": "always",
            "m_battlegroundsEveryGameEvent": "never",
            "m_cardTextBuilderType": 7,
            "m_watermarkTextureOverride": ""
        },

But honestly I think it will be better to shelve that specific issue for now and wait until I extract all the patch pipeline to another repo that I can make public

@piedpiper358
Copy link
Contributor Author

Thank you. I'll take a look at what's going on here when I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants