forked from mirrors/0ad
Fix biome-specific mappreviews in 7f602037ba for zipped mods, refs #4962.
Add TextureExists to avoid needless redundant hardcoding of the
filenames.
Remove mapBiome.Preview from gamedescription.js, obsolete following
8cde469501.
Differential Revision: https://code.wildfiregames.com/D1583
Accepted By: Vladislav
This was SVN commit r21859.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<bool, &JSI_Renderer::Get##NAME##Enabled>("Renderer_Get" #NAME "Enabled"); \
|
||||
@@ -79,6 +84,7 @@ void JSI_Renderer::RegisterScriptFunctions(const ScriptInterface& scriptInterfac
|
||||
scriptInterface.RegisterFunction<std::string, &JSI_Renderer::GetRenderPath>("Renderer_GetRenderPath");
|
||||
scriptInterface.RegisterFunction<void, std::string, &JSI_Renderer::SetRenderPath>("Renderer_SetRenderPath");
|
||||
scriptInterface.RegisterFunction<void, &JSI_Renderer::RecreateShadowMap>("Renderer_RecreateShadowMap");
|
||||
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_Renderer::TextureExists>("TextureExists");
|
||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Shadows);
|
||||
REGISTER_BOOLEAN_SCRIPT_SETTING(ShadowPCF);
|
||||
REGISTER_BOOLEAN_SCRIPT_SETTING(Particles);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user