osb/source/frontend/StarScriptPane.cpp
Kai Blaschke 431a9c00a5
Fixed a huge amount of Clang warnings
On Linux and macOS, using Clang to compile OpenStarbound produces about 400 MB worth of warnings during the build, making the compiler output unreadable and slowing the build down considerably.

99% of the warnings were unqualified uses of std::move and std::forward, which are now all properly qualified.

Fixed a few other minor warnings about non-virtual destructors and some uses of std::move preventing copy elision on temporary objects.

Most remaining warnings are now unused parameters.
2024-02-19 16:55:19 +01:00

96 lines
3.0 KiB
C++

#include "StarScriptPane.hpp"
#include "StarRoot.hpp"
#include "StarAssets.hpp"
#include "StarGuiReader.hpp"
#include "StarJsonExtra.hpp"
#include "StarConfigLuaBindings.hpp"
#include "StarPlayerLuaBindings.hpp"
#include "StarStatusControllerLuaBindings.hpp"
#include "StarCelestialLuaBindings.hpp"
#include "StarLuaGameConverters.hpp"
#include "StarWorldClient.hpp"
#include "StarPlayer.hpp"
#include "StarUniverseClient.hpp"
#include "StarWidgetLuaBindings.hpp"
#include "StarInterfaceLuaBindings.hpp"
#include "StarCanvasWidget.hpp"
#include "StarItemTooltip.hpp"
#include "StarItemGridWidget.hpp"
#include "StarSimpleTooltip.hpp"
#include "StarImageWidget.hpp"
namespace Star {
ScriptPane::ScriptPane(UniverseClientPtr client, Json config, EntityId sourceEntityId) : BaseScriptPane(config) {
auto& root = Root::singleton();
auto assets = root.assets();
m_client = std::move(client);
m_sourceEntityId = sourceEntityId;
m_script.addCallbacks("player", LuaBindings::makePlayerCallbacks(m_client->mainPlayer().get()));
m_script.addCallbacks("status", LuaBindings::makeStatusControllerCallbacks(m_client->mainPlayer()->statusController()));
m_script.addCallbacks("celestial", LuaBindings::makeCelestialCallbacks(m_client.get()));
}
void ScriptPane::displayed() {
auto world = m_client->worldClient();
if (world && world->inWorld()) {
m_script.setLuaRoot(world->luaRoot());
m_script.addCallbacks("world", LuaBindings::makeWorldCallbacks(world.get()));
}
BaseScriptPane::displayed();
}
void ScriptPane::dismissed() {
BaseScriptPane::dismissed();
m_script.removeCallbacks("world");
}
void ScriptPane::tick(float dt) {
if (m_sourceEntityId != NullEntityId && !m_client->worldClient()->playerCanReachEntity(m_sourceEntityId))
dismiss();
BaseScriptPane::tick(dt);
}
PanePtr ScriptPane::createTooltip(Vec2I const& screenPosition) {
auto result = m_script.invoke<Json>("createTooltip", screenPosition);
if (result && !result.value().isNull()) {
if (result->type() == Json::Type::String) {
return SimpleTooltipBuilder::buildTooltip(result->toString());
} else {
PanePtr tooltip = make_shared<Pane>();
m_reader->construct(*result, tooltip.get());
return tooltip;
}
} else {
ItemPtr item;
if (auto child = getChildAt(screenPosition)) {
if (auto itemSlot = as<ItemSlotWidget>(child))
item = itemSlot->item();
if (auto itemGrid = as<ItemGridWidget>(child))
item = itemGrid->itemAt(screenPosition);
}
if (item)
return ItemTooltipBuilder::buildItemTooltip(item, m_client->mainPlayer());
return {};
}
}
LuaCallbacks ScriptPane::makePaneCallbacks() {
LuaCallbacks callbacks = BaseScriptPane::makePaneCallbacks();
callbacks.registerCallback("sourceEntity", [this]() { return m_sourceEntityId; });
return callbacks;
}
bool ScriptPane::openWithInventory() const {
return m_config.getBool("openWithInventory", false);
}
EntityId ScriptPane::sourceEntityId() const {
return m_sourceEntityId;
}
}