diff --git a/binaries/data/mods/public/gui/common/gamedescription.js b/binaries/data/mods/public/gui/common/gamedescription.js index 283ca1b596..848584decb 100644 --- a/binaries/data/mods/public/gui/common/gamedescription.js +++ b/binaries/data/mods/public/gui/common/gamedescription.js @@ -34,6 +34,21 @@ var g_Buddies = Engine.ConfigDB_GetValue("user", "lobby.buddies").split(g_BuddyL */ var g_BuddySymbol = '•'; +var g_MapPreviewPath = "session/icons/mappreview/"; + +/** + * Returns the biome specific mappreview image if it exists, or empty string otherwise. + */ +function getBiomePreview(mapName, biomeName) +{ + let biomePreview = basename(mapName) + "_" + basename(biomeName) + ".png"; + + if (Engine.TextureExists("art/textures/ui/" + g_MapPreviewPath + biomePreview)) + return biomePreview; + + return ""; +} + /** * Returns map description and preview image or placeholder. */ @@ -47,11 +62,11 @@ function getMapDescriptionAndPreview(mapType, mapName, gameAttributes = undefine else if (Engine.FileExists(mapName + ".xml")) mapData = Engine.LoadMapSettings(mapName + ".xml"); - let mapBiome = gameAttributes && g_Settings.Biomes.find(biome => biome.Id == gameAttributes.settings.Biome); + let biomePreview = getBiomePreview(mapName, gameAttributes.settings.Biome || ""); return deepfreeze({ "description": mapData && mapData.settings && mapData.settings.Description ? translate(mapData.settings.Description) : translate("Sorry, no description available."), - "preview": mapBiome && mapBiome.Preview ? mapBiome.Preview : + "preview": biomePreview ? biomePreview : mapData && mapData.settings && mapData.settings.Preview ? mapData.settings.Preview : "nopreview.png" }); } @@ -67,7 +82,7 @@ function setMapPreviewImage(guiObject, filename) { Engine.GetGUIObjectByName(guiObject).sprite = "cropped:" + 400 / 512 + "," + 300 / 512 + ":" + - "session/icons/mappreview/" + filename; + g_MapPreviewPath + filename; } /** diff --git a/binaries/data/mods/public/gui/gamesetup/gamesetup.js b/binaries/data/mods/public/gui/gamesetup/gamesetup.js index 7096014305..f40fa617ba 100644 --- a/binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ b/binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -1659,12 +1659,9 @@ function getMapDisplayName(map) function getMapPreview(map) { - if (g_GameAttributes.settings.Biome) - { - let biomePreview = basename(map) + "_" + basename(g_GameAttributes.settings.Biome) + ".png"; - if (Engine.FileExists("art/textures/ui/session/icons/mappreview/" + biomePreview)) - return biomePreview; - } + let biomePreview = g_GameAttributes.settings.Biome && getBiomePreview(map, g_GameAttributes.settings.Biome); + if (biomePreview) + return biomePreview; let mapData = loadMapData(map); if (!mapData || !mapData.settings || !mapData.settings.Preview) diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index 827a3c1e06..87158b9a8c 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -316,6 +316,12 @@ public: m_TextureConverter.ConvertTexture(texture, sourcePath, looseCachePath, settings); } + bool TextureExists(const VfsPath& path) const + { + return m_VFS->GetFileInfo(m_CacheLoader.ArchiveCachePath(path), 0) == INFO::OK || + m_VFS->GetFileInfo(path, 0) == INFO::OK; + } + bool GenerateCachedTexture(const VfsPath& sourcePath, VfsPath& archiveCachePath) { archiveCachePath = m_CacheLoader.ArchiveCachePath(sourcePath); @@ -653,6 +659,11 @@ CTexturePtr CTextureManager::CreateTexture(const CTextureProperties& props) return m->CreateTexture(props); } +bool CTextureManager::TextureExists(const VfsPath& path) const +{ + return m->TextureExists(path); +} + CTexturePtr CTextureManager::GetErrorTexture() { return m->GetErrorTexture(); diff --git a/source/graphics/TextureManager.h b/source/graphics/TextureManager.h index 4913814830..0a11bfc1aa 100644 --- a/source/graphics/TextureManager.h +++ b/source/graphics/TextureManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -111,6 +111,12 @@ public: */ bool GenerateCachedTexture(const VfsPath& path, VfsPath& outputPath); + /** + * Returns true if the given texture exists. + * This tests both for the original and converted filename. + */ + bool TextureExists(const VfsPath& path) const; + /** * Returns total number of bytes uploaded for all current texture. */ diff --git a/source/ps/CacheLoader.cpp b/source/ps/CacheLoader.cpp index f31b7d9738..749def8331 100644 --- a/source/ps/CacheLoader.cpp +++ b/source/ps/CacheLoader.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -109,7 +109,7 @@ bool CCacheLoader::CanUseArchiveCache(const VfsPath& sourcePath, const VfsPath& return true; } -VfsPath CCacheLoader::ArchiveCachePath(const VfsPath& sourcePath) +VfsPath CCacheLoader::ArchiveCachePath(const VfsPath& sourcePath) const { return sourcePath.ChangeExtension(sourcePath.Extension().string() + L".cached" + m_FileExtension); } diff --git a/source/ps/CacheLoader.h b/source/ps/CacheLoader.h index a406052a84..9580e36ef5 100644 --- a/source/ps/CacheLoader.h +++ b/source/ps/CacheLoader.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -59,7 +59,7 @@ public: /** * Return the path of the archive cache for the given source file. */ - VfsPath ArchiveCachePath(const VfsPath& sourcePath); + VfsPath ArchiveCachePath(const VfsPath& sourcePath) const; /** * Return the path of the loose cache for the given source file. diff --git a/source/renderer/scripting/JSInterface_Renderer.cpp b/source/renderer/scripting/JSInterface_Renderer.cpp index 6f6f35c7ab..c47b9338f4 100644 --- a/source/renderer/scripting/JSInterface_Renderer.cpp +++ b/source/renderer/scripting/JSInterface_Renderer.cpp @@ -19,6 +19,7 @@ #include "JSInterface_Renderer.h" +#include "graphics/TextureManager.h" #include "ps/Profile.h" #include "renderer/Renderer.h" #include "renderer/ShadowMap.h" @@ -69,6 +70,10 @@ void JSI_Renderer::RecreateShadowMap(ScriptInterface::CxPrivate* UNUSED(pCxPriva g_Renderer.GetShadowMap().RecreateTexture(); } +bool JSI_Renderer::TextureExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename) +{ + return g_Renderer.GetTextureManager().TextureExists(filename); +} #define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \ scriptInterface.RegisterFunction("Renderer_Get" #NAME "Enabled"); \ @@ -79,6 +84,7 @@ void JSI_Renderer::RegisterScriptFunctions(const ScriptInterface& scriptInterfac scriptInterface.RegisterFunction("Renderer_GetRenderPath"); scriptInterface.RegisterFunction("Renderer_SetRenderPath"); scriptInterface.RegisterFunction("Renderer_RecreateShadowMap"); + scriptInterface.RegisterFunction("TextureExists"); REGISTER_BOOLEAN_SCRIPT_SETTING(Shadows); REGISTER_BOOLEAN_SCRIPT_SETTING(ShadowPCF); REGISTER_BOOLEAN_SCRIPT_SETTING(Particles); diff --git a/source/renderer/scripting/JSInterface_Renderer.h b/source/renderer/scripting/JSInterface_Renderer.h index f72fa18d9f..2ea995e778 100644 --- a/source/renderer/scripting/JSInterface_Renderer.h +++ b/source/renderer/scripting/JSInterface_Renderer.h @@ -29,6 +29,7 @@ namespace JSI_Renderer std::string GetRenderPath(ScriptInterface::CxPrivate* pCxPrivate); void SetRenderPath(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name); void RecreateShadowMap(ScriptInterface::CxPrivate* pCxPrivate); + bool TextureExists(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename); DECLARE_BOOLEAN_SCRIPT_SETTING(Shadows); DECLARE_BOOLEAN_SCRIPT_SETTING(ShadowPCF);