Move stuff in GameScriptDisplayString around to remove a sol.hpp include from a header file.

This commit is contained in:
hispidence 2021-12-04 21:16:40 +00:00
parent f6aa2ac653
commit 8a519ef819
2 changed files with 21 additions and 24 deletions

View file

@ -1,7 +1,4 @@
#pragma once
#include "framework.h"
#include <variant>
#include <sol.hpp>
#include "GameScriptColor.h"
enum class DisplayStringOptions : size_t
@ -48,22 +45,6 @@ using SetItemCallback = std::function<bool(DisplayStringIDType, UserDisplayStrin
using RemoveItemCallback = std::function<bool(DisplayStringIDType)>;
using GetItemCallback = std::function<std::optional<std::reference_wrapper<UserDisplayString>>(DisplayStringIDType)>;
// Helper type to allow us to more easily specify "give a value of type X or just give nil" parameters.
// Sol doesn't (at the time of writing) have any mechanisms to do this kind of optional argument without
// drawbacks, or at least no mechanisms that I could find.
//
// sol::optional doesn't distinguish between nil values and values of the wrong type
// (so we can't provide the user with an error message to tell them they messed up).
//
// std::variant works better, providing an error if the user passes in an arg of the wrong type, but
// the error isn't too helpful and exposes a lot of C++ code which will not help them fix the error.
//
// sol::object lets us check that the user has given the right type, but takes valuable type information
// away from the function's C++ signature, giving us things like void func(sol::object, sol::object, sol::object),
// even if the function's actual expected parameter types are (for example) float, sol::table, SomeUserType.
//
// This alias is an effort to avoid the above problems.
template <typename ... Ts> using TypeOrNil = std::variant<Ts..., sol::nil_t, sol::object>;
class GameScriptDisplayString
{
@ -98,5 +79,4 @@ public:
s_getItemCallback = cbg;
}
static std::unique_ptr<GameScriptDisplayString> Create(std::string const& key, int x, int y, GameScriptColor col, TypeOrNil<sol::table>, TypeOrNil<bool>);
};