[WIP] Fixed loaded of multiple addons at the same time

This commit is contained in:
KiritoDv 2021-05-07 21:55:52 +00:00
parent d86c5246cd
commit 1aff0121d5
6 changed files with 100 additions and 7 deletions

View File

@ -1,6 +1,6 @@
#include "engine.h"
#include "moon/mod-engine/interfaces/mod-module.h"
#include "moon/mod-engine/modules/test-module.h"
#include "moon/mod-engine/interfaces/bit-module.h"
#include "interfaces/file-entry.h"
#include "moon/wrapper.h"
@ -14,7 +14,6 @@ using json = nlohmann::json;
#include <limits.h>
#include <stdlib.h>
#include <dirent.h>
#include <vector>
#include <map>
using namespace std;
@ -45,7 +44,6 @@ void Moon_LoadDefaultAddon(){
Moon_LoadAddonTextures(bit);
}
void Moon_LoadAddon(string path){
miniz_cpp::zip_file file(path);
@ -68,6 +66,15 @@ void Moon_LoadAddon(string path){
std::cout << file.read(bit->main) << std::endl;
}
if(file.has_file(bit->icon)){
vector<string> allowedTextures = {"png", "jpg", "jpeg"};
if(std::count(allowedTextures.begin(), allowedTextures.end(), string(get_filename_ext(bit->icon.c_str())))){
TextureFileEntry *entry = new TextureFileEntry();
file.read_texture(bit->icon, &entry);
bit->textures.insert(pair<string, TextureFileEntry*>("mod-icons://"+bit->name, entry));
}
}
if(file.has_file("assets/")){
for(auto &name : file.namelist()){
string graphicsPath = "assets/graphics/";
@ -159,10 +166,42 @@ TextureData* Moon_GetTexture(string texture){
return textureMap.find(texture) != textureMap.end() ? textureMap.find(texture)->second : nullptr;
}
void Moon_TextFlyLoad(int id){
switch(id){
case 0:
Moon_LoadDefaultAddon();
break;
case 1:
Moon_LoadDefaultAddon();
Moon_LoadAddon("/home/alex/Downloads/packs/converted/mc.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit");
break;
case 2:
Moon_LoadDefaultAddon();
Moon_LoadAddon("/home/alex/Downloads/packs/converted/owo.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit");
break;
case 3:
Moon_LoadDefaultAddon();
Moon_LoadAddon("/home/alex/Downloads/packs/converted/r96-hd.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit");
break;
}
}
void Moon_PreInitModEngine(){
Moon_LoadDefaultAddon();
// Moon_LoadAddon("/home/alex/disks/uwu/Projects/UnderVolt/example.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/mc.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/owo.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/r96-hd.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit");
Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit");
}
void Moon_InitModEngine(){

View File

@ -1,15 +1,21 @@
#ifndef Moon64ModEngine
#define Moon64ModEngine
#include "moon/mod-engine/interfaces/bit-module.h"
#include <vector>
extern "C" {
#include "pc/gfx/gfx_pc.h"
}
void Moon_SaveTexture(TextureData* data, string tex);
TextureData* Moon_GetTexture(string texture);
extern std::vector<BitModule*> addons;
void Moon_SaveTexture(TextureData* data, std::string tex);
TextureData* Moon_GetTexture(std::string texture);
void Moon_PreInitModEngine();
void Moon_InitModEngine();
void Moon_LoadBaseTexture(char* data, long size, string texture);
void Moon_LoadBaseTexture(char* data, long size, std::string texture);
void Moon_TextFlyLoad(int id);
#endif

View File

@ -21,6 +21,7 @@ public:
std::map<std::string, TextureFileEntry*> textures;
// GFXTextureCache* textureCache;
bool readOnly;
bool enabled;
};
#endif

View File

@ -0,0 +1,32 @@
#include "mtextures.h"
#include "moon/network/moon-consumer.h"
#include "moon/texts/moon-loader.h"
#include "moon/ui/widgets/mw-value.h"
#include "moon/mod-engine/engine.h"
using namespace std;
extern "C" {
#include "pc/configfile.h"
}
MTexturesCategory::MTexturesCategory() : MoonCategory("TEXT_OPT_AUDIO"){
int idx = 0;
// for(auto &addon : addons){
// this->catOptions.push_back(new MWValue(22, 57 + (17 * idx), addon->name, {.bvar = &addon->enabled}, false));
// idx++;
// }
this->catOptions.push_back(new MWValue(22, 57, "Load main pack", {.btn = [](){
Moon_TextFlyLoad(0);
}}, false));
this->catOptions.push_back(new MWValue(22, 57 + (17 * 1), "Load minecraft pack", {.btn = [](){
Moon_TextFlyLoad(1);
}}, false));
this->catOptions.push_back(new MWValue(22, 57 + (17 * 2), "Load owo pack", {.btn = [](){
Moon_TextFlyLoad(2);
}}, false));
this->catOptions.push_back(new MWValue(22, 57 + (17 * 3), "Load Render96 pack", {.btn = [](){
Moon_TextFlyLoad(2);
}}, false));
}

View File

@ -0,0 +1,13 @@
#ifndef MoonTexturesCategory
#define MoonTexturesCategory
#include "mcategory.h"
#include <vector>
#include <string>
class MTexturesCategory : public MoonCategory {
public:
MTexturesCategory();
};
#endif

View File

@ -14,6 +14,7 @@
#ifdef BETTERCAMERA
#include "moon/ui/screens/options/categories/mcamera.h"
#endif
#include "moon/ui/screens/options/categories/mtextures.h"
#include "moon/io/moon-io.h"
#include "moon/io/modules/mouse-io.h"
@ -49,6 +50,7 @@ void MoonOptMain::Mount(){
categories.push_back(new MVideoCategory());
categories.push_back(new MAudioCategory());
categories.push_back(new MCheatsCategory());
categories.push_back(new MTexturesCategory());
this->setCategory(categoryIndex);
MoonScreen::Mount();
}