Skip to content

Commit

Permalink
fix(ci): linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Sep 2, 2024
1 parent 15b315b commit c42fe7e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 74 deletions.
2 changes: 1 addition & 1 deletion include/bedrock/world/level/block/block_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BlockDescriptor {
enum class CompareType;

public:
ENDSTONE_HOOK [[nodiscard]] Block const *tryGetBlockNoLogging() const;
[[nodiscard]] ENDSTONE_HOOK Block const *tryGetBlockNoLogging() const;

private:
void *unknown1_; // +0
Expand Down
21 changes: 7 additions & 14 deletions include/endstone/block/block_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <fmt/format.h>

#include "endstone/endstone.h"

namespace endstone {

using BlockStates = std::unordered_map<std::string, std::variant<bool, std::string, int>>;
Expand Down Expand Up @@ -58,20 +60,11 @@ struct formatter<endstone::BlockStates::mapped_type> : formatter<string_view> {
template <typename FormatContext>
auto format(const Type &val, FormatContext &ctx) const -> format_context::iterator
{
return std::visit(
[&ctx](auto &&arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, std::string>) {
return format_to(ctx.out(), "{:?}", arg);
}
else if constexpr (std::is_same_v<T, bool> || std::is_same_v<T, int>) {
return format_to(ctx.out(), "{}", arg);
}
else {
static_assert(false, "non-exhaustive visitor!");
}
},
val);
return std::visit(endstone::overloaded{
[&ctx](const std::string &arg) { return format_to(ctx.out(), "{:?}", arg); },
[&ctx](auto &&arg) { return format_to(ctx.out(), "{}", arg); },
},
val);
}
};

Expand Down
33 changes: 17 additions & 16 deletions src/endstone_core/form/form_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <entt/entt.hpp>
#include <nlohmann/json.hpp>

#include "endstone/endstone.h"
#include "endstone/form/action_form.h"
#include "endstone/form/controls/dropdown.h"
#include "endstone/form/controls/label.h"
Expand All @@ -33,21 +34,21 @@ namespace endstone::detail {
template <>
nlohmann::json FormCodec::toJson(const Message &message)
{
return std::visit(entt::overloaded{[&](const std::string &arg) -> nlohmann::json {
nlohmann::json json;
json["rawtext"].push_back({
{"text", arg},
});
return json;
},
[&](const Translatable &arg) -> nlohmann::json {
nlohmann::json json;
json["rawtext"].push_back({
{"translate", arg.getTranslationKey()},
{"with", arg.getParameters()},
});
return json;
}},
return std::visit(overloaded{[&](const std::string &arg) -> nlohmann::json {
nlohmann::json json;
json["rawtext"].push_back({
{"text", arg},
});
return json;
},
[&](const Translatable &arg) -> nlohmann::json {
nlohmann::json json;
json["rawtext"].push_back({
{"translate", arg.getTranslationKey()},
{"with", arg.getParameters()},
});
return json;
}},
message);
}

Expand Down Expand Up @@ -181,7 +182,7 @@ nlohmann::json FormCodec::toJson(const ModalForm &form)
json["title"] = toJson(form.getTitle());
json["content"] = nlohmann::json::array();
for (const auto &control : form.getControls()) {
json["content"].push_back(std::visit(entt::overloaded{[](auto &&arg) {
json["content"].push_back(std::visit(overloaded{[](auto &&arg) {
return toJson(arg);
}},
control));
Expand Down
6 changes: 3 additions & 3 deletions src/endstone_core/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void EndstonePlayer::sendForm(FormVariant form)
auto packet = MinecraftPackets::createPacket(MinecraftPacketIds::ShowModalForm);
std::shared_ptr<ModalFormRequestPacket> pk = std::static_pointer_cast<ModalFormRequestPacket>(packet);
pk->form_id = ++form_ids_;
pk->form_json = std::visit(entt::overloaded{[](auto &&arg) {
pk->form_json = std::visit(overloaded{[](auto &&arg) {
return FormCodec::toJson(arg);
}},
form)
Expand Down Expand Up @@ -587,7 +587,7 @@ void EndstonePlayer::onFormClose(int form_id, PlayerFormCloseReason /*reason*/)

if (!isDead()) {
try {
std::visit(entt::overloaded{[this](auto &&arg) {
std::visit(overloaded{[this](auto &&arg) {
auto callback = arg.getOnClose();
if (callback) {
callback(this);
Expand All @@ -611,7 +611,7 @@ void EndstonePlayer::onFormResponse(int form_id, const nlohmann::json &json)

if (!isDead()) {
try {
std::visit(entt::overloaded{
std::visit(overloaded{
[&](const MessageForm &form) {
if (auto callback = form.getOnSubmit()) {
callback(this, json.get<bool>() ? 0 : 1);
Expand Down
43 changes: 21 additions & 22 deletions src/endstone_core/scoreboard/scoreboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,16 @@ std::string EndstoneScoreboard::getDisplaySlotName(DisplaySlot slot)

const ::ScoreboardId &EndstoneScoreboard::getScoreboardId(ScoreEntry entry) const
{
return std::visit(
entt::overloaded{[&](Player *player) -> const ::ScoreboardId & {
return board_.getScoreboardId(static_cast<EndstonePlayer *>(player)->getHandle());
},
[&](Actor *actor) -> const ::ScoreboardId & {
return board_.getScoreboardId(static_cast<EndstoneActor *>(actor)->getActor());
},
[&](const std::string &fake) -> const ::ScoreboardId & {
return board_.getScoreboardId(fake);
}},
entry);
return std::visit(overloaded{[&](Player *player) -> const ::ScoreboardId & {
return board_.getScoreboardId(static_cast<EndstonePlayer *>(player)->getHandle());
},
[&](Actor *actor) -> const ::ScoreboardId & {
return board_.getScoreboardId(static_cast<EndstoneActor *>(actor)->getActor());
},
[&](const std::string &fake) -> const ::ScoreboardId & {
return board_.getScoreboardId(fake);
}},
entry);
}

const ::ScoreboardId &EndstoneScoreboard::getOrCreateScoreboardId(ScoreEntry entry)
Expand All @@ -221,17 +220,17 @@ const ::ScoreboardId &EndstoneScoreboard::getOrCreateScoreboardId(ScoreEntry ent
return scoreboard_id;
}

return std::visit(
entt::overloaded{[&](Player *player) -> const ::ScoreboardId & {
return board_.createScoreboardId(static_cast<EndstonePlayer *>(player)->getHandle());
},
[&](Actor *actor) -> const ::ScoreboardId & {
return board_.createScoreboardId(static_cast<EndstoneActor *>(actor)->getActor());
},
[&](const std::string &fake) -> const ::ScoreboardId & {
return board_.createScoreboardId(fake);
}},
entry);
return std::visit(overloaded{[&](Player *player) -> const ::ScoreboardId & {
return board_.createScoreboardId(
static_cast<EndstonePlayer *>(player)->getHandle());
},
[&](Actor *actor) -> const ::ScoreboardId & {
return board_.createScoreboardId(static_cast<EndstoneActor *>(actor)->getActor());
},
[&](const std::string &fake) -> const ::ScoreboardId & {
return board_.createScoreboardId(fake);
}},
entry);
}

::Scoreboard &EndstoneScoreboard::getHandle() const
Expand Down
8 changes: 4 additions & 4 deletions src/endstone_core/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ std::shared_ptr<BlockData> EndstoneServer::createBlockData(std::string type) con
std::shared_ptr<BlockData> EndstoneServer::createBlockData(std::string type, BlockStates block_states) const
{
std::unordered_map<std::string, std::variant<int, std::string, bool>> states;
for (const auto &[key, value] : block_states) {
std::visit(entt::overloaded{[&](auto &&arg) {
states.emplace(key, arg);
for (const auto &state : block_states) {
std::visit(overloaded{[&](auto &&arg) {
states.emplace(state.first, arg);
}},
value);
state.second);
}

const auto block_descriptor = ScriptModuleMinecraft::ScriptBlockUtils::createBlockDescriptor(type, states);
Expand Down
26 changes: 13 additions & 13 deletions src/endstone_devtools/devtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "endstone/detail/devtools/vanilla_data.h"
#include "endstone/detail/logger_factory.h"
#include "endstone/detail/os.h"
#include "endstone/endstone.h"

namespace fs = std::filesystem;

Expand Down Expand Up @@ -260,19 +261,18 @@ void render()
gFileBrowser->Display();
if (gFileBrowser->HasSelected()) {
auto path = gFileBrowser->GetSelected();
std::visit(
entt::overloaded{[&](std::monostate) { gLogger.error("Unable to save to {}: Empty.", path.string()); },
[&](const nlohmann::json &arg) {
std::ofstream file(path);
file << arg;
},
[&](const CompoundTag &arg) {
BigEndianStringByteOutput output;
NbtIo::writeNamedTag("", arg, output);
zstr::ofstream file(path.string(), std::ios::out | std::ios::binary);
file << output.buffer;
}},
file_to_save);
std::visit(overloaded{[&](std::monostate) { gLogger.error("Unable to save to {}: Empty.", path.string()); },
[&](const nlohmann::json &arg) {
std::ofstream file(path);
file << arg;
},
[&](const CompoundTag &arg) {
BigEndianStringByteOutput output;
NbtIo::writeNamedTag("", arg, output);
zstr::ofstream file(path.string(), std::ios::out | std::ios::binary);
file << output.buffer;
}},
file_to_save);
file_to_save = std::monostate();
gFileBrowser->ClearSelected();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void PlayerEventCoordinator::sendEvent(const EventRef<PlayerGameplayEvent<void>>
{
void (PlayerEventCoordinator::*fp)(const EventRef<PlayerGameplayEvent<void>> &) =
&PlayerEventCoordinator::sendEvent;
auto visitor = entt::overloaded{
auto visitor = endstone::overloaded{
[](const Details::ValueOrRef<PlayerFormCloseEvent const> &value) {
const auto event = value.asValue();
const auto &weak_ref = event.player;
Expand Down

0 comments on commit c42fe7e

Please sign in to comment.