From 6352e8e3196f78388b6c771073f9e03eaa612673 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:33:09 +1000 Subject: everything everywhere all at once --- source/frontend/StarInterfaceCursor.cpp | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 source/frontend/StarInterfaceCursor.cpp (limited to 'source/frontend/StarInterfaceCursor.cpp') diff --git a/source/frontend/StarInterfaceCursor.cpp b/source/frontend/StarInterfaceCursor.cpp new file mode 100644 index 0000000..8844da2 --- /dev/null +++ b/source/frontend/StarInterfaceCursor.cpp @@ -0,0 +1,62 @@ +#include "StarInterfaceCursor.hpp" +#include "StarJsonExtra.hpp" +#include "StarRoot.hpp" +#include "StarAssets.hpp" +#include "StarImageMetadataDatabase.hpp" + +namespace Star { + +InterfaceCursor::InterfaceCursor() { + resetCursor(); +} + +void InterfaceCursor::resetCursor() { + auto& root = Root::singleton(); + auto assets = root.assets(); + setCursor(assets->json("/interface.config:defaultCursor").toString()); +} + +void InterfaceCursor::setCursor(String const& configFile) { + if (m_configFile == configFile) + return; + + m_configFile = configFile; + + auto& root = Root::singleton(); + auto assets = root.assets(); + auto imageMetadata = root.imageMetadataDatabase(); + + auto config = assets->json(m_configFile); + + m_offset = jsonToVec2I(config.get("offset")); + if (config.contains("image")) { + m_drawable = config.getString("image"); + m_size = Vec2I{imageMetadata->imageSize(config.getString("image"))}; + } else { + m_drawable = Animation(config.get("animation"), "/interface"); + m_size = Vec2I(m_drawable.get().drawable(1.0f).boundBox(false).size()); + } +} + +Drawable InterfaceCursor::drawable() const { + if (m_drawable.is()) + return Drawable::makeImage(m_drawable.get(), 1.0f, false, {}); + else + return m_drawable.get().drawable(1.0f); +} + +Vec2I InterfaceCursor::size() const { + return m_size; +} + +Vec2I InterfaceCursor::offset() const { + return m_offset; +} + +void InterfaceCursor::update(float dt) { + if (m_drawable.is()) { + m_drawable.get().update(dt); + } +} + +} -- cgit v1.2.3