mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-09 17:52:08 -10:00
Many of the recent scripting API enhancements are missing validity functions and validity checks, so this adds them. There are also some documentation fixes and a >= vs. > bugfix.
71 lines
1.5 KiB
C++
71 lines
1.5 KiB
C++
#include "rank.h"
|
|
|
|
#include "stats/scoring.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
rank_h::rank_h() : rank(-1) {}
|
|
rank_h::rank_h(int l_rank) : rank(l_rank) {}
|
|
|
|
rank_stuff* rank_h::getRank() const
|
|
{
|
|
if (!isValid())
|
|
return nullptr;
|
|
|
|
return &Ranks[rank];
|
|
}
|
|
|
|
bool rank_h::isValid() const
|
|
{
|
|
return rank >= 0 && rank < (int)Ranks.size();
|
|
}
|
|
|
|
//**********HANDLE: rank
|
|
ADE_OBJ(l_Rank, rank_h, "rank", "Rank handle");
|
|
|
|
ADE_FUNC(isValid, l_Rank, nullptr, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
|
|
{
|
|
rank_h current;
|
|
if (!ade_get_args(L, "o", l_Rank.Get(¤t)))
|
|
return ADE_RETURN_NIL;
|
|
|
|
return ade_set_args(L, "b", current.isValid());
|
|
}
|
|
|
|
ADE_VIRTVAR(Name, l_Rank, nullptr, "The name of the rank", "string", "The name")
|
|
{
|
|
rank_h current;
|
|
if (!ade_get_args(L, "o", l_Rank.Get(¤t))) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
if (!current.isValid()) {
|
|
return ade_set_error(L, "s", "");
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "This property is read only.");
|
|
}
|
|
|
|
return ade_set_args(L, "s", current.getRank()->name);
|
|
}
|
|
|
|
ADE_VIRTVAR(Bitmap, l_Rank, nullptr, "The bitmap of the rank", "string", "The bitmap")
|
|
{
|
|
rank_h current;
|
|
if (!ade_get_args(L, "o", l_Rank.Get(¤t))) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
if (!current.isValid()) {
|
|
return ade_set_error(L, "s", "");
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "This property is read only.");
|
|
}
|
|
|
|
return ade_set_args(L, "s", current.getRank()->bitmap);
|
|
}
|
|
|
|
} // namespace api
|
|
} // namespace scripting
|