assets loading removed from UiXmlReader. Use preload.json instead

This commit is contained in:
MihailRis 2024-03-18 19:06:50 +03:00
parent 9310454271
commit bca4de179d
5 changed files with 6 additions and 22 deletions

View File

@ -151,7 +151,7 @@ bool assetload::layout(
) {
try {
auto cfg = dynamic_cast<LayoutCfg*>(config.get());
auto document = UiDocument::read(loader, cfg->env, name, file);
auto document = UiDocument::read(cfg->env, name, file);
assets->store(document.release(), name);
return true;
} catch (const parsing_error& err) {

View File

@ -59,12 +59,12 @@ void UiDocument::collect(uinodes_map& map, std::shared_ptr<gui::UINode> node) {
}
}
std::unique_ptr<UiDocument> UiDocument::read(AssetsLoader& loader, int penv, std::string namesp, fs::path file) {
std::unique_ptr<UiDocument> UiDocument::read(int penv, std::string namesp, fs::path file) {
const std::string text = files::read_string(file);
auto xmldoc = xml::parse(file.u8string(), text);
auto env = scripting::create_doc_environment(penv, namesp);
gui::UiXmlReader reader(*env, loader);
gui::UiXmlReader reader(*env);
InventoryView::createReaders(reader);
auto view = reader.readXML(
file.u8string(), xmldoc->getRoot()

View File

@ -24,8 +24,6 @@ struct uidocscript {
using uinodes_map = std::unordered_map<std::string, std::shared_ptr<gui::UINode>>;
class AssetsLoader;
class UiDocument {
std::string id;
uidocscript script;
@ -49,7 +47,7 @@ public:
/* Collect map of all uinodes having identifiers */
static void collect(uinodes_map& map, std::shared_ptr<gui::UINode> node);
static std::unique_ptr<UiDocument> read(AssetsLoader& loader, int env, std::string namesp, fs::path file);
static std::unique_ptr<UiDocument> read(int env, std::string namesp, fs::path file);
};
#endif // FRONTEND_UI_DOCUMENT_H_

View File

@ -6,7 +6,6 @@
#include "containers.h"
#include "controls.h"
#include "../../assets/AssetsLoader.h"
#include "../locale/langs.h"
#include "../../logic/scripting/scripting.h"
#include "../../util/stringutil.h"
@ -289,7 +288,6 @@ static std::shared_ptr<UINode> readImage(UiXmlReader& reader, xml::xmlelement el
std::string src = element->attr("src", "").getText();
auto image = std::make_shared<Image>(src);
_readUINode(reader, element, *image);
reader.getAssetsLoader().add(AssetType::texture, "textures/"+src, src, nullptr);
return image;
}
@ -323,9 +321,7 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
return bar;
}
UiXmlReader::UiXmlReader(const scripting::Environment& env, AssetsLoader& assetsLoader)
: env(env), assetsLoader(assetsLoader)
{
UiXmlReader::UiXmlReader(const scripting::Environment& env) : env(env) {
add("image", readImage);
add("label", readLabel);
add("panel", readPanel);
@ -386,7 +382,3 @@ const std::string& UiXmlReader::getFilename() const {
const scripting::Environment& UiXmlReader::getEnvironment() const {
return env;
}
AssetsLoader& UiXmlReader::getAssetsLoader() {
return assetsLoader;
}

View File

@ -12,8 +12,6 @@ namespace scripting {
class Environment;
}
class AssetsLoader;
namespace gui {
class UiXmlReader;
@ -24,10 +22,8 @@ namespace gui {
std::unordered_set<std::string> ignored;
std::string filename;
const scripting::Environment& env;
AssetsLoader& assetsLoader;
public:
UiXmlReader(const scripting::Environment& env, AssetsLoader& assetsLoader);
UiXmlReader(const scripting::Environment& env);
void add(const std::string& tag, uinode_reader reader);
bool hasReader(const std::string& tag) const;
@ -59,8 +55,6 @@ namespace gui {
const scripting::Environment& getEnvironment() const;
const std::string& getFilename() const;
AssetsLoader& getAssetsLoader();
};
}