- migrating 'tint .def command.

This commit is contained in:
Christoph Oelckers 2021-04-11 15:23:42 +02:00
parent 42d02834b1
commit c33eea2540
2 changed files with 36 additions and 52 deletions

View file

@ -1446,55 +1446,7 @@ static int32_t defsparser(scriptfile *script)
} }
break; break;
case T_TINT: case T_TINT:
{ parseTint(*script, pos);
auto tintpos = scriptfile_getposition(script);
int32_t red=255, green=255, blue=255, shadered=0, shadegreen=0, shadeblue=0, pal=-1, flags=0;
FScanner::SavedPos tintend;
static const tokenlist tinttokens[] =
{
{ "pal", T_PAL },
{ "red", T_RED },{ "r", T_RED },
{ "green", T_GREEN },{ "g", T_GREEN },
{ "blue", T_BLUE },{ "b", T_BLUE },
{ "shadered", T_SHADERED },{ "sr", T_SHADERED },
{ "shadegreen", T_SHADEGREEN },{ "sg", T_SHADEGREEN },
{ "shadeblue", T_SHADEBLUE },{ "sb", T_SHADEBLUE },
{ "flags", T_FLAGS }
};
if (scriptfile_getbraces(script,&tintend)) break;
while (!scriptfile_endofblock(script, tintend))
{
switch (getatoken(script,tinttokens,countof(tinttokens)))
{
case T_PAL:
scriptfile_getsymbol(script,&pal); break;
case T_RED:
scriptfile_getnumber(script,&red); red = min(255,max(0,red)); break;
case T_GREEN:
scriptfile_getnumber(script,&green); green = min(255,max(0,green)); break;
case T_BLUE:
scriptfile_getnumber(script,&blue); blue = min(255,max(0,blue)); break;
case T_SHADERED:
scriptfile_getnumber(script,&shadered); shadered = min(255,max(0,shadered)); break;
case T_SHADEGREEN:
scriptfile_getnumber(script,&shadegreen); shadegreen = min(255,max(0,shadegreen)); break;
case T_SHADEBLUE:
scriptfile_getnumber(script,&shadeblue); shadeblue = min(255,max(0,shadeblue)); break;
case T_FLAGS:
scriptfile_getsymbol(script,&flags); break;
}
}
if (pal < 0)
{
tintpos.Message(MSG_ERROR, "tint: missing 'palette number'");
break;
}
lookups.setPaletteTint(pal,red,green,blue,shadered,shadegreen,shadeblue,flags);
}
break; break;
case T_MAKEPALOOKUP: case T_MAKEPALOOKUP:
{ {

View file

@ -146,8 +146,6 @@ static void parseTextureSpecialBlock(FScanner& sc, FScriptPosition& pos, int til
FString fn; FString fn;
double xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0; double xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0;
if (!sc.GetNumber(pal, true)) return;
if (sc.StartBraces(&blockend)) return; if (sc.StartBraces(&blockend)) return;
while (!sc.FoundEndBrace(blockend)) while (!sc.FoundEndBrace(blockend))
{ {
@ -404,3 +402,37 @@ void parseNoFloorpalRange(FScanner& sc, FScriptPosition& pos)
for (int i = start; i <= end; i++) for (int i = start; i <= end; i++)
lookups.tables[i].noFloorPal = true; lookups.tables[i].noFloorPal = true;
} }
//===========================================================================
//
//
//
//===========================================================================
void parseTint(FScanner& sc, FScriptPosition& pos)
{
int red = 255, green = 255, blue = 255, shadered = 0, shadegreen = 0, shadeblue = 0, pal = -1, flags = 0;
FScanner::SavedPos tintend;
FScanner::SavedPos blockend;
if (sc.StartBraces(&blockend)) return;
while (!sc.FoundEndBrace(blockend))
{
sc.MustGetString();
if (sc.Compare("pal")) sc.GetNumber(pal, true);
else if (sc.Compare({"red", "r"})) sc.GetNumber(red);
else if (sc.Compare({ "green", "g" })) sc.GetNumber(green);
else if (sc.Compare({ "blue", "b" })) sc.GetNumber(blue);
else if (sc.Compare({ "shadered", "sr" })) sc.GetNumber(shadered);
else if (sc.Compare({ "shadegreen", "sg" })) sc.GetNumber(shadegreen);
else if (sc.Compare({ "shadeblue", "sb" })) sc.GetNumber(shadeblue);
else if (sc.Compare("flags")) sc.GetNumber(flags, true);
}
if (pal < 0)
pos.Message(MSG_ERROR, "tint: missing palette number");
else
lookups.setPaletteTint(pal, clamp(red, 0, 255), clamp(green, 0, 255), clamp(blue, 0, 255),
clamp(shadered, 0, 255), clamp(shadegreen, 0, 255), clamp(shadeblue, 0, 255), flags);
}