mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-05 12:32:27 +00:00
Implement folderTexturePack
This commit is contained in:
parent
077a60ef89
commit
66343a5ba1
|
|
@ -1,35 +1,119 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "FolderTexturePack.h"
|
#include "FolderTexturePack.h"
|
||||||
|
#include "TexturePackRepository.h"
|
||||||
|
#include "..\Minecraft.World\StringHelpers.h"
|
||||||
|
|
||||||
FolderTexturePack::FolderTexturePack(DWORD id, const wstring &name, File *folder, TexturePack *fallback) : AbstractTexturePack(id, folder, name, fallback)
|
FolderTexturePack::FolderTexturePack(DWORD id, const wstring &name, File *folder, TexturePack *fallback) : AbstractTexturePack(id, folder, name, fallback)
|
||||||
{
|
{
|
||||||
// 4J Stu - These calls need to be in the most derived version of the class
|
// 4J Stu - These calls need to be in the most derived version of the class
|
||||||
|
cacheFiles(*folder, folder->getPath().length() + 1);
|
||||||
|
loadColourTable();
|
||||||
loadIcon();
|
loadIcon();
|
||||||
loadName();
|
loadName();
|
||||||
loadDescription();
|
loadDescription();
|
||||||
|
checkTexSize();
|
||||||
|
|
||||||
bUILoaded = false;
|
bUILoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream *FolderTexturePack::getResourceImplementation(const wstring &name) //throws IOException
|
DLCPack* FolderTexturePack::getDLCPack()
|
||||||
{
|
{
|
||||||
#if 0
|
return NULL;
|
||||||
final File file = new File(this.file, name.substring(1));
|
}
|
||||||
if (!file.exists()) {
|
|
||||||
throw new FileNotFoundException(name);
|
void FolderTexturePack::loadName() {
|
||||||
|
texname = file->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderTexturePack::loadIcon()
|
||||||
|
{
|
||||||
|
if (hasFile(L"pack.png") && _iconData.empty())
|
||||||
|
{
|
||||||
|
app.DebugPrintf("Found pack.png in folder, loading as icon\n");
|
||||||
|
File iconFile(file->getPath() + L"\\pack.png");
|
||||||
|
FileInputStream is(iconFile);
|
||||||
|
|
||||||
|
_iconData.resize(iconFile.length());
|
||||||
|
byteArray arr(iconFile.length());
|
||||||
|
is.read(arr, 0, _iconData.size());
|
||||||
|
memcpy(_iconData.data(), arr.data, _iconData.size());
|
||||||
|
delete arr.data;
|
||||||
|
|
||||||
|
if (!_iconData.empty()) {
|
||||||
|
iconImage = new BufferedImage(_iconData.data(), _iconData.size());
|
||||||
|
m_iconData = _iconData.data();
|
||||||
|
m_iconSize = _iconData.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
app.DebugPrintf("Failed to load pack.png from folder\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderTexturePack::loadDescription()
|
||||||
|
{
|
||||||
|
desc1 = L"";
|
||||||
|
desc2 = L"";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FolderTexturePack::hasData()
|
||||||
|
{
|
||||||
|
return _cachedFiles.find(L"pack.mcmeta") != _cachedFiles.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FolderTexturePack::isLoadingData()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderTexturePack::cacheFiles(File &dir, int folderLen)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for (auto file : *dir.listFiles()) {
|
||||||
|
if (i++ < 2) continue; // skip `.` and `..`
|
||||||
|
if (file->isDirectory()) {
|
||||||
|
cacheFiles(*file, folderLen);
|
||||||
|
} else {
|
||||||
|
_cachedFiles[file->getPath().substr(folderLen)] = file->getPath().substr(folderLen);
|
||||||
|
_cachedFiles[file->getName()] = file->getPath().substr(folderLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wstring FolderTexturePack::getAnimationString(const wstring& textureName, const wstring& path, bool allowFallback) {
|
||||||
|
// copy paste of base class method, except I return null and check for existence in getResource
|
||||||
|
|
||||||
|
std::wstring result = L"";
|
||||||
|
InputStream* fileStream = getResource(L"\\" + path + textureName + L".txt", true);
|
||||||
|
|
||||||
|
if (fileStream) {
|
||||||
|
InputStreamReader isr(fileStream);
|
||||||
|
BufferedReader br(&isr);
|
||||||
|
|
||||||
|
wstring line = br.readLine();
|
||||||
|
while (!line.empty())
|
||||||
|
{
|
||||||
|
line = trimString(line);
|
||||||
|
if (line.length() > 0)
|
||||||
|
{
|
||||||
|
result.append(L",");
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
line = br.readLine();
|
||||||
|
}
|
||||||
|
delete fileStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BufferedInputStream(new FileInputStream(file));
|
return result;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
wstring wDrive = L"";
|
InputStream *FolderTexturePack::getResourceImplementation(const wstring &name) //throws IOException
|
||||||
|
{
|
||||||
// Make the content package point to to the UPDATE: drive is needed
|
// Make the content package point to to the UPDATE: drive is needed
|
||||||
#ifdef _XBOX
|
std::wstring wDrive = this->file->getPath();
|
||||||
wDrive=L"GAME:\\DummyTexturePack\\res";
|
if (!hasFile(name))
|
||||||
#else
|
return nullptr;
|
||||||
wDrive = L"Common\\DummyTexturePack\\res";
|
|
||||||
#endif
|
InputStream *resource = InputStream::getResourceAsStream(name);
|
||||||
InputStream *resource = InputStream::getResourceAsStream(wDrive + name);
|
|
||||||
//InputStream *stream = DefaultTexturePack::class->getResourceAsStream(name);
|
//InputStream *stream = DefaultTexturePack::class->getResourceAsStream(name);
|
||||||
//if (stream == nullptr)
|
//if (stream == nullptr)
|
||||||
//{
|
//{
|
||||||
|
|
@ -40,11 +124,46 @@ InputStream *FolderTexturePack::getResourceImplementation(const wstring &name) /
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BufferedImage* FolderTexturePack::getImageResource(const wstring& file, bool filenameHasExtension, bool bTitleUpdateTexture, const wstring& drive) {
|
||||||
|
app.DebugPrintf("FolderPack: image - %ls\n", file.c_str());
|
||||||
|
|
||||||
|
if (file == L"terrain.png" && terrainAtlas.get() != nullptr)
|
||||||
|
return terrainAtlas.release();
|
||||||
|
|
||||||
|
if (file == L"items.png" && itemAtlas.get() != nullptr)
|
||||||
|
return itemAtlas.release();
|
||||||
|
|
||||||
|
std::wstring f = file;
|
||||||
|
auto it = AbstractTexturePack::INDEXED_TO_JAVA_MAP.find(L"res/" + file);
|
||||||
|
if (it != INDEXED_TO_JAVA_MAP.end()) {
|
||||||
|
f = L"assets/minecraft/textures/" + it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = replaceAll(f, L"/", L"\\");
|
||||||
|
if (hasFile(f)) {
|
||||||
|
f = _cachedFiles[f];
|
||||||
|
|
||||||
|
File img(this->file->getPath() + L"\\" + f);
|
||||||
|
FileInputStream is(img);
|
||||||
|
|
||||||
|
byteArray arr(img.length());
|
||||||
|
is.read(arr, 0, img.length());
|
||||||
|
return new BufferedImage(arr.data, arr.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.DebugPrintf("FolderPack: failed to find %ls fetching from default\n", f.c_str());
|
||||||
|
|
||||||
|
TexturePackRepository* repo = Minecraft::GetInstance()->skins;
|
||||||
|
return repo->getDefault()->getImageResource(file, filenameHasExtension, bTitleUpdateTexture);
|
||||||
|
}
|
||||||
|
|
||||||
bool FolderTexturePack::hasFile(const wstring &name)
|
bool FolderTexturePack::hasFile(const wstring &name)
|
||||||
{
|
{
|
||||||
File file = File( getPath() + name);
|
std::wstring f = name;
|
||||||
return file.exists() && file.isFile();
|
if (f.find(L"/") != f.npos)
|
||||||
//return true;
|
for (int i = 0; i < f.length(); i++)
|
||||||
|
f[i] == L'/' ? f[i] = L'\\' : 0; // putting zero there just works ig
|
||||||
|
return _cachedFiles.find(f) != _cachedFiles.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FolderTexturePack::isTerrainUpdateCompatible()
|
bool FolderTexturePack::isTerrainUpdateCompatible()
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,29 @@ class FolderTexturePack : public AbstractTexturePack
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool bUILoaded;
|
bool bUILoaded;
|
||||||
|
unordered_map<wstring, wstring> _cachedFiles;
|
||||||
|
vector<byte> _iconData;
|
||||||
|
void cacheFiles(File& dir, int folderLen);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FolderTexturePack(DWORD id, const wstring &name, File *folder, TexturePack *fallback);
|
FolderTexturePack(DWORD id, const wstring &name, File *folder, TexturePack *fallback);
|
||||||
|
DLCPack* getDLCPack();
|
||||||
|
void loadIcon();
|
||||||
|
void loadDescription();
|
||||||
|
bool hasData();
|
||||||
|
bool isLoadingData();
|
||||||
|
wstring getAnimationString(const wstring& textureName, const wstring& path, bool allowFallback);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//@Override
|
//@Override
|
||||||
InputStream *getResourceImplementation(const wstring &name); //throws IOException
|
InputStream *getResourceImplementation(const wstring &name); //throws IOException
|
||||||
|
void loadName();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//@Override
|
//@Override
|
||||||
bool hasFile(const wstring &name);
|
bool hasFile(const wstring &name);
|
||||||
bool isTerrainUpdateCompatible();
|
bool isTerrainUpdateCompatible();
|
||||||
|
BufferedImage* getImageResource(const wstring& File, bool filenameHasExtension = false, bool bTitleUpdateTexture = false, const wstring& drive = L"");
|
||||||
|
|
||||||
// 4J Added
|
// 4J Added
|
||||||
virtual wstring getPath(bool bTitleUpdateTexture = false, const char *pchBDPatchFilename=nullptr);
|
virtual wstring getPath(bool bTitleUpdateTexture = false, const char *pchBDPatchFilename=nullptr);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue