Beispiel #1
0
void R_ParseTrnslate()
{
	customTranslationMap.Clear();
	translationtables[TRANSLATION_Custom].Clear();

	int lump;
	int lastlump = 0;
	while (-1 != (lump = Wads.FindLump("TRNSLATE", &lastlump)))
	{
		FScanner sc(lump);
		while (sc.GetToken())
		{
			sc.TokenMustBe(TK_Identifier);

			FName newtrans = sc.String;
			FRemapTable *base = nullptr;
			if (sc.CheckToken(':'))
			{
				sc.MustGetAnyToken();
				if (sc.TokenType == TK_IntConst)
				{
					int max = 6;
					if (sc.Number < 0 || sc.Number > max)
					{
						sc.ScriptError("Translation must be in the range [0,%d]", max);
					}
					base = translationtables[TRANSLATION_Standard][sc.Number];
				}
				else if (sc.TokenType == TK_Identifier)
				{
					int tnum = R_FindCustomTranslation(sc.String);
					if (tnum == -1)
					{
						sc.ScriptError("Base translation '%s' not found in '%s'", sc.String, newtrans.GetChars());
					}
					base = translationtables[GetTranslationType(tnum)][GetTranslationIndex(tnum)];
				}
				else
				{
					// error out.
					sc.TokenMustBe(TK_Identifier);
				}
			}
			sc.MustGetToken('=');
			FRemapTable NewTranslation;
			if (base != nullptr)  NewTranslation = *base;
			else NewTranslation.MakeIdentity();
			do
			{
				sc.MustGetToken(TK_StringConst);
				NewTranslation.AddToTranslation(sc.String);
			} while (sc.CheckToken(','));

			int trans = NewTranslation.StoreTranslation(TRANSLATION_Custom);
			customTranslationMap[newtrans] = trans;
		}
	}
}
Beispiel #2
0
DEFINE_ACTION_FUNCTION(_Translation, AddTranslation)
{
	PARAM_SELF_STRUCT_PROLOGUE(FTranslation);

	FRemapTable NewTranslation;
	memcpy(&NewTranslation.Palette[0], self->colors, 256 * sizeof(PalEntry));
	for (int i = 0; i < 256; i++)
	{
		NewTranslation.Remap[i] = ColorMatcher.Pick(self->colors[i]);
	}
	int trans = NewTranslation.StoreTranslation(TRANSLATION_Custom);
	ACTION_RETURN_INT(trans);
}