mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 06:51:51 +00:00
assets loading removed from UiXmlReader. Use preload.json instead
This commit is contained in:
parent
9310454271
commit
bca4de179d
5 changed files with 6 additions and 22 deletions
|
|
@ -151,7 +151,7 @@ bool assetload::layout(
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
auto cfg = dynamic_cast<LayoutCfg*>(config.get());
|
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);
|
assets->store(document.release(), name);
|
||||||
return true;
|
return true;
|
||||||
} catch (const parsing_error& err) {
|
} catch (const parsing_error& err) {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
const std::string text = files::read_string(file);
|
||||||
auto xmldoc = xml::parse(file.u8string(), text);
|
auto xmldoc = xml::parse(file.u8string(), text);
|
||||||
|
|
||||||
auto env = scripting::create_doc_environment(penv, namesp);
|
auto env = scripting::create_doc_environment(penv, namesp);
|
||||||
gui::UiXmlReader reader(*env, loader);
|
gui::UiXmlReader reader(*env);
|
||||||
InventoryView::createReaders(reader);
|
InventoryView::createReaders(reader);
|
||||||
auto view = reader.readXML(
|
auto view = reader.readXML(
|
||||||
file.u8string(), xmldoc->getRoot()
|
file.u8string(), xmldoc->getRoot()
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ struct uidocscript {
|
||||||
|
|
||||||
using uinodes_map = std::unordered_map<std::string, std::shared_ptr<gui::UINode>>;
|
using uinodes_map = std::unordered_map<std::string, std::shared_ptr<gui::UINode>>;
|
||||||
|
|
||||||
class AssetsLoader;
|
|
||||||
|
|
||||||
class UiDocument {
|
class UiDocument {
|
||||||
std::string id;
|
std::string id;
|
||||||
uidocscript script;
|
uidocscript script;
|
||||||
|
|
@ -49,7 +47,7 @@ public:
|
||||||
/* Collect map of all uinodes having identifiers */
|
/* Collect map of all uinodes having identifiers */
|
||||||
static void collect(uinodes_map& map, std::shared_ptr<gui::UINode> node);
|
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_
|
#endif // FRONTEND_UI_DOCUMENT_H_
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
#include "containers.h"
|
#include "containers.h"
|
||||||
#include "controls.h"
|
#include "controls.h"
|
||||||
|
|
||||||
#include "../../assets/AssetsLoader.h"
|
|
||||||
#include "../locale/langs.h"
|
#include "../locale/langs.h"
|
||||||
#include "../../logic/scripting/scripting.h"
|
#include "../../logic/scripting/scripting.h"
|
||||||
#include "../../util/stringutil.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();
|
std::string src = element->attr("src", "").getText();
|
||||||
auto image = std::make_shared<Image>(src);
|
auto image = std::make_shared<Image>(src);
|
||||||
_readUINode(reader, element, *image);
|
_readUINode(reader, element, *image);
|
||||||
reader.getAssetsLoader().add(AssetType::texture, "textures/"+src, src, nullptr);
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,9 +321,7 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
UiXmlReader::UiXmlReader(const scripting::Environment& env, AssetsLoader& assetsLoader)
|
UiXmlReader::UiXmlReader(const scripting::Environment& env) : env(env) {
|
||||||
: env(env), assetsLoader(assetsLoader)
|
|
||||||
{
|
|
||||||
add("image", readImage);
|
add("image", readImage);
|
||||||
add("label", readLabel);
|
add("label", readLabel);
|
||||||
add("panel", readPanel);
|
add("panel", readPanel);
|
||||||
|
|
@ -386,7 +382,3 @@ const std::string& UiXmlReader::getFilename() const {
|
||||||
const scripting::Environment& UiXmlReader::getEnvironment() const {
|
const scripting::Environment& UiXmlReader::getEnvironment() const {
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetsLoader& UiXmlReader::getAssetsLoader() {
|
|
||||||
return assetsLoader;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ namespace scripting {
|
||||||
class Environment;
|
class Environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AssetsLoader;
|
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class UiXmlReader;
|
class UiXmlReader;
|
||||||
|
|
||||||
|
|
@ -24,10 +22,8 @@ namespace gui {
|
||||||
std::unordered_set<std::string> ignored;
|
std::unordered_set<std::string> ignored;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
const scripting::Environment& env;
|
const scripting::Environment& env;
|
||||||
AssetsLoader& assetsLoader;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UiXmlReader(const scripting::Environment& env, AssetsLoader& assetsLoader);
|
UiXmlReader(const scripting::Environment& env);
|
||||||
|
|
||||||
void add(const std::string& tag, uinode_reader reader);
|
void add(const std::string& tag, uinode_reader reader);
|
||||||
bool hasReader(const std::string& tag) const;
|
bool hasReader(const std::string& tag) const;
|
||||||
|
|
@ -59,8 +55,6 @@ namespace gui {
|
||||||
|
|
||||||
const scripting::Environment& getEnvironment() const;
|
const scripting::Environment& getEnvironment() const;
|
||||||
const std::string& getFilename() const;
|
const std::string& getFilename() const;
|
||||||
|
|
||||||
AssetsLoader& getAssetsLoader();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue