diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index dc8300d2e..20b57fb75 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -1446,56 +1446,8 @@ static int32_t defsparser(scriptfile *script) } break; case T_TINT: - { - 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; + parseTint(*script, pos); + break; case T_MAKEPALOOKUP: { int32_t red=0, green=0, blue=0, pal=-1; diff --git a/source/core/parsefuncs.h b/source/core/parsefuncs.h index 4704988e8..94dd79dde 100644 --- a/source/core/parsefuncs.h +++ b/source/core/parsefuncs.h @@ -146,8 +146,6 @@ static void parseTextureSpecialBlock(FScanner& sc, FScriptPosition& pos, int til FString fn; double xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0; - if (!sc.GetNumber(pal, true)) return; - if (sc.StartBraces(&blockend)) return; while (!sc.FoundEndBrace(blockend)) { @@ -404,3 +402,37 @@ void parseNoFloorpalRange(FScanner& sc, FScriptPosition& pos) for (int i = start; i <= end; i++) 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); +}