simplify texture pack logic a little bit

This commit is contained in:
UnknownShadow200 2019-06-20 09:49:27 +10:00
parent 9cf3910db1
commit 27881b6acc
7 changed files with 19 additions and 20 deletions

View File

@ -559,9 +559,7 @@ static void Cw_Callback_4(struct NbtTag* tag) {
if (IsTag(tag, "TextureURL")) {
String url = NbtTag_String(tag);
if (Game_AllowServerTextures && url.length) {
Server_RetrieveTexturePack(&url);
}
if (url.length) Server_RetrieveTexturePack(&url);
return;
}
}

View File

@ -190,11 +190,7 @@ void Game_Reset(void) {
struct IGameComponent* comp;
World_Reset();
Event_RaiseVoid(&WorldEvents.NewMap);
if (World_TextureUrl.length) {
TexturePack_ExtractDefault();
World_TextureUrl.length = 0;
}
if (World_TextureUrl.length) TexturePack_ExtractDefault();
for (comp = comps_head; comp; comp = comp->next) {
if (comp->Reset) comp->Reset();

View File

@ -17,7 +17,7 @@
#include "Block.h"
#include "Menus.h"
#include "Gui.h"
#include "PacketHandlers.h"
#include "Protocol.h"
#include "AxisLinesRenderer.h"
static bool input_buttonsDown[3];

View File

@ -1,4 +1,4 @@
#include "PacketHandlers.h"
#include "Protocol.h"
#include "Deflate.h"
#include "Utils.h"
#include "Server.h"
@ -1206,15 +1206,11 @@ static void CPE_SetMapEnvUrl(uint8_t* data) {
String_InitArray(url, urlBuffer);
Protocol_ReadString(&data, &url);
if (!Game_AllowServerTextures) return;
if (!url.length) {
/* don't extract default texture pack if we can */
if (World_TextureUrl.length) TexturePack_ExtractDefault();
} else if (Utils_IsUrlPrefix(&url, 0)) {
if (!url.length || Utils_IsUrlPrefix(&url, 0)) {
Server_RetrieveTexturePack(&url);
}
Platform_Log1("Image url: %s", &url);
Platform_Log1("Tex url: %s", &url);
}
static void CPE_SetMapEnvProperty(uint8_t* data) {

View File

@ -18,7 +18,7 @@
#include "TexturePack.h"
#include "Menus.h"
#include "Logger.h"
#include "PacketHandlers.h"
#include "Protocol.h"
#include "Inventory.h"
#include "Platform.h"
#include "GameStructs.h"
@ -41,10 +41,15 @@ static void Server_ResetState(void) {
}
void Server_RetrieveTexturePack(const String* url) {
if (!TextureCache_HasAccepted(url) && !TextureCache_HasDenied(url)) {
Gui_ShowOverlay(TexPackOverlay_MakeInstance(url));
} else {
if (!Game_AllowServerTextures || TextureCache_HasDenied(url)) return;
if (!url->length) {
/* Only extract default texture pack when necessary */
if (World_TextureUrl.length) TexturePack_ExtractDefault();
} else if (TextureCache_HasAccepted(url)) {
Server_DownloadTexturePack(url);
} else {
Gui_ShowOverlay(TexPackOverlay_MakeInstance(url));
}
}
@ -57,6 +62,8 @@ void Server_DownloadTexturePack(const String* url) {
String_InitArray(etag, etagBuffer);
String_InitArray(time, timeBuffer);
/* Only retrieve etag/last-modified headers if the file exists */
/* This can occur if user decided to delete some cached files */
if (TextureCache_Has(url)) {
TextureCache_GetLastModified(url, &time);
TextureCache_GetETag(url, &etag);

View File

@ -95,6 +95,7 @@ void TextureCache_GetETag(const String* url, String* etag);
void TextureCache_Set(const String* url, const uint8_t* data, uint32_t length);
void TexturePack_ExtractZip_File(const String* filename);
/* Extracts user's default texture pack, then resets World_TextureUrl. */
void TexturePack_ExtractDefault(void);
void TexturePack_ExtractCurrent(const String* url);
void TexturePack_Extract_Req(struct HttpRequest* item);

View File

@ -317,6 +317,7 @@ void EntryList_Load(struct EntryList* list, EntryList_Filter filter) {
if (res == ERR_END_OF_STREAM) break;
if (res) { Logger_Warn2(res, "reading from", &path); break; }
/* whitespace lines are ignored (e.g. if user manually edits file) */
String_UNSAFE_TrimStart(&entry);
String_UNSAFE_TrimEnd(&entry);