commit 295792e31ded0b95c6decf52c3e052ec0e67fb43
parent 610d816057afe0a221f3b358114487c4c5739717
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sun, 20 Mar 2022 17:12:05 +0100
move load of json file to base class
Diffstat:
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/source/jucePlugin/ui3/VirusEditor.cpp b/source/jucePlugin/ui3/VirusEditor.cpp
@@ -15,9 +15,7 @@ namespace genericVirusUI
m_parameterBinding(_binding),
m_openMenuCallback(std::move(_openMenuCallback))
{
- uint32_t jsonSize;
- const auto json = getResourceByFilename(_jsonFilename, jsonSize);
- create(std::string(json, jsonSize));
+ create(_jsonFilename);
m_parts.reset(new Parts(*this));
m_tabs.reset(new Tabs(*this));
diff --git a/source/juceUiLib/editor.cpp b/source/juceUiLib/editor.cpp
@@ -8,15 +8,19 @@ namespace genericUI
{
}
- void Editor::create(const std::string& _json)
+ void Editor::create(const std::string& _jsonFilename)
{
- juce::var json;
+ uint32_t jsonSize;
+ const auto jsonData = m_interface.getResourceByFilename(_jsonFilename, jsonSize);
- const auto error = juce::JSON::parse(juce::String(_json), json);
+ juce::var json;
+ const auto error = juce::JSON::parse(juce::String(std::string(jsonData, jsonSize)), json);
if (error.failed())
throw std::runtime_error("Failed to load json");
+ m_jsonFilename = _jsonFilename;
+
m_rootObject.reset(new UiObject(json));
std::set<std::string> textures;
diff --git a/source/juceUiLib/editor.h b/source/juceUiLib/editor.h
@@ -17,7 +17,7 @@ namespace genericUI
Editor(const Editor&) = delete;
Editor(Editor&&) = delete;
- void create(const std::string& _json);
+ void create(const std::string& _jsonFilename);
juce::Drawable* getImageDrawable(const std::string& _texture);
std::unique_ptr<juce::Drawable> createImageDrawable(const std::string& _texture);
@@ -55,6 +55,8 @@ namespace genericUI
private:
EditorInterface& m_interface;
+ std::string m_jsonFilename;
+
std::map<std::string, std::unique_ptr<juce::Drawable>> m_drawables;
std::map<std::string, juce::Font> m_fonts;