Make one-way recolors check for specific files

So, 2.3 added recoloring one-way tiles to no longer make them be always
yellow. However, custom levels that retexture the one-way tiles might
not want them to be recolored. So, if there are ANY custom assets
mounted, then the one-ways will not be recolored. However, if the XML
has a <onewaycol_override>1</onewaycol_override> tag, then the one-way
will be recolored again anyways.

When I added one-way recoloring, I didn't intend for any custom asset to
disable the recoloring; I only did it because I couldn't find a way to
check if a specific file was customized by the custom level or not.

However, I have figured out how to do so, and so now tiles.png one-way
recolors will only be disabled if there's a custom tiles.png, and
tiles2.png one-way recolors will only be disabled if there's a custom
tiles2.png.

In order to make sure we're not calling PhysFS functions on every single
deltaframe, I've added caching variables, tiles1_mounted and
tiles2_mounted, to Graphics; these get assigned every time
reloadresources() is called.
This commit is contained in:
Misa
2021-03-06 10:52:11 -08:00
committed by Ethan Lee
parent 34865a8ef1
commit c1572de9e2
4 changed files with 21 additions and 19 deletions

View File

@@ -146,6 +146,11 @@ void Graphics::init(void)
col_tb = 0;
kludgeswnlinewidth = false;
#ifndef NO_CUSTOM_LEVELS
tiles1_mounted = false;
tiles2_mounted = false;
#endif
}
void Graphics::destroy(void)
@@ -710,10 +715,10 @@ void Graphics::drawsprite(int x, int y, int t, Uint32 c)
}
#ifndef NO_CUSTOM_LEVELS
bool Graphics::shouldrecoloroneway(const int tilenum)
bool Graphics::shouldrecoloroneway(const int tilenum, const bool mounted)
{
return (tilenum >= 14 && tilenum <= 17
&& (!FILESYSTEM_assetsmounted
&& (!mounted
|| ed.onewaycol_override));
}
#endif
@@ -729,7 +734,7 @@ void Graphics::drawtile( int x, int y, int t )
SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
#if !defined(NO_CUSTOM_LEVELS)
if (shouldrecoloroneway(t))
if (shouldrecoloroneway(t, tiles1_mounted))
{
colourTransform thect = {ed.getonewaycol()};
BlitSurfaceTinted(tiles[t], NULL, backBuffer, &rect, thect);
@@ -753,7 +758,7 @@ void Graphics::drawtile2( int x, int y, int t )
SDL_Rect rect = { Sint16(x), Sint16(y), tiles_rect.w, tiles_rect.h };
#if !defined(NO_CUSTOM_LEVELS)
if (shouldrecoloroneway(t))
if (shouldrecoloroneway(t, tiles2_mounted))
{
colourTransform thect = {ed.getonewaycol()};
BlitSurfaceTinted(tiles2[t], NULL, backBuffer, &rect, thect);
@@ -3153,7 +3158,7 @@ void Graphics::drawforetile(int x, int y, int t)
setRect(rect, x,y,tiles_rect.w, tiles_rect.h);
#if !defined(NO_CUSTOM_LEVELS)
if (shouldrecoloroneway(t))
if (shouldrecoloroneway(t, tiles1_mounted))
{
colourTransform thect = {ed.getonewaycol()};
BlitSurfaceTinted(tiles[t], NULL, foregroundBuffer, &rect, thect);
@@ -3177,7 +3182,7 @@ void Graphics::drawforetile2(int x, int y, int t)
setRect(rect, x,y,tiles_rect.w, tiles_rect.h);
#if !defined(NO_CUSTOM_LEVELS)
if (shouldrecoloroneway(t))
if (shouldrecoloroneway(t, tiles2_mounted))
{
colourTransform thect = {ed.getonewaycol()};
BlitSurfaceTinted(tiles2[t], NULL, foregroundBuffer, &rect, thect);
@@ -3268,6 +3273,11 @@ void Graphics::reloadresources()
music.destroy();
music.init();
#ifndef NO_CUSTOM_LEVELS
tiles1_mounted = FILESYSTEM_isAssetMounted("graphics/tiles.png");
tiles2_mounted = FILESYSTEM_isAssetMounted("graphics/tiles2.png");
#endif
}
Uint32 Graphics::crewcolourreal(int t)